circuitscript 0.0.22 → 0.0.25
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/dist/cjs/BaseVisitor.js +487 -0
- package/dist/cjs/SemanticTokenVisitor.js +218 -0
- package/dist/cjs/SymbolValidatorVisitor.js +233 -0
- package/dist/cjs/antlr/CircuitScriptLexer.js +302 -0
- package/dist/cjs/antlr/CircuitScriptParser.js +5128 -0
- package/dist/cjs/antlr/CircuitScriptVisitor.js +7 -0
- package/dist/cjs/draw_symbols.js +819 -0
- package/dist/cjs/execute.js +778 -0
- package/{src/export.ts → dist/cjs/export.js} +34 -56
- package/dist/cjs/fonts.js +4 -0
- package/dist/cjs/geometry.js +450 -0
- package/dist/cjs/globals.js +60 -0
- package/dist/cjs/helpers.js +269 -0
- package/dist/cjs/index.js +31 -0
- package/{src/layout.ts → dist/cjs/layout.js} +421 -1002
- package/dist/cjs/lexer.js +111 -0
- package/dist/cjs/logger.js +17 -0
- package/dist/cjs/main.js +82 -0
- package/dist/cjs/objects/ClassComponent.js +145 -0
- package/dist/cjs/objects/ExecutionScope.js +135 -0
- package/dist/cjs/objects/Frame.js +22 -0
- package/{src/objects/Net.ts → dist/cjs/objects/Net.js} +9 -24
- package/dist/cjs/objects/ParamDefinition.js +42 -0
- package/dist/cjs/objects/PinDefinition.js +31 -0
- package/dist/cjs/objects/PinTypes.js +11 -0
- package/dist/cjs/objects/Wire.js +9 -0
- package/dist/cjs/objects/types.js +15 -0
- package/dist/cjs/parser.js +70 -0
- package/dist/cjs/regenerate-tests.js +23 -0
- package/dist/cjs/render.js +155 -0
- package/{src/server.ts → dist/cjs/server.js} +15 -21
- package/dist/cjs/sizing.js +105 -0
- package/{src/utils.ts → dist/cjs/utils.js} +25 -35
- package/dist/cjs/validate.js +81 -0
- package/dist/cjs/visitor.js +844 -0
- package/dist/esm/BaseVisitor.mjs +488 -0
- package/dist/esm/SemanticTokenVisitor.mjs +215 -0
- package/dist/esm/SymbolValidatorVisitor.mjs +222 -0
- package/dist/esm/antlr/CircuitScriptLexer.mjs +276 -0
- package/dist/esm/antlr/CircuitScriptParser.mjs +5038 -0
- package/{build/src/antlr/CircuitScriptVisitor.js → dist/esm/antlr/CircuitScriptVisitor.mjs} +8 -3
- package/{build/src/draw_symbols.js → dist/esm/draw_symbols.mjs} +78 -33
- package/{build/src/execute.js → dist/esm/execute.mjs} +59 -60
- package/{build/src/export.js → dist/esm/export.mjs} +2 -2
- package/{build/src/geometry.js → dist/esm/geometry.mjs} +31 -15
- package/dist/esm/helpers.mjs +252 -0
- package/dist/esm/index.mjs +15 -0
- package/{build/src/layout.js → dist/esm/layout.mjs} +19 -11
- package/{build/src/lexer.js → dist/esm/lexer.mjs} +10 -10
- package/{build/src/main.js → dist/esm/main.mjs} +9 -14
- package/{build/src/objects/ClassComponent.js → dist/esm/objects/ClassComponent.mjs} +6 -3
- package/{build/src/objects/ExecutionScope.js → dist/esm/objects/ExecutionScope.mjs} +1 -0
- package/{build/src/objects/PinDefinition.js → dist/esm/objects/PinDefinition.mjs} +1 -1
- package/dist/esm/objects/types.mjs +12 -0
- package/dist/esm/parser.mjs +64 -0
- package/{build/src/regenerate-tests.js → dist/esm/regenerate-tests.mjs} +1 -1
- package/{build/src/render.js → dist/esm/render.mjs} +7 -24
- package/{build/src/sizing.js → dist/esm/sizing.mjs} +22 -8
- package/{src/main.ts → dist/esm/validate.mjs} +31 -62
- package/dist/esm/visitor.mjs +838 -0
- package/dist/types/BaseVisitor.d.ts +69 -0
- package/dist/types/SemanticTokenVisitor.d.ts +36 -0
- package/dist/types/SymbolValidatorVisitor.d.ts +61 -0
- package/{build/src → dist/types}/antlr/CircuitScriptLexer.d.ts +28 -27
- package/dist/types/antlr/CircuitScriptParser.d.ts +719 -0
- package/{build/src → dist/types}/antlr/CircuitScriptVisitor.d.ts +69 -59
- package/{build/src → dist/types}/draw_symbols.d.ts +11 -2
- package/{build/src → dist/types}/execute.d.ts +6 -9
- package/{build/src → dist/types}/geometry.d.ts +5 -1
- package/dist/types/helpers.d.ts +40 -0
- package/dist/types/index.d.ts +15 -0
- package/{build/src → dist/types}/layout.d.ts +10 -10
- package/{build/src → dist/types}/lexer.d.ts +2 -2
- package/{build/src → dist/types}/objects/ClassComponent.d.ts +2 -2
- package/{build/src → dist/types}/objects/ExecutionScope.d.ts +4 -1
- package/{build/src → dist/types}/objects/PinDefinition.d.ts +1 -1
- package/{build/src → dist/types}/objects/types.d.ts +5 -0
- package/dist/types/parser.d.ts +25 -0
- package/{build/src → dist/types}/render.d.ts +1 -1
- package/{build/src → dist/types}/sizing.d.ts +3 -1
- package/dist/types/validate.d.ts +2 -0
- package/dist/types/visitor.d.ts +80 -0
- package/libs/lib.cst +0 -2
- package/package.json +38 -15
- package/.editorconfig +0 -15
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -27
- package/.gitlab-ci.yml +0 -81
- package/.prettierignore +0 -8
- package/.prettierrc +0 -16
- package/__tests__/expectedResults.ts +0 -657
- package/__tests__/helpers.ts +0 -82
- package/__tests__/parseScripts.ts +0 -593
- package/__tests__/renderData/script1.cst +0 -58
- package/__tests__/renderData/script1.cst.svg +0 -1
- package/__tests__/renderData/script2.cst +0 -16
- package/__tests__/renderData/script2.cst.svg +0 -1
- package/__tests__/renderData/script3.cst +0 -30
- package/__tests__/renderData/script3.cst.svg +0 -1
- package/__tests__/renderData/script4.cst +0 -54
- package/__tests__/renderData/script4.cst.svg +0 -1
- package/__tests__/renderData/script5.cst +0 -23
- package/__tests__/renderData/script5.cst.svg +0 -1
- package/__tests__/renderData/script6.cst +0 -28
- package/__tests__/renderData/script6.cst.svg +0 -1
- package/__tests__/renderData/script7.cst +0 -26
- package/__tests__/renderData/script7.cst.svg +0 -1
- package/__tests__/renderData/script8.cst +0 -37
- package/__tests__/renderData/script8.cst.svg +0 -1
- package/__tests__/testCLI.ts +0 -68
- package/__tests__/testMathOps.ts +0 -36
- package/__tests__/testMergeWires.ts +0 -141
- package/__tests__/testParse.ts +0 -263
- package/__tests__/testRender.ts +0 -38
- package/build/src/antlr/CircuitScriptLexer.js +0 -287
- package/build/src/antlr/CircuitScriptParser.d.ts +0 -674
- package/build/src/antlr/CircuitScriptParser.js +0 -4841
- package/build/src/helpers.d.ts +0 -1
- package/build/src/helpers.js +0 -73
- package/build/src/objects/types.js +0 -6
- package/build/src/parser.js +0 -69
- package/build/src/visitor.d.ts +0 -133
- package/build/src/visitor.js +0 -1154
- package/documentation.md +0 -238
- package/examples/example_arduino_uno.cst +0 -1146
- package/examples/example_garden_pump.cst +0 -567
- package/examples/lib.cst +0 -185
- package/jest.config.js +0 -23
- package/refresh.html +0 -42
- package/server.cjs +0 -50
- package/src/antlr/CircuitScript.g4 +0 -209
- package/src/antlr/CircuitScriptLexer.ts +0 -317
- package/src/antlr/CircuitScriptParser.ts +0 -4979
- package/src/antlr/CircuitScriptVisitor.ts +0 -420
- package/src/draw_symbols.ts +0 -1085
- package/src/execute.ts +0 -1227
- package/src/fonts.ts +0 -1
- package/src/geometry.ts +0 -638
- package/src/globals.ts +0 -67
- package/src/helpers.ts +0 -114
- package/src/lexer.ts +0 -151
- package/src/logger.ts +0 -17
- package/src/objects/ClassComponent.ts +0 -223
- package/src/objects/ExecutionScope.ts +0 -201
- package/src/objects/Frame.ts +0 -20
- package/src/objects/ParamDefinition.ts +0 -49
- package/src/objects/PinDefinition.ts +0 -49
- package/src/objects/PinTypes.ts +0 -7
- package/src/objects/Wire.ts +0 -19
- package/src/objects/types.ts +0 -66
- package/src/parser.ts +0 -106
- package/src/regenerate-tests.ts +0 -25
- package/src/render.ts +0 -260
- package/src/sizing.ts +0 -96
- package/src/visitor.ts +0 -1691
- package/tsconfig.json +0 -27
- package/tsconfig.release.json +0 -8
- /package/{build/src/fonts.js → dist/esm/fonts.mjs} +0 -0
- /package/{build/src/globals.js → dist/esm/globals.mjs} +0 -0
- /package/{build/src/logger.js → dist/esm/logger.mjs} +0 -0
- /package/{build/src/objects/Frame.js → dist/esm/objects/Frame.mjs} +0 -0
- /package/{build/src/objects/Net.js → dist/esm/objects/Net.mjs} +0 -0
- /package/{build/src/objects/ParamDefinition.js → dist/esm/objects/ParamDefinition.mjs} +0 -0
- /package/{build/src/objects/PinTypes.js → dist/esm/objects/PinTypes.mjs} +0 -0
- /package/{build/src/objects/Wire.js → dist/esm/objects/Wire.mjs} +0 -0
- /package/{build/src/server.js → dist/esm/server.mjs} +0 -0
- /package/{build/src/utils.js → dist/esm/utils.mjs} +0 -0
- /package/{build/src → dist/types}/export.d.ts +0 -0
- /package/{build/src → dist/types}/fonts.d.ts +0 -0
- /package/{build/src → dist/types}/globals.d.ts +0 -0
- /package/{build/src → dist/types}/logger.d.ts +0 -0
- /package/{build/src → dist/types}/main.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Frame.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Net.d.ts +0 -0
- /package/{build/src → dist/types}/objects/ParamDefinition.d.ts +0 -0
- /package/{build/src → dist/types}/objects/PinTypes.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Wire.d.ts +0 -0
- /package/{build/src → dist/types}/regenerate-tests.d.ts +0 -0
- /package/{build/src → dist/types}/server.d.ts +0 -0
- /package/{build/src → dist/types}/utils.d.ts +0 -0
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { ExpressionContext } from "./antlr/CircuitScriptParser";
|
|
4
|
+
import { CircuitScriptVisitor } from "./antlr/CircuitScriptVisitor";
|
|
5
|
+
import { ExecutionContext } from "./execute";
|
|
6
|
+
import { Logger } from "./logger";
|
|
7
|
+
import { ClassComponent } from "./objects/ClassComponent";
|
|
8
|
+
import { NumericValue, PercentageValue, PinBlankValue } from "./objects/ParamDefinition";
|
|
9
|
+
import { PinTypes } from "./objects/PinTypes";
|
|
10
|
+
import { UndeclaredReference } from "./objects/types";
|
|
11
|
+
export class BaseVisitor extends CircuitScriptVisitor {
|
|
12
|
+
indentLevel = 0;
|
|
13
|
+
startingContext;
|
|
14
|
+
executionStack;
|
|
15
|
+
silent = false;
|
|
16
|
+
logger;
|
|
17
|
+
currentDirectory;
|
|
18
|
+
defaultLibsPath;
|
|
19
|
+
printStream = [];
|
|
20
|
+
printToConsole = true;
|
|
21
|
+
acceptedDirections = ['left', 'right', 'up', 'down'];
|
|
22
|
+
acceptedFlip = ['flipX', 'flipY'];
|
|
23
|
+
resultData = new Map;
|
|
24
|
+
paramData = new Map;
|
|
25
|
+
pinTypesList = [
|
|
26
|
+
PinTypes.Any,
|
|
27
|
+
PinTypes.Input,
|
|
28
|
+
PinTypes.Output,
|
|
29
|
+
PinTypes.IO,
|
|
30
|
+
PinTypes.Power,
|
|
31
|
+
];
|
|
32
|
+
onErrorCallbackHandler = null;
|
|
33
|
+
onImportFile = (visitor, filePath) => {
|
|
34
|
+
throw "Import file not implemented";
|
|
35
|
+
};
|
|
36
|
+
constructor(silent = false, onErrorHandler = null, currentDirectory, defaultLibsPath) {
|
|
37
|
+
super();
|
|
38
|
+
this.logger = new Logger();
|
|
39
|
+
this.onErrorCallbackHandler = onErrorHandler;
|
|
40
|
+
this.startingContext = new ExecutionContext('__', '__.', '/', 0, 0, silent, this.logger, null);
|
|
41
|
+
this.setupPrintFunction(this.startingContext);
|
|
42
|
+
this.executionStack = [this.startingContext];
|
|
43
|
+
this.startingContext.resolveNet =
|
|
44
|
+
this.createNetResolver(this.executionStack);
|
|
45
|
+
this.silent = silent;
|
|
46
|
+
this.currentDirectory = currentDirectory;
|
|
47
|
+
this.defaultLibsPath = defaultLibsPath;
|
|
48
|
+
}
|
|
49
|
+
getExecutor() {
|
|
50
|
+
return this.executionStack[this.executionStack.length - 1];
|
|
51
|
+
}
|
|
52
|
+
setupPrintFunction(context) {
|
|
53
|
+
context.createFunction('print', (params) => {
|
|
54
|
+
const items = params.map(([, , value]) => {
|
|
55
|
+
return value;
|
|
56
|
+
});
|
|
57
|
+
if (this.printToConsole) {
|
|
58
|
+
console.log('::', ...items);
|
|
59
|
+
}
|
|
60
|
+
this.printStream.push(...items);
|
|
61
|
+
return [this, null];
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
createNetResolver(executionStack) {
|
|
65
|
+
const resolveNet = (netName, netNamespace) => {
|
|
66
|
+
this.log('find net', netNamespace, netName);
|
|
67
|
+
const reversed = [...executionStack].reverse();
|
|
68
|
+
for (let i = 0; i < reversed.length; i++) {
|
|
69
|
+
const context = reversed[i];
|
|
70
|
+
const net = context.scope.getNetWithName(netName);
|
|
71
|
+
if (net !== null && net.namespace === netNamespace) {
|
|
72
|
+
return {
|
|
73
|
+
found: true,
|
|
74
|
+
net,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
found: false
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
return resolveNet;
|
|
83
|
+
}
|
|
84
|
+
log(...params) {
|
|
85
|
+
const indentOutput = ''.padStart(this.indentLevel * 4, ' ');
|
|
86
|
+
const indentLevelText = this.indentLevel.toString().padStart(3, ' ');
|
|
87
|
+
const args = ['[' + indentLevelText + ']', indentOutput, ...params];
|
|
88
|
+
this.logger.add(args.join(' '));
|
|
89
|
+
if (!this.silent) {
|
|
90
|
+
console.log.apply(null, args);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
log2(message) {
|
|
94
|
+
this.getExecutor().log(message);
|
|
95
|
+
}
|
|
96
|
+
visitScript = (ctx) => {
|
|
97
|
+
this.log('===', 'start', '===');
|
|
98
|
+
const result = this.visitChildren(ctx);
|
|
99
|
+
this.log('===', 'end', '===');
|
|
100
|
+
return result;
|
|
101
|
+
};
|
|
102
|
+
visitAssignment_expr = (ctx) => {
|
|
103
|
+
const atomStr = ctx.atom_expr().getText();
|
|
104
|
+
if (atomStr.indexOf('(') !== -1 || atomStr.indexOf(')') !== -1) {
|
|
105
|
+
throw "Invalid assignment expression!";
|
|
106
|
+
}
|
|
107
|
+
const ctxAtomExpr = ctx.atom_expr();
|
|
108
|
+
this.visit(ctxAtomExpr);
|
|
109
|
+
const reference = this.getResult(ctxAtomExpr);
|
|
110
|
+
const ctxDataExpr = ctx.data_expr();
|
|
111
|
+
this.visit(ctxDataExpr);
|
|
112
|
+
const value = this.getResult(ctxDataExpr);
|
|
113
|
+
if (value instanceof ClassComponent) {
|
|
114
|
+
const instances = this.getExecutor().scope.instances;
|
|
115
|
+
const tmpComponent = value;
|
|
116
|
+
const oldName = tmpComponent.instanceName;
|
|
117
|
+
tmpComponent.instanceName = reference.name;
|
|
118
|
+
instances.delete(oldName);
|
|
119
|
+
instances.set(reference.name, tmpComponent);
|
|
120
|
+
this.getExecutor().log(`assigned '${reference.name}' to ClassComponent`);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const trailers = reference.trailers ?? [];
|
|
124
|
+
if (trailers.length === 0) {
|
|
125
|
+
this.getExecutor().scope.variables.set(reference.name, value);
|
|
126
|
+
}
|
|
127
|
+
else if (reference.value instanceof ClassComponent) {
|
|
128
|
+
this.setInstanceParam(reference.value, trailers, value);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
this.setResult(ctx, value);
|
|
132
|
+
};
|
|
133
|
+
visitAtom_expr = (ctx) => {
|
|
134
|
+
const executor = this.getExecutor();
|
|
135
|
+
const firstId = ctx.ID(0);
|
|
136
|
+
const atomId = firstId.getText();
|
|
137
|
+
let currentReference;
|
|
138
|
+
if (this.pinTypesList.indexOf(atomId) !== -1) {
|
|
139
|
+
currentReference = {
|
|
140
|
+
found: true,
|
|
141
|
+
value: atomId
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
currentReference = executor.resolveVariable(this.executionStack, atomId);
|
|
146
|
+
}
|
|
147
|
+
if (currentReference.found && currentReference.type === 'instance') {
|
|
148
|
+
const tmpComponent = currentReference.value;
|
|
149
|
+
for (const [pinId, net] of tmpComponent.pinNets) {
|
|
150
|
+
executor.scope.setNet(tmpComponent, pinId, net);
|
|
151
|
+
}
|
|
152
|
+
if (ctx.ID().length > 1) {
|
|
153
|
+
currentReference.trailers = [];
|
|
154
|
+
const idLength = ctx.ID().length;
|
|
155
|
+
for (let i = 1; i < idLength; i++) {
|
|
156
|
+
const tmpCtx = ctx.ID(i);
|
|
157
|
+
currentReference.trailers.push(tmpCtx.getText());
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (ctx.parent instanceof ExpressionContext && !currentReference.found) {
|
|
162
|
+
throw "Unknown symbol: " + atomId;
|
|
163
|
+
}
|
|
164
|
+
this.setResult(ctx, currentReference);
|
|
165
|
+
};
|
|
166
|
+
visitFunctionCallExpr = (ctx) => {
|
|
167
|
+
const tmpCtx = ctx.function_call_expr();
|
|
168
|
+
this.visit(tmpCtx);
|
|
169
|
+
const result = this.getResult(tmpCtx);
|
|
170
|
+
this.setResult(ctx, result);
|
|
171
|
+
};
|
|
172
|
+
visitFunction_call_expr = (ctx) => {
|
|
173
|
+
const executor = this.getExecutor();
|
|
174
|
+
const atomId = ctx.ID().getText();
|
|
175
|
+
let passedNetNamespace = null;
|
|
176
|
+
const netNameSpaceExpr = ctx.net_namespace_expr();
|
|
177
|
+
if (netNameSpaceExpr) {
|
|
178
|
+
this.visit(netNameSpaceExpr);
|
|
179
|
+
passedNetNamespace = this.getResult(netNameSpaceExpr);
|
|
180
|
+
}
|
|
181
|
+
let currentReference = executor.resolveVariable(this.executionStack, atomId);
|
|
182
|
+
if (ctx.trailer_expr().length > 0) {
|
|
183
|
+
if (!currentReference.found) {
|
|
184
|
+
throw "Unknown function name: " + atomId;
|
|
185
|
+
}
|
|
186
|
+
currentReference.trailers = [];
|
|
187
|
+
ctx.trailer_expr().forEach(item => {
|
|
188
|
+
const itemValue = item.getText();
|
|
189
|
+
if (item.OPEN_PAREN() && item.CLOSE_PAREN()) {
|
|
190
|
+
let parameters = [];
|
|
191
|
+
const ctxParameters = item.parameters();
|
|
192
|
+
if (ctxParameters) {
|
|
193
|
+
this.visit(ctxParameters);
|
|
194
|
+
parameters = this.getResult(ctxParameters);
|
|
195
|
+
}
|
|
196
|
+
const useNetNamespace = this.getNetNamespace(executor.netNamespace, passedNetNamespace);
|
|
197
|
+
const [, functionResult] = executor.callFunction(currentReference.name, parameters, this.executionStack, useNetNamespace);
|
|
198
|
+
currentReference = {
|
|
199
|
+
found: true,
|
|
200
|
+
value: functionResult,
|
|
201
|
+
type: (functionResult instanceof ClassComponent) ?
|
|
202
|
+
'instance' : 'value',
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
currentReference.trailers.push(itemValue);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
this.setResult(ctx, currentReference.value);
|
|
211
|
+
};
|
|
212
|
+
visitValue_expr = (ctx) => {
|
|
213
|
+
const sign = ctx.Minus() ? -1 : 1;
|
|
214
|
+
const ctxIntegerValue = ctx.INTEGER_VALUE();
|
|
215
|
+
const ctxDecimalValue = ctx.DECIMAL_VALUE();
|
|
216
|
+
const ctxNumericValue = ctx.NUMERIC_VALUE();
|
|
217
|
+
const ctxBooleanValue = ctx.BOOLEAN_VALUE();
|
|
218
|
+
const ctxStringValue = ctx.STRING_VALUE();
|
|
219
|
+
const ctxPercentageValue = ctx.PERCENTAGE_VALUE();
|
|
220
|
+
const ctxBlankExpr = ctx.blank_expr();
|
|
221
|
+
let result = null;
|
|
222
|
+
if (ctxIntegerValue || ctxDecimalValue || ctxNumericValue) {
|
|
223
|
+
if (ctxIntegerValue) {
|
|
224
|
+
result = sign * Number(ctxIntegerValue.getText());
|
|
225
|
+
}
|
|
226
|
+
else if (ctxDecimalValue) {
|
|
227
|
+
result = sign * Number(ctxDecimalValue.getText());
|
|
228
|
+
}
|
|
229
|
+
else if (ctxNumericValue) {
|
|
230
|
+
const textExtra = ctx.Minus() ? '-' : '';
|
|
231
|
+
result = new NumericValue(textExtra + ctxNumericValue.getText());
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
if (sign === -1) {
|
|
236
|
+
throw "Invalid value!";
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (ctxBooleanValue) {
|
|
240
|
+
const stringValue = ctxBooleanValue.getText();
|
|
241
|
+
if (stringValue === 'true') {
|
|
242
|
+
result = true;
|
|
243
|
+
}
|
|
244
|
+
else if (stringValue === 'false') {
|
|
245
|
+
result = false;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
else if (ctxStringValue) {
|
|
249
|
+
result = this.prepareStringValue(ctxStringValue.getText());
|
|
250
|
+
}
|
|
251
|
+
else if (ctxPercentageValue) {
|
|
252
|
+
result = new PercentageValue(ctxPercentageValue.getText());
|
|
253
|
+
}
|
|
254
|
+
else if (ctxBlankExpr) {
|
|
255
|
+
this.visit(ctxBlankExpr);
|
|
256
|
+
result = this.getResult(ctxBlankExpr);
|
|
257
|
+
}
|
|
258
|
+
this.setResult(ctx, result);
|
|
259
|
+
};
|
|
260
|
+
visitBlank_expr = (ctx) => {
|
|
261
|
+
this.setResult(ctx, new PinBlankValue(Number(ctx.INTEGER_VALUE().getText())));
|
|
262
|
+
};
|
|
263
|
+
visitValueAtomExpr = (ctx) => {
|
|
264
|
+
let value = null;
|
|
265
|
+
const ctxValueExpr = ctx.value_expr();
|
|
266
|
+
const ctxAtomExpr = ctx.atom_expr();
|
|
267
|
+
if (ctxValueExpr) {
|
|
268
|
+
this.visit(ctxValueExpr);
|
|
269
|
+
value = this.getResult(ctxValueExpr);
|
|
270
|
+
}
|
|
271
|
+
else if (ctxAtomExpr) {
|
|
272
|
+
this.visit(ctxAtomExpr);
|
|
273
|
+
const reference = this.getResult(ctxAtomExpr);
|
|
274
|
+
if (!reference.found) {
|
|
275
|
+
value = new UndeclaredReference(reference);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
value = reference.value;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
this.setResult(ctx, value);
|
|
282
|
+
};
|
|
283
|
+
visitFunction_args_expr = (ctx) => {
|
|
284
|
+
const defaultValuesProvided = ctx.value_expr();
|
|
285
|
+
const IDs = ctx.ID();
|
|
286
|
+
const boundary = IDs.length - defaultValuesProvided.length;
|
|
287
|
+
const result = IDs.map((id, index) => {
|
|
288
|
+
const idText = id.getText();
|
|
289
|
+
if (index >= boundary) {
|
|
290
|
+
const tmpCtx = defaultValuesProvided[index - boundary];
|
|
291
|
+
this.visit(tmpCtx);
|
|
292
|
+
const defaultValue = this.getResult(tmpCtx);
|
|
293
|
+
return [idText, defaultValue];
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
return [idText];
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
this.setResult(ctx, result);
|
|
300
|
+
};
|
|
301
|
+
visitParameters = (ctx) => {
|
|
302
|
+
const dataExpressions = ctx.data_expr();
|
|
303
|
+
const keywordAssignmentExpressions = ctx.keyword_assignment_expr();
|
|
304
|
+
const returnList = [];
|
|
305
|
+
dataExpressions.forEach((item, index) => {
|
|
306
|
+
this.visit(item);
|
|
307
|
+
const value = this.getResult(item);
|
|
308
|
+
returnList.push(['position', index, value]);
|
|
309
|
+
});
|
|
310
|
+
keywordAssignmentExpressions.forEach((item) => {
|
|
311
|
+
this.visit(item);
|
|
312
|
+
const [key, value] = this.getResult(item);
|
|
313
|
+
returnList.push(['keyword', key, value]);
|
|
314
|
+
});
|
|
315
|
+
this.setResult(ctx, returnList);
|
|
316
|
+
};
|
|
317
|
+
visitImport_expr = (ctx) => {
|
|
318
|
+
const ID = ctx.ID().toString();
|
|
319
|
+
this.log('import', ID);
|
|
320
|
+
this.handleImportFile(ID, true);
|
|
321
|
+
this.log('done import', ID);
|
|
322
|
+
};
|
|
323
|
+
visitFunction_return_expr = (ctx) => {
|
|
324
|
+
const executor = this.getExecutor();
|
|
325
|
+
executor.log('return from function');
|
|
326
|
+
const ctxDataExpr = ctx.data_expr();
|
|
327
|
+
this.visit(ctxDataExpr);
|
|
328
|
+
const returnValue = this.getResult(ctxDataExpr);
|
|
329
|
+
executor.stopFurtherExpressions = true;
|
|
330
|
+
executor.returnValue = returnValue;
|
|
331
|
+
this.setResult(ctx, returnValue);
|
|
332
|
+
};
|
|
333
|
+
visitBreak_keyword = (ctx) => {
|
|
334
|
+
this.getExecutor().breakBranch();
|
|
335
|
+
this.setResult(ctx, -1);
|
|
336
|
+
};
|
|
337
|
+
setResult(ctx, value) {
|
|
338
|
+
this.resultData.set(ctx, value);
|
|
339
|
+
}
|
|
340
|
+
getResult(ctx) {
|
|
341
|
+
return this.resultData.get(ctx);
|
|
342
|
+
}
|
|
343
|
+
setParam(ctx, value) {
|
|
344
|
+
this.paramData.set(ctx, value);
|
|
345
|
+
}
|
|
346
|
+
getParam(ctx) {
|
|
347
|
+
return this.paramData.get(ctx);
|
|
348
|
+
}
|
|
349
|
+
hasParam(ctx) {
|
|
350
|
+
return this.paramData.has(ctx);
|
|
351
|
+
}
|
|
352
|
+
handleImportFile(name, throwErrors = true) {
|
|
353
|
+
let hasError = false;
|
|
354
|
+
let hasParseError = false;
|
|
355
|
+
let pathExists = false;
|
|
356
|
+
const tmpFilePath = join(this.currentDirectory, name + ".cst");
|
|
357
|
+
this.log('importing path:', tmpFilePath);
|
|
358
|
+
let fileData = null;
|
|
359
|
+
try {
|
|
360
|
+
fileData = readFileSync(tmpFilePath, { encoding: 'utf8' });
|
|
361
|
+
pathExists = true;
|
|
362
|
+
}
|
|
363
|
+
catch (err) {
|
|
364
|
+
pathExists = false;
|
|
365
|
+
}
|
|
366
|
+
if (!pathExists) {
|
|
367
|
+
try {
|
|
368
|
+
const tmpFilePath2 = join(this.defaultLibsPath, name + ".cst");
|
|
369
|
+
fileData = readFileSync(tmpFilePath2, { encoding: 'utf8' });
|
|
370
|
+
pathExists = true;
|
|
371
|
+
}
|
|
372
|
+
catch (err) {
|
|
373
|
+
pathExists = false;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
try {
|
|
377
|
+
if (pathExists) {
|
|
378
|
+
this.log('done reading imported file data');
|
|
379
|
+
const importResult = this.onImportFile(this, fileData, this.onErrorCallbackHandler);
|
|
380
|
+
hasError = importResult.hasError;
|
|
381
|
+
hasParseError = importResult.hasParseError;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
catch (err) {
|
|
385
|
+
this.log('Failed to import file: ', err.message);
|
|
386
|
+
}
|
|
387
|
+
if (throwErrors && (hasError || hasParseError || !pathExists)) {
|
|
388
|
+
if (!pathExists) {
|
|
389
|
+
throw `File does not exist: ${name}`;
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
throw `Failed to import: ${name}`;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return {
|
|
396
|
+
hasError,
|
|
397
|
+
hasParseError,
|
|
398
|
+
pathExists,
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
visitRoundedBracketsExpr = (ctx) => {
|
|
402
|
+
const ctxDataExpr = ctx.data_expr();
|
|
403
|
+
this.visit(ctxDataExpr);
|
|
404
|
+
const innerResult = this.getResult(ctxDataExpr);
|
|
405
|
+
this.setResult(ctx, innerResult);
|
|
406
|
+
};
|
|
407
|
+
setupDefinedParameters(funcDefinedParameters, passedInParameters, executor) {
|
|
408
|
+
for (let i = 0; i < funcDefinedParameters.length; i++) {
|
|
409
|
+
const tmpFuncArg = funcDefinedParameters[i];
|
|
410
|
+
if (i < passedInParameters.length) {
|
|
411
|
+
const tmpPassedInArgs = passedInParameters[i];
|
|
412
|
+
if (tmpPassedInArgs[0] === 'position') {
|
|
413
|
+
const variableName = tmpFuncArg[0];
|
|
414
|
+
executor.log('set variable in scope, var name: ', variableName);
|
|
415
|
+
executor.scope.variables.set(variableName, tmpPassedInArgs[2]);
|
|
416
|
+
if (tmpPassedInArgs[2] instanceof ClassComponent) {
|
|
417
|
+
const component = tmpPassedInArgs[2];
|
|
418
|
+
for (const [pinNumber, net] of component.pinNets) {
|
|
419
|
+
executor.scope.setNet(component, pinNumber, net);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
else if (tmpFuncArg.length === 2) {
|
|
425
|
+
const variableName = tmpFuncArg[0];
|
|
426
|
+
const defaultValue = tmpFuncArg[1];
|
|
427
|
+
executor.log('set variable in scope, var name: ', variableName);
|
|
428
|
+
executor.scope.variables.set(variableName, defaultValue);
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
throw `Invalid arguments got: ` + passedInParameters;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
runExpressions(executor, expressions) {
|
|
436
|
+
let returnValue = null;
|
|
437
|
+
for (let i = 0; i < expressions.length; i++) {
|
|
438
|
+
const expr = expressions[i];
|
|
439
|
+
this.visit(expr);
|
|
440
|
+
if (executor.stopFurtherExpressions) {
|
|
441
|
+
returnValue = executor.returnValue;
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return returnValue;
|
|
446
|
+
}
|
|
447
|
+
getNetNamespace(executorNetNamespace, passedNetNamespace) {
|
|
448
|
+
let result = executorNetNamespace;
|
|
449
|
+
if (passedNetNamespace !== null && passedNetNamespace.length > 0) {
|
|
450
|
+
if (passedNetNamespace === '/' || passedNetNamespace === '_') {
|
|
451
|
+
result = '';
|
|
452
|
+
}
|
|
453
|
+
else if (passedNetNamespace[0] === '+') {
|
|
454
|
+
if (executorNetNamespace === '/') {
|
|
455
|
+
result = passedNetNamespace.slice(1);
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
result = executorNetNamespace + passedNetNamespace.slice(2);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
result = passedNetNamespace;
|
|
463
|
+
}
|
|
464
|
+
result = result + '/';
|
|
465
|
+
}
|
|
466
|
+
return result;
|
|
467
|
+
}
|
|
468
|
+
setInstanceParam(object, trailers, value) {
|
|
469
|
+
const paramName = trailers[0];
|
|
470
|
+
object.setParam(paramName, value);
|
|
471
|
+
this.getExecutor().log(`set instance ${object.instanceName} param ${paramName} to ${value}`);
|
|
472
|
+
}
|
|
473
|
+
enterNewChildContext(executionStack, parentContext, executionContextName, options, funcDefinedParameters, passedInParameters) {
|
|
474
|
+
const { netNamespace = "" } = options;
|
|
475
|
+
const currentExecutionContext = executionStack[executionStack.length - 1];
|
|
476
|
+
const executionLevel = currentExecutionContext.executionLevel;
|
|
477
|
+
const executionContextNamespace = currentExecutionContext.namespace
|
|
478
|
+
+ executionContextName + ".";
|
|
479
|
+
const newExecutor = new ExecutionContext(executionContextName, executionContextNamespace, netNamespace, executionLevel + 1, this.getExecutor().scope.indentLevel + 1, currentExecutionContext.silent, currentExecutionContext.logger, parentContext);
|
|
480
|
+
this.setupPrintFunction(newExecutor);
|
|
481
|
+
executionStack.push(newExecutor);
|
|
482
|
+
this.setupDefinedParameters(funcDefinedParameters, passedInParameters, newExecutor);
|
|
483
|
+
return newExecutor;
|
|
484
|
+
}
|
|
485
|
+
prepareStringValue(value) {
|
|
486
|
+
return value.slice(1, value.length - 1);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { Assignment_exprContext } from "./antlr/CircuitScriptParser";
|
|
2
|
+
import { BaseVisitor } from "./BaseVisitor";
|
|
3
|
+
export class SemanticTokensVisitor extends BaseVisitor {
|
|
4
|
+
parsedTokens = [];
|
|
5
|
+
lexer;
|
|
6
|
+
script;
|
|
7
|
+
semanticTokens = new Map();
|
|
8
|
+
constructor(silent = false, onErrorHandler = null, currentDirectory, defaultsLibsPath, lexer, script) {
|
|
9
|
+
super(silent, onErrorHandler, currentDirectory, defaultsLibsPath);
|
|
10
|
+
this.lexer = lexer;
|
|
11
|
+
this.script = script;
|
|
12
|
+
}
|
|
13
|
+
visitFunction_args_expr = (ctx) => {
|
|
14
|
+
const IDs = ctx.ID();
|
|
15
|
+
IDs.map(id => {
|
|
16
|
+
this.addSemanticToken(id, ['declaration'], 'parameter');
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
visitFunction_call_expr = (ctx) => {
|
|
20
|
+
this.addSemanticToken(ctx.ID(), [], 'function');
|
|
21
|
+
};
|
|
22
|
+
visitFunction_def_expr = (ctx) => {
|
|
23
|
+
const functionName = ctx.ID().getText();
|
|
24
|
+
this.addSemanticToken(ctx.ID(), ['declaration'], 'function');
|
|
25
|
+
const ctxFunctionArgsExpr = ctx.function_args_expr();
|
|
26
|
+
if (ctxFunctionArgsExpr) {
|
|
27
|
+
this.visit(ctxFunctionArgsExpr);
|
|
28
|
+
}
|
|
29
|
+
const executionContextName = functionName + '_validate';
|
|
30
|
+
const newExecutor = this.enterNewChildContext(this.executionStack, this.getExecutor(), executionContextName, { netNamespace: "" }, [], []);
|
|
31
|
+
this.runExpressions(newExecutor, ctx.function_expr());
|
|
32
|
+
this.executionStack.pop();
|
|
33
|
+
};
|
|
34
|
+
visitCreate_component_expr = (ctx) => {
|
|
35
|
+
this.addSemanticToken(ctx.Create(), ['defaultLibrary'], 'function');
|
|
36
|
+
ctx.property_expr().forEach(property_expr => {
|
|
37
|
+
this.visit(property_expr);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
visitCreate_graphic_expr = (ctx) => {
|
|
41
|
+
this.addSemanticToken(ctx.Create(), ['defaultLibrary'], 'function');
|
|
42
|
+
ctx.sub_expr().forEach(sub_expr => {
|
|
43
|
+
this.visit(sub_expr);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
visitProperty_key_expr = (ctx) => {
|
|
47
|
+
let useValue = null;
|
|
48
|
+
const ctxId = ctx.ID();
|
|
49
|
+
const ctxIntegerValue = ctx.INTEGER_VALUE();
|
|
50
|
+
const ctxStringValue = ctx.STRING_VALUE();
|
|
51
|
+
if (ctxId) {
|
|
52
|
+
useValue = ctxId;
|
|
53
|
+
}
|
|
54
|
+
else if (ctxIntegerValue) {
|
|
55
|
+
useValue = ctxIntegerValue;
|
|
56
|
+
}
|
|
57
|
+
else if (ctxStringValue) {
|
|
58
|
+
useValue = ctxStringValue;
|
|
59
|
+
}
|
|
60
|
+
if (useValue) {
|
|
61
|
+
this.addSemanticToken(useValue, [], 'property');
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
visitSub_expr = (ctx) => {
|
|
65
|
+
let useValue = null;
|
|
66
|
+
const ctxId = ctx.ID();
|
|
67
|
+
const ctxPin = ctx.Pin();
|
|
68
|
+
if (ctxId) {
|
|
69
|
+
useValue = ctxId;
|
|
70
|
+
}
|
|
71
|
+
else if (ctxPin) {
|
|
72
|
+
useValue = ctxPin;
|
|
73
|
+
}
|
|
74
|
+
if (useValue) {
|
|
75
|
+
this.addSemanticToken(useValue, [], 'property');
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
visitValueAtomExpr = (ctx) => {
|
|
79
|
+
const ctxValueExpr = ctx.value_expr();
|
|
80
|
+
const ctxAtomExpr = ctx.atom_expr();
|
|
81
|
+
if (ctxValueExpr) {
|
|
82
|
+
this.visit(ctxValueExpr);
|
|
83
|
+
}
|
|
84
|
+
else if (ctxAtomExpr) {
|
|
85
|
+
this.visit(ctxAtomExpr);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
visitAssignment_expr = (ctx) => {
|
|
89
|
+
this.visit(ctx.atom_expr());
|
|
90
|
+
this.visit(ctx.data_expr());
|
|
91
|
+
};
|
|
92
|
+
visitAtom_expr = (ctx) => {
|
|
93
|
+
if (ctx.parent instanceof Assignment_exprContext && ctx.ID(0)) {
|
|
94
|
+
this.addSemanticToken(ctx.ID(0), [], 'variable');
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
visitImport_expr = (ctx) => {
|
|
98
|
+
this.addSemanticToken(ctx.ID(), [], 'namespace');
|
|
99
|
+
};
|
|
100
|
+
addSemanticToken(node, modifiers, tokenType = null) {
|
|
101
|
+
const parsedToken = this.parseToken(node, modifiers, tokenType);
|
|
102
|
+
this.semanticTokens.set(parsedToken.line + "_" + parsedToken.column, parsedToken);
|
|
103
|
+
}
|
|
104
|
+
parseToken(node, modifiers, tokenType = null) {
|
|
105
|
+
const token = node.symbol;
|
|
106
|
+
let stringValue = "";
|
|
107
|
+
let textPart = "";
|
|
108
|
+
if (this.lexer.symbolicNames[token.type] !== null && this.lexer.symbolicNames[token.type] !== undefined) {
|
|
109
|
+
stringValue = this.lexer.symbolicNames[token.type];
|
|
110
|
+
if (stringValue !== "NEWLINE") {
|
|
111
|
+
textPart = this.script.substring(token.start, token.stop + 1);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
textPart = token.text.length - 1;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else if (this.lexer.literalNames[token.type] !== null && this.lexer.literalNames[token.type] !== undefined) {
|
|
118
|
+
stringValue = this.lexer.literalNames[token.type];
|
|
119
|
+
textPart = this.script.substring(token.start, token.stop + 1);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
stringValue = token._text;
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
line: token.line,
|
|
126
|
+
column: token.column,
|
|
127
|
+
length: token.stop - token.start + 1,
|
|
128
|
+
tokenType: tokenType !== null ? tokenType : stringValue,
|
|
129
|
+
tokenModifiers: modifiers,
|
|
130
|
+
textValue: textPart,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
dumpTokens() {
|
|
134
|
+
for (const [id, value] of this.semanticTokens) {
|
|
135
|
+
console.log(id, value);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
getTokens() {
|
|
139
|
+
return this.semanticTokens;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export function prepareTokens(tokens, lexer, script) {
|
|
143
|
+
const parsedTokens = [];
|
|
144
|
+
tokens.forEach(item => {
|
|
145
|
+
if (item.type !== -1) {
|
|
146
|
+
let stringValue = "";
|
|
147
|
+
let textPart = "";
|
|
148
|
+
if (lexer.symbolicNames[item.type] !== null && lexer.symbolicNames[item.type] !== undefined) {
|
|
149
|
+
stringValue = lexer.symbolicNames[item.type];
|
|
150
|
+
if (stringValue !== "NEWLINE") {
|
|
151
|
+
textPart = script.substring(item.start, item.stop + 1);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
textPart = item.text.length - 1;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else if (lexer.literalNames[item.type] !== null && lexer.literalNames[item.type] !== undefined) {
|
|
158
|
+
stringValue = lexer.literalNames[item.type];
|
|
159
|
+
textPart = script.substring(item.start, item.stop + 1);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
stringValue = item._text;
|
|
163
|
+
}
|
|
164
|
+
if (textPart !== 0 && textPart !== '') {
|
|
165
|
+
parsedTokens.push({
|
|
166
|
+
line: item.line,
|
|
167
|
+
column: item.column,
|
|
168
|
+
length: item.stop - item.start + 1,
|
|
169
|
+
tokenType: resolveTokenType(stringValue),
|
|
170
|
+
tokenModifiers: resolveTokenModifiers(stringValue),
|
|
171
|
+
textValue: textPart,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
return parsedTokens;
|
|
177
|
+
}
|
|
178
|
+
const languageKeywords = [
|
|
179
|
+
'break', 'branch', 'create', 'component',
|
|
180
|
+
'graphic', 'wire', 'pin', 'add', 'at', 'to',
|
|
181
|
+
'point', 'join', 'parallel', 'return', 'def', 'import',
|
|
182
|
+
'true', 'false', 'nc', 'frame',
|
|
183
|
+
];
|
|
184
|
+
const operatorKeywords = [
|
|
185
|
+
'at', 'to', 'wire', 'add', 'frame', 'join', 'parallel', 'point'
|
|
186
|
+
];
|
|
187
|
+
function resolveTokenType(tokenType) {
|
|
188
|
+
if (operatorKeywords.indexOf(tokenType.toLowerCase()) !== -1) {
|
|
189
|
+
return 'graphKeyword';
|
|
190
|
+
}
|
|
191
|
+
else if (languageKeywords.indexOf(tokenType.toLowerCase()) !== -1) {
|
|
192
|
+
return 'keyword';
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
switch (tokenType) {
|
|
196
|
+
case 'INTEGER_VALUE':
|
|
197
|
+
case 'NUMERIC_VALUE':
|
|
198
|
+
case 'DECIMAL_VALUE':
|
|
199
|
+
case 'PERCENTAGE_VALUE':
|
|
200
|
+
return 'number';
|
|
201
|
+
case 'STRING_VALUE':
|
|
202
|
+
return 'string';
|
|
203
|
+
case 'ID':
|
|
204
|
+
return 'variable';
|
|
205
|
+
case 'Define':
|
|
206
|
+
return 'keyword';
|
|
207
|
+
case 'COMMENT':
|
|
208
|
+
return 'comment';
|
|
209
|
+
}
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function resolveTokenModifiers(tokenType) {
|
|
214
|
+
return [];
|
|
215
|
+
}
|