-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove JS Zed Query Parser #2972
Changes from all commits
efe9106
7e82877
934f640
39b030f
6c80015
d530273
95b763f
cd19ab6
bc9346c
68b03c9
e76911b
9829a33
44cb836
596cece
bd85774
a56bdc3
c9b364c
84ea49e
5a553cb
3be329a
86b8e52
c1bb708
86bf01f
94b5519
976c0e2
14fc6e3
76ce4d6
4da3d6e
9884132
6efaf2a
0e85afb
b953b1f
f4964b6
d331ab6
8f0bd19
1fa0b66
b028542
8304d83
4001f37
e9683df
65d6956
414c094
25bd72e
f5dddf7
318b5e7
0b294b3
58d7751
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
16.10.0 | ||
18.18.2 |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,4 @@ | |
"type": "commonjs", | ||
"ignoreDynamic": true | ||
} | ||
|
||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,8 @@ | ||
import {parse as parseAst} from "zed/compiler/parser/parser" | ||
import {fieldExprToName} from "src/js/models/ast" | ||
import {toFieldPath} from "src/js/zed-script/toZedScript" | ||
import {fieldExprToName} from "./zed-expr" | ||
|
||
export class ZedAst { | ||
public tree: any | ||
public error: Error | null | ||
|
||
constructor(public script: string) { | ||
try { | ||
this.tree = parseAst(script) | ||
} catch (e) { | ||
this.tree = null | ||
this.error = e | ||
} | ||
} | ||
constructor(public tree: any, public error: Error | null) {} | ||
|
||
get poolName() { | ||
const from = this.from | ||
|
@@ -34,6 +23,12 @@ export class ZedAst { | |
return trunks.filter((t) => t.source.kind === "Pool").map((t) => t.source) | ||
} | ||
|
||
get groupByKeys() { | ||
const g = this.ops.find((op) => op.kind === "Summarize") | ||
const keys = g ? g.keys : [] | ||
return keys.map((k) => fieldExprToName(k.lhs || k.rhs)) | ||
} | ||
|
||
Comment on lines
+26
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to capture something I think was discussed on Zoom, at some point in the future we'd hope that we could rely on the Zed backend to start providing this kind of summary hinting rather than the app having to pick apart the AST to make its own conclusions. @jameskerr is that accurate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that is correct. |
||
private _ops: any[] | ||
get ops() { | ||
if (this._ops) return this._ops | ||
|
@@ -77,3 +72,11 @@ export class ZedAst { | |
|
||
export const OP_EXPR_PROC = "OpExpr" | ||
export const PARALLEL_PROC = "Parallel" | ||
// are all these needed? | ||
export const HEAD_PROC = "Head" | ||
export const TAIL_PROC = "Tail" | ||
export const SORT_PROC = "Sort" | ||
export const FILTER_PROC = "Filter" | ||
export const PRIMITIVE_PROC = "Primitive" | ||
export const REGEXP_SEARCH_PROC = "RegexpSearch" | ||
export const ANALYTIC_PROCS = ["Summarize"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {toFieldPath} from "src/js/zed-script/toZedScript" | ||
|
||
export function fieldExprToName(expr) { | ||
let s = _fieldExprToName(expr) | ||
// const r = toFieldPath(s) | ||
return s | ||
} | ||
|
||
function _fieldExprToName(expr): string | string[] { | ||
switch (expr.kind) { | ||
case "BinaryExpr": | ||
if (expr.op == "." || expr.op == "[") { | ||
return [] | ||
.concat(_fieldExprToName(expr.lhs), _fieldExprToName(expr.rhs)) | ||
.filter((n) => n !== "this") | ||
} | ||
return "<not-a-field>" | ||
case "ID": | ||
return expr.name | ||
case "This": | ||
return "this" | ||
case "Primitive": | ||
return expr.text | ||
case "Call": | ||
var args = expr.args | ||
.map((e) => toFieldPath(_fieldExprToName(e))) | ||
.join(",") | ||
return `${expr.name}(${args})` | ||
default: | ||
return "<not-a-field>" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export function createWaitForSelector(store) { | ||
return function waitForSelector( | ||
select, | ||
options: {signal?: AbortSignal} = {} | ||
) { | ||
let resolve | ||
let targetValue | ||
|
||
const unsubscribe = store.subscribe(() => { | ||
const state = store.getState() | ||
if (select(state) === targetValue) { | ||
unsubscribe() | ||
resolve() | ||
} | ||
}) | ||
|
||
let promise = new Promise((res, reject) => { | ||
resolve = res | ||
options.signal?.addEventListener("abort", () => { | ||
unsubscribe() | ||
reject(new DOMException("AbortError")) | ||
}) | ||
}) | ||
|
||
return { | ||
toReturn(value) { | ||
targetValue = value | ||
return promise | ||
}, | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.