circuitscript 0.3.2 → 0.4.1
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 +394 -262
- package/dist/cjs/LexerDiagnosticListener.js +375 -0
- package/dist/cjs/{ComponentAnnotater.js → annotate/ComponentAnnotater.js} +29 -15
- package/dist/cjs/annotate/DefaultPostAnnotationCallback.js +126 -0
- package/dist/cjs/{RefdesAnnotationVisitor.js → annotate/RefdesAnnotationVisitor.js} +8 -82
- package/dist/cjs/annotate/utils.js +70 -0
- package/dist/cjs/antlr/CircuitScriptLexer.js +279 -286
- package/dist/cjs/antlr/CircuitScriptParser.js +1954 -3535
- package/dist/cjs/antlr/CircuitScriptParserVisitor.js +7 -0
- package/dist/cjs/cache/deserializer.js +34 -0
- package/dist/cjs/cache/hash.js +8 -0
- package/dist/cjs/cache/serializer.js +122 -0
- package/dist/cjs/cache/storage.js +45 -0
- package/dist/cjs/cache/types.js +4 -0
- package/dist/cjs/{environment.js → environment/environment.js} +18 -6
- package/dist/cjs/environment/esm-environment.js +21 -0
- package/dist/cjs/environment/helpers.js +8 -0
- package/dist/cjs/execute.js +49 -15
- package/dist/cjs/globals.js +9 -1
- package/dist/cjs/helpers.js +3 -485
- package/dist/cjs/importResolver.js +102 -0
- package/dist/cjs/index.js +12 -7
- package/dist/cjs/lexer.js +48 -12
- package/dist/cjs/main.js +14 -4
- package/dist/cjs/objects/ClassComponent.js +1 -1
- package/dist/cjs/objects/ExecutionScope.js +0 -1
- package/dist/cjs/objects/types.js +17 -1
- package/dist/cjs/parser.js +18 -4
- package/dist/cjs/pipeline.js +284 -0
- package/dist/cjs/regenerate-tests.js +4 -3
- package/dist/cjs/render/KiCadNetListOutputHandler.js +30 -0
- package/dist/cjs/render/PaperSizes.js +46 -0
- package/dist/cjs/{draw_symbols.js → render/draw_symbols.js} +58 -36
- package/dist/cjs/{export.js → render/export.js} +2 -2
- package/dist/cjs/{geometry.js → render/geometry.js} +5 -5
- package/dist/cjs/{graph.js → render/graph.js} +7 -7
- package/dist/cjs/{layout.js → render/layout.js} +8 -8
- package/dist/cjs/{render.js → render/render.js} +9 -8
- package/dist/cjs/rules-check/no-connect-on-connected-pin.js +1 -1
- package/dist/cjs/rules-check/unconnected-pins.js +1 -1
- package/dist/cjs/{SemanticTokenVisitor.js → semantic-tokens/SemanticTokenVisitor.js} +12 -14
- package/dist/cjs/semantic-tokens/getSemanticTokens.js +55 -0
- package/dist/cjs/sizing.js +2 -2
- package/dist/cjs/utils.js +2 -2
- package/dist/cjs/validate/SymbolValidatorResolveVisitor.js +6 -0
- package/dist/cjs/validate/SymbolValidatorVisitor.js +34 -39
- package/dist/cjs/validate/validateScript.js +54 -0
- package/dist/cjs/validate.js +5 -4
- package/dist/cjs/visitor.js +140 -204
- package/dist/esm/BaseVisitor.js +396 -264
- package/dist/esm/LexerDiagnosticListener.js +371 -0
- package/dist/esm/{ComponentAnnotater.js → annotate/ComponentAnnotater.js} +29 -15
- package/dist/esm/annotate/DefaultPostAnnotationCallback.js +122 -0
- package/dist/esm/{RefdesAnnotationVisitor.js → annotate/RefdesAnnotationVisitor.js} +8 -82
- package/dist/esm/annotate/utils.js +66 -0
- package/dist/esm/antlr/CircuitScriptLexer.js +279 -286
- package/dist/esm/antlr/CircuitScriptParser.js +1962 -3522
- package/dist/esm/antlr/{CircuitScriptVisitor.js → CircuitScriptParserVisitor.js} +14 -35
- package/dist/esm/cache/deserializer.js +30 -0
- package/dist/esm/cache/hash.js +4 -0
- package/dist/esm/cache/serializer.js +118 -0
- package/dist/esm/cache/storage.js +39 -0
- package/dist/esm/cache/types.js +1 -0
- package/dist/esm/{environment.js → environment/environment.js} +18 -6
- package/dist/esm/environment/esm-environment.js +17 -0
- package/dist/esm/environment/helpers.js +4 -0
- package/dist/esm/execute.js +49 -15
- package/dist/esm/globals.js +8 -0
- package/dist/esm/helpers.js +5 -474
- package/dist/esm/importResolver.js +96 -0
- package/dist/esm/index.js +12 -7
- package/dist/esm/lexer.js +51 -12
- package/dist/esm/main.js +13 -3
- package/dist/esm/objects/ClassComponent.js +1 -1
- package/dist/esm/objects/ExecutionScope.js +0 -1
- package/dist/esm/objects/types.js +21 -1
- package/dist/esm/parser.js +19 -5
- package/dist/esm/pipeline.js +276 -0
- package/dist/esm/regenerate-tests.js +3 -2
- package/dist/esm/render/KiCadNetListOutputHandler.js +20 -0
- package/dist/esm/render/PaperSizes.js +41 -0
- package/dist/esm/{draw_symbols.js → render/draw_symbols.js} +58 -36
- package/dist/esm/{export.js → render/export.js} +2 -2
- package/dist/esm/{geometry.js → render/geometry.js} +5 -5
- package/dist/esm/{graph.js → render/graph.js} +7 -7
- package/dist/esm/{layout.js → render/layout.js} +8 -8
- package/dist/esm/{render.js → render/render.js} +8 -7
- package/dist/esm/rules-check/no-connect-on-connected-pin.js +1 -1
- package/dist/esm/rules-check/unconnected-pins.js +1 -1
- package/dist/esm/{SemanticTokenVisitor.js → semantic-tokens/SemanticTokenVisitor.js} +12 -14
- package/dist/esm/semantic-tokens/getSemanticTokens.js +51 -0
- package/dist/esm/sizing.js +2 -2
- package/dist/esm/utils.js +2 -2
- package/dist/esm/validate/SymbolValidatorResolveVisitor.js +3 -0
- package/dist/esm/validate/SymbolValidatorVisitor.js +36 -41
- package/dist/esm/validate/validateScript.js +50 -0
- package/dist/esm/validate.js +4 -3
- package/dist/esm/visitor.js +142 -206
- package/dist/libs/std.cst +15 -19
- package/dist/types/BaseVisitor.d.ts +25 -18
- package/dist/types/BomGeneration.d.ts +1 -1
- package/dist/types/LexerDiagnosticListener.d.ts +85 -0
- package/dist/types/{ComponentAnnotater.d.ts → annotate/ComponentAnnotater.d.ts} +1 -1
- package/dist/types/annotate/DefaultPostAnnotationCallback.d.ts +7 -0
- package/dist/types/{RefdesAnnotationVisitor.d.ts → annotate/RefdesAnnotationVisitor.d.ts} +6 -8
- package/dist/types/annotate/utils.d.ts +6 -0
- package/dist/types/antlr/CircuitScriptLexer.d.ts +71 -70
- package/dist/types/antlr/CircuitScriptParser.d.ts +357 -515
- package/dist/types/antlr/{CircuitScriptVisitor.d.ts → CircuitScriptParserVisitor.d.ts} +27 -69
- package/dist/types/cache/deserializer.d.ts +5 -0
- package/dist/types/cache/hash.d.ts +1 -0
- package/dist/types/cache/serializer.d.ts +3 -0
- package/dist/types/cache/storage.d.ts +4 -0
- package/dist/types/cache/types.d.ts +20 -0
- package/dist/types/{environment.d.ts → environment/environment.d.ts} +5 -4
- package/dist/types/environment/esm-environment.d.ts +4 -0
- package/dist/types/environment/helpers.d.ts +2 -0
- package/dist/types/execute.d.ts +3 -2
- package/dist/types/globals.d.ts +1 -0
- package/dist/types/helpers.d.ts +31 -36
- package/dist/types/importResolver.d.ts +4 -0
- package/dist/types/index.d.ts +12 -7
- package/dist/types/lexer.d.ts +9 -5
- package/dist/types/objects/ClassComponent.d.ts +1 -1
- package/dist/types/objects/ExecutionScope.d.ts +1 -4
- package/dist/types/objects/types.d.ts +16 -2
- package/dist/types/parser.d.ts +9 -2
- package/dist/types/pipeline.d.ts +9 -0
- package/dist/types/render/KiCadNetListOutputHandler.d.ts +10 -0
- package/dist/types/render/PaperSizes.d.ts +12 -0
- package/dist/types/{draw_symbols.d.ts → render/draw_symbols.d.ts} +4 -4
- package/dist/types/{export.d.ts → render/export.d.ts} +1 -1
- package/dist/types/{geometry.d.ts → render/geometry.d.ts} +2 -2
- package/dist/types/{graph.d.ts → render/graph.d.ts} +6 -6
- package/dist/types/{layout.d.ts → render/layout.d.ts} +10 -10
- package/dist/types/{render.d.ts → render/render.d.ts} +1 -1
- package/dist/types/{SemanticTokenVisitor.d.ts → semantic-tokens/SemanticTokenVisitor.d.ts} +6 -6
- package/dist/types/semantic-tokens/getSemanticTokens.d.ts +6 -0
- package/dist/types/sizing.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/validate/SymbolValidatorResolveVisitor.d.ts +3 -0
- package/dist/types/validate/SymbolValidatorVisitor.d.ts +8 -8
- package/dist/types/validate/validateScript.d.ts +3 -0
- package/dist/types/visitor.d.ts +8 -14
- package/libs/std.cst +15 -19
- package/package.json +3 -6
- package/dist/cjs/antlr/CircuitScriptVisitor.js +0 -7
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RefdesAnnotationVisitor = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const BaseVisitor_js_1 = require("../BaseVisitor.js");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
6
|
class RefdesAnnotationVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
7
7
|
constructor(silent, sourceText, tokenStream, componentCtxLinks) {
|
|
8
8
|
super(true);
|
|
@@ -12,7 +12,7 @@ class RefdesAnnotationVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
12
12
|
this.visitScript = async (ctx) => {
|
|
13
13
|
this.runExpressions(this.getExecutor(), ctx.expression());
|
|
14
14
|
this.getExecutor().closeOpenPathBlocks();
|
|
15
|
-
this.resultText = this.
|
|
15
|
+
this.resultText = (0, utils_js_1.generateModifiedSourceText)(this.modifications, this.tokenStream.getTokens(), this.sourceText);
|
|
16
16
|
};
|
|
17
17
|
this.visitAdd_component_expr = (ctx) => {
|
|
18
18
|
this.addRefdesAnnotationComment(ctx);
|
|
@@ -60,11 +60,16 @@ class RefdesAnnotationVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
60
60
|
};
|
|
61
61
|
this.visitParameters = (ctx) => {
|
|
62
62
|
};
|
|
63
|
+
this.visitTrailer = (ctx) => {
|
|
64
|
+
};
|
|
63
65
|
this.addedRefdesAnnotations = [];
|
|
64
66
|
this.sourceText = sourceText;
|
|
65
67
|
this.tokenStream = tokenStream;
|
|
66
68
|
this.componentCtxLinks = componentCtxLinks;
|
|
67
69
|
}
|
|
70
|
+
getModifications() {
|
|
71
|
+
return this.modifications;
|
|
72
|
+
}
|
|
68
73
|
getOriginalText(ctx) {
|
|
69
74
|
if (!ctx.start || !ctx.stop) {
|
|
70
75
|
return '';
|
|
@@ -126,89 +131,10 @@ class RefdesAnnotationVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
126
131
|
});
|
|
127
132
|
return result;
|
|
128
133
|
}
|
|
129
|
-
generateModifiedText() {
|
|
130
|
-
const output = [];
|
|
131
|
-
const allTokens = this.tokenStream.getTokens();
|
|
132
|
-
const processedTokens = new Set();
|
|
133
|
-
let lastSourcePos = 0;
|
|
134
|
-
const contextTokenRanges = this.buildContextTokenRanges();
|
|
135
|
-
for (let i = 0; i < allTokens.length; i++) {
|
|
136
|
-
const token = allTokens[i];
|
|
137
|
-
if (processedTokens.has(i)) {
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
const tokenText = this.sourceText.substring(token.start, token.stop + 1);
|
|
141
|
-
this.log(i, `token: [${tokenText}], length: ${tokenText.length}, text: [${token.text}]`);
|
|
142
|
-
if (token.type === CircuitScriptParser_js_1.CircuitScriptParser.DEDENT
|
|
143
|
-
|| token.type === CircuitScriptParser_js_1.CircuitScriptParser.EOF
|
|
144
|
-
|| (token.type === CircuitScriptParser_js_1.CircuitScriptParser.NEWLINE && token.__skip)) {
|
|
145
|
-
this.log('--skip dedent/EOF token');
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
const ctx = this.findContextForToken(token, contextTokenRanges);
|
|
149
|
-
if (ctx) {
|
|
150
|
-
const isFirstTokenInContext = token.tokenIndex === ctx.start?.tokenIndex;
|
|
151
|
-
if (isFirstTokenInContext) {
|
|
152
|
-
if (token.start > lastSourcePos) {
|
|
153
|
-
output.push(this.sourceText.substring(lastSourcePos, token.start));
|
|
154
|
-
}
|
|
155
|
-
if (this.modifications.has(ctx)) {
|
|
156
|
-
output.push(this.generateReplacementText(this.modifications.get(ctx)));
|
|
157
|
-
this.markTokensAsProcessed(ctx, processedTokens);
|
|
158
|
-
if (ctx.stop) {
|
|
159
|
-
lastSourcePos = ctx.stop.stop + 1;
|
|
160
|
-
}
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (token.start > lastSourcePos) {
|
|
166
|
-
output.push(this.sourceText.substring(lastSourcePos, token.start));
|
|
167
|
-
}
|
|
168
|
-
if (tokenText.length > 0) {
|
|
169
|
-
output.push(tokenText);
|
|
170
|
-
}
|
|
171
|
-
processedTokens.add(i);
|
|
172
|
-
lastSourcePos = token.stop + 1;
|
|
173
|
-
}
|
|
174
|
-
if (lastSourcePos < this.sourceText.length) {
|
|
175
|
-
output.push(this.sourceText.substring(lastSourcePos));
|
|
176
|
-
}
|
|
177
|
-
return output.join('');
|
|
178
|
-
}
|
|
179
|
-
buildContextTokenRanges() {
|
|
180
|
-
const ranges = new Map();
|
|
181
|
-
for (const ctx of this.modifications.keys()) {
|
|
182
|
-
if (ctx.start && ctx.stop) {
|
|
183
|
-
ranges.set(ctx, [ctx.start.tokenIndex, ctx.stop.tokenIndex]);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return ranges;
|
|
187
|
-
}
|
|
188
|
-
findContextForToken(token, contextRanges) {
|
|
189
|
-
for (const [ctx, [start, end]] of contextRanges) {
|
|
190
|
-
if (token.tokenIndex >= start && token.tokenIndex <= end) {
|
|
191
|
-
return ctx;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
markTokensAsProcessed(ctx, processedTokens) {
|
|
197
|
-
if (!ctx.start || !ctx.stop) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
for (let i = ctx.start.tokenIndex; i <= ctx.stop.tokenIndex; i++) {
|
|
201
|
-
processedTokens.add(i);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
134
|
log(...message) {
|
|
205
135
|
if (this.debug) {
|
|
206
136
|
console.log(...message);
|
|
207
137
|
}
|
|
208
138
|
}
|
|
209
|
-
generateReplacementText(modification) {
|
|
210
|
-
const joinedRefdes = modification.refdes.join(', ');
|
|
211
|
-
return `${modification.originalText} #= ${joinedRefdes}`;
|
|
212
|
-
}
|
|
213
139
|
}
|
|
214
140
|
exports.RefdesAnnotationVisitor = RefdesAnnotationVisitor;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateModifiedSourceText = void 0;
|
|
4
|
+
const CircuitScriptParser_js_1 = require("../antlr/CircuitScriptParser.js");
|
|
5
|
+
function generateModifiedSourceText(modifications, tokens, sourceText, tokenStartOffset = 0) {
|
|
6
|
+
const output = [];
|
|
7
|
+
const processedTokens = new Set();
|
|
8
|
+
let lastSourcePos = 0;
|
|
9
|
+
const contextTokenRanges = new Map();
|
|
10
|
+
for (const ctx of modifications.keys()) {
|
|
11
|
+
if (ctx.start && ctx.stop) {
|
|
12
|
+
contextTokenRanges.set(ctx, [ctx.start.tokenIndex, ctx.stop.tokenIndex]);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
16
|
+
const token = tokens[i];
|
|
17
|
+
if (processedTokens.has(i)) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const tokenText = sourceText.substring(token.start - tokenStartOffset, token.stop + 1 - tokenStartOffset);
|
|
21
|
+
if (token.type === CircuitScriptParser_js_1.CircuitScriptParser.DEDENT
|
|
22
|
+
|| token.type === CircuitScriptParser_js_1.CircuitScriptParser.EOF
|
|
23
|
+
|| (token.type === CircuitScriptParser_js_1.CircuitScriptParser.NEWLINE && token.__skip)) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
let ctx = null;
|
|
27
|
+
for (const [c, [start, end]] of contextTokenRanges) {
|
|
28
|
+
if (token.tokenIndex >= start && token.tokenIndex <= end) {
|
|
29
|
+
ctx = c;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (ctx) {
|
|
34
|
+
const isFirstTokenInContext = token.tokenIndex === ctx.start?.tokenIndex;
|
|
35
|
+
if (isFirstTokenInContext) {
|
|
36
|
+
if (token.start - tokenStartOffset > lastSourcePos) {
|
|
37
|
+
output.push(sourceText.substring(lastSourcePos, token.start - tokenStartOffset));
|
|
38
|
+
}
|
|
39
|
+
if (modifications.has(ctx)) {
|
|
40
|
+
const modification = modifications.get(ctx);
|
|
41
|
+
const joinedRefdes = modification.refdes.join(', ');
|
|
42
|
+
output.push(`${modification.originalText} #= ${joinedRefdes}`);
|
|
43
|
+
if (ctx.start && ctx.stop) {
|
|
44
|
+
const tokensNum = ctx.stop.tokenIndex - ctx.start.tokenIndex;
|
|
45
|
+
for (let j = i; j <= i + tokensNum; j++) {
|
|
46
|
+
processedTokens.add(j);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (ctx.stop) {
|
|
50
|
+
lastSourcePos = ctx.stop.stop + 1 - tokenStartOffset;
|
|
51
|
+
}
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (token.start - tokenStartOffset > lastSourcePos) {
|
|
57
|
+
output.push(sourceText.substring(lastSourcePos, token.start - tokenStartOffset));
|
|
58
|
+
}
|
|
59
|
+
if (tokenText.length > 0) {
|
|
60
|
+
output.push(tokenText);
|
|
61
|
+
}
|
|
62
|
+
processedTokens.add(i);
|
|
63
|
+
lastSourcePos = token.stop + 1 - tokenStartOffset;
|
|
64
|
+
}
|
|
65
|
+
if (lastSourcePos < sourceText.length) {
|
|
66
|
+
output.push(sourceText.substring(lastSourcePos));
|
|
67
|
+
}
|
|
68
|
+
return output.join('');
|
|
69
|
+
}
|
|
70
|
+
exports.generateModifiedSourceText = generateModifiedSourceText;
|