@rsconcept/domain 1.0.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 +21 -0
- package/README.md +55 -0
- package/dist/cctext/index.d.ts +1 -0
- package/dist/cctext/index.js +42 -0
- package/dist/cctext/index.js.map +1 -0
- package/dist/cctext/language-api.d.ts +43 -0
- package/dist/cctext/language-api.js +252 -0
- package/dist/cctext/language-api.js.map +1 -0
- package/dist/cctext/language.d.ts +58 -0
- package/dist/cctext/language.js +44 -0
- package/dist/cctext/language.js.map +1 -0
- package/dist/graph/graph.d.ts +62 -0
- package/dist/graph/graph.js +385 -0
- package/dist/graph/graph.js.map +1 -0
- package/dist/graph/index.d.ts +1 -0
- package/dist/graph/index.js +384 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +5851 -0
- package/dist/index.js.map +1 -0
- package/dist/library/folder-tree.d.ts +32 -0
- package/dist/library/folder-tree.js +136 -0
- package/dist/library/folder-tree.js.map +1 -0
- package/dist/library/index.d.ts +17 -0
- package/dist/library/index.js +2800 -0
- package/dist/library/index.js.map +1 -0
- package/dist/library/library-api.d.ts +6 -0
- package/dist/library/library-api.js +13 -0
- package/dist/library/library-api.js.map +1 -0
- package/dist/library/library.d.ts +56 -0
- package/dist/library/library.js +23 -0
- package/dist/library/library.js.map +1 -0
- package/dist/library/oss-api.d.ts +47 -0
- package/dist/library/oss-api.js +1105 -0
- package/dist/library/oss-api.js.map +1 -0
- package/dist/library/oss-layout-api.d.ts +36 -0
- package/dist/library/oss-layout-api.js +330 -0
- package/dist/library/oss-layout-api.js.map +1 -0
- package/dist/library/oss-layout.d.ts +25 -0
- package/dist/library/oss-layout.js +1 -0
- package/dist/library/oss-layout.js.map +1 -0
- package/dist/library/oss.d.ts +136 -0
- package/dist/library/oss.js +30 -0
- package/dist/library/oss.js.map +1 -0
- package/dist/library/rsengine.d.ts +116 -0
- package/dist/library/rsengine.js +2604 -0
- package/dist/library/rsengine.js.map +1 -0
- package/dist/library/rsform-api.d.ts +74 -0
- package/dist/library/rsform-api.js +879 -0
- package/dist/library/rsform-api.js.map +1 -0
- package/dist/library/rsform.d.ts +206 -0
- package/dist/library/rsform.js +32 -0
- package/dist/library/rsform.js.map +1 -0
- package/dist/library/rsmodel-api.d.ts +43 -0
- package/dist/library/rsmodel-api.js +836 -0
- package/dist/library/rsmodel-api.js.map +1 -0
- package/dist/library/rsmodel.d.ts +52 -0
- package/dist/library/rsmodel.js +25 -0
- package/dist/library/rsmodel.js.map +1 -0
- package/dist/library/structure-planner.d.ts +33 -0
- package/dist/library/structure-planner.js +481 -0
- package/dist/library/structure-planner.js.map +1 -0
- package/dist/parsing/ast.d.ts +49 -0
- package/dist/parsing/ast.js +93 -0
- package/dist/parsing/ast.js.map +1 -0
- package/dist/parsing/index.d.ts +3 -0
- package/dist/parsing/index.js +141 -0
- package/dist/parsing/index.js.map +1 -0
- package/dist/parsing/lezer-tree.d.ts +13 -0
- package/dist/parsing/lezer-tree.js +50 -0
- package/dist/parsing/lezer-tree.js.map +1 -0
- package/dist/rslang/api.d.ts +53 -0
- package/dist/rslang/api.js +846 -0
- package/dist/rslang/api.js.map +1 -0
- package/dist/rslang/ast-annotations.d.ts +18 -0
- package/dist/rslang/ast-annotations.js +56 -0
- package/dist/rslang/ast-annotations.js.map +1 -0
- package/dist/rslang/error.d.ts +85 -0
- package/dist/rslang/error.js +159 -0
- package/dist/rslang/error.js.map +1 -0
- package/dist/rslang/eval/calculator.d.ts +43 -0
- package/dist/rslang/eval/calculator.js +1639 -0
- package/dist/rslang/eval/calculator.js.map +1 -0
- package/dist/rslang/eval/evaluation-cache.d.ts +36 -0
- package/dist/rslang/eval/evaluation-cache.js +310 -0
- package/dist/rslang/eval/evaluation-cache.js.map +1 -0
- package/dist/rslang/eval/evaluator.d.ts +70 -0
- package/dist/rslang/eval/evaluator.js +1514 -0
- package/dist/rslang/eval/evaluator.js.map +1 -0
- package/dist/rslang/eval/value-api.d.ts +48 -0
- package/dist/rslang/eval/value-api.js +490 -0
- package/dist/rslang/eval/value-api.js.map +1 -0
- package/dist/rslang/eval/value.d.ts +36 -0
- package/dist/rslang/eval/value.js +118 -0
- package/dist/rslang/eval/value.js.map +1 -0
- package/dist/rslang/index.d.ts +17 -0
- package/dist/rslang/index.js +4314 -0
- package/dist/rslang/index.js.map +1 -0
- package/dist/rslang/labels.d.ts +16 -0
- package/dist/rslang/labels.js +315 -0
- package/dist/rslang/labels.js.map +1 -0
- package/dist/rslang/parser/expression-generator.d.ts +10 -0
- package/dist/rslang/parser/expression-generator.js +451 -0
- package/dist/rslang/parser/expression-generator.js.map +1 -0
- package/dist/rslang/parser/normalize.d.ts +11 -0
- package/dist/rslang/parser/normalize.js +507 -0
- package/dist/rslang/parser/normalize.js.map +1 -0
- package/dist/rslang/parser/parser.d.ts +5 -0
- package/dist/rslang/parser/parser.js +24 -0
- package/dist/rslang/parser/parser.js.map +1 -0
- package/dist/rslang/parser/parser.terms.d.ts +42 -0
- package/dist/rslang/parser/parser.terms.js +84 -0
- package/dist/rslang/parser/parser.terms.js.map +1 -0
- package/dist/rslang/parser/syntax-errors.d.ts +11 -0
- package/dist/rslang/parser/syntax-errors.js +403 -0
- package/dist/rslang/parser/syntax-errors.js.map +1 -0
- package/dist/rslang/parser/token.d.ts +79 -0
- package/dist/rslang/parser/token.js +95 -0
- package/dist/rslang/parser/token.js.map +1 -0
- package/dist/rslang/semantic/analyzer.d.ts +39 -0
- package/dist/rslang/semantic/analyzer.js +2604 -0
- package/dist/rslang/semantic/analyzer.js.map +1 -0
- package/dist/rslang/semantic/arguments-extractor.d.ts +42 -0
- package/dist/rslang/semantic/arguments-extractor.js +366 -0
- package/dist/rslang/semantic/arguments-extractor.js.map +1 -0
- package/dist/rslang/semantic/type-auditor.d.ts +73 -0
- package/dist/rslang/semantic/type-auditor.js +1570 -0
- package/dist/rslang/semantic/type-auditor.js.map +1 -0
- package/dist/rslang/semantic/typification-api.d.ts +27 -0
- package/dist/rslang/semantic/typification-api.js +320 -0
- package/dist/rslang/semantic/typification-api.js.map +1 -0
- package/dist/rslang/semantic/typification-parser.d.ts +12 -0
- package/dist/rslang/semantic/typification-parser.js +226 -0
- package/dist/rslang/semantic/typification-parser.js.map +1 -0
- package/dist/rslang/semantic/typification.d.ts +119 -0
- package/dist/rslang/semantic/typification.js +74 -0
- package/dist/rslang/semantic/typification.js.map +1 -0
- package/dist/rslang/semantic/value-auditor.d.ts +43 -0
- package/dist/rslang/semantic/value-auditor.js +523 -0
- package/dist/rslang/semantic/value-auditor.js.map +1 -0
- package/dist/rslang/semantic/value-class.d.ts +10 -0
- package/dist/rslang/semantic/value-class.js +9 -0
- package/dist/rslang/semantic/value-class.js.map +1 -0
- package/dist/rslang/typification-graph.d.ts +33 -0
- package/dist/rslang/typification-graph.js +311 -0
- package/dist/rslang/typification-graph.js.map +1 -0
- package/dist/shared/branded.d.ts +7 -0
- package/dist/shared/branded.js +1 -0
- package/dist/shared/branded.js.map +1 -0
- package/dist/shared/hash.d.ts +6 -0
- package/dist/shared/hash.js +18 -0
- package/dist/shared/hash.js.map +1 -0
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/index.js +18 -0
- package/dist/shared/index.js.map +1 -0
- package/package.json +184 -0
- package/src/cctext/index.ts +9 -0
- package/src/cctext/language-api.test.ts +149 -0
- package/src/cctext/language-api.ts +285 -0
- package/src/cctext/language.ts +80 -0
- package/src/graph/graph.test.ts +392 -0
- package/src/graph/graph.ts +433 -0
- package/src/graph/index.ts +1 -0
- package/src/index.ts +96 -0
- package/src/library/folder-tree.test.ts +47 -0
- package/src/library/folder-tree.ts +156 -0
- package/src/library/index.ts +46 -0
- package/src/library/library-api.test.ts +32 -0
- package/src/library/library-api.ts +11 -0
- package/src/library/library.ts +61 -0
- package/src/library/oss-api.ts +449 -0
- package/src/library/oss-layout-api.ts +377 -0
- package/src/library/oss-layout.ts +27 -0
- package/src/library/oss.ts +150 -0
- package/src/library/rsengine.ts +593 -0
- package/src/library/rsform-api.ts +533 -0
- package/src/library/rsform.ts +228 -0
- package/src/library/rsmodel-api.ts +340 -0
- package/src/library/rsmodel.ts +50 -0
- package/src/library/structure-planner.ts +143 -0
- package/src/parsing/ast.ts +136 -0
- package/src/parsing/index.ts +15 -0
- package/src/parsing/lezer-tree.ts +69 -0
- package/src/rslang/api.test.ts +116 -0
- package/src/rslang/api.ts +183 -0
- package/src/rslang/ast-annotations.ts +70 -0
- package/src/rslang/error.ts +129 -0
- package/src/rslang/eval/calculator.test.ts +124 -0
- package/src/rslang/eval/calculator.ts +121 -0
- package/src/rslang/eval/evaluation-cache.ts +257 -0
- package/src/rslang/eval/evaluator.test.ts +352 -0
- package/src/rslang/eval/evaluator.ts +935 -0
- package/src/rslang/eval/value-api.test.ts +105 -0
- package/src/rslang/eval/value-api.ts +444 -0
- package/src/rslang/eval/value.ts +102 -0
- package/src/rslang/index.ts +23 -0
- package/src/rslang/labels.ts +191 -0
- package/src/rslang/parser/expression-generator.test.ts +100 -0
- package/src/rslang/parser/expression-generator.ts +466 -0
- package/src/rslang/parser/normalize.test.ts +99 -0
- package/src/rslang/parser/normalize.ts +462 -0
- package/src/rslang/parser/parser.terms.ts +42 -0
- package/src/rslang/parser/parser.test.ts +153 -0
- package/src/rslang/parser/parser.ts +20 -0
- package/src/rslang/parser/rslang.grammar +251 -0
- package/src/rslang/parser/syntax-errors.ts +209 -0
- package/src/rslang/parser/token.ts +106 -0
- package/src/rslang/semantic/analyzer.test.ts +59 -0
- package/src/rslang/semantic/analyzer.ts +179 -0
- package/src/rslang/semantic/arguments-extractor.ts +327 -0
- package/src/rslang/semantic/type-auditor.test.ts +326 -0
- package/src/rslang/semantic/type-auditor.ts +1049 -0
- package/src/rslang/semantic/typification-api.test.ts +46 -0
- package/src/rslang/semantic/typification-api.ts +321 -0
- package/src/rslang/semantic/typification-parser.test.ts +50 -0
- package/src/rslang/semantic/typification-parser.ts +220 -0
- package/src/rslang/semantic/typification.ts +180 -0
- package/src/rslang/semantic/value-auditor.test.ts +206 -0
- package/src/rslang/semantic/value-auditor.ts +332 -0
- package/src/rslang/semantic/value-class.ts +11 -0
- package/src/rslang/typification-graph.ts +155 -0
- package/src/shared/branded.ts +6 -0
- package/src/shared/hash.ts +17 -0
- package/src/shared/index.ts +2 -0
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module: Transforming AST to a simple form.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { type AstNode, visitAstDFS } from '../../parsing';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
Arguments,
|
|
9
|
+
BigPr,
|
|
10
|
+
Bool,
|
|
11
|
+
Boolean,
|
|
12
|
+
Card,
|
|
13
|
+
Debool,
|
|
14
|
+
Declaration,
|
|
15
|
+
Declarative,
|
|
16
|
+
EmptySet,
|
|
17
|
+
Enumeration,
|
|
18
|
+
Expr_enum_min2,
|
|
19
|
+
Expression,
|
|
20
|
+
Filter,
|
|
21
|
+
Filter_expression,
|
|
22
|
+
Function,
|
|
23
|
+
Function_decl,
|
|
24
|
+
Global,
|
|
25
|
+
Imp_blocks,
|
|
26
|
+
Imperative,
|
|
27
|
+
Integer,
|
|
28
|
+
IntegerSet,
|
|
29
|
+
Local,
|
|
30
|
+
Logic,
|
|
31
|
+
Logic_binary,
|
|
32
|
+
Logic_predicates,
|
|
33
|
+
Logic_quantor,
|
|
34
|
+
Logic_unary,
|
|
35
|
+
Predicate,
|
|
36
|
+
PrefixD,
|
|
37
|
+
Radical,
|
|
38
|
+
Recursion,
|
|
39
|
+
Red,
|
|
40
|
+
Setexpr,
|
|
41
|
+
Setexpr_binary,
|
|
42
|
+
SmallPr,
|
|
43
|
+
Tuple,
|
|
44
|
+
Variable,
|
|
45
|
+
Variable_pack
|
|
46
|
+
} from './parser.terms';
|
|
47
|
+
import { TokenID } from './token';
|
|
48
|
+
|
|
49
|
+
/** Normalizes AST to a simple form. */
|
|
50
|
+
export function normalizeAST(ast: AstNode, input: string) {
|
|
51
|
+
visitAstDFS(ast, node => normalizeNode(node, input));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ====== Internals =========
|
|
55
|
+
const idRecord: Record<number, TokenID> = {
|
|
56
|
+
[Global]: TokenID.ID_GLOBAL,
|
|
57
|
+
[Local]: TokenID.ID_LOCAL,
|
|
58
|
+
[Radical]: TokenID.ID_RADICAL,
|
|
59
|
+
[Function]: TokenID.ID_FUNCTION,
|
|
60
|
+
[Predicate]: TokenID.ID_PREDICATE,
|
|
61
|
+
[Integer]: TokenID.LIT_INTEGER,
|
|
62
|
+
[EmptySet]: TokenID.LIT_EMPTYSET,
|
|
63
|
+
[IntegerSet]: TokenID.LIT_WHOLE_NUMBERS,
|
|
64
|
+
|
|
65
|
+
[Boolean]: TokenID.BOOLEAN,
|
|
66
|
+
|
|
67
|
+
[BigPr]: TokenID.BIGPR,
|
|
68
|
+
[SmallPr]: TokenID.SMALLPR,
|
|
69
|
+
[Filter]: TokenID.FILTER,
|
|
70
|
+
|
|
71
|
+
[Bool]: TokenID.BOOL,
|
|
72
|
+
[Debool]: TokenID.DEBOOL,
|
|
73
|
+
[Red]: TokenID.REDUCE,
|
|
74
|
+
[Card]: TokenID.CARD,
|
|
75
|
+
|
|
76
|
+
[Enumeration]: TokenID.NT_ENUMERATION,
|
|
77
|
+
[Tuple]: TokenID.NT_TUPLE,
|
|
78
|
+
[Arguments]: TokenID.NT_ARGUMENTS,
|
|
79
|
+
[Declaration]: TokenID.NT_ARG_DECL,
|
|
80
|
+
[Function_decl]: TokenID.NT_FUNC_DEFINITION,
|
|
81
|
+
[Variable_pack]: TokenID.NT_ENUM_DECL,
|
|
82
|
+
[Declarative]: TokenID.NT_DECLARATIVE_EXPR,
|
|
83
|
+
[Imperative]: TokenID.NT_IMPERATIVE_EXPR
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
function normalizeNode(node: AstNode, input: string) {
|
|
87
|
+
if (node.hasError) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
switch (node.typeID) {
|
|
91
|
+
case 0:
|
|
92
|
+
return;
|
|
93
|
+
|
|
94
|
+
case Expression:
|
|
95
|
+
promoteSingleChild(node);
|
|
96
|
+
return;
|
|
97
|
+
|
|
98
|
+
case EmptySet:
|
|
99
|
+
case IntegerSet:
|
|
100
|
+
node.typeID = idRecord[node.typeID];
|
|
101
|
+
clearData(node);
|
|
102
|
+
return;
|
|
103
|
+
|
|
104
|
+
case Integer:
|
|
105
|
+
node.typeID = idRecord[node.typeID];
|
|
106
|
+
node.data.dataType = 'number';
|
|
107
|
+
node.data.value = Number(input.slice(node.from, node.to));
|
|
108
|
+
return;
|
|
109
|
+
|
|
110
|
+
case Function:
|
|
111
|
+
case Predicate:
|
|
112
|
+
case Global:
|
|
113
|
+
case Local:
|
|
114
|
+
case Radical:
|
|
115
|
+
case Integer:
|
|
116
|
+
node.typeID = idRecord[node.typeID];
|
|
117
|
+
node.data.dataType = 'string';
|
|
118
|
+
node.data.value = input.slice(node.from, node.to);
|
|
119
|
+
return;
|
|
120
|
+
|
|
121
|
+
case Boolean:
|
|
122
|
+
node.typeID = idRecord[node.typeID];
|
|
123
|
+
if (node.children.length === 4) {
|
|
124
|
+
node.children = [node.children[2]];
|
|
125
|
+
} else {
|
|
126
|
+
node.children = [node.children[1]];
|
|
127
|
+
}
|
|
128
|
+
clearData(node);
|
|
129
|
+
return;
|
|
130
|
+
|
|
131
|
+
case Filter:
|
|
132
|
+
case BigPr:
|
|
133
|
+
case SmallPr:
|
|
134
|
+
node.typeID = idRecord[node.typeID];
|
|
135
|
+
node.data.dataType = 'string[]';
|
|
136
|
+
node.data.value = parseIndex(input.slice(node.from + 2, node.to));
|
|
137
|
+
return;
|
|
138
|
+
|
|
139
|
+
case Red:
|
|
140
|
+
case Debool:
|
|
141
|
+
case Bool:
|
|
142
|
+
case Card:
|
|
143
|
+
node.typeID = idRecord[node.typeID];
|
|
144
|
+
clearData(node);
|
|
145
|
+
return;
|
|
146
|
+
|
|
147
|
+
case Function_decl:
|
|
148
|
+
node.typeID = idRecord[node.typeID];
|
|
149
|
+
clearData(node);
|
|
150
|
+
node.children = [node.children[1], node.children[3]];
|
|
151
|
+
return;
|
|
152
|
+
case Declaration:
|
|
153
|
+
node.typeID = idRecord[node.typeID];
|
|
154
|
+
clearData(node);
|
|
155
|
+
node.children = [node.children[0], node.children[2]];
|
|
156
|
+
return;
|
|
157
|
+
|
|
158
|
+
case Arguments:
|
|
159
|
+
node.typeID = idRecord[node.typeID];
|
|
160
|
+
clearData(node);
|
|
161
|
+
if (node.children.length === 3) {
|
|
162
|
+
processLeftEnum(node);
|
|
163
|
+
}
|
|
164
|
+
return;
|
|
165
|
+
|
|
166
|
+
case Expr_enum_min2:
|
|
167
|
+
processLeftEnum(node);
|
|
168
|
+
return;
|
|
169
|
+
|
|
170
|
+
case Setexpr:
|
|
171
|
+
if (node.children.length === 1) {
|
|
172
|
+
promoteSingleChild(node);
|
|
173
|
+
} else if (node.children.length === 4) {
|
|
174
|
+
processTextFunction(node);
|
|
175
|
+
}
|
|
176
|
+
return;
|
|
177
|
+
|
|
178
|
+
case Tuple:
|
|
179
|
+
case Enumeration:
|
|
180
|
+
node.typeID = idRecord[node.typeID];
|
|
181
|
+
clearData(node);
|
|
182
|
+
if (node.children[1].typeID === Expr_enum_min2) {
|
|
183
|
+
for (const child of node.children[1].children) {
|
|
184
|
+
child.parent = node;
|
|
185
|
+
}
|
|
186
|
+
node.children = node.children[1].children;
|
|
187
|
+
} else {
|
|
188
|
+
node.children = [node.children[1]];
|
|
189
|
+
}
|
|
190
|
+
return;
|
|
191
|
+
|
|
192
|
+
case Logic_binary:
|
|
193
|
+
case Logic_predicates:
|
|
194
|
+
case Setexpr_binary:
|
|
195
|
+
if (node.children[0].data.value === '(') {
|
|
196
|
+
processParenthesis(node);
|
|
197
|
+
} else {
|
|
198
|
+
clearData(node);
|
|
199
|
+
node.typeID = symbolToToken(node.children[1].data.value as string);
|
|
200
|
+
if (node.typeID === TokenID.DECART) {
|
|
201
|
+
processDecartChildren(node);
|
|
202
|
+
} else {
|
|
203
|
+
node.children = [node.children[0], node.children[2]];
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return;
|
|
207
|
+
|
|
208
|
+
case Filter_expression:
|
|
209
|
+
processFilter(node);
|
|
210
|
+
return;
|
|
211
|
+
|
|
212
|
+
case Logic:
|
|
213
|
+
if (node.children[0].data.value === '(') {
|
|
214
|
+
processParenthesis(node);
|
|
215
|
+
} else {
|
|
216
|
+
promoteSingleChild(node);
|
|
217
|
+
}
|
|
218
|
+
return;
|
|
219
|
+
|
|
220
|
+
case Logic_unary:
|
|
221
|
+
if (node.children[0].data.value === '¬') {
|
|
222
|
+
clearData(node);
|
|
223
|
+
node.typeID = TokenID.LOGIC_NOT;
|
|
224
|
+
node.children = [node.children[1]];
|
|
225
|
+
} else if (node.children[0].typeID === TokenID.ID_PREDICATE) {
|
|
226
|
+
processTextFunction(node);
|
|
227
|
+
} else {
|
|
228
|
+
promoteSingleChild(node);
|
|
229
|
+
}
|
|
230
|
+
return;
|
|
231
|
+
|
|
232
|
+
case Logic_quantor:
|
|
233
|
+
clearData(node);
|
|
234
|
+
node.typeID = symbolToToken(node.children[0].data.value as string);
|
|
235
|
+
node.children = [node.children[1], node.children[3], node.children[4]];
|
|
236
|
+
return;
|
|
237
|
+
|
|
238
|
+
case Variable:
|
|
239
|
+
convertTupleDeclaration(node.children[0]);
|
|
240
|
+
promoteSingleChild(node);
|
|
241
|
+
return;
|
|
242
|
+
|
|
243
|
+
case Variable_pack:
|
|
244
|
+
if (node.children.length === 1) {
|
|
245
|
+
promoteSingleChild(node);
|
|
246
|
+
} else {
|
|
247
|
+
node.typeID = idRecord[node.typeID];
|
|
248
|
+
processLeftEnum(node);
|
|
249
|
+
}
|
|
250
|
+
return;
|
|
251
|
+
|
|
252
|
+
case Declarative:
|
|
253
|
+
node.typeID = idRecord[node.typeID];
|
|
254
|
+
clearData(node);
|
|
255
|
+
if (node.children[0].typeID === PrefixD) {
|
|
256
|
+
node.children = [node.children[2], node.children[4], node.children[6]];
|
|
257
|
+
} else {
|
|
258
|
+
node.children = [node.children[1], node.children[3], node.children[5]];
|
|
259
|
+
}
|
|
260
|
+
return;
|
|
261
|
+
|
|
262
|
+
case Imp_blocks:
|
|
263
|
+
if (node.children.length === 1) {
|
|
264
|
+
if (node.parent?.typeID === Imp_blocks) {
|
|
265
|
+
promoteSingleChild(node);
|
|
266
|
+
}
|
|
267
|
+
} else {
|
|
268
|
+
processLeftEnum(node);
|
|
269
|
+
}
|
|
270
|
+
return;
|
|
271
|
+
|
|
272
|
+
case Imperative:
|
|
273
|
+
node.typeID = idRecord[node.typeID];
|
|
274
|
+
clearData(node);
|
|
275
|
+
for (const child of node.children[4].children) {
|
|
276
|
+
child.parent = node;
|
|
277
|
+
}
|
|
278
|
+
node.children = [node.children[2], ...node.children[4].children];
|
|
279
|
+
return;
|
|
280
|
+
|
|
281
|
+
case Recursion:
|
|
282
|
+
if (node.children.length > 9) {
|
|
283
|
+
node.typeID = TokenID.NT_RECURSIVE_FULL;
|
|
284
|
+
node.children = [node.children[2], node.children[4], node.children[6], node.children[8]];
|
|
285
|
+
} else {
|
|
286
|
+
node.typeID = TokenID.NT_RECURSIVE_SHORT;
|
|
287
|
+
node.children = [node.children[2], node.children[4], node.children[6]];
|
|
288
|
+
}
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function convertTupleDeclaration(node: AstNode) {
|
|
294
|
+
if (node.typeID !== TokenID.NT_TUPLE) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
node.typeID = TokenID.NT_TUPLE_DECL;
|
|
298
|
+
for (const child of node.children) {
|
|
299
|
+
convertTupleDeclaration(child);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function clearData(node: AstNode) {
|
|
304
|
+
node.data.value = null;
|
|
305
|
+
node.data.dataType = 'null';
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function promoteSingleChild(node: AstNode, index: number = 0) {
|
|
309
|
+
for (const child of node.children[index].children) {
|
|
310
|
+
child.parent = node;
|
|
311
|
+
}
|
|
312
|
+
node.typeID = node.children[index].typeID;
|
|
313
|
+
node.data = node.children[index].data;
|
|
314
|
+
node.parenthesis = node.children[index].parenthesis;
|
|
315
|
+
node.children = node.children[index].children;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function parseIndex(text: string): string[] {
|
|
319
|
+
return text.split(',');
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function symbolToToken(symbol: string): TokenID {
|
|
323
|
+
switch (symbol) {
|
|
324
|
+
case '+':
|
|
325
|
+
return TokenID.PLUS;
|
|
326
|
+
case '-':
|
|
327
|
+
return TokenID.MINUS;
|
|
328
|
+
case '*':
|
|
329
|
+
return TokenID.MULTIPLY;
|
|
330
|
+
|
|
331
|
+
case '∪':
|
|
332
|
+
return TokenID.SET_UNION;
|
|
333
|
+
case '\\':
|
|
334
|
+
return TokenID.SET_MINUS;
|
|
335
|
+
case '∆':
|
|
336
|
+
return TokenID.SET_SYMMETRIC_MINUS;
|
|
337
|
+
case '∩':
|
|
338
|
+
return TokenID.SET_INTERSECTION;
|
|
339
|
+
case '×':
|
|
340
|
+
return TokenID.DECART;
|
|
341
|
+
|
|
342
|
+
case '∈':
|
|
343
|
+
return TokenID.SET_IN;
|
|
344
|
+
case '∉':
|
|
345
|
+
return TokenID.SET_NOT_IN;
|
|
346
|
+
case '⊆':
|
|
347
|
+
return TokenID.SUBSET_OR_EQ;
|
|
348
|
+
case '⊄':
|
|
349
|
+
return TokenID.NOT_SUBSET;
|
|
350
|
+
case '⊂':
|
|
351
|
+
return TokenID.SUBSET;
|
|
352
|
+
|
|
353
|
+
case '>':
|
|
354
|
+
return TokenID.GREATER;
|
|
355
|
+
case '≥':
|
|
356
|
+
return TokenID.GREATER_OR_EQ;
|
|
357
|
+
case '<':
|
|
358
|
+
return TokenID.LESSER;
|
|
359
|
+
case '≤':
|
|
360
|
+
return TokenID.LESSER_OR_EQ;
|
|
361
|
+
|
|
362
|
+
case '≠':
|
|
363
|
+
return TokenID.NOTEQUAL;
|
|
364
|
+
case '=':
|
|
365
|
+
return TokenID.EQUAL;
|
|
366
|
+
|
|
367
|
+
case ':∈':
|
|
368
|
+
return TokenID.ITERATE;
|
|
369
|
+
case ':=':
|
|
370
|
+
return TokenID.ASSIGN;
|
|
371
|
+
|
|
372
|
+
case '¬':
|
|
373
|
+
return TokenID.LOGIC_NOT;
|
|
374
|
+
|
|
375
|
+
case '⇔':
|
|
376
|
+
return TokenID.LOGIC_EQUIVALENT;
|
|
377
|
+
case '⇒':
|
|
378
|
+
return TokenID.LOGIC_IMPLICATION;
|
|
379
|
+
case '∨':
|
|
380
|
+
return TokenID.LOGIC_OR;
|
|
381
|
+
case '&':
|
|
382
|
+
return TokenID.LOGIC_AND;
|
|
383
|
+
|
|
384
|
+
case '∀':
|
|
385
|
+
return TokenID.QUANTOR_UNIVERSAL;
|
|
386
|
+
case '∃':
|
|
387
|
+
return TokenID.QUANTOR_EXISTS;
|
|
388
|
+
}
|
|
389
|
+
return TokenID.ERROR;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function processParenthesis(node: AstNode) {
|
|
393
|
+
promoteSingleChild(node, 1);
|
|
394
|
+
node.parenthesis = true;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function processLeftEnum(node: AstNode) {
|
|
398
|
+
if (node.children[0].typeID === node.typeID) {
|
|
399
|
+
for (const child of node.children[0].children) {
|
|
400
|
+
child.parent = node;
|
|
401
|
+
}
|
|
402
|
+
node.children = [...node.children[0].children, node.children[2]];
|
|
403
|
+
} else {
|
|
404
|
+
node.children = [node.children[0], node.children[2]];
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function processDecartChildren(node: AstNode) {
|
|
409
|
+
const newChildren: AstNode[] = [];
|
|
410
|
+
if (node.children[0].typeID === TokenID.DECART && !node.children[0].parenthesis) {
|
|
411
|
+
for (const child of node.children[0].children) {
|
|
412
|
+
child.parent = node;
|
|
413
|
+
newChildren.push(child);
|
|
414
|
+
}
|
|
415
|
+
} else {
|
|
416
|
+
newChildren.push(node.children[0]);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (node.children[2].typeID === TokenID.DECART && !node.children[2].parenthesis) {
|
|
420
|
+
for (const child of node.children[2].children) {
|
|
421
|
+
child.parent = node;
|
|
422
|
+
newChildren.push(child);
|
|
423
|
+
}
|
|
424
|
+
} else {
|
|
425
|
+
newChildren.push(node.children[2]);
|
|
426
|
+
}
|
|
427
|
+
node.children = newChildren;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function processTextFunction(node: AstNode) {
|
|
431
|
+
if (node.children[0].typeID === TokenID.ID_FUNCTION || node.children[0].typeID === TokenID.ID_PREDICATE) {
|
|
432
|
+
node.typeID = TokenID.NT_FUNC_CALL;
|
|
433
|
+
clearData(node);
|
|
434
|
+
if (node.children[2].typeID === Expr_enum_min2) {
|
|
435
|
+
for (const child of node.children[2].children) {
|
|
436
|
+
child.parent = node;
|
|
437
|
+
}
|
|
438
|
+
node.children = [node.children[0], ...node.children[2].children];
|
|
439
|
+
} else {
|
|
440
|
+
node.children = [node.children[0], node.children[2]];
|
|
441
|
+
}
|
|
442
|
+
} else {
|
|
443
|
+
node.typeID = node.children[0].typeID;
|
|
444
|
+
node.data = node.children[0].data;
|
|
445
|
+
node.children = [node.children[2]];
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function processFilter(node: AstNode) {
|
|
450
|
+
const children: AstNode[] = [];
|
|
451
|
+
if (node.children[2].typeID === Expr_enum_min2) {
|
|
452
|
+
for (const child of node.children[2].children) {
|
|
453
|
+
child.parent = node;
|
|
454
|
+
children.push(child);
|
|
455
|
+
}
|
|
456
|
+
} else {
|
|
457
|
+
children.push(node.children[2]);
|
|
458
|
+
}
|
|
459
|
+
children.push(node.children[5]);
|
|
460
|
+
promoteSingleChild(node);
|
|
461
|
+
node.children = children;
|
|
462
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
2
|
+
export const
|
|
3
|
+
Expression = 1,
|
|
4
|
+
Logic = 2,
|
|
5
|
+
Logic_predicates = 3,
|
|
6
|
+
Variable = 4,
|
|
7
|
+
Local = 5,
|
|
8
|
+
Tuple = 8,
|
|
9
|
+
Expr_enum_min2 = 9,
|
|
10
|
+
Logic_unary = 24,
|
|
11
|
+
Predicate = 26,
|
|
12
|
+
Logic_quantor = 29,
|
|
13
|
+
Variable_pack = 31,
|
|
14
|
+
Logic_binary = 33,
|
|
15
|
+
Setexpr = 38,
|
|
16
|
+
Integer = 39,
|
|
17
|
+
EmptySet = 40,
|
|
18
|
+
IntegerSet = 41,
|
|
19
|
+
Global = 42,
|
|
20
|
+
Radical = 43,
|
|
21
|
+
Setexpr_binary = 44,
|
|
22
|
+
Enumeration = 55,
|
|
23
|
+
Boolean = 56,
|
|
24
|
+
Filter_expression = 58,
|
|
25
|
+
Filter = 59,
|
|
26
|
+
Declarative = 60,
|
|
27
|
+
PrefixD = 62,
|
|
28
|
+
PrefixI = 63,
|
|
29
|
+
Imperative = 64,
|
|
30
|
+
Imp_blocks = 65,
|
|
31
|
+
PrefixR = 67,
|
|
32
|
+
Recursion = 68,
|
|
33
|
+
Function = 69,
|
|
34
|
+
BigPr = 70,
|
|
35
|
+
SmallPr = 71,
|
|
36
|
+
Card = 72,
|
|
37
|
+
Bool = 73,
|
|
38
|
+
Debool = 74,
|
|
39
|
+
Red = 75,
|
|
40
|
+
Function_decl = 76,
|
|
41
|
+
Arguments = 77,
|
|
42
|
+
Declaration = 78
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { buildTree, printTree } from '../../parsing';
|
|
4
|
+
import { RSErrorCode, type RSErrorDescription } from '../error';
|
|
5
|
+
|
|
6
|
+
import { parser } from './parser';
|
|
7
|
+
import { extractSyntaxErrors } from './syntax-errors';
|
|
8
|
+
|
|
9
|
+
const testSuccess = [
|
|
10
|
+
['a1', '[Expression[Setexpr[Local]]]'],
|
|
11
|
+
['A1', '[Expression[Setexpr[Global]]]'],
|
|
12
|
+
['∅', '[Expression[Setexpr[EmptySet]]]'],
|
|
13
|
+
['Z', '[Expression[Setexpr[IntegerSet]]]'],
|
|
14
|
+
['1', '[Expression[Setexpr[Integer]]]'],
|
|
15
|
+
['¬2=2', '[Expression[Logic[Logic_unary[¬][Logic[Logic_predicates[Setexpr[Integer]][=][Setexpr[Integer]]]]]]]'],
|
|
16
|
+
['12+41', '[Expression[Setexpr[Setexpr_binary[Setexpr[Integer]][+][Setexpr[Integer]]]]]'],
|
|
17
|
+
[
|
|
18
|
+
'1+2*5',
|
|
19
|
+
'[Expression[Setexpr[Setexpr_binary[Setexpr[Integer]][+][Setexpr[Setexpr_binary[Setexpr[Integer]][*][Setexpr[Integer]]]]]]]'
|
|
20
|
+
],
|
|
21
|
+
['a1∪Z', '[Expression[Setexpr[Setexpr_binary[Setexpr[Local]][∪][Setexpr[IntegerSet]]]]]'],
|
|
22
|
+
['pr1(S1)', '[Expression[Setexpr[SmallPr][(][Setexpr[Global]][)]]]'],
|
|
23
|
+
['Pr1,2(X1)', '[Expression[Setexpr[BigPr][(][Setexpr[Global]][)]]]'],
|
|
24
|
+
['debool(X1)', '[Expression[Setexpr[Debool][(][Setexpr[Global]][)]]]'],
|
|
25
|
+
[
|
|
26
|
+
'Fi1,2[ξ, ξ](ξ)',
|
|
27
|
+
'[Expression[Setexpr[Filter_expression[Filter][[][Expr_enum_min2[Setexpr[Local]][,][Setexpr[Local]]][]][(][Setexpr[Local]][)]]]]'
|
|
28
|
+
],
|
|
29
|
+
['ℬℬ(X1)', '[Expression[Setexpr[Boolean[ℬ][Boolean[ℬ][(][Setexpr[Global]][)]]]]]'],
|
|
30
|
+
['P2[S1]', '[Expression[Logic[Logic_unary[Predicate][[][Setexpr[Global]][]]]]]'],
|
|
31
|
+
[
|
|
32
|
+
'[σ∈R1×R1] F6[σ]',
|
|
33
|
+
'[Expression[Function_decl[[][Arguments[Declaration[Variable[Local]][∈][Setexpr[Setexpr_binary[Setexpr[Radical]][×][Setexpr[Radical]]]]]][]][Setexpr[Function][[][Setexpr[Local]][]]]]]'
|
|
34
|
+
],
|
|
35
|
+
[
|
|
36
|
+
'[(α,β)∈Z×X1] (α,β)',
|
|
37
|
+
'[Expression[Function_decl[[][Arguments[Declaration[Variable[Tuple[(][Expr_enum_min2[Setexpr[Local]][,][Setexpr[Local]]][)]]][∈][Setexpr[Setexpr_binary[Setexpr[IntegerSet]][×][Setexpr[Global]]]]]][]][Setexpr[Tuple[(][Expr_enum_min2[Setexpr[Local]][,][Setexpr[Local]]][)]]]]]'
|
|
38
|
+
],
|
|
39
|
+
[
|
|
40
|
+
'D{ξ∈red(S1) | ξ=ξ}',
|
|
41
|
+
'[Expression[Setexpr[Declarative[PrefixD][{][Variable[Local]][∈][Setexpr[Red][(][Setexpr[Global]][)]][|][Logic[Logic_predicates[Setexpr[Local]][=][Setexpr[Local]]]][}]]]]'
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
'I{(σ, γ) | σ:∈X1; γ:=F1[σ]; P1[σ, γ]}',
|
|
45
|
+
'[Expression[Setexpr[Imperative[PrefixI][{][Setexpr[Tuple[(][Expr_enum_min2[Setexpr[Local]][,][Setexpr[Local]]][)]]][|][Imp_blocks[Imp_blocks[Imp_blocks[Logic[Logic_predicates[Variable[Local]][:∈][Setexpr[Global]]]]][;][Logic[Logic_predicates[Variable[Local]][:=][Setexpr[Function][[][Setexpr[Local]][]]]]]][;][Logic[Logic_unary[Predicate][[][Expr_enum_min2[Setexpr[Local]][,][Setexpr[Local]]][]]]]][}]]]]'
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
'R{ξ:=D1 | F1[ξ]≠∅ | ξ∪F1[ξ]}',
|
|
49
|
+
'[Expression[Setexpr[Recursion[PrefixR][{][Variable[Local]][:=][Setexpr[Global]][|][Logic[Logic_predicates[Setexpr[Function][[][Setexpr[Local]][]]][≠][Setexpr[EmptySet]]]][|][Setexpr[Setexpr_binary[Setexpr[Local]][∪][Setexpr[Function][[][Setexpr[Local]][]]]]][}]]]]'
|
|
50
|
+
],
|
|
51
|
+
[
|
|
52
|
+
'∀ξ∈∅ 1=1',
|
|
53
|
+
'[Expression[Logic[Logic_unary[Logic_quantor[∀][Variable_pack[Variable[Local]]][∈][Setexpr[EmptySet]][Logic[Logic_predicates[Setexpr[Integer]][=][Setexpr[Integer]]]]]]]]'
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
'∀ξ1∈β (ξ1≠∅ & ∀ξ2∈β ξ1∩ξ2=∅)',
|
|
57
|
+
'[Expression[Logic[Logic_unary[Logic_quantor[∀][Variable_pack[Variable[Local]]][∈][Setexpr[Local]][Logic[(][Logic[Logic_binary[Logic[Logic_predicates[Setexpr[Local]][≠][Setexpr[EmptySet]]]][&][Logic[Logic_unary[Logic_quantor[∀][Variable_pack[Variable[Local]]][∈][Setexpr[Local]][Logic[Logic_predicates[Setexpr[Setexpr_binary[Setexpr[Local]][∩][Setexpr[Local]]]][=][Setexpr[EmptySet]]]]]]]]][)]]]]]]'
|
|
58
|
+
],
|
|
59
|
+
[
|
|
60
|
+
'∀α1∈α2 1=1',
|
|
61
|
+
'[Expression[Logic[Logic_unary[Logic_quantor[∀][Variable_pack[Variable[Local]]][∈][Setexpr[Local]][Logic[Logic_predicates[Setexpr[Integer]][=][Setexpr[Integer]]]]]]]]'
|
|
62
|
+
]
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
const testError = [
|
|
66
|
+
['', '[Expression[⚠]]'],
|
|
67
|
+
['!', '[Expression[⚠]]']
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
const testErrorData = [
|
|
71
|
+
['(', { code: RSErrorCode.missingParenthesis, from: 1, to: 1 }],
|
|
72
|
+
['{X1', { code: RSErrorCode.missingCurlyBrace, from: 3, to: 3 }],
|
|
73
|
+
['∀∈X1 (1=1)', { code: RSErrorCode.expectedLocal, from: 1, to: 1 }],
|
|
74
|
+
['∀σ∈S2 ∀(ξ,δ,π)∈σ (ξ∈δ & δ∈{pr1(π), pr2(π)}', { code: RSErrorCode.missingParenthesis, from: 42, to: 42 }],
|
|
75
|
+
['Fi1[X1) (X1)', { code: RSErrorCode.bracketMismatch, from: 6, to: 7, params: [']', ')'] }],
|
|
76
|
+
[')X1', { code: RSErrorCode.missingOpenBracket, from: 0, to: 1, params: ['('] }],
|
|
77
|
+
['Fi1[X1(X1)', { code: RSErrorCode.missingSquareBracket, from: 10, to: 10 }]
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
describe('Testing RSParser correct inputs', () => {
|
|
81
|
+
testSuccess.forEach(([input, expectedTree]) => {
|
|
82
|
+
it(`Parse "${input}"`, () => {
|
|
83
|
+
const tree = parser.parse(input);
|
|
84
|
+
expect(printTree(tree)).toBe(expectedTree);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('Testing RSParser error inputs AST', () => {
|
|
90
|
+
testError.forEach(([input, expectedTree]) => {
|
|
91
|
+
it(`Parse "${input}"`, () => {
|
|
92
|
+
const tree = parser.parse(input);
|
|
93
|
+
expect(printTree(tree)).toBe(expectedTree);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('Testing RSParser error data', () => {
|
|
99
|
+
testErrorData.forEach(([input, expectedError]) => {
|
|
100
|
+
it(`Parse "${input as string}"`, () => {
|
|
101
|
+
const tree = parser.parse(input as string);
|
|
102
|
+
const ast = buildTree(tree.cursor());
|
|
103
|
+
expect(ast.hasError).toBe(true);
|
|
104
|
+
const errors: RSErrorDescription[] = [];
|
|
105
|
+
extractSyntaxErrors(ast, input as string, error => errors.push(error));
|
|
106
|
+
expect(errors.length).toBe(1);
|
|
107
|
+
expect(errors[0]).toMatchObject(expectedError as RSErrorDescription);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('Quantor expressions', () => {
|
|
112
|
+
const input = '∀X1∈X1 (1=1)';
|
|
113
|
+
const tree = parser.parse(input);
|
|
114
|
+
const ast = buildTree(tree.cursor());
|
|
115
|
+
const errors: RSErrorDescription[] = [];
|
|
116
|
+
extractSyntaxErrors(ast, input, error => errors.push(error));
|
|
117
|
+
expect(errors.length).toBe(2);
|
|
118
|
+
expect(errors[1]).toMatchObject({ code: RSErrorCode.expectedLocal, from: 3, to: 3 });
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('Includes end position for ranged syntax errors', () => {
|
|
122
|
+
const input = '∀∈X1 (1=1)';
|
|
123
|
+
const tree = parser.parse(input);
|
|
124
|
+
const ast = buildTree(tree.cursor());
|
|
125
|
+
const errors: RSErrorDescription[] = [];
|
|
126
|
+
extractSyntaxErrors(ast, input, error => errors.push(error));
|
|
127
|
+
expect(errors[0]).toMatchObject({
|
|
128
|
+
code: RSErrorCode.expectedLocal,
|
|
129
|
+
from: 1,
|
|
130
|
+
to: 1
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('Reports true double parentheses only', () => {
|
|
135
|
+
const withDoubleParentheses = 'R{ξ:=S1 | 1=1 | ξ∪((S2))}';
|
|
136
|
+
const treeDouble = parser.parse(withDoubleParentheses);
|
|
137
|
+
const astDouble = buildTree(treeDouble.cursor());
|
|
138
|
+
const errorsDouble: RSErrorDescription[] = [];
|
|
139
|
+
extractSyntaxErrors(astDouble, withDoubleParentheses, error => errorsDouble.push(error));
|
|
140
|
+
|
|
141
|
+
expect(errorsDouble.some(error => error.code === RSErrorCode.doubleParenthesis)).toBe(true);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('Does not report tuple as double parentheses', () => {
|
|
145
|
+
const withTuple = 'R{ξ:={((S3, ∅),0)}| pr1(F8[ξ])∩S2=∅ | ξ∪((),card(ξ))}';
|
|
146
|
+
const treeTuple = parser.parse(withTuple);
|
|
147
|
+
const astTuple = buildTree(treeTuple.cursor());
|
|
148
|
+
const errorsTuple: RSErrorDescription[] = [];
|
|
149
|
+
extractSyntaxErrors(astTuple, withTuple, error => errorsTuple.push(error));
|
|
150
|
+
|
|
151
|
+
expect(errorsTuple.some(error => error.code === RSErrorCode.doubleParenthesis)).toBe(false);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
2
|
+
import {LRParser} from "@lezer/lr"
|
|
3
|
+
export const parser = LRParser.deserialize({
|
|
4
|
+
version: 14,
|
|
5
|
+
states: "2lO!sQPOOOVQPO'#CdO$qQPO'#C`O&pQPO'#C`O*bQPO'#C_Q*jQPOOO,TQPO'#CyOVQPO'#CtO,]QPO'#CtOOQO'#Ct'#CtOOQO'#C^'#C^OOQO'#ES'#ESOOQO'#ET'#ETO,bQPO'#DeO,iQPO'#DfO,qQPO'#DhO,vQPO'#DjO,{QPO'#DnO-QQPO'#DrOOQO'#EU'#EUOOQO'#EV'#EVOOQO'#DS'#DSO-VQPO'#DSO-[QPO'#DSOOQO'#EQ'#EQO,TQPO'#DzQOQPOOO-aQPO'#ERO-nQPO,59OO-vQPO'#CeO-{QPO,58xO/lQPO,59tOVQPO,58yOVQPO,58yOVQPO,59iOVQPO,59iOVQPO,59iOVQPO,59iOVQPO,59tOVQPO,59tOVQPO,59tOVQPO,59tOVQPO,59tOVQPO,59tOVQPO,59tOVQPO,59tOVQPO'#CdOOQO'#C`'#C`OOQO'#C{'#C{O1]QPO,59eO2rQPO,59`OVQPO,59`OOQO'#ER'#ERO5TQPO,5:PO5]QPO,5:UOVQPO,5:QOOQO,5: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e#f#m#n#p#x!sgOPV]pqrstuvwxyz{|}!O!T!X!Z!]!_!`!e!v!y#R#T#W#]#^#_#e#f#m#n#p#x",
|
|
8
|
+
nodeNames: "⚠ Expression Logic Logic_predicates Variable Local ) ( Tuple Expr_enum_min2 , :∈ := ∈ ∉ ⊆ ⊄ ⊂ > ≥ < ≤ ≠ = Logic_unary ¬ Predicate [ ] Logic_quantor ∀ Variable_pack ∃ Logic_binary ⇔ ⇒ ∨ & Setexpr Integer EmptySet IntegerSet Global Radical Setexpr_binary * + - ∪ \\ ∆ ∩ × } { Enumeration Boolean ℬ Filter_expression Filter Declarative | PrefixD PrefixI Imperative Imp_blocks ; PrefixR Recursion Function BigPr SmallPr Card Bool Debool Red Function_decl Arguments Declaration",
|
|
9
|
+
maxTerm: 87,
|
|
10
|
+
nodeProps: [
|
|
11
|
+
["openedBy", 6,"(",53,"{"],
|
|
12
|
+
["closedBy", 7,")",54,"}"]
|
|
13
|
+
],
|
|
14
|
+
skippedNodes: [0],
|
|
15
|
+
repeatNodeCount: 0,
|
|
16
|
+
tokenData: "6j~R!jX^%spq%svw&hxy&myz&rz{&w{|&||}'R}!O'W!Q![']![!]'e!]!^'x!^!_'}!_!`(S!`!a(X!c!d(^!e!f(^!f!g(l!h!i(t!k!l)h!p!q(^!r!s)m!t!u*a!u!v(^!v!w(^!z!{(^!|!}*q!}#O*v#O#P*{#P#Q+Q#R#S+V#T#U+V#U#V+m#V#W-]#W#X.x#X#d+V#d#e1b#e#f+V#f#g2w#g#o+V#o#p4R#p#q4W#q#r4]#y#z%s$f$g%s$r$s4b%o%p4g5i6S+V#BY#BZ%s$IS$I_%s$I|$JO%s$JT$JU%s$KV$KW%s% l% m4l%%Y%%Z4q%%[%%]4v%&Y%&Z4{%&]%&^5Q%&_%&`5V%&`%&a5[%&b%&c5a%&c%&d5f%'S%'T5k%'T%'U5p%'U%'V5u%(^%(_5z%(b%(c6P%(c%(d6U%)Q%)R6Z%)S%)T6`%)U%)V6e&FU&FV%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