circuitscript 0.3.2 → 0.4.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/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 +7 -6
- 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 +7 -6
- 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 +7 -6
- 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,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { BaseVisitor } from '../BaseVisitor.js';
|
|
2
|
+
import { generateModifiedSourceText } from './utils.js';
|
|
3
3
|
export class RefdesAnnotationVisitor extends BaseVisitor {
|
|
4
4
|
sourceText;
|
|
5
5
|
tokenStream;
|
|
@@ -13,6 +13,9 @@ export class RefdesAnnotationVisitor extends BaseVisitor {
|
|
|
13
13
|
this.tokenStream = tokenStream;
|
|
14
14
|
this.componentCtxLinks = componentCtxLinks;
|
|
15
15
|
}
|
|
16
|
+
getModifications() {
|
|
17
|
+
return this.modifications;
|
|
18
|
+
}
|
|
16
19
|
getOriginalText(ctx) {
|
|
17
20
|
if (!ctx.start || !ctx.stop) {
|
|
18
21
|
return '';
|
|
@@ -24,7 +27,7 @@ export class RefdesAnnotationVisitor extends BaseVisitor {
|
|
|
24
27
|
visitScript = async (ctx) => {
|
|
25
28
|
this.runExpressions(this.getExecutor(), ctx.expression());
|
|
26
29
|
this.getExecutor().closeOpenPathBlocks();
|
|
27
|
-
this.resultText = this.
|
|
30
|
+
this.resultText = generateModifiedSourceText(this.modifications, this.tokenStream.getTokens(), this.sourceText);
|
|
28
31
|
};
|
|
29
32
|
visitAdd_component_expr = (ctx) => {
|
|
30
33
|
this.addRefdesAnnotationComment(ctx);
|
|
@@ -72,6 +75,8 @@ export class RefdesAnnotationVisitor extends BaseVisitor {
|
|
|
72
75
|
};
|
|
73
76
|
visitParameters = (ctx) => {
|
|
74
77
|
};
|
|
78
|
+
visitTrailer = (ctx) => {
|
|
79
|
+
};
|
|
75
80
|
addedRefdesAnnotations = [];
|
|
76
81
|
generateRefdesAnnotationComment(ctx) {
|
|
77
82
|
if (this.componentCtxLinks.has(ctx)) {
|
|
@@ -126,88 +131,9 @@ export class RefdesAnnotationVisitor extends 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.DEDENT
|
|
143
|
-
|| token.type === CircuitScriptParser.EOF
|
|
144
|
-
|| (token.type === 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
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { CircuitScriptParser } from '../antlr/CircuitScriptParser.js';
|
|
2
|
+
export function generateModifiedSourceText(modifications, tokens, sourceText, tokenStartOffset = 0) {
|
|
3
|
+
const output = [];
|
|
4
|
+
const processedTokens = new Set();
|
|
5
|
+
let lastSourcePos = 0;
|
|
6
|
+
const contextTokenRanges = new Map();
|
|
7
|
+
for (const ctx of modifications.keys()) {
|
|
8
|
+
if (ctx.start && ctx.stop) {
|
|
9
|
+
contextTokenRanges.set(ctx, [ctx.start.tokenIndex, ctx.stop.tokenIndex]);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
13
|
+
const token = tokens[i];
|
|
14
|
+
if (processedTokens.has(i)) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const tokenText = sourceText.substring(token.start - tokenStartOffset, token.stop + 1 - tokenStartOffset);
|
|
18
|
+
if (token.type === CircuitScriptParser.DEDENT
|
|
19
|
+
|| token.type === CircuitScriptParser.EOF
|
|
20
|
+
|| (token.type === CircuitScriptParser.NEWLINE && token.__skip)) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
let ctx = null;
|
|
24
|
+
for (const [c, [start, end]] of contextTokenRanges) {
|
|
25
|
+
if (token.tokenIndex >= start && token.tokenIndex <= end) {
|
|
26
|
+
ctx = c;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (ctx) {
|
|
31
|
+
const isFirstTokenInContext = token.tokenIndex === ctx.start?.tokenIndex;
|
|
32
|
+
if (isFirstTokenInContext) {
|
|
33
|
+
if (token.start - tokenStartOffset > lastSourcePos) {
|
|
34
|
+
output.push(sourceText.substring(lastSourcePos, token.start - tokenStartOffset));
|
|
35
|
+
}
|
|
36
|
+
if (modifications.has(ctx)) {
|
|
37
|
+
const modification = modifications.get(ctx);
|
|
38
|
+
const joinedRefdes = modification.refdes.join(', ');
|
|
39
|
+
output.push(`${modification.originalText} #= ${joinedRefdes}`);
|
|
40
|
+
if (ctx.start && ctx.stop) {
|
|
41
|
+
const tokensNum = ctx.stop.tokenIndex - ctx.start.tokenIndex;
|
|
42
|
+
for (let j = i; j <= i + tokensNum; j++) {
|
|
43
|
+
processedTokens.add(j);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (ctx.stop) {
|
|
47
|
+
lastSourcePos = ctx.stop.stop + 1 - tokenStartOffset;
|
|
48
|
+
}
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (token.start - tokenStartOffset > lastSourcePos) {
|
|
54
|
+
output.push(sourceText.substring(lastSourcePos, token.start - tokenStartOffset));
|
|
55
|
+
}
|
|
56
|
+
if (tokenText.length > 0) {
|
|
57
|
+
output.push(tokenText);
|
|
58
|
+
}
|
|
59
|
+
processedTokens.add(i);
|
|
60
|
+
lastSourcePos = token.stop + 1 - tokenStartOffset;
|
|
61
|
+
}
|
|
62
|
+
if (lastSourcePos < sourceText.length) {
|
|
63
|
+
output.push(sourceText.substring(lastSourcePos));
|
|
64
|
+
}
|
|
65
|
+
return output.join('');
|
|
66
|
+
}
|