circuitscript 0.1.26 → 0.1.28
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/SemanticTokenVisitor.js +15 -1
- package/dist/cjs/helpers.js +1 -1
- package/dist/cjs/validate.js +3 -0
- package/dist/esm/SemanticTokenVisitor.js +15 -1
- package/dist/esm/helpers.js +1 -1
- package/dist/esm/validate.js +3 -0
- package/dist/types/SemanticTokenVisitor.d.ts +3 -1
- package/dist/types/helpers.d.ts +5 -5
- package/package.json +1 -1
|
@@ -10,6 +10,16 @@ class SemanticTokensVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
10
10
|
super(silent, onErrorHandler, environment);
|
|
11
11
|
this.parsedTokens = [];
|
|
12
12
|
this.semanticTokens = new Map();
|
|
13
|
+
this.visitScript = async (ctx) => {
|
|
14
|
+
this.log('===', 'start', '===');
|
|
15
|
+
ctx.import_expr().forEach(ctxImport => {
|
|
16
|
+
this.visit(ctxImport);
|
|
17
|
+
});
|
|
18
|
+
const result = this.runExpressions(this.getExecutor(), ctx.expression());
|
|
19
|
+
this.setResult(ctx, result);
|
|
20
|
+
this.getExecutor().closeOpenPathBlocks();
|
|
21
|
+
this.log('===', 'end', '===');
|
|
22
|
+
};
|
|
13
23
|
this.visitFunction_args_expr = (ctx) => {
|
|
14
24
|
const IDs = ctx.ID();
|
|
15
25
|
IDs.map(id => {
|
|
@@ -105,12 +115,16 @@ class SemanticTokensVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
105
115
|
this.addSemanticToken(item, [], 'variable');
|
|
106
116
|
});
|
|
107
117
|
};
|
|
118
|
+
this.visitAnnotation_comment_expr = (ctx) => {
|
|
119
|
+
this.addSemanticToken(ctx.ANNOTATION_START(), [], 'comment');
|
|
120
|
+
this.addSemanticToken(ctx.ID(), [], 'comment');
|
|
121
|
+
};
|
|
108
122
|
this.lexer = lexer;
|
|
109
123
|
this.script = script;
|
|
110
124
|
}
|
|
111
125
|
addSemanticToken(node, modifiers, tokenType = null) {
|
|
112
126
|
const parsedToken = this.parseToken(node, modifiers, tokenType);
|
|
113
|
-
this.semanticTokens.set(parsedToken.line
|
|
127
|
+
this.semanticTokens.set(`${parsedToken.line}_${parsedToken.column}_${parsedToken.length}`, parsedToken);
|
|
114
128
|
}
|
|
115
129
|
parseToken(node, modifiers, tokenType = null) {
|
|
116
130
|
const token = node.symbol;
|
package/dist/cjs/helpers.js
CHANGED
|
@@ -82,7 +82,7 @@ async function getSemanticTokens(scriptData, options) {
|
|
|
82
82
|
const parsedTokens = (0, SemanticTokenVisitor_js_1.prepareTokens)(tokens.getTokens(), lexer, scriptData);
|
|
83
83
|
const finalParsedTokens = [];
|
|
84
84
|
parsedTokens.forEach(token => {
|
|
85
|
-
const location = `${token.line}_${token.column}`;
|
|
85
|
+
const location = `${token.line}_${token.column}_${token.length}`;
|
|
86
86
|
if (semanticTokens.has(location)) {
|
|
87
87
|
finalParsedTokens.push(semanticTokens.get(location));
|
|
88
88
|
}
|
package/dist/cjs/validate.js
CHANGED
|
@@ -70,6 +70,7 @@ async function validate() {
|
|
|
70
70
|
const visitor = await (0, helpers_js_1.validateScript)(inputFilePath, scriptData, scriptOptions);
|
|
71
71
|
const symbols = visitor.getSymbols().getSymbols();
|
|
72
72
|
const undefinedSymbols = [];
|
|
73
|
+
console.log('----- symbols -----');
|
|
73
74
|
symbols.forEach((value, key) => {
|
|
74
75
|
if (value.type !== types_js_1.ParseSymbolType.Undefined) {
|
|
75
76
|
value = value;
|
|
@@ -83,7 +84,9 @@ async function validate() {
|
|
|
83
84
|
undefinedSymbols.push(value);
|
|
84
85
|
}
|
|
85
86
|
});
|
|
87
|
+
console.log('----- tokens -----');
|
|
86
88
|
const { parsedTokens } = await (0, helpers_js_1.getSemanticTokens)(scriptData, scriptOptions);
|
|
89
|
+
console.log('----- dump tokens -----');
|
|
87
90
|
parsedTokens.forEach(item => {
|
|
88
91
|
const { line, column, tokenType, tokenModifiers, textValue } = item;
|
|
89
92
|
console.log(`${line}:${column} - ${textValue} - ${tokenType} | ${tokenModifiers.join(',')}`);
|
|
@@ -12,6 +12,16 @@ export class SemanticTokensVisitor extends BaseVisitor {
|
|
|
12
12
|
this.lexer = lexer;
|
|
13
13
|
this.script = script;
|
|
14
14
|
}
|
|
15
|
+
visitScript = async (ctx) => {
|
|
16
|
+
this.log('===', 'start', '===');
|
|
17
|
+
ctx.import_expr().forEach(ctxImport => {
|
|
18
|
+
this.visit(ctxImport);
|
|
19
|
+
});
|
|
20
|
+
const result = this.runExpressions(this.getExecutor(), ctx.expression());
|
|
21
|
+
this.setResult(ctx, result);
|
|
22
|
+
this.getExecutor().closeOpenPathBlocks();
|
|
23
|
+
this.log('===', 'end', '===');
|
|
24
|
+
};
|
|
15
25
|
visitFunction_args_expr = (ctx) => {
|
|
16
26
|
const IDs = ctx.ID();
|
|
17
27
|
IDs.map(id => {
|
|
@@ -107,9 +117,13 @@ export class SemanticTokensVisitor extends BaseVisitor {
|
|
|
107
117
|
this.addSemanticToken(item, [], 'variable');
|
|
108
118
|
});
|
|
109
119
|
};
|
|
120
|
+
visitAnnotation_comment_expr = (ctx) => {
|
|
121
|
+
this.addSemanticToken(ctx.ANNOTATION_START(), [], 'comment');
|
|
122
|
+
this.addSemanticToken(ctx.ID(), [], 'comment');
|
|
123
|
+
};
|
|
110
124
|
addSemanticToken(node, modifiers, tokenType = null) {
|
|
111
125
|
const parsedToken = this.parseToken(node, modifiers, tokenType);
|
|
112
|
-
this.semanticTokens.set(parsedToken.line
|
|
126
|
+
this.semanticTokens.set(`${parsedToken.line}_${parsedToken.column}_${parsedToken.length}`, parsedToken);
|
|
113
127
|
}
|
|
114
128
|
parseToken(node, modifiers, tokenType = null) {
|
|
115
129
|
const token = node.symbol;
|
package/dist/esm/helpers.js
CHANGED
|
@@ -75,7 +75,7 @@ export async function getSemanticTokens(scriptData, options) {
|
|
|
75
75
|
const parsedTokens = prepareTokens(tokens.getTokens(), lexer, scriptData);
|
|
76
76
|
const finalParsedTokens = [];
|
|
77
77
|
parsedTokens.forEach(token => {
|
|
78
|
-
const location = `${token.line}_${token.column}`;
|
|
78
|
+
const location = `${token.line}_${token.column}_${token.length}`;
|
|
79
79
|
if (semanticTokens.has(location)) {
|
|
80
80
|
finalParsedTokens.push(semanticTokens.get(location));
|
|
81
81
|
}
|
package/dist/esm/validate.js
CHANGED
|
@@ -68,6 +68,7 @@ export default async function validate() {
|
|
|
68
68
|
const visitor = await validateScript(inputFilePath, scriptData, scriptOptions);
|
|
69
69
|
const symbols = visitor.getSymbols().getSymbols();
|
|
70
70
|
const undefinedSymbols = [];
|
|
71
|
+
console.log('----- symbols -----');
|
|
71
72
|
symbols.forEach((value, key) => {
|
|
72
73
|
if (value.type !== ParseSymbolType.Undefined) {
|
|
73
74
|
value = value;
|
|
@@ -81,7 +82,9 @@ export default async function validate() {
|
|
|
81
82
|
undefinedSymbols.push(value);
|
|
82
83
|
}
|
|
83
84
|
});
|
|
85
|
+
console.log('----- tokens -----');
|
|
84
86
|
const { parsedTokens } = await getSemanticTokens(scriptData, scriptOptions);
|
|
87
|
+
console.log('----- dump tokens -----');
|
|
85
88
|
parsedTokens.forEach(item => {
|
|
86
89
|
const { line, column, tokenType, tokenModifiers, textValue } = item;
|
|
87
90
|
console.log(`${line}:${column} - ${textValue} - ${tokenType} | ${tokenModifiers.join(',')}`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TerminalNode, Token } from "antlr4ng";
|
|
2
2
|
import { CircuitScriptLexer } from "./antlr/CircuitScriptLexer.js";
|
|
3
|
-
import { Function_def_exprContext, Create_component_exprContext, Create_graphic_exprContext, Atom_exprContext, Property_key_exprContext, ValueAtomExprContext, Assignment_exprContext, Import_exprContext, Function_args_exprContext, Function_call_exprContext, GraphicCommandExprContext, For_exprContext } from "./antlr/CircuitScriptParser.js";
|
|
3
|
+
import { Function_def_exprContext, Create_component_exprContext, Create_graphic_exprContext, Atom_exprContext, Property_key_exprContext, ValueAtomExprContext, Assignment_exprContext, Import_exprContext, Function_args_exprContext, Function_call_exprContext, GraphicCommandExprContext, For_exprContext, Annotation_comment_exprContext, ScriptContext } from "./antlr/CircuitScriptParser.js";
|
|
4
4
|
import { BaseVisitor, OnErrorHandler } from "./BaseVisitor.js";
|
|
5
5
|
import { NodeScriptEnvironment } from "./environment.js";
|
|
6
6
|
export declare class SemanticTokensVisitor extends BaseVisitor {
|
|
@@ -9,6 +9,7 @@ export declare class SemanticTokensVisitor extends BaseVisitor {
|
|
|
9
9
|
script: string;
|
|
10
10
|
semanticTokens: Map<string, IParsedToken>;
|
|
11
11
|
constructor(silent: boolean | undefined, onErrorHandler: OnErrorHandler | null | undefined, environment: NodeScriptEnvironment, lexer: CircuitScriptLexer, script: string);
|
|
12
|
+
visitScript: (ctx: ScriptContext) => Promise<void>;
|
|
12
13
|
visitFunction_args_expr: (ctx: Function_args_exprContext) => void;
|
|
13
14
|
visitFunction_call_expr: (ctx: Function_call_exprContext) => void;
|
|
14
15
|
visitFunction_def_expr: (ctx: Function_def_exprContext) => void;
|
|
@@ -21,6 +22,7 @@ export declare class SemanticTokensVisitor extends BaseVisitor {
|
|
|
21
22
|
visitAtom_expr: (ctx: Atom_exprContext) => void;
|
|
22
23
|
visitImport_expr: (ctx: Import_exprContext) => void;
|
|
23
24
|
visitFor_expr: (ctx: For_exprContext) => void;
|
|
25
|
+
visitAnnotation_comment_expr: (ctx: Annotation_comment_exprContext) => void;
|
|
24
26
|
addSemanticToken(node: TerminalNode, modifiers: string[], tokenType?: string | null): void;
|
|
25
27
|
parseToken(node: TerminalNode, modifiers: string[], tokenType?: string | null): IParsedToken;
|
|
26
28
|
dumpTokens(): void;
|
package/dist/types/helpers.d.ts
CHANGED
|
@@ -19,13 +19,13 @@ export type ScriptOptions = {
|
|
|
19
19
|
dumpNets: boolean;
|
|
20
20
|
dumpData: boolean;
|
|
21
21
|
showStats: boolean;
|
|
22
|
-
enableErc: boolean;
|
|
23
|
-
enableBom: boolean;
|
|
24
|
-
bomOutputPath?: string;
|
|
25
22
|
environment: NodeScriptEnvironment;
|
|
26
23
|
inputPath?: string;
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
enableErc?: boolean;
|
|
25
|
+
enableBom?: boolean;
|
|
26
|
+
bomOutputPath?: string;
|
|
27
|
+
updateSource?: boolean;
|
|
28
|
+
saveAnnotatedCopy?: string | boolean;
|
|
29
29
|
};
|
|
30
30
|
export declare function prepareFile(textData: string): {
|
|
31
31
|
parser: CircuitScriptParser;
|