openalgo-script 0.1.0-alpha.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/LICENSE +201 -0
- package/NOTICE +12 -0
- package/README.md +255 -0
- package/dist/core/ast/annotations.d.ts +56 -0
- package/dist/core/ast/annotations.d.ts.map +1 -0
- package/dist/core/ast/annotations.js +27 -0
- package/dist/core/ast/annotations.js.map +1 -0
- package/dist/core/ast/build.d.ts +25 -0
- package/dist/core/ast/build.d.ts.map +1 -0
- package/dist/core/ast/build.js +26 -0
- package/dist/core/ast/build.js.map +1 -0
- package/dist/core/ast/children.d.ts +15 -0
- package/dist/core/ast/children.d.ts.map +1 -0
- package/dist/core/ast/children.js +103 -0
- package/dist/core/ast/children.js.map +1 -0
- package/dist/core/ast/expressions.d.ts +178 -0
- package/dist/core/ast/expressions.d.ts.map +1 -0
- package/dist/core/ast/expressions.js +50 -0
- package/dist/core/ast/expressions.js.map +1 -0
- package/dist/core/ast/header.d.ts +50 -0
- package/dist/core/ast/header.d.ts.map +1 -0
- package/dist/core/ast/header.js +2 -0
- package/dist/core/ast/header.js.map +1 -0
- package/dist/core/ast/index.d.ts +30 -0
- package/dist/core/ast/index.d.ts.map +1 -0
- package/dist/core/ast/index.js +21 -0
- package/dist/core/ast/index.js.map +1 -0
- package/dist/core/ast/name.d.ts +24 -0
- package/dist/core/ast/name.d.ts.map +1 -0
- package/dist/core/ast/name.js +2 -0
- package/dist/core/ast/name.js.map +1 -0
- package/dist/core/ast/node.d.ts +34 -0
- package/dist/core/ast/node.d.ts.map +1 -0
- package/dist/core/ast/node.js +70 -0
- package/dist/core/ast/node.js.map +1 -0
- package/dist/core/ast/script.d.ts +57 -0
- package/dist/core/ast/script.d.ts.map +1 -0
- package/dist/core/ast/script.js +2 -0
- package/dist/core/ast/script.js.map +1 -0
- package/dist/core/ast/statements.d.ts +161 -0
- package/dist/core/ast/statements.d.ts.map +1 -0
- package/dist/core/ast/statements.js +10 -0
- package/dist/core/ast/statements.js.map +1 -0
- package/dist/core/ast/walk.d.ts +39 -0
- package/dist/core/ast/walk.d.ts.map +1 -0
- package/dist/core/ast/walk.js +54 -0
- package/dist/core/ast/walk.js.map +1 -0
- package/dist/core/catalogue/catalogue.generated.d.ts +1590 -0
- package/dist/core/catalogue/catalogue.generated.d.ts.map +1 -0
- package/dist/core/catalogue/catalogue.generated.js +162 -0
- package/dist/core/catalogue/catalogue.generated.js.map +1 -0
- package/dist/core/catalogue/index.d.ts +15 -0
- package/dist/core/catalogue/index.d.ts.map +1 -0
- package/dist/core/catalogue/index.js +4 -0
- package/dist/core/catalogue/index.js.map +1 -0
- package/dist/core/catalogue/lookup.d.ts +14 -0
- package/dist/core/catalogue/lookup.d.ts.map +1 -0
- package/dist/core/catalogue/lookup.js +19 -0
- package/dist/core/catalogue/lookup.js.map +1 -0
- package/dist/core/catalogue/template.d.ts +15 -0
- package/dist/core/catalogue/template.d.ts.map +1 -0
- package/dist/core/catalogue/template.js +33 -0
- package/dist/core/catalogue/template.js.map +1 -0
- package/dist/core/catalogue/types.d.ts +34 -0
- package/dist/core/catalogue/types.d.ts.map +1 -0
- package/dist/core/catalogue/types.js +6 -0
- package/dist/core/catalogue/types.js.map +1 -0
- package/dist/core/catalogue/values.generated.d.ts +565 -0
- package/dist/core/catalogue/values.generated.d.ts.map +1 -0
- package/dist/core/catalogue/values.generated.js +6 -0
- package/dist/core/catalogue/values.generated.js.map +1 -0
- package/dist/core/diagnostics/collector.d.ts +46 -0
- package/dist/core/diagnostics/collector.d.ts.map +1 -0
- package/dist/core/diagnostics/collector.js +55 -0
- package/dist/core/diagnostics/collector.js.map +1 -0
- package/dist/core/diagnostics/diagnostic.d.ts +40 -0
- package/dist/core/diagnostics/diagnostic.d.ts.map +1 -0
- package/dist/core/diagnostics/diagnostic.js +29 -0
- package/dist/core/diagnostics/diagnostic.js.map +1 -0
- package/dist/core/diagnostics/index.d.ts +12 -0
- package/dist/core/diagnostics/index.d.ts.map +1 -0
- package/dist/core/diagnostics/index.js +3 -0
- package/dist/core/diagnostics/index.js.map +1 -0
- package/dist/core/index.d.ts +28 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +22 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/lex/blocks.d.ts +51 -0
- package/dist/core/lex/blocks.d.ts.map +1 -0
- package/dist/core/lex/blocks.js +56 -0
- package/dist/core/lex/blocks.js.map +1 -0
- package/dist/core/lex/characters.d.ts +38 -0
- package/dist/core/lex/characters.d.ts.map +1 -0
- package/dist/core/lex/characters.js +50 -0
- package/dist/core/lex/characters.js.map +1 -0
- package/dist/core/lex/comments.d.ts +50 -0
- package/dist/core/lex/comments.d.ts.map +1 -0
- package/dist/core/lex/comments.js +64 -0
- package/dist/core/lex/comments.js.map +1 -0
- package/dist/core/lex/index.d.ts +12 -0
- package/dist/core/lex/index.d.ts.map +1 -0
- package/dist/core/lex/index.js +12 -0
- package/dist/core/lex/index.js.map +1 -0
- package/dist/core/lex/layout.d.ts +40 -0
- package/dist/core/lex/layout.d.ts.map +1 -0
- package/dist/core/lex/layout.js +143 -0
- package/dist/core/lex/layout.js.map +1 -0
- package/dist/core/lex/lexer.d.ts +13 -0
- package/dist/core/lex/lexer.d.ts.map +1 -0
- package/dist/core/lex/lexer.js +419 -0
- package/dist/core/lex/lexer.js.map +1 -0
- package/dist/core/lex/numbers.d.ts +22 -0
- package/dist/core/lex/numbers.d.ts.map +1 -0
- package/dist/core/lex/numbers.js +58 -0
- package/dist/core/lex/numbers.js.map +1 -0
- package/dist/core/lex/statements.d.ts +24 -0
- package/dist/core/lex/statements.d.ts.map +1 -0
- package/dist/core/lex/statements.js +90 -0
- package/dist/core/lex/statements.js.map +1 -0
- package/dist/core/lex/strings.d.ts +27 -0
- package/dist/core/lex/strings.d.ts.map +1 -0
- package/dist/core/lex/strings.js +92 -0
- package/dist/core/lex/strings.js.map +1 -0
- package/dist/core/lex/unexpected.d.ts +31 -0
- package/dist/core/lex/unexpected.d.ts.map +1 -0
- package/dist/core/lex/unexpected.js +114 -0
- package/dist/core/lex/unexpected.js.map +1 -0
- package/dist/core/parse/annotations.d.ts +4 -0
- package/dist/core/parse/annotations.d.ts.map +1 -0
- package/dist/core/parse/annotations.js +49 -0
- package/dist/core/parse/annotations.js.map +1 -0
- package/dist/core/parse/blocks.d.ts +18 -0
- package/dist/core/parse/blocks.d.ts.map +1 -0
- package/dist/core/parse/blocks.js +47 -0
- package/dist/core/parse/blocks.js.map +1 -0
- package/dist/core/parse/branches.d.ts +17 -0
- package/dist/core/parse/branches.d.ts.map +1 -0
- package/dist/core/parse/branches.js +66 -0
- package/dist/core/parse/branches.js.map +1 -0
- package/dist/core/parse/cursor.d.ts +119 -0
- package/dist/core/parse/cursor.d.ts.map +1 -0
- package/dist/core/parse/cursor.js +305 -0
- package/dist/core/parse/cursor.js.map +1 -0
- package/dist/core/parse/expressions.d.ts +57 -0
- package/dist/core/parse/expressions.d.ts.map +1 -0
- package/dist/core/parse/expressions.js +373 -0
- package/dist/core/parse/expressions.js.map +1 -0
- package/dist/core/parse/functions.d.ts +16 -0
- package/dist/core/parse/functions.d.ts.map +1 -0
- package/dist/core/parse/functions.js +92 -0
- package/dist/core/parse/functions.js.map +1 -0
- package/dist/core/parse/index.d.ts +13 -0
- package/dist/core/parse/index.d.ts.map +1 -0
- package/dist/core/parse/index.js +13 -0
- package/dist/core/parse/index.js.map +1 -0
- package/dist/core/parse/loops.d.ts +13 -0
- package/dist/core/parse/loops.d.ts.map +1 -0
- package/dist/core/parse/loops.js +78 -0
- package/dist/core/parse/loops.js.map +1 -0
- package/dist/core/parse/names.d.ts +34 -0
- package/dist/core/parse/names.d.ts.map +1 -0
- package/dist/core/parse/names.js +122 -0
- package/dist/core/parse/names.js.map +1 -0
- package/dist/core/parse/script.d.ts +23 -0
- package/dist/core/parse/script.d.ts.map +1 -0
- package/dist/core/parse/script.js +55 -0
- package/dist/core/parse/script.js.map +1 -0
- package/dist/core/parse/statements.d.ts +14 -0
- package/dist/core/parse/statements.d.ts.map +1 -0
- package/dist/core/parse/statements.js +292 -0
- package/dist/core/parse/statements.js.map +1 -0
- package/dist/core/parse/switches.d.ts +16 -0
- package/dist/core/parse/switches.d.ts.map +1 -0
- package/dist/core/parse/switches.js +98 -0
- package/dist/core/parse/switches.js.map +1 -0
- package/dist/core/render/index.d.ts +10 -0
- package/dist/core/render/index.d.ts.map +1 -0
- package/dist/core/render/index.js +10 -0
- package/dist/core/render/index.js.map +1 -0
- package/dist/core/render/terminal.d.ts +11 -0
- package/dist/core/render/terminal.d.ts.map +1 -0
- package/dist/core/render/terminal.js +51 -0
- package/dist/core/render/terminal.js.map +1 -0
- package/dist/core/source/index.d.ts +7 -0
- package/dist/core/source/index.d.ts.map +1 -0
- package/dist/core/source/index.js +2 -0
- package/dist/core/source/index.js.map +1 -0
- package/dist/core/source/source.d.ts +41 -0
- package/dist/core/source/source.d.ts.map +1 -0
- package/dist/core/source/source.js +67 -0
- package/dist/core/source/source.js.map +1 -0
- package/dist/core/span/index.d.ts +3 -0
- package/dist/core/span/index.d.ts.map +1 -0
- package/dist/core/span/index.js +2 -0
- package/dist/core/span/index.js.map +1 -0
- package/dist/core/span/span.d.ts +67 -0
- package/dist/core/span/span.d.ts.map +1 -0
- package/dist/core/span/span.js +27 -0
- package/dist/core/span/span.js.map +1 -0
- package/dist/core/tokens/index.d.ts +8 -0
- package/dist/core/tokens/index.d.ts.map +1 -0
- package/dist/core/tokens/index.js +2 -0
- package/dist/core/tokens/index.js.map +1 -0
- package/dist/core/tokens/kind.d.ts +53 -0
- package/dist/core/tokens/kind.d.ts.map +1 -0
- package/dist/core/tokens/kind.js +94 -0
- package/dist/core/tokens/kind.js.map +1 -0
- package/dist/core/tokens/token.d.ts +36 -0
- package/dist/core/tokens/token.d.ts.map +1 -0
- package/dist/core/tokens/token.js +2 -0
- package/dist/core/tokens/token.js.map +1 -0
- package/package.json +52 -0
- package/spec/README.md +48 -0
- package/spec/errors.json +3204 -0
- package/src/core/ast/annotations.ts +68 -0
- package/src/core/ast/build.ts +35 -0
- package/src/core/ast/children.ts +110 -0
- package/src/core/ast/expressions.ts +254 -0
- package/src/core/ast/header.ts +53 -0
- package/src/core/ast/index.ts +102 -0
- package/src/core/ast/name.ts +24 -0
- package/src/core/ast/node.ts +120 -0
- package/src/core/ast/script.ts +60 -0
- package/src/core/ast/statements.ts +193 -0
- package/src/core/ast/walk.ts +67 -0
- package/src/core/catalogue/catalogue.generated.ts +171 -0
- package/src/core/catalogue/index.ts +20 -0
- package/src/core/catalogue/lookup.ts +23 -0
- package/src/core/catalogue/template.ts +38 -0
- package/src/core/catalogue/types.ts +37 -0
- package/src/core/catalogue/values.generated.ts +160 -0
- package/src/core/diagnostics/collector.ts +87 -0
- package/src/core/diagnostics/diagnostic.ts +72 -0
- package/src/core/diagnostics/index.ts +12 -0
- package/src/core/index.ts +146 -0
- package/src/core/lex/blocks.ts +92 -0
- package/src/core/lex/characters.ts +56 -0
- package/src/core/lex/comments.ts +75 -0
- package/src/core/lex/index.ts +11 -0
- package/src/core/lex/layout.ts +188 -0
- package/src/core/lex/lexer.ts +486 -0
- package/src/core/lex/numbers.ts +77 -0
- package/src/core/lex/statements.ts +94 -0
- package/src/core/lex/strings.ts +119 -0
- package/src/core/lex/unexpected.ts +125 -0
- package/src/core/parse/annotations.ts +60 -0
- package/src/core/parse/blocks.ts +52 -0
- package/src/core/parse/branches.ts +77 -0
- package/src/core/parse/cursor.ts +348 -0
- package/src/core/parse/expressions.ts +441 -0
- package/src/core/parse/functions.ts +109 -0
- package/src/core/parse/index.ts +12 -0
- package/src/core/parse/loops.ts +97 -0
- package/src/core/parse/names.ts +135 -0
- package/src/core/parse/script.ts +64 -0
- package/src/core/parse/statements.ts +329 -0
- package/src/core/parse/switches.ts +105 -0
- package/src/core/render/index.ts +9 -0
- package/src/core/render/terminal.ts +62 -0
- package/src/core/source/index.ts +6 -0
- package/src/core/source/source.ts +102 -0
- package/src/core/span/index.ts +2 -0
- package/src/core/span/span.ts +84 -0
- package/src/core/tokens/index.ts +15 -0
- package/src/core/tokens/kind.ts +123 -0
- package/src/core/tokens/token.ts +39 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
const NO_CHILDREN = [];
|
|
2
|
+
/** The nodes among these that are there, keeping the order they were given in. */
|
|
3
|
+
function present(...nodes) {
|
|
4
|
+
return nodes.filter((node) => node !== undefined);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The children of a node, in source order.
|
|
8
|
+
*
|
|
9
|
+
* This is the only place the shape of the tree is written down twice, and it is
|
|
10
|
+
* deliberately the only one. Everything that walks the tree walks it through
|
|
11
|
+
* here, so a field added to a node is connected once and every pass sees it,
|
|
12
|
+
* rather than being connected in the checker, forgotten in the code generator,
|
|
13
|
+
* and found by a user whose script compiled to something with a hole in it.
|
|
14
|
+
*
|
|
15
|
+
* The switch has no default arm on purpose: a new node kind stops the build
|
|
16
|
+
* here, at the one place that has to know about it.
|
|
17
|
+
*/
|
|
18
|
+
export function childrenOf(node) {
|
|
19
|
+
switch (node.kind) {
|
|
20
|
+
// The file and what only the file holds.
|
|
21
|
+
case 'script':
|
|
22
|
+
return node.items;
|
|
23
|
+
case 'functionDeclaration':
|
|
24
|
+
return [node.name, ...node.parameters, node.body];
|
|
25
|
+
case 'parameter':
|
|
26
|
+
return present(node.name, node.annotation, node.defaultValue);
|
|
27
|
+
// The header lines, which are statements wherever they are written.
|
|
28
|
+
case 'versionLine':
|
|
29
|
+
return [node.version];
|
|
30
|
+
case 'scriptDeclaration':
|
|
31
|
+
return node.args;
|
|
32
|
+
case 'limitsLine':
|
|
33
|
+
return node.args;
|
|
34
|
+
// Statements.
|
|
35
|
+
case 'expressionStatement':
|
|
36
|
+
return [node.expression];
|
|
37
|
+
case 'assignment':
|
|
38
|
+
return [node.target, node.value];
|
|
39
|
+
case 'varDeclaration':
|
|
40
|
+
return present(node.name, node.annotation, node.initialiser);
|
|
41
|
+
case 'ifStatement':
|
|
42
|
+
return present(...node.branches, node.elseBranch);
|
|
43
|
+
case 'ifBranch':
|
|
44
|
+
return [node.condition, node.body];
|
|
45
|
+
case 'elseBranch':
|
|
46
|
+
return [node.body];
|
|
47
|
+
case 'forRangeStatement':
|
|
48
|
+
return present(node.variable, node.from, node.to, node.step, node.body);
|
|
49
|
+
case 'forInStatement':
|
|
50
|
+
return [node.variable, node.iterable, node.body];
|
|
51
|
+
case 'whileStatement':
|
|
52
|
+
return [node.condition, node.body];
|
|
53
|
+
case 'switchStatement':
|
|
54
|
+
return present(node.subject, ...node.cases, node.defaultCase);
|
|
55
|
+
case 'switchCase':
|
|
56
|
+
return [...node.values, node.body];
|
|
57
|
+
case 'switchDefault':
|
|
58
|
+
return [node.body];
|
|
59
|
+
case 'breakStatement':
|
|
60
|
+
case 'continueStatement':
|
|
61
|
+
return NO_CHILDREN;
|
|
62
|
+
case 'returnStatement':
|
|
63
|
+
return present(node.value);
|
|
64
|
+
case 'block':
|
|
65
|
+
return node.statements;
|
|
66
|
+
// Expressions.
|
|
67
|
+
case 'numberLiteral':
|
|
68
|
+
case 'stringLiteral':
|
|
69
|
+
case 'booleanLiteral':
|
|
70
|
+
case 'colorLiteral':
|
|
71
|
+
case 'noneLiteral':
|
|
72
|
+
case 'nameReference':
|
|
73
|
+
case 'missingExpression':
|
|
74
|
+
return NO_CHILDREN;
|
|
75
|
+
case 'arrayLiteral':
|
|
76
|
+
return node.elements;
|
|
77
|
+
case 'grouping':
|
|
78
|
+
return [node.expression];
|
|
79
|
+
case 'unary':
|
|
80
|
+
return [node.operand];
|
|
81
|
+
case 'binary':
|
|
82
|
+
return [node.left, node.right];
|
|
83
|
+
case 'ternary':
|
|
84
|
+
return [node.condition, node.whenTrue, node.whenFalse];
|
|
85
|
+
case 'call':
|
|
86
|
+
return [node.callee, ...node.args];
|
|
87
|
+
case 'argument':
|
|
88
|
+
return present(node.label, node.value);
|
|
89
|
+
case 'index':
|
|
90
|
+
return [node.target, node.index];
|
|
91
|
+
case 'member':
|
|
92
|
+
return [node.object, node.member];
|
|
93
|
+
// Type annotations, and a name where one is written.
|
|
94
|
+
case 'namedType':
|
|
95
|
+
return NO_CHILDREN;
|
|
96
|
+
case 'seriesType':
|
|
97
|
+
case 'arrayType':
|
|
98
|
+
return [node.element];
|
|
99
|
+
case 'name':
|
|
100
|
+
return NO_CHILDREN;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=children.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"children.js","sourceRoot":"","sources":["../../../src/core/ast/children.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,GAAuB,EAAE,CAAC;AAE3C,kFAAkF;AAClF,SAAS,OAAO,CAAC,GAAG,KAAuC;IACzD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAmB,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;AACrE,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CAAC,IAAa;IACtC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,yCAAyC;QACzC,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,KAAK,qBAAqB;YACxB,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACpD,KAAK,WAAW;YACd,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAEhE,oEAAoE;QACpE,KAAK,aAAa;YAChB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACxB,KAAK,mBAAmB;YACtB,OAAO,IAAI,CAAC,IAAI,CAAC;QACnB,KAAK,YAAY;YACf,OAAO,IAAI,CAAC,IAAI,CAAC;QAEnB,cAAc;QACd,KAAK,qBAAqB;YACxB,OAA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,IAAI,CAAC,OAAO,CAAC,CAAC;QACxB,KAAK,MAAM;YACT,OAAO,WAAW,CAAC;IACvB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import type { Positioned } from '../span/index.js';
|
|
2
|
+
import type { Name } from './name.js';
|
|
3
|
+
/**
|
|
4
|
+
* Every expression form of language.md section 9.
|
|
5
|
+
*
|
|
6
|
+
* Precedence is not a field anywhere below. It is in the shape of the tree: the
|
|
7
|
+
* parser reads the levels of 9.1 and the result is already grouped, so a later
|
|
8
|
+
* pass never has to know that `*` binds tighter than `+`. The one thing the
|
|
9
|
+
* tree does keep is the brackets a script wrote, because they are the
|
|
10
|
+
* difference between a caret under `(a < b)` and a caret under a whole line.
|
|
11
|
+
*/
|
|
12
|
+
export declare const ARITHMETIC_OPERATORS: readonly ["+", "-", "*", "/", "%"];
|
|
13
|
+
export type ArithmeticOperator = (typeof ARITHMETIC_OPERATORS)[number];
|
|
14
|
+
export declare const COMPARISON_OPERATORS: readonly ["<", "<=", ">", ">="];
|
|
15
|
+
export type ComparisonOperator = (typeof COMPARISON_OPERATORS)[number];
|
|
16
|
+
export declare const EQUALITY_OPERATORS: readonly ["==", "!="];
|
|
17
|
+
export type EqualityOperator = (typeof EQUALITY_OPERATORS)[number];
|
|
18
|
+
export declare const LOGICAL_OPERATORS: readonly ["and", "or"];
|
|
19
|
+
export type LogicalOperator = (typeof LOGICAL_OPERATORS)[number];
|
|
20
|
+
export type BinaryOperator = ArithmeticOperator | ComparisonOperator | EqualityOperator | LogicalOperator;
|
|
21
|
+
export declare const UNARY_OPERATORS: readonly ["-", "+", "not"];
|
|
22
|
+
export type UnaryOperator = (typeof UNARY_OPERATORS)[number];
|
|
23
|
+
export declare function binaryPrecedence(operator: BinaryOperator): number;
|
|
24
|
+
/**
|
|
25
|
+
* The value a number literal denotes, already read.
|
|
26
|
+
*
|
|
27
|
+
* The digit group underscores and the hexadecimal form of language.md 3.5 are
|
|
28
|
+
* resolved by the lexer, so nothing downstream reads the text a second time and
|
|
29
|
+
* nothing downstream can disagree with the lexer about what it meant.
|
|
30
|
+
*/
|
|
31
|
+
export interface NumberLiteral extends Positioned {
|
|
32
|
+
readonly kind: 'numberLiteral';
|
|
33
|
+
readonly value: number;
|
|
34
|
+
}
|
|
35
|
+
/** A string literal with its escape sequences already resolved. */
|
|
36
|
+
export interface StringLiteral extends Positioned {
|
|
37
|
+
readonly kind: 'stringLiteral';
|
|
38
|
+
readonly value: string;
|
|
39
|
+
}
|
|
40
|
+
export interface BooleanLiteral extends Positioned {
|
|
41
|
+
readonly kind: 'booleanLiteral';
|
|
42
|
+
readonly value: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The `#rrggbb` and `#rrggbbaa` forms of language.md 3.8, text and all.
|
|
46
|
+
*
|
|
47
|
+
* A named colour is not one of these. The nineteen names are ordinary globals
|
|
48
|
+
* so the standard library can add more without a grammar change, so `aqua` is a
|
|
49
|
+
* `nameReference` and the checker resolves it like any other name.
|
|
50
|
+
*
|
|
51
|
+
* The text is kept rather than four channel numbers, because the channels are
|
|
52
|
+
* the checker's reading of it and a diagnostic about a malformed colour has to
|
|
53
|
+
* quote what was written.
|
|
54
|
+
*/
|
|
55
|
+
export interface ColorLiteral extends Positioned {
|
|
56
|
+
readonly kind: 'colorLiteral';
|
|
57
|
+
readonly text: string;
|
|
58
|
+
}
|
|
59
|
+
/** `none`, the absent value of language.md section 6. */
|
|
60
|
+
export interface NoneLiteral extends Positioned {
|
|
61
|
+
readonly kind: 'noneLiteral';
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* `[1, 2, 3]`, and `[]`.
|
|
65
|
+
*
|
|
66
|
+
* An empty literal is legal here. Its element type is unknown until the checker
|
|
67
|
+
* finds an annotation or a first use, and OS2015 when it finds neither.
|
|
68
|
+
*/
|
|
69
|
+
export interface ArrayLiteral extends Positioned {
|
|
70
|
+
readonly kind: 'arrayLiteral';
|
|
71
|
+
readonly elements: readonly Expression[];
|
|
72
|
+
}
|
|
73
|
+
/** A name used as a value. Its span is the name, so it carries no child. */
|
|
74
|
+
export interface NameReference extends Positioned {
|
|
75
|
+
readonly kind: 'nameReference';
|
|
76
|
+
readonly name: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* `(expression)`.
|
|
80
|
+
*
|
|
81
|
+
* Kept rather than folded away, because both passes that point back at source
|
|
82
|
+
* need it: a diagnostic about a grouped expression underlines the brackets a
|
|
83
|
+
* reader can see, and a formatter that dropped them would turn `(a + b) * c`
|
|
84
|
+
* into something else on its first reprint. A pass that wants the value inside
|
|
85
|
+
* calls `withoutGrouping`.
|
|
86
|
+
*/
|
|
87
|
+
export interface Grouping extends Positioned {
|
|
88
|
+
readonly kind: 'grouping';
|
|
89
|
+
readonly expression: Expression;
|
|
90
|
+
}
|
|
91
|
+
export interface Unary extends Positioned {
|
|
92
|
+
readonly kind: 'unary';
|
|
93
|
+
readonly operator: UnaryOperator;
|
|
94
|
+
readonly operand: Expression;
|
|
95
|
+
}
|
|
96
|
+
export interface Binary extends Positioned {
|
|
97
|
+
readonly kind: 'binary';
|
|
98
|
+
readonly operator: BinaryOperator;
|
|
99
|
+
readonly left: Expression;
|
|
100
|
+
readonly right: Expression;
|
|
101
|
+
}
|
|
102
|
+
/** `condition ? whenTrue : whenFalse`, language.md 9.5. */
|
|
103
|
+
export interface Ternary extends Positioned {
|
|
104
|
+
readonly kind: 'ternary';
|
|
105
|
+
readonly condition: Expression;
|
|
106
|
+
readonly whenTrue: Expression;
|
|
107
|
+
readonly whenFalse: Expression;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* One argument of a call, of `study()`, of `strategy()` or of `limits()`.
|
|
111
|
+
*
|
|
112
|
+
* A label is a `Name` and not a `nameReference` because it is never resolved.
|
|
113
|
+
* It is matched against the callee's parameter list, which is what lets a
|
|
114
|
+
* reserved word stand as one (language.md 3.4).
|
|
115
|
+
*/
|
|
116
|
+
export interface Argument extends Positioned {
|
|
117
|
+
readonly kind: 'argument';
|
|
118
|
+
readonly label: Name | undefined;
|
|
119
|
+
readonly value: Expression;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* A call, with its arguments in the order they were written.
|
|
123
|
+
*
|
|
124
|
+
* Positional after named is OS3005, a check rather than a shape, so nothing is
|
|
125
|
+
* sorted on the way in and the tree keeps the order that error has to quote.
|
|
126
|
+
* The callee is an expression because `draw.box(...)` is an argument list
|
|
127
|
+
* applied to a member access, and because `f(1)(2)` has to parse before it can
|
|
128
|
+
* be told that it is not a thing OpenScript does.
|
|
129
|
+
*/
|
|
130
|
+
export interface Call extends Positioned {
|
|
131
|
+
readonly kind: 'call';
|
|
132
|
+
readonly callee: Expression;
|
|
133
|
+
readonly args: readonly Argument[];
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* `target[index]`: history when the target is a series, element access when it
|
|
137
|
+
* is an array, and the checker decides which from the target's type
|
|
138
|
+
* (language.md 9.6). There is no run-time dispatch and no third meaning.
|
|
139
|
+
*
|
|
140
|
+
* The explicit forms `history(expr, n)` and `element(arr, i)` are ordinary
|
|
141
|
+
* calls and are not this node.
|
|
142
|
+
*/
|
|
143
|
+
export interface Index extends Positioned {
|
|
144
|
+
readonly kind: 'index';
|
|
145
|
+
readonly target: Expression;
|
|
146
|
+
readonly index: Expression;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* `object.member`.
|
|
150
|
+
*
|
|
151
|
+
* A namespace read such as `bar.index` and a field of a runtime object are one
|
|
152
|
+
* shape here. Which of the two it is, and whether the member exists at all
|
|
153
|
+
* (OS2009), is the checker's answer.
|
|
154
|
+
*/
|
|
155
|
+
export interface Member extends Positioned {
|
|
156
|
+
readonly kind: 'member';
|
|
157
|
+
readonly object: Expression;
|
|
158
|
+
readonly member: Name;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* A hole where an expression was required and none was written.
|
|
162
|
+
*
|
|
163
|
+
* The parser puts one here after reporting OS1022, OS1011 or OS1015, so a file
|
|
164
|
+
* with a mistake in it still produces a tree. Everything downstream runs on
|
|
165
|
+
* broken files by definition: an editor asks for completions inside a half
|
|
166
|
+
* typed line, and a checker that stopped at the first syntax error would report
|
|
167
|
+
* one mistake per compile.
|
|
168
|
+
*
|
|
169
|
+
* The span is where the expression should have been, and is usually empty, so
|
|
170
|
+
* it never takes a caret meant for its neighbour.
|
|
171
|
+
*/
|
|
172
|
+
export interface MissingExpression extends Positioned {
|
|
173
|
+
readonly kind: 'missingExpression';
|
|
174
|
+
}
|
|
175
|
+
export type Expression = NumberLiteral | StringLiteral | BooleanLiteral | ColorLiteral | NoneLiteral | ArrayLiteral | NameReference | Grouping | Unary | Binary | Ternary | Call | Index | Member | MissingExpression;
|
|
176
|
+
/** The expression inside however many brackets were written around it. */
|
|
177
|
+
export declare function withoutGrouping(expression: Expression): Expression;
|
|
178
|
+
//# sourceMappingURL=expressions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expressions.d.ts","sourceRoot":"","sources":["../../../src/core/ast/expressions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC;;;;;;;;GAQG;AAEH,eAAO,MAAM,oBAAoB,oCAAqC,CAAC;AACvE,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvE,eAAO,MAAM,oBAAoB,iCAAkC,CAAC;AACpE,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvE,eAAO,MAAM,kBAAkB,uBAAwB,CAAC;AACxD,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnE,eAAO,MA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Q,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,SAAS,QAAQ,EAAE,CAAC;CACpC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,KAAM,SAAQ,UAAU;IACvC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,MAAO,SAAQ,UAAU;IACxC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC;CACvB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACnD,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;CACpC;AAED,MAAM,MAAM,UAAU,GAClB,aAAa,GACb,aAAa,GACb,cAAc,GACd,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,aAAa,GACb,QAAQ,GACR,KAAK,GACL,MAAM,GACN,OAAO,GACP,IAAI,GACJ,KAAK,GACL,MAAM,GACN,iBAAiB,CAAC;AAEtB,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAIlE"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every expression form of language.md section 9.
|
|
3
|
+
*
|
|
4
|
+
* Precedence is not a field anywhere below. It is in the shape of the tree: the
|
|
5
|
+
* parser reads the levels of 9.1 and the result is already grouped, so a later
|
|
6
|
+
* pass never has to know that `*` binds tighter than `+`. The one thing the
|
|
7
|
+
* tree does keep is the brackets a script wrote, because they are the
|
|
8
|
+
* difference between a caret under `(a < b)` and a caret under a whole line.
|
|
9
|
+
*/
|
|
10
|
+
export const ARITHMETIC_OPERATORS = ['+', '-', '*', '/', '%'];
|
|
11
|
+
export const COMPARISON_OPERATORS = ['<', '<=', '>', '>='];
|
|
12
|
+
export const EQUALITY_OPERATORS = ['==', '!='];
|
|
13
|
+
export const LOGICAL_OPERATORS = ['and', 'or'];
|
|
14
|
+
export const UNARY_OPERATORS = ['-', '+', 'not'];
|
|
15
|
+
/**
|
|
16
|
+
* The level each binary operator sits at in language.md 9.1, where a lower
|
|
17
|
+
* number binds more tightly.
|
|
18
|
+
*
|
|
19
|
+
* The numbers are the specification's own rather than a private scale that runs
|
|
20
|
+
* the other way, so a reader can check this table against language.md 9.1
|
|
21
|
+
* without translating it as they read. It sits next to the operators because a
|
|
22
|
+
* parser and a formatter that each kept a copy would disagree about one
|
|
23
|
+
* operator eventually, and that disagreement reaches a chart as a wrong number.
|
|
24
|
+
*/
|
|
25
|
+
const BINARY_PRECEDENCE = {
|
|
26
|
+
'*': 3,
|
|
27
|
+
'/': 3,
|
|
28
|
+
'%': 3,
|
|
29
|
+
'+': 4,
|
|
30
|
+
'-': 4,
|
|
31
|
+
'<': 5,
|
|
32
|
+
'<=': 5,
|
|
33
|
+
'>': 5,
|
|
34
|
+
'>=': 5,
|
|
35
|
+
'==': 6,
|
|
36
|
+
'!=': 6,
|
|
37
|
+
and: 7,
|
|
38
|
+
or: 8,
|
|
39
|
+
};
|
|
40
|
+
export function binaryPrecedence(operator) {
|
|
41
|
+
return BINARY_PRECEDENCE[operator];
|
|
42
|
+
}
|
|
43
|
+
/** The expression inside however many brackets were written around it. */
|
|
44
|
+
export function withoutGrouping(expression) {
|
|
45
|
+
let inner = expression;
|
|
46
|
+
while (inner.kind === 'grouping')
|
|
47
|
+
inner = inner.expression;
|
|
48
|
+
return inner;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=expressions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expressions.js","sourceRoot":"","sources":["../../../src/core/ast/expressions.ts"],"names":[],"mappings":"AAGA;;;;;;;;G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/**
|
|
4
|
+
* The three lines that describe the file rather than compute anything: the
|
|
5
|
+
* version line, the study or strategy declaration, and the limits line.
|
|
6
|
+
*
|
|
7
|
+
* All three are statements, and the tree lets them appear anywhere a statement
|
|
8
|
+
* appears. The specification calls each one a statement (4, 13.1 and 10.7), and
|
|
9
|
+
* more to the point the errors for putting one in the wrong place are OS1021,
|
|
10
|
+
* OS2007 and OS2008, which name a line and suggest a move. A tree with one slot
|
|
11
|
+
* for the declaration could not hold the second one long enough for OS2008 to
|
|
12
|
+
* say where it was, and a tree that refused a file with no declaration at all
|
|
13
|
+
* would turn OS2007 into a parse failure with nothing else checked.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* `version 1`.
|
|
17
|
+
*
|
|
18
|
+
* `version` is not a reserved word: it is an ordinary identifier to the lexer,
|
|
19
|
+
* recognised here by its position, so that a script written before the word
|
|
20
|
+
* existed keeps compiling (language.md 3.4 and 4.1).
|
|
21
|
+
*/
|
|
22
|
+
export interface VersionLine extends Positioned {
|
|
23
|
+
readonly kind: 'versionLine';
|
|
24
|
+
readonly version: NumberLiteral;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* `study("Name", ...)` or `strategy("Name", ...)`, language.md 13.1.
|
|
28
|
+
*
|
|
29
|
+
* The form is kept as the word that was written rather than as a boolean,
|
|
30
|
+
* because it is what OS2008 and OS7001 quote back to the reader, and because a
|
|
31
|
+
* later version that adds a third form adds a member here rather than a second
|
|
32
|
+
* flag.
|
|
33
|
+
*/
|
|
34
|
+
export interface ScriptDeclaration extends Positioned {
|
|
35
|
+
readonly kind: 'scriptDeclaration';
|
|
36
|
+
readonly form: 'study' | 'strategy';
|
|
37
|
+
readonly args: readonly Argument[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* `limits(loops = 50_000_000)`, language.md 10.7.
|
|
41
|
+
*
|
|
42
|
+
* Which options exist, that the values are literal numbers, and that the host
|
|
43
|
+
* is willing to run them (OS5003) are all decided later. The tree carries the
|
|
44
|
+
* arguments as written.
|
|
45
|
+
*/
|
|
46
|
+
export interface LimitsLine extends Positioned {
|
|
47
|
+
readonly kind: 'limitsLine';
|
|
48
|
+
readonly args: readonly Argument[];
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=header.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"header.d.ts","sourceRoot":"","sources":["../../../src/core/ast/header.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEhE;;;;;;;;;;;GAWG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,WAAY,SAAQ,UAAU;IAC7C,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;CACjC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACnD,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,UAAU,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,SAAS,QAAQ,EAAE,CAAC;CACpC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,UAAW,SAAQ,UAAU;IAC5C,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,SAAS,QAAQ,EAAE,CAAC;CACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"header.js","sourceRoot":"","sources":["../../../src/core/ast/header.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The syntax tree of language.md, and the one traversal over it.
|
|
3
|
+
*
|
|
4
|
+
* Types and constructors, and no parsing: the tree is what the parser produces
|
|
5
|
+
* and what the checker, the code generator and the editor's intelligence all
|
|
6
|
+
* read, so it is defined on its own and none of the four owns it.
|
|
7
|
+
*
|
|
8
|
+
* Two things here are worth knowing before reading the rest. Every node carries
|
|
9
|
+
* a `Span`, so anything the compiler says about a node has a caret. And every
|
|
10
|
+
* node is a member of one discriminated union, `AstNode`, so a pass that
|
|
11
|
+
* switches on `kind` without a default arm is told at compile time about the
|
|
12
|
+
* kinds it has not handled.
|
|
13
|
+
*/
|
|
14
|
+
export type { Name } from './name.js';
|
|
15
|
+
export type { ArrayType, NamedType, ObjectTypeName, SeriesType, TypeAnnotation, ValueTypeName, } from './annotations.js';
|
|
16
|
+
export { OBJECT_TYPE_NAMES, VALUE_TYPE_NAMES, isObjectTypeName, isValueTypeName, } from './annotations.js';
|
|
17
|
+
export type { ArithmeticOperator, Argument, ArrayLiteral, Binary, BinaryOperator, BooleanLiteral, Call, ColorLiteral, ComparisonOperator, EqualityOperator, Expression, Grouping, Index, LogicalOperator, Member, MissingExpression, NameReference, NoneLiteral, NumberLiteral, StringLiteral, Ternary, Unary, UnaryOperator, } from './expressions.js';
|
|
18
|
+
export { ARITHMETIC_OPERATORS, COMPARISON_OPERATORS, EQUALITY_OPERATORS, LOGICAL_OPERATORS, UNARY_OPERATORS, binaryPrecedence, withoutGrouping, } from './expressions.js';
|
|
19
|
+
export type { LimitsLine, ScriptDeclaration, VersionLine } from './header.js';
|
|
20
|
+
export type { Assignment, AssignmentOperator, Block, BreakStatement, ContinueStatement, ElseBranch, ExpressionStatement, ForInStatement, ForRangeStatement, IfBranch, IfStatement, ReturnStatement, Statement, SwitchCase, SwitchDefault, SwitchStatement, VarDeclaration, WhileStatement, } from './statements.js';
|
|
21
|
+
export { ASSIGNMENT_OPERATORS } from './statements.js';
|
|
22
|
+
export type { FunctionDeclaration, Parameter, Script, TopLevelItem } from './script.js';
|
|
23
|
+
export type { AstNode, NodeKind, NodeOfKind } from './node.js';
|
|
24
|
+
export { isExpression, isStatement, isTypeAnnotation, typeAnnotationText } from './node.js';
|
|
25
|
+
export type { NodeFields } from './build.js';
|
|
26
|
+
export { makeNode } from './build.js';
|
|
27
|
+
export { childrenOf } from './children.js';
|
|
28
|
+
export type { Visit, Visitor } from './walk.js';
|
|
29
|
+
export { nodeAtOffset, pathAtOffset, walk } from './walk.js';
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/ast/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,YAAY,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,YAAY,EACV,SAAS,EACT,SAAS,EACT,cAAc,EACd,UAAU,EACV,cAAc,EACd,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,kBAAkB,EAClB,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,cAAc,EACd,cAAc,EACd,IAAI,EACJ,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,UAAU,EACV,QAAQ,EACR,KAAK,EACL,eAAe,EACf,MAAM,EACN,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,aAAa,EACb,aAAa,EACb,OAAO,EACP,KAAK,EACL,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE9E,YAAY,EACV,UAAU,EACV,kBAAkB,EAClB,KAAK,EACL,cAAc,EACd,iBAAiB,EACjB,UAAU,EACV,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,eAAe,EACf,SAAS,EACT,UAAU,EACV,aAAa,EACb,eAAe,EACf,cAAc,EACd,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAExF,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE5F,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The syntax tree of language.md, and the one traversal over it.
|
|
3
|
+
*
|
|
4
|
+
* Types and constructors, and no parsing: the tree is what the parser produces
|
|
5
|
+
* and what the checker, the code generator and the editor's intelligence all
|
|
6
|
+
* read, so it is defined on its own and none of the four owns it.
|
|
7
|
+
*
|
|
8
|
+
* Two things here are worth knowing before reading the rest. Every node carries
|
|
9
|
+
* a `Span`, so anything the compiler says about a node has a caret. And every
|
|
10
|
+
* node is a member of one discriminated union, `AstNode`, so a pass that
|
|
11
|
+
* switches on `kind` without a default arm is told at compile time about the
|
|
12
|
+
* kinds it has not handled.
|
|
13
|
+
*/
|
|
14
|
+
export { OBJECT_TYPE_NAMES, VALUE_TYPE_NAMES, isObjectTypeName, isValueTypeName, } from './annotations.js';
|
|
15
|
+
export { ARITHMETIC_OPERATORS, COMPARISON_OPERATORS, EQUALITY_OPERATORS, LOGICAL_OPERATORS, UNARY_OPERATORS, binaryPrecedence, withoutGrouping, } from './expressions.js';
|
|
16
|
+
export { ASSIGNMENT_OPERATORS } from './statements.js';
|
|
17
|
+
export { isExpression, isStatement, isTypeAnnotation, typeAnnotationText } from './node.js';
|
|
18
|
+
export { makeNode } from './build.js';
|
|
19
|
+
export { childrenOf } from './children.js';
|
|
20
|
+
export { nodeAtOffset, pathAtOffset, walk } from './walk.js';
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/ast/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAYH,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AA2B1B,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAwB1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAKvD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAG5F,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Positioned } from '../span/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* A name at the place it is written rather than the place it is read.
|
|
4
|
+
*
|
|
5
|
+
* A name used as a value is a `nameReference`, which the checker resolves
|
|
6
|
+
* against a scope. Every other name in the language is this node instead: the
|
|
7
|
+
* left side of an assignment, the name a `var` introduces, a loop variable, a
|
|
8
|
+
* function's name, a parameter's name, the word after a dot, and the label of a
|
|
9
|
+
* named argument.
|
|
10
|
+
*
|
|
11
|
+
* The two are separate kinds because a pass that walks the tree collecting uses
|
|
12
|
+
* of a name must not collect the places that introduce one. With a single kind
|
|
13
|
+
* every such pass has to ask the parent what it is holding, and the pass that
|
|
14
|
+
* forgets reports OS2001 on the very name being declared.
|
|
15
|
+
*
|
|
16
|
+
* The text is not always a legal identifier: a named argument's label may be a
|
|
17
|
+
* reserved word, because a label is matched against a parameter list and is
|
|
18
|
+
* never looked up in a scope (language.md 3.4).
|
|
19
|
+
*/
|
|
20
|
+
export interface Name extends Positioned {
|
|
21
|
+
readonly kind: 'name';
|
|
22
|
+
readonly text: string;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=name.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"name.d.ts","sourceRoot":"","sources":["../../../src/core/ast/name.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,IAAK,SAAQ,UAAU;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"name.js","sourceRoot":"","sources":["../../../src/core/ast/name.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { TypeAnnotation } from './annotations.js';
|
|
2
|
+
import type { Argument, Expression } from './expressions.js';
|
|
3
|
+
import type { Name } from './name.js';
|
|
4
|
+
import type { FunctionDeclaration, Parameter, Script } from './script.js';
|
|
5
|
+
import type { Block, ElseBranch, IfBranch, Statement, SwitchCase, SwitchDefault } from './statements.js';
|
|
6
|
+
/**
|
|
7
|
+
* Every node of the tree, as one discriminated union.
|
|
8
|
+
*
|
|
9
|
+
* A pass switches on `kind` with no default arm, and the compiler names the
|
|
10
|
+
* kinds it has not handled. Three passes walk this tree, each of them added
|
|
11
|
+
* months apart, and each of them will otherwise forget a case: the shape of the
|
|
12
|
+
* union is the only thing that tells them before a user does.
|
|
13
|
+
*
|
|
14
|
+
* The union is `AstNode` rather than `Node` because an adapter that draws into
|
|
15
|
+
* a page has a `Node` of its own, and a file holding both would be one import
|
|
16
|
+
* away from a mistake that type checks.
|
|
17
|
+
*/
|
|
18
|
+
export type AstNode = Script | FunctionDeclaration | Parameter | Statement | Block | IfBranch | ElseBranch | SwitchCase | SwitchDefault | Expression | Argument | TypeAnnotation | Name;
|
|
19
|
+
export type NodeKind = AstNode['kind'];
|
|
20
|
+
/** The node type behind one kind, for a pass that indexes by kind. */
|
|
21
|
+
export type NodeOfKind<K extends NodeKind> = Extract<AstNode, {
|
|
22
|
+
readonly kind: K;
|
|
23
|
+
}>;
|
|
24
|
+
export declare function isExpression(node: AstNode): node is Expression;
|
|
25
|
+
export declare function isStatement(node: AstNode): node is Statement;
|
|
26
|
+
export declare function isTypeAnnotation(node: AstNode): node is TypeAnnotation;
|
|
27
|
+
/**
|
|
28
|
+
* The name a type annotation carries, for a diagnostic that has to quote it.
|
|
29
|
+
*
|
|
30
|
+
* OS2016 and OS2019 both put the annotation into their message, and the reader
|
|
31
|
+
* expects to see what was written rather than the outermost word of it.
|
|
32
|
+
*/
|
|
33
|
+
export declare function typeAnnotationText(annotation: TypeAnnotation): string;
|
|
34
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/core/ast/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,KAAK,EACV,KAAK,EACL,UAAU,EACV,QAAQ,EACR,SAAS,EACT,UAAU,EACV,aAAa,EACd,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,OAAO,GACf,MAAM,GACN,mBAAmB,GACnB,SAAS,GACT,SAAS,GACT,KAAK,GACL,QAAQ,GACR,UAAU,GACV,UAAU,GACV,aAAa,GACb,UAAU,GACV,QAAQ,GACR,cAAc,GACd,IAAI,CAAC;AAET,MAAM,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAEvC,sEAAsE;AACtE,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,QAAQ,IAAI,OAAO,CAAC,OAAO,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAiDpF,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,UAAU,CAE9D;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,SAAS,CAE5D;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,cAAc,CAEtE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,cAAc,GAAG,MAAM,CASrE"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The three tables below are written as a record over the kinds of each group,
|
|
3
|
+
* so a node kind added to a group without being added here does not compile.
|
|
4
|
+
* A set built from an array would accept the omission and the guard would
|
|
5
|
+
* quietly answer false for the new kind.
|
|
6
|
+
*/
|
|
7
|
+
const EXPRESSION_KINDS = {
|
|
8
|
+
numberLiteral: true,
|
|
9
|
+
stringLiteral: true,
|
|
10
|
+
booleanLiteral: true,
|
|
11
|
+
colorLiteral: true,
|
|
12
|
+
noneLiteral: true,
|
|
13
|
+
arrayLiteral: true,
|
|
14
|
+
nameReference: true,
|
|
15
|
+
grouping: true,
|
|
16
|
+
unary: true,
|
|
17
|
+
binary: true,
|
|
18
|
+
ternary: true,
|
|
19
|
+
call: true,
|
|
20
|
+
index: true,
|
|
21
|
+
member: true,
|
|
22
|
+
missingExpression: true,
|
|
23
|
+
};
|
|
24
|
+
const STATEMENT_KINDS = {
|
|
25
|
+
expressionStatement: true,
|
|
26
|
+
assignment: true,
|
|
27
|
+
varDeclaration: true,
|
|
28
|
+
ifStatement: true,
|
|
29
|
+
forRangeStatement: true,
|
|
30
|
+
forInStatement: true,
|
|
31
|
+
whileStatement: true,
|
|
32
|
+
switchStatement: true,
|
|
33
|
+
breakStatement: true,
|
|
34
|
+
continueStatement: true,
|
|
35
|
+
returnStatement: true,
|
|
36
|
+
versionLine: true,
|
|
37
|
+
scriptDeclaration: true,
|
|
38
|
+
limitsLine: true,
|
|
39
|
+
};
|
|
40
|
+
const TYPE_ANNOTATION_KINDS = {
|
|
41
|
+
namedType: true,
|
|
42
|
+
seriesType: true,
|
|
43
|
+
arrayType: true,
|
|
44
|
+
};
|
|
45
|
+
export function isExpression(node) {
|
|
46
|
+
return Object.hasOwn(EXPRESSION_KINDS, node.kind);
|
|
47
|
+
}
|
|
48
|
+
export function isStatement(node) {
|
|
49
|
+
return Object.hasOwn(STATEMENT_KINDS, node.kind);
|
|
50
|
+
}
|
|
51
|
+
export function isTypeAnnotation(node) {
|
|
52
|
+
return Object.hasOwn(TYPE_ANNOTATION_KINDS, node.kind);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The name a type annotation carries, for a diagnostic that has to quote it.
|
|
56
|
+
*
|
|
57
|
+
* OS2016 and OS2019 both put the annotation into their message, and the reader
|
|
58
|
+
* expects to see what was written rather than the outermost word of it.
|
|
59
|
+
*/
|
|
60
|
+
export function typeAnnotationText(annotation) {
|
|
61
|
+
switch (annotation.kind) {
|
|
62
|
+
case 'namedType':
|
|
63
|
+
return annotation.name;
|
|
64
|
+
case 'seriesType':
|
|
65
|
+
return `series ${typeAnnotationText(annotation.element)}`;
|
|
66
|
+
case 'arrayType':
|
|
67
|
+
return `array<${typeAnnotationText(annotation.element)}>`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../../src/core/ast/node.ts"],"names":[],"mappings":"AA6CA;;;;;GAKG;AACH,MAAM,gBAAgB,GAA+C;IACnE,aAAa,EAAE,IAAI;IACnB,aAAa,EAAE,IAAI;IACnB,cAAc,EAAE,IAAI;IACpB,YAAY,EAAE,IAAI;IAClB,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,IAAI;IAClB,aAAa,EAAE,IAAI;IACnB,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;IACZ,OAAO,EAAE,IAAI;IACb,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;IACZ,iBAAiB,EAAE,IAAI;CACxB,CAAC;AAEF,MAAM,eAAe,GAA8C;IACjE,mBAAmB,EAAE,IAAI;IACzB,UAAU,EAAE,IAAI;IAChB,cAAc,EAAE,IAAI;IACpB,WAAW,EAAE,IAAI;IACjB,iBAAiB,EAAE,IAAI;IACvB,cAAc,EAAE,IAAI;IACpB,cAAc,EAAE,IAAI;IACpB,eAAe,EAAE,IAAI;IACrB,cAAc,EAAE,IAAI;IACpB,iBAAiB,EAAE,IAAI;IACvB,eAAe,EAAE,IAAI;IACrB,WAAW,EAAE,IAAI;IACjB,iBAAiB,EAAE,IAAI;IACvB,UAAU,EAAE,IAAI;CACjB,CAAC;AAE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