simple-graph-query 3.0.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LANGUAGE.md +317 -0
- package/README.md +17 -0
- package/dist/ForgeExprEvaluator.d.ts +16 -3
- package/dist/ForgeExprFreeVariableFinder.d.ts +1 -3
- package/dist/ForgeExprStaticAnalyzer.d.ts +4 -1
- package/dist/forge-antlr/ForgeLexer.d.ts +41 -52
- package/dist/forge-antlr/ForgeListener.d.ts +0 -22
- package/dist/forge-antlr/ForgeParser.d.ts +73 -119
- package/dist/forge-antlr/ForgeVisitor.d.ts +0 -14
- package/dist/forge-antlr/utils.d.ts +2 -1
- package/dist/simple-graph-query.bundle.js +1 -1
- package/docs/sgq-language.json +2541 -0
- package/package.json +6 -1
package/LANGUAGE.md
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
<!-- GENERATED FILE — DO NOT EDIT.
|
|
2
|
+
Built from src/forge-antlr/ForgeLexer.g4, src/forge-antlr/Forge.g4, and
|
|
3
|
+
the evaluator's builtin tables by scripts/generate-lang-ref.mjs.
|
|
4
|
+
Regenerate with: npm run docs:lang -->
|
|
5
|
+
|
|
6
|
+
# The Expression Language
|
|
7
|
+
|
|
8
|
+
This library evaluates a single **expression** (the `parseExpr` grammar entry
|
|
9
|
+
point) against a data instance. The language is the expression fragment of
|
|
10
|
+
[Forge](https://forge-fm.org) (itself a dialect of Alloy), with a few
|
|
11
|
+
extensions (string literals, label access) and deliberate omissions.
|
|
12
|
+
|
|
13
|
+
**Everything is a set of tuples.** A sig name denotes the set of its atoms, a
|
|
14
|
+
relation name the set of its tuples, and a scalar (one atom, one number, one
|
|
15
|
+
string) is a singleton set. Boolean formulas evaluate to `true`/`false`.
|
|
16
|
+
|
|
17
|
+
**There is no temporal fragment.** The temporal operators (`always`,
|
|
18
|
+
`eventually`, `after`, `before`, `once`, `historically`, `until`,
|
|
19
|
+
`release`, `since`, `triggered`) and primed expressions (`e'`) were
|
|
20
|
+
removed from the grammar; their syntax is a parse error, and the former
|
|
21
|
+
keywords are ordinary identifiers.
|
|
22
|
+
|
|
23
|
+
## Lexical structure
|
|
24
|
+
|
|
25
|
+
- **STRING_TOK** — A double-quoted string literal: `"dark blue"`. Escapes: `\"`, `\\`, `\n`, `\t`, `\r`, `\0`; any other escaped character stands for itself.
|
|
26
|
+
- **NUM_CONST_TOK** — An integer or decimal literal: `42`, `3.5`. Negate with a leading `-`.
|
|
27
|
+
- **QUOTED_IDENTIFIER_TOK** — A backquoted name: `` `n0 ``. Names an atom by id, and escapes reserved words.
|
|
28
|
+
- **IDENTIFIER_TOK** — A name: letters, digits, `_`, `$`, `/` (not starting with a digit).
|
|
29
|
+
|
|
30
|
+
Comments run from `//` or `--` to the end of the line, or between `/*`
|
|
31
|
+
and `*/`. A `#lang` line is ignored.
|
|
32
|
+
|
|
33
|
+
### Reserved words
|
|
34
|
+
|
|
35
|
+
`Int`, `abstract`, `all`, `and`, `as`, `assert`, `bind`, `but`, `check`, `checked`, `consistent`, `disj`, `else`, `eval`, `exactly`, `example`, `expect`, `extends`, `for`, `forge_error`, `fun`, `func`, `iden`, `iff`, `implies`, `in`, `inconsistent`, `inst`, `is`, `let`, `lone`, `necessary`, `ni`, `no`, `none`, `not`, `one`, `open`, `option`, `or`, `pfunc`, `pred`, `run`, `sat`, `set`, `sexpr`, `sig`, `some`, `sufficient`, `suite`, `sum`, `test`, `theorem`, `this`, `two`, `univ`, `unsat`, `var`, `wheat`, `with`, `xor`
|
|
36
|
+
|
|
37
|
+
A data-instance entity whose name collides with a reserved word is still
|
|
38
|
+
reachable by backquoting: `` `set` `` names the *atom* with id `set`.
|
|
39
|
+
|
|
40
|
+
### Names that must be backquoted
|
|
41
|
+
|
|
42
|
+
`/` matches the identifier pattern but lexes as the qualified-name separator. A name that is exactly `/` can only be written backquoted (`` `/` ``); a name that merely contains it, like `foo/bar`, is an ordinary identifier and needs no quoting.
|
|
43
|
+
|
|
44
|
+
### Machine-readable form
|
|
45
|
+
|
|
46
|
+
Code that *generates* expressions needs this page's content as data rather than
|
|
47
|
+
as prose. [`docs/sgq-language.json`](docs/sgq-language.json) carries it: the
|
|
48
|
+
bare-identifier character classes, both quoting forms with their escape tables,
|
|
49
|
+
every spelling a bare identifier cannot carry, and the whole cascade below —
|
|
50
|
+
each construct with its spellings, its precedence, and the level each of its
|
|
51
|
+
operands descends to. It is generated from this same grammar, ships in the npm
|
|
52
|
+
package, and is checked against the real lexer and parser by a test.
|
|
53
|
+
|
|
54
|
+
The parenthesisation rule is the one thing worth restating: a subexpression
|
|
55
|
+
needs parentheses exactly when its own `precedence` is below the level of the
|
|
56
|
+
slot it fills. Those levels are not always the neighbouring one — `+` takes
|
|
57
|
+
its right operand two levels in, so `a + #b` is a parse error.
|
|
58
|
+
|
|
59
|
+
## Operators and precedence
|
|
60
|
+
|
|
61
|
+
Constructs are listed loosest-binding first; higher numbers bind tighter.
|
|
62
|
+
"Evaluates ✗" marks syntax the grammar accepts but the evaluator rejects.
|
|
63
|
+
|
|
64
|
+
| # | Construct | Example | Operators | Yields | Evaluates | Meaning |
|
|
65
|
+
|---|-----------|---------|-----------|--------|:---------:|---------|
|
|
66
|
+
| 1 | let binding | `let x = e \| body` | — | — | ✗ | Bind names to expression values inside a body. Parses, but evaluation is not implemented and fails. |
|
|
67
|
+
| 1 | bind | `bind x = e \| body` | — | — | ✗ | Alloy `bind`. Parses, but evaluation is rejected. |
|
|
68
|
+
| 1 | quantified formula | `all x: S \| body` | — | boolean (`sum` number) | ✓ | Quantifiers `all`, `no`, `some`, `lone`, `one`, `two`, and the aggregator `sum x: S \| intExpr`. `disj` requires the bound variables to take pairwise-distinct values. The body must use the bar form (`\| expr`). |
|
|
69
|
+
| 2 | disjunction | `a or b` | `\|\|` / `or` | boolean | ✓ | Logical or (short-circuits). |
|
|
70
|
+
| 3 | exclusive or | `a xor b` | `xor` | boolean | ✓ | Logical exclusive or. |
|
|
71
|
+
| 4 | biconditional | `a iff b` | `<=>` / `iff` | boolean | ✓ | Logical if-and-only-if. |
|
|
72
|
+
| 5 | implication | `a implies b else c` | `implies` / `=>`, `else` | boolean | ✓ | Implication, with an optional else branch (`a => b else c` means `(a and b) or ((not a) and c)`). |
|
|
73
|
+
| 6 | conjunction | `a and b` | `&&` / `and` | boolean | ✓ | Logical and (short-circuits). |
|
|
74
|
+
| 7 | negation | `not a` | `!` / `not` | boolean | ✓ | Logical negation of a boolean formula. |
|
|
75
|
+
| 8 | comparison | `a in b` | `in`, `=`, `<`, `>`, `<=` / `=<`, `>=`, `ni`, `is` | boolean | ✓ | Subset (`in`), reverse containment (`ni`), set equality (`=`), and numeric comparisons. A scalar is a singleton set, so `in` doubles as membership. A leading `!`/`not` negates the comparison. `is` parses but its evaluation is rejected. |
|
|
76
|
+
| 9 | multiplicity test | `some e` | `no`, `some`, `lone`, `one`, `two`, `set` | boolean (`set` operand) | ✓ | Cardinality predicates over a set: `no` (empty), `some` (non-empty), `lone` (at most one), `one` (exactly one), `two` (exactly two). `set e` is the identity. |
|
|
77
|
+
| 10 | union / difference | `a + b` | `+`, `-` | relation | ✓ | Set union and set difference. (For integer arithmetic use the `add[...]`/`subtract[...]` builtins; `1 + 2` is the two-element set.) |
|
|
78
|
+
| 11 | cardinality | `#e` | `#` | number | ✓ | Number of tuples in the set. |
|
|
79
|
+
| 12 | override | `a ++ b` | `++` | relation | ✓ | Relational override: tuples of `b`, plus the tuples of `a` whose first atom is not a first atom of `b`. |
|
|
80
|
+
| 13 | intersection | `a & b` | `&` | relation | ✓ | Set intersection. |
|
|
81
|
+
| 14 | product | `a -> b` | `->` | relation | ✓ | Cartesian product. Multiplicity annotations (`a one -> lone b`) are declaration syntax and are rejected in expressions. |
|
|
82
|
+
| 15 | restriction | `S <: r` | `<:`, `:>` | relation | ✓ | Domain restriction (`S <: r`: tuples of `r` starting in `S`) and range restriction (`r :> S`: tuples ending in `S`). |
|
|
83
|
+
| 16 | box join / builtin call | `f[a, b]` | `[`, `]` | — | ✓ | `a[b]` is the box join `b.a`. When the callee names a builtin (see the builtin table) it is a function call instead: `add[1, 2]`. |
|
|
84
|
+
| 17 | join | `a.f` | `.` | relation | ✓ | Relational join: match the last column of the left operand against the first column of the right. |
|
|
85
|
+
| 17 | applied name (grammar corner) | `x.f[a]` | — | — | ✗ | A bracket application whose callee is parsed as a bare name inside a dot-chain. Redundant with box join; evaluation is not implemented. |
|
|
86
|
+
| 18 | unary prefixes | `^r` | `~`, `^`, `*`, `@:`, `@str:`, `@bool:`, `@num:` | relation (`@:` string, `@str:` string, `@bool:` boolean, `@num:` number) | ✓ | `~r` transpose, `^r` transitive closure, `*r` reflexive-transitive closure. `@:`/`@str:` label of an atom as a string, `@bool:`/`@num:` label converted to boolean/number (extensions; not Forge). |
|
|
87
|
+
| 19 | constant | `none` | — | — (`none` relation, `univ` relation, `iden` relation) | ✓ | `none` (empty set), `univ` (all atoms), `iden` (identity relation), integer literals (incl. negative), and `"..."` string literals. |
|
|
88
|
+
| 19 | name | `Person` | — | relation | ✓ | A type, relation, atom, or bound variable. An unresolved name evaluates to the empty set and raises an `unresolved-name` diagnostic. |
|
|
89
|
+
| 19 | @name | `@x` | — | — | ✗ | Alloy-specific; evaluation is rejected. |
|
|
90
|
+
| 19 | atom literal | <code>`n0</code> | — | relation | ✓ | The atom with exactly this id, bypassing type/relation/variable lookup. |
|
|
91
|
+
| 19 | this | `this` | — | — | ✗ | Alloy-specific; evaluation is rejected. |
|
|
92
|
+
| 19 | set comprehension | `{x: S \| body}` | — | relation | ✓ | The set of bindings satisfying the body. Multiple binders build a relation: `{x: A, y: B \| body}` is a set of pairs. |
|
|
93
|
+
| 19 | parentheses | `(e)` | — | operand | ✓ | Grouping. |
|
|
94
|
+
| 19 | block | `{ e1 e2 }` | — | boolean | ✓ | A conjunction of boolean expressions, separated by whitespace (there is no `;` in the language). |
|
|
95
|
+
| 19 | s-expression | `sexpr` | — | — | ✗ | Reserved for internal use; evaluation is rejected. |
|
|
96
|
+
|
|
97
|
+
## Builtin functions
|
|
98
|
+
|
|
99
|
+
Called with square brackets, e.g. `add[1, 2]`.
|
|
100
|
+
|
|
101
|
+
| Builtins | Arity | Notes |
|
|
102
|
+
|----------|-------|-------|
|
|
103
|
+
| `add`, `subtract`, `multiply`, `divide`, `remainder` | 2 | Integer/real arithmetic. `divide` is real division. |
|
|
104
|
+
| `abs`, `sign`, `floor`, `ceil` | 1 | |
|
|
105
|
+
| `min`, `max`, `sum` | set | Aggregate over a set; numeric strings resolve to numbers. `sum` also has a quantifier form `sum x: S \| intExpr`. |
|
|
106
|
+
|
|
107
|
+
Builtin names are **not** reserved words: a data instance that names an
|
|
108
|
+
entity `add` shadows the builtin (see issue #59).
|
|
109
|
+
|
|
110
|
+
## Grammar
|
|
111
|
+
|
|
112
|
+
The expression grammar, with token literals substituted in. Pattern tokens
|
|
113
|
+
(see [Lexical structure](#lexical-structure)) keep their names.
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
parseExpr
|
|
117
|
+
: expr EOF
|
|
118
|
+
;
|
|
119
|
+
|
|
120
|
+
expr
|
|
121
|
+
: expr1
|
|
122
|
+
| 'let' letDeclList blockOrBar
|
|
123
|
+
| 'bind' letDeclList blockOrBar
|
|
124
|
+
| quant 'disj'? quantDeclList blockOrBar
|
|
125
|
+
;
|
|
126
|
+
|
|
127
|
+
expr1
|
|
128
|
+
: expr1_5
|
|
129
|
+
| expr1 ('||' | 'or') expr1_5
|
|
130
|
+
;
|
|
131
|
+
|
|
132
|
+
letDeclList
|
|
133
|
+
: letDecl
|
|
134
|
+
| letDecl ',' letDeclList
|
|
135
|
+
;
|
|
136
|
+
|
|
137
|
+
blockOrBar
|
|
138
|
+
: block
|
|
139
|
+
| '|' expr
|
|
140
|
+
;
|
|
141
|
+
|
|
142
|
+
quant
|
|
143
|
+
: 'all'
|
|
144
|
+
| 'no'
|
|
145
|
+
| 'sum'
|
|
146
|
+
| mult
|
|
147
|
+
;
|
|
148
|
+
|
|
149
|
+
quantDeclList
|
|
150
|
+
: quantDecl
|
|
151
|
+
| quantDecl ',' quantDeclList
|
|
152
|
+
;
|
|
153
|
+
|
|
154
|
+
expr1_5
|
|
155
|
+
: expr2
|
|
156
|
+
| expr1_5 'xor' expr2
|
|
157
|
+
;
|
|
158
|
+
|
|
159
|
+
letDecl
|
|
160
|
+
: name '=' expr
|
|
161
|
+
;
|
|
162
|
+
|
|
163
|
+
block
|
|
164
|
+
: '{' expr* '}'
|
|
165
|
+
;
|
|
166
|
+
|
|
167
|
+
mult
|
|
168
|
+
: 'lone'
|
|
169
|
+
| 'some'
|
|
170
|
+
| 'one'
|
|
171
|
+
| 'two'
|
|
172
|
+
;
|
|
173
|
+
|
|
174
|
+
quantDecl
|
|
175
|
+
: 'disj'? nameList ':' 'set'? expr
|
|
176
|
+
;
|
|
177
|
+
|
|
178
|
+
expr2
|
|
179
|
+
: expr3
|
|
180
|
+
| expr2 ('<=>' | 'iff') expr3
|
|
181
|
+
;
|
|
182
|
+
|
|
183
|
+
name
|
|
184
|
+
: IDENTIFIER_TOK
|
|
185
|
+
| QUOTED_IDENTIFIER_TOK
|
|
186
|
+
;
|
|
187
|
+
|
|
188
|
+
nameList
|
|
189
|
+
: name
|
|
190
|
+
| name ',' nameList
|
|
191
|
+
;
|
|
192
|
+
|
|
193
|
+
expr3
|
|
194
|
+
: expr4
|
|
195
|
+
| expr4 ('implies' | '=>') expr3 ('else' expr3)?
|
|
196
|
+
;
|
|
197
|
+
|
|
198
|
+
expr4
|
|
199
|
+
: expr5
|
|
200
|
+
| expr4 ('&&' | 'and') expr5
|
|
201
|
+
;
|
|
202
|
+
|
|
203
|
+
expr5
|
|
204
|
+
: expr6
|
|
205
|
+
| ('!' | 'not') expr5
|
|
206
|
+
;
|
|
207
|
+
|
|
208
|
+
expr6
|
|
209
|
+
: expr7
|
|
210
|
+
| expr6 ('!' | 'not')? compareOp expr7
|
|
211
|
+
;
|
|
212
|
+
|
|
213
|
+
expr7
|
|
214
|
+
: expr8
|
|
215
|
+
| ('no' | 'some' | 'lone' | 'one' | 'two' | 'set') expr8
|
|
216
|
+
;
|
|
217
|
+
|
|
218
|
+
compareOp
|
|
219
|
+
: 'in'
|
|
220
|
+
| '='
|
|
221
|
+
| '<'
|
|
222
|
+
| '>'
|
|
223
|
+
| ('<=' | '=<')
|
|
224
|
+
| '>='
|
|
225
|
+
| 'is'
|
|
226
|
+
| 'ni'
|
|
227
|
+
;
|
|
228
|
+
|
|
229
|
+
expr8
|
|
230
|
+
: expr9
|
|
231
|
+
| expr8 ('+' | '-') expr10
|
|
232
|
+
;
|
|
233
|
+
|
|
234
|
+
expr9
|
|
235
|
+
: expr10
|
|
236
|
+
| '#' expr9
|
|
237
|
+
;
|
|
238
|
+
|
|
239
|
+
expr10
|
|
240
|
+
: expr11
|
|
241
|
+
| expr10 '++' expr11
|
|
242
|
+
;
|
|
243
|
+
|
|
244
|
+
expr11
|
|
245
|
+
: expr12
|
|
246
|
+
| expr11 '&' expr12
|
|
247
|
+
;
|
|
248
|
+
|
|
249
|
+
expr12
|
|
250
|
+
: expr13
|
|
251
|
+
| expr12 arrowOp expr13
|
|
252
|
+
;
|
|
253
|
+
|
|
254
|
+
expr13
|
|
255
|
+
: expr14
|
|
256
|
+
| expr13 ('<:' | ':>') expr14
|
|
257
|
+
;
|
|
258
|
+
|
|
259
|
+
arrowOp
|
|
260
|
+
: (mult | 'set')? '->' (mult | 'set')?
|
|
261
|
+
;
|
|
262
|
+
|
|
263
|
+
expr14
|
|
264
|
+
: expr15
|
|
265
|
+
| expr14 '[' exprList ']'
|
|
266
|
+
;
|
|
267
|
+
|
|
268
|
+
expr15
|
|
269
|
+
: expr17
|
|
270
|
+
| expr15 '.' expr17
|
|
271
|
+
| name '[' exprList ']'
|
|
272
|
+
;
|
|
273
|
+
|
|
274
|
+
exprList
|
|
275
|
+
: expr
|
|
276
|
+
| expr ',' exprList
|
|
277
|
+
;
|
|
278
|
+
|
|
279
|
+
expr17
|
|
280
|
+
: expr18
|
|
281
|
+
| ('~' | '^' | '*' | '@:' | '@str:' | '@bool:' | '@num:') expr17
|
|
282
|
+
;
|
|
283
|
+
|
|
284
|
+
expr18
|
|
285
|
+
: const
|
|
286
|
+
| qualName
|
|
287
|
+
| '@' name
|
|
288
|
+
| '`' name
|
|
289
|
+
| 'this'
|
|
290
|
+
| '{' quantDeclList blockOrBar '}'
|
|
291
|
+
| '(' expr ')'
|
|
292
|
+
| block
|
|
293
|
+
| sexpr
|
|
294
|
+
;
|
|
295
|
+
|
|
296
|
+
const
|
|
297
|
+
: 'none'
|
|
298
|
+
| 'univ'
|
|
299
|
+
| 'iden'
|
|
300
|
+
| '-'? number
|
|
301
|
+
| STRING_TOK
|
|
302
|
+
;
|
|
303
|
+
|
|
304
|
+
qualName
|
|
305
|
+
: ('this' '/')? (name '/')* name
|
|
306
|
+
| 'Int'
|
|
307
|
+
| 'sum'
|
|
308
|
+
;
|
|
309
|
+
|
|
310
|
+
sexpr
|
|
311
|
+
: 'sexpr'
|
|
312
|
+
;
|
|
313
|
+
|
|
314
|
+
number
|
|
315
|
+
: NUM_CONST_TOK
|
|
316
|
+
;
|
|
317
|
+
```
|
package/README.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
A TypeScript library for evaluating relational + some more expressions with a browser-compatible UMD bundle.
|
|
4
4
|
|
|
5
|
+
The full language — operators, precedence, reserved words, builtins, and the
|
|
6
|
+
grammar itself — is documented in [LANGUAGE.md](LANGUAGE.md), which is
|
|
7
|
+
**generated from the ANTLR grammars** (`npm run docs`) and kept fresh by
|
|
8
|
+
a test. Note that the language has no temporal fragment: the temporal
|
|
9
|
+
operators (`always`, `until`, ...) and primed expressions (`e'`) were removed
|
|
10
|
+
from the grammar, and their former keywords are ordinary identifiers.
|
|
11
|
+
|
|
12
|
+
Tools that *generate* expressions should read
|
|
13
|
+
[`docs/sgq-language.json`](docs/sgq-language.json) instead of copying the rules
|
|
14
|
+
into their own source. It is generated from the same grammar, ships in the
|
|
15
|
+
package, and states the bare-identifier character classes, the reserved
|
|
16
|
+
spellings, the escape tables for both quoting forms, the builtins, and the
|
|
17
|
+
precedence cascade — each construct with its operator spellings and the level
|
|
18
|
+
each operand descends to, which is what decides parentheses.
|
|
19
|
+
`test/language-manifest.test.ts` checks it by building expressions from the
|
|
20
|
+
manifest alone and running them through the lexer and parser.
|
|
21
|
+
|
|
5
22
|
## License
|
|
6
23
|
|
|
7
24
|
MIT
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import { AbstractParseTreeVisitor } from "antlr4ts/tree/AbstractParseTreeVisitor";
|
|
2
2
|
import { ForgeVisitor } from "./forge-antlr/ForgeVisitor";
|
|
3
|
-
import { ExprContext, Expr1Context, Expr1_5Context, Expr2Context, Expr3Context, Expr4Context,
|
|
3
|
+
import { ExprContext, Expr1Context, Expr1_5Context, Expr2Context, Expr3Context, Expr4Context, Expr5Context, Expr6Context, Expr7Context, Expr8Context, Expr9Context, Expr10Context, Expr11Context, Expr12Context, Expr13Context, Expr14Context, Expr15Context, Expr17Context, Expr18Context, ExprListContext, NameContext, PredDeclContext, BlockContext, QualNameContext, QuantDeclListContext, NameListContext, QuantDeclContext, CompareOpContext } from "./forge-antlr/ForgeParser";
|
|
4
4
|
import { IDataInstance } from "./types";
|
|
5
5
|
export type SingleValue = string | number | boolean;
|
|
6
6
|
export type Tuple = SingleValue[];
|
|
7
7
|
export type EvalResult = SingleValue | Tuple[];
|
|
8
8
|
export declare function areTupleArraysEqual(a: Tuple[], b: Tuple[]): boolean;
|
|
9
9
|
export declare const SUPPORTED_BUILTINS: string[];
|
|
10
|
+
/**
|
|
11
|
+
* The canonical spelling of a comparison operator.
|
|
12
|
+
*
|
|
13
|
+
* Some operators have two spellings that the lexer folds into a single token —
|
|
14
|
+
* `<=` and `=<` are both `LEQ_TOK`. Reading `compareOp().text` gives back
|
|
15
|
+
* whichever one the author typed, so any dispatch on that text has to enumerate
|
|
16
|
+
* both, and every new dispatch site has to rediscover the fact. Every OTHER
|
|
17
|
+
* multi-spelling operator in the grammar (`||`/`or`, `!`/`not`, `=>`/`implies`)
|
|
18
|
+
* is dispatched on token presence and so never had the problem; this brings
|
|
19
|
+
* `compareOp` in line, and makes the alias unrepresentable rather than merely
|
|
20
|
+
* handled.
|
|
21
|
+
*/
|
|
22
|
+
export declare function compareOpKind(op: CompareOpContext): string;
|
|
10
23
|
/**
|
|
11
24
|
* A non-fatal condition noticed while evaluating an expression.
|
|
12
25
|
*
|
|
@@ -71,6 +84,7 @@ export declare class ForgeExprEvaluator extends AbstractParseTreeVisitor<EvalRes
|
|
|
71
84
|
private isConvertibleToNumber;
|
|
72
85
|
private isConvertibleToBoolean;
|
|
73
86
|
private convertToBoolean;
|
|
87
|
+
private atomValue;
|
|
74
88
|
private dotJoin;
|
|
75
89
|
private cacheResult;
|
|
76
90
|
private getIden;
|
|
@@ -84,7 +98,6 @@ export declare class ForgeExprEvaluator extends AbstractParseTreeVisitor<EvalRes
|
|
|
84
98
|
visitExpr2(ctx: Expr2Context): EvalResult;
|
|
85
99
|
visitExpr3(ctx: Expr3Context): EvalResult;
|
|
86
100
|
visitExpr4(ctx: Expr4Context): EvalResult;
|
|
87
|
-
visitExpr4_5(ctx: Expr4_5Context): EvalResult;
|
|
88
101
|
visitExpr5(ctx: Expr5Context): EvalResult;
|
|
89
102
|
visitExpr6(ctx: Expr6Context): EvalResult;
|
|
90
103
|
visitExpr7(ctx: Expr7Context): EvalResult;
|
|
@@ -96,7 +109,6 @@ export declare class ForgeExprEvaluator extends AbstractParseTreeVisitor<EvalRes
|
|
|
96
109
|
visitExpr13(ctx: Expr13Context): EvalResult;
|
|
97
110
|
visitExpr14(ctx: Expr14Context): EvalResult;
|
|
98
111
|
visitExpr15(ctx: Expr15Context): EvalResult;
|
|
99
|
-
visitExpr16(ctx: Expr16Context): EvalResult;
|
|
100
112
|
visitExpr17(ctx: Expr17Context): EvalResult;
|
|
101
113
|
getNameListValues(ctx: NameListContext): string[];
|
|
102
114
|
getQuantDeclValues(ctx: QuantDeclContext): Record<string, Tuple[]>;
|
|
@@ -107,6 +119,7 @@ export declare class ForgeExprEvaluator extends AbstractParseTreeVisitor<EvalRes
|
|
|
107
119
|
visitQualName(ctx: QualNameContext): EvalResult;
|
|
108
120
|
private evaluateBinaryOperation;
|
|
109
121
|
private evaluateUnaryOperation;
|
|
122
|
+
private setOperandAsNumber;
|
|
110
123
|
private evaluateSetOperation;
|
|
111
124
|
}
|
|
112
125
|
export declare class NameNotFoundError extends Error {
|
|
@@ -2,7 +2,7 @@ import { AbstractParseTreeVisitor } from "antlr4ts/tree/AbstractParseTreeVisitor
|
|
|
2
2
|
import { ParseTree } from "antlr4ts/tree/ParseTree";
|
|
3
3
|
import { ForgeVisitor } from "./forge-antlr/ForgeVisitor";
|
|
4
4
|
import { IDataInstance } from "./types";
|
|
5
|
-
import { BlockContext, Expr10Context, Expr11Context, Expr12Context, Expr13Context, Expr14Context, Expr15Context,
|
|
5
|
+
import { BlockContext, Expr10Context, Expr11Context, Expr12Context, Expr13Context, Expr14Context, Expr15Context, Expr17Context, Expr18Context, Expr1Context, Expr1_5Context, Expr2Context, Expr3Context, Expr4Context, Expr5Context, Expr6Context, Expr7Context, Expr8Context, Expr9Context, ExprContext, ExprListContext, NameContext, NameListContext, PredDeclContext, QuantDeclContext, QuantDeclListContext } from "./forge-antlr/ForgeParser";
|
|
6
6
|
export type FreeVariables = Map<ParseTree, Set<string>>;
|
|
7
7
|
/**
|
|
8
8
|
* A recursive visitor to find all the free variables referenced in a forge
|
|
@@ -25,7 +25,6 @@ export declare class ForgeExprFreeVariableFinder extends AbstractParseTreeVisito
|
|
|
25
25
|
visitExpr2(ctx: Expr2Context): FreeVariables;
|
|
26
26
|
visitExpr3(ctx: Expr3Context): FreeVariables;
|
|
27
27
|
visitExpr4(ctx: Expr4Context): FreeVariables;
|
|
28
|
-
visitExpr4_5(ctx: Expr4_5Context): FreeVariables;
|
|
29
28
|
visitExpr5(ctx: Expr5Context): FreeVariables;
|
|
30
29
|
visitExpr6(ctx: Expr6Context): FreeVariables;
|
|
31
30
|
visitExpr7(ctx: Expr7Context): FreeVariables;
|
|
@@ -37,7 +36,6 @@ export declare class ForgeExprFreeVariableFinder extends AbstractParseTreeVisito
|
|
|
37
36
|
visitExpr13(ctx: Expr13Context): FreeVariables;
|
|
38
37
|
visitExpr14(ctx: Expr14Context): FreeVariables;
|
|
39
38
|
visitExpr15(ctx: Expr15Context): FreeVariables;
|
|
40
|
-
visitExpr16(ctx: Expr16Context): FreeVariables;
|
|
41
39
|
visitExpr17(ctx: Expr17Context): FreeVariables;
|
|
42
40
|
visitExpr18(ctx: Expr18Context): FreeVariables;
|
|
43
41
|
visitExprList(ctx: ExprListContext): FreeVariables;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AbstractParseTreeVisitor } from "antlr4ts/tree/AbstractParseTreeVisitor";
|
|
2
2
|
import { ParseTree } from "antlr4ts/tree/ParseTree";
|
|
3
3
|
import { ForgeVisitor } from "./forge-antlr/ForgeVisitor";
|
|
4
|
-
import { Expr1Context, Expr1_5Context, Expr2Context, Expr3Context, Expr4Context, Expr5Context, Expr6Context, Expr7Context, Expr8Context, Expr9Context, Expr11Context, Expr12Context, Expr14Context, Expr15Context, Expr17Context, Expr18Context, ExprContext, NameContext, BlockContext } from "./forge-antlr/ForgeParser";
|
|
4
|
+
import { Expr1Context, Expr1_5Context, Expr2Context, Expr3Context, Expr4Context, Expr5Context, Expr6Context, Expr7Context, Expr8Context, Expr9Context, Expr10Context, Expr11Context, Expr12Context, Expr13Context, Expr14Context, Expr15Context, Expr17Context, Expr18Context, ExprContext, NameContext, BlockContext } from "./forge-antlr/ForgeParser";
|
|
5
5
|
import { IForgeSchema } from "./types";
|
|
6
6
|
type Abstract = {
|
|
7
7
|
kind: "bool";
|
|
@@ -15,6 +15,7 @@ type Abstract = {
|
|
|
15
15
|
kind: "typed";
|
|
16
16
|
arity: number;
|
|
17
17
|
columnTypes?: readonly string[];
|
|
18
|
+
exact?: boolean;
|
|
18
19
|
} | {
|
|
19
20
|
kind: "ill-typed";
|
|
20
21
|
reason: string;
|
|
@@ -79,7 +80,9 @@ export declare class ForgeExprStaticAnalyzer extends AbstractParseTreeVisitor<Ab
|
|
|
79
80
|
visitExpr7(ctx: Expr7Context): Abstract;
|
|
80
81
|
visitExpr8(ctx: Expr8Context): Abstract;
|
|
81
82
|
visitExpr9(ctx: Expr9Context): Abstract;
|
|
83
|
+
visitExpr10(ctx: Expr10Context): Abstract;
|
|
82
84
|
visitExpr12(ctx: Expr12Context): Abstract;
|
|
85
|
+
visitExpr13(ctx: Expr13Context): Abstract;
|
|
83
86
|
visitExpr11(ctx: Expr11Context): Abstract;
|
|
84
87
|
visitExpr14(ctx: Expr14Context): Abstract;
|
|
85
88
|
visitExpr15(ctx: Expr15Context): Abstract;
|
|
@@ -65,58 +65,47 @@ export declare class ForgeLexer extends Lexer {
|
|
|
65
65
|
static readonly IMP_TOK = 60;
|
|
66
66
|
static readonly ELSE_TOK = 61;
|
|
67
67
|
static readonly AND_TOK = 62;
|
|
68
|
-
static readonly
|
|
69
|
-
static readonly
|
|
70
|
-
static readonly
|
|
71
|
-
static readonly
|
|
72
|
-
static readonly
|
|
73
|
-
static readonly
|
|
74
|
-
static readonly
|
|
75
|
-
static readonly
|
|
76
|
-
static readonly
|
|
77
|
-
static readonly
|
|
78
|
-
static readonly
|
|
79
|
-
static readonly
|
|
80
|
-
static readonly
|
|
81
|
-
static readonly
|
|
82
|
-
static readonly
|
|
83
|
-
static readonly
|
|
84
|
-
static readonly
|
|
85
|
-
static readonly
|
|
86
|
-
static readonly
|
|
87
|
-
static readonly
|
|
88
|
-
static readonly
|
|
89
|
-
static readonly
|
|
90
|
-
static readonly
|
|
91
|
-
static readonly
|
|
92
|
-
static readonly
|
|
93
|
-
static readonly
|
|
94
|
-
static readonly
|
|
95
|
-
static readonly
|
|
96
|
-
static readonly
|
|
97
|
-
static readonly
|
|
98
|
-
static readonly
|
|
99
|
-
static readonly
|
|
100
|
-
static readonly
|
|
101
|
-
static readonly
|
|
102
|
-
static readonly
|
|
103
|
-
static readonly
|
|
104
|
-
static readonly
|
|
105
|
-
static readonly
|
|
106
|
-
static readonly
|
|
107
|
-
static readonly
|
|
108
|
-
static readonly
|
|
109
|
-
static readonly OPTION_TOK = 104;
|
|
110
|
-
static readonly COMMA_TOK = 105;
|
|
111
|
-
static readonly SLASH_TOK = 106;
|
|
112
|
-
static readonly NUM_CONST_TOK = 107;
|
|
113
|
-
static readonly QUOTED_IDENTIFIER_TOK = 108;
|
|
114
|
-
static readonly IDENTIFIER_TOK = 109;
|
|
115
|
-
static readonly WS = 110;
|
|
116
|
-
static readonly CCOMMENT = 111;
|
|
117
|
-
static readonly COMMENT = 112;
|
|
118
|
-
static readonly MULTCOMMENT = 113;
|
|
119
|
-
static readonly LANG_DECL = 114;
|
|
68
|
+
static readonly NEG_TOK = 63;
|
|
69
|
+
static readonly CARD_TOK = 64;
|
|
70
|
+
static readonly PPLUS_TOK = 65;
|
|
71
|
+
static readonly AMP_TOK = 66;
|
|
72
|
+
static readonly SUBT_TOK = 67;
|
|
73
|
+
static readonly SUPT_TOK = 68;
|
|
74
|
+
static readonly TILDE_TOK = 69;
|
|
75
|
+
static readonly EXP_TOK = 70;
|
|
76
|
+
static readonly STAR_TOK = 71;
|
|
77
|
+
static readonly AT_TOK = 72;
|
|
78
|
+
static readonly BACKQUOTE_TOK = 73;
|
|
79
|
+
static readonly THIS_TOK = 74;
|
|
80
|
+
static readonly SEXPR_TOK = 75;
|
|
81
|
+
static readonly INST_TOK = 76;
|
|
82
|
+
static readonly EVAL_TOK = 77;
|
|
83
|
+
static readonly EXAMPLE_TOK = 78;
|
|
84
|
+
static readonly ARROW_TOK = 79;
|
|
85
|
+
static readonly GET_LABEL_TOK = 80;
|
|
86
|
+
static readonly GET_LABEL_STR_TOK = 81;
|
|
87
|
+
static readonly GET_LABEL_BOOL_TOK = 82;
|
|
88
|
+
static readonly GET_LABEL_NUM_TOK = 83;
|
|
89
|
+
static readonly EQ_TOK = 84;
|
|
90
|
+
static readonly LT_TOK = 85;
|
|
91
|
+
static readonly GT_TOK = 86;
|
|
92
|
+
static readonly LEQ_TOK = 87;
|
|
93
|
+
static readonly GEQ_TOK = 88;
|
|
94
|
+
static readonly NI_TOK = 89;
|
|
95
|
+
static readonly NO_TOK = 90;
|
|
96
|
+
static readonly SUM_TOK = 91;
|
|
97
|
+
static readonly INT_TOK = 92;
|
|
98
|
+
static readonly OPTION_TOK = 93;
|
|
99
|
+
static readonly COMMA_TOK = 94;
|
|
100
|
+
static readonly SLASH_TOK = 95;
|
|
101
|
+
static readonly NUM_CONST_TOK = 96;
|
|
102
|
+
static readonly QUOTED_IDENTIFIER_TOK = 97;
|
|
103
|
+
static readonly IDENTIFIER_TOK = 98;
|
|
104
|
+
static readonly WS = 99;
|
|
105
|
+
static readonly CCOMMENT = 100;
|
|
106
|
+
static readonly COMMENT = 101;
|
|
107
|
+
static readonly MULTCOMMENT = 102;
|
|
108
|
+
static readonly LANG_DECL = 103;
|
|
120
109
|
static readonly channelNames: string[];
|
|
121
110
|
static readonly modeNames: string[];
|
|
122
111
|
static readonly ruleNames: string[];
|
|
@@ -52,7 +52,6 @@ import { Expr1_5Context } from "./ForgeParser";
|
|
|
52
52
|
import { Expr2Context } from "./ForgeParser";
|
|
53
53
|
import { Expr3Context } from "./ForgeParser";
|
|
54
54
|
import { Expr4Context } from "./ForgeParser";
|
|
55
|
-
import { Expr4_5Context } from "./ForgeParser";
|
|
56
55
|
import { Expr5Context } from "./ForgeParser";
|
|
57
56
|
import { Expr6Context } from "./ForgeParser";
|
|
58
57
|
import { Expr7Context } from "./ForgeParser";
|
|
@@ -64,7 +63,6 @@ import { Expr12Context } from "./ForgeParser";
|
|
|
64
63
|
import { Expr13Context } from "./ForgeParser";
|
|
65
64
|
import { Expr14Context } from "./ForgeParser";
|
|
66
65
|
import { Expr15Context } from "./ForgeParser";
|
|
67
|
-
import { Expr16Context } from "./ForgeParser";
|
|
68
66
|
import { Expr17Context } from "./ForgeParser";
|
|
69
67
|
import { Expr18Context } from "./ForgeParser";
|
|
70
68
|
import { ArrowExprContext } from "./ForgeParser";
|
|
@@ -619,16 +617,6 @@ export interface ForgeListener extends ParseTreeListener {
|
|
|
619
617
|
* @param ctx the parse tree
|
|
620
618
|
*/
|
|
621
619
|
exitExpr4?: (ctx: Expr4Context) => void;
|
|
622
|
-
/**
|
|
623
|
-
* Enter a parse tree produced by `ForgeParser.expr4_5`.
|
|
624
|
-
* @param ctx the parse tree
|
|
625
|
-
*/
|
|
626
|
-
enterExpr4_5?: (ctx: Expr4_5Context) => void;
|
|
627
|
-
/**
|
|
628
|
-
* Exit a parse tree produced by `ForgeParser.expr4_5`.
|
|
629
|
-
* @param ctx the parse tree
|
|
630
|
-
*/
|
|
631
|
-
exitExpr4_5?: (ctx: Expr4_5Context) => void;
|
|
632
620
|
/**
|
|
633
621
|
* Enter a parse tree produced by `ForgeParser.expr5`.
|
|
634
622
|
* @param ctx the parse tree
|
|
@@ -739,16 +727,6 @@ export interface ForgeListener extends ParseTreeListener {
|
|
|
739
727
|
* @param ctx the parse tree
|
|
740
728
|
*/
|
|
741
729
|
exitExpr15?: (ctx: Expr15Context) => void;
|
|
742
|
-
/**
|
|
743
|
-
* Enter a parse tree produced by `ForgeParser.expr16`.
|
|
744
|
-
* @param ctx the parse tree
|
|
745
|
-
*/
|
|
746
|
-
enterExpr16?: (ctx: Expr16Context) => void;
|
|
747
|
-
/**
|
|
748
|
-
* Exit a parse tree produced by `ForgeParser.expr16`.
|
|
749
|
-
* @param ctx the parse tree
|
|
750
|
-
*/
|
|
751
|
-
exitExpr16?: (ctx: Expr16Context) => void;
|
|
752
730
|
/**
|
|
753
731
|
* Enter a parse tree produced by `ForgeParser.expr17`.
|
|
754
732
|
* @param ctx the parse tree
|