circuitscript 0.4.0 → 0.5.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 +16 -10
- package/dist/cjs/BomGeneration.js +3 -3
- package/dist/cjs/ComponentMatchConditions.js +2 -2
- package/dist/cjs/annotate/RefdesAnnotationVisitor.js +4 -0
- package/dist/cjs/builtinMethods.js +10 -10
- package/dist/cjs/execute.js +25 -23
- package/dist/cjs/globals.js +7 -14
- package/dist/cjs/helpers.js +4 -3
- package/dist/cjs/index.js +6 -2
- package/dist/cjs/lexer.js +8 -4
- package/dist/cjs/objects/BlockTypes.js +10 -0
- package/dist/cjs/objects/NumericValue.js +196 -0
- package/dist/cjs/objects/ParamDefinition.js +1 -149
- package/dist/cjs/objects/PercentageValue.js +15 -0
- package/dist/cjs/objects/PinDefinition.js +2 -2
- package/dist/cjs/objects/WrappedNumber.js +15 -0
- package/dist/cjs/pipeline.js +2 -2
- package/dist/cjs/render/draw_symbols.js +78 -78
- package/dist/cjs/render/export.js +2 -2
- package/dist/cjs/render/geometry.js +11 -12
- package/dist/cjs/render/graph.js +2 -2
- package/dist/cjs/render/layout.js +46 -46
- package/dist/cjs/render/render.js +19 -19
- package/dist/cjs/semantic-tokens/SemanticTokenVisitor.js +59 -59
- package/dist/cjs/utils.js +21 -83
- package/dist/cjs/visitor.js +45 -31
- package/dist/esm/BaseVisitor.js +8 -2
- package/dist/esm/BomGeneration.js +1 -1
- package/dist/esm/ComponentMatchConditions.js +1 -1
- package/dist/esm/annotate/RefdesAnnotationVisitor.js +4 -0
- package/dist/esm/builtinMethods.js +2 -2
- package/dist/esm/execute.js +4 -2
- package/dist/esm/globals.js +1 -8
- package/dist/esm/helpers.js +3 -2
- package/dist/esm/index.js +6 -2
- package/dist/esm/lexer.js +8 -4
- package/dist/esm/objects/BlockTypes.js +7 -0
- package/dist/esm/objects/NumericValue.js +189 -0
- package/dist/esm/objects/ParamDefinition.js +0 -148
- package/dist/esm/objects/PercentageValue.js +12 -0
- package/dist/esm/objects/PinDefinition.js +1 -1
- package/dist/esm/objects/WrappedNumber.js +12 -0
- package/dist/esm/pipeline.js +2 -2
- package/dist/esm/render/draw_symbols.js +2 -2
- package/dist/esm/render/export.js +1 -1
- package/dist/esm/render/geometry.js +1 -2
- package/dist/esm/render/graph.js +1 -1
- package/dist/esm/render/layout.js +2 -2
- package/dist/esm/render/render.js +1 -1
- package/dist/esm/semantic-tokens/SemanticTokenVisitor.js +58 -58
- package/dist/esm/utils.js +16 -74
- package/dist/esm/visitor.js +17 -3
- package/dist/types/ComponentMatchConditions.d.ts +1 -1
- package/dist/types/annotate/RefdesAnnotationVisitor.d.ts +3 -1
- package/dist/types/execute.d.ts +4 -2
- package/dist/types/globals.d.ts +1 -7
- package/dist/types/helpers.d.ts +2 -2
- package/dist/types/index.d.ts +6 -2
- package/dist/types/lexer.d.ts +1 -0
- package/dist/types/objects/BlockTypes.d.ts +6 -0
- package/dist/types/objects/ClassComponent.d.ts +1 -1
- package/dist/types/objects/ExecutionScope.d.ts +2 -1
- package/dist/types/objects/NumericValue.d.ts +35 -0
- package/dist/types/objects/ParamDefinition.d.ts +0 -41
- package/dist/types/objects/PercentageValue.d.ts +6 -0
- package/dist/types/objects/PinDefinition.d.ts +1 -1
- package/dist/types/objects/WrappedNumber.d.ts +6 -0
- package/dist/types/objects/types.d.ts +2 -1
- package/dist/types/render/draw_symbols.d.ts +1 -1
- package/dist/types/render/geometry.d.ts +1 -1
- package/dist/types/render/layout.d.ts +1 -1
- package/dist/types/semantic-tokens/SemanticTokenVisitor.d.ts +3 -4
- package/dist/types/utils.d.ts +1 -7
- package/package.json +1 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Assignment_exprContext } from "../antlr/CircuitScriptParser.js";
|
|
2
2
|
import { BaseVisitor } from "../BaseVisitor.js";
|
|
3
|
-
import { buildInMethodNamesList } from "../builtinMethods.js";
|
|
4
3
|
import { SymbolValidatorContext } from "../globals.js";
|
|
5
4
|
export class SemanticTokensVisitor extends BaseVisitor {
|
|
6
5
|
parsedTokens = [];
|
|
@@ -28,13 +27,6 @@ export class SemanticTokensVisitor extends BaseVisitor {
|
|
|
28
27
|
this.addSemanticToken(id, ['declaration'], 'parameter');
|
|
29
28
|
});
|
|
30
29
|
};
|
|
31
|
-
visitFunction_call_expr = (ctx) => {
|
|
32
|
-
const modifiers = [];
|
|
33
|
-
if (buildInMethodNamesList.indexOf(ctx.ID().getText()) !== -1) {
|
|
34
|
-
modifiers.push('defaultLibrary');
|
|
35
|
-
}
|
|
36
|
-
this.addSemanticToken(ctx.ID(), modifiers, 'function');
|
|
37
|
-
};
|
|
38
30
|
visitFunction_def_expr = (ctx) => {
|
|
39
31
|
const functionName = ctx.ID().getText();
|
|
40
32
|
this.addSemanticToken(ctx.ID(), ['declaration'], 'function');
|
|
@@ -48,17 +40,13 @@ export class SemanticTokensVisitor extends BaseVisitor {
|
|
|
48
40
|
this.executionStack.pop();
|
|
49
41
|
};
|
|
50
42
|
visitCreateExpr = (ctx) => {
|
|
51
|
-
this.addSemanticToken(ctx.Create(), ['defaultLibrary'], 'function');
|
|
52
43
|
this.visit(ctx.create_expr());
|
|
53
44
|
};
|
|
54
45
|
visitCreate_component_expr = (ctx) => {
|
|
55
|
-
ctx.
|
|
56
|
-
this.visit(property_expr);
|
|
57
|
-
});
|
|
46
|
+
this.visitResult(ctx.properties_block());
|
|
58
47
|
};
|
|
59
48
|
visitCreate_graphic_expr = (ctx) => {
|
|
60
|
-
|
|
61
|
-
this.visitResult(graphicsExpressionsCtx);
|
|
49
|
+
this.visitResult(ctx.graphic_expressions_block());
|
|
62
50
|
};
|
|
63
51
|
visitProperty_key_expr = (ctx) => {
|
|
64
52
|
let useValue = null;
|
|
@@ -92,27 +80,36 @@ export class SemanticTokensVisitor extends BaseVisitor {
|
|
|
92
80
|
this.addSemanticToken(useValue, [], 'property');
|
|
93
81
|
}
|
|
94
82
|
};
|
|
95
|
-
visitValueAtomExpr = (ctx) => {
|
|
96
|
-
const ctxValueExpr = ctx.value_expr();
|
|
97
|
-
const ctxAtomExpr = ctx.atom_expr();
|
|
98
|
-
if (ctxValueExpr) {
|
|
99
|
-
this.visit(ctxValueExpr);
|
|
100
|
-
}
|
|
101
|
-
else if (ctxAtomExpr) {
|
|
102
|
-
this.visit(ctxAtomExpr);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
83
|
visitAssignment_expr = (ctx) => {
|
|
106
84
|
this.visit(ctx.callable_expr());
|
|
107
85
|
this.visit(ctx.data_expr());
|
|
108
86
|
};
|
|
109
87
|
visitCallable_expr = (ctx) => {
|
|
110
|
-
|
|
111
|
-
|
|
88
|
+
const id = ctx.ID();
|
|
89
|
+
if (!id)
|
|
90
|
+
return;
|
|
91
|
+
if (ctx.parent instanceof Assignment_exprContext) {
|
|
92
|
+
this.addSemanticToken(id, [], 'variable');
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const trailers = ctx.trailer();
|
|
96
|
+
if (trailers && trailers.length > 0) {
|
|
97
|
+
const firstTrailer = trailers[0];
|
|
98
|
+
if (firstTrailer.LParen()) {
|
|
99
|
+
this.addSemanticToken(id, [], 'function');
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
112
102
|
}
|
|
113
103
|
};
|
|
114
|
-
|
|
115
|
-
|
|
104
|
+
visitImport_simple = (ctx) => {
|
|
105
|
+
};
|
|
106
|
+
visitImport_specific_or_all = (ctx) => {
|
|
107
|
+
const funcNames = ctx.ID();
|
|
108
|
+
if (funcNames && funcNames.length > 0) {
|
|
109
|
+
funcNames.forEach(funcName => {
|
|
110
|
+
this.addSemanticToken(funcName, ['defaultLibrary'], 'function');
|
|
111
|
+
});
|
|
112
|
+
}
|
|
116
113
|
};
|
|
117
114
|
visitFor_expr = (ctx) => {
|
|
118
115
|
ctx.ID().forEach(item => {
|
|
@@ -123,7 +120,12 @@ export class SemanticTokensVisitor extends BaseVisitor {
|
|
|
123
120
|
};
|
|
124
121
|
visitAnnotation_comment_expr = (ctx) => {
|
|
125
122
|
this.addSemanticToken(ctx.ANNOTATION_START(), [], 'comment');
|
|
126
|
-
|
|
123
|
+
const ids = ctx.ID();
|
|
124
|
+
if (ids && ids.length > 0) {
|
|
125
|
+
ids.forEach(id => {
|
|
126
|
+
this.addSemanticToken(id, [], 'comment');
|
|
127
|
+
});
|
|
128
|
+
}
|
|
127
129
|
};
|
|
128
130
|
addSemanticToken(node, modifiers, tokenType = null) {
|
|
129
131
|
const parsedToken = this.parseToken(node, modifiers, tokenType);
|
|
@@ -134,20 +136,21 @@ export class SemanticTokensVisitor extends BaseVisitor {
|
|
|
134
136
|
let stringValue = "";
|
|
135
137
|
let textPart = "";
|
|
136
138
|
if (this.lexer.symbolicNames[token.type] !== null && this.lexer.symbolicNames[token.type] !== undefined) {
|
|
137
|
-
stringValue = this.lexer.symbolicNames[token.type];
|
|
139
|
+
stringValue = this.lexer.symbolicNames[token.type] ?? '';
|
|
138
140
|
if (stringValue !== "NEWLINE") {
|
|
139
141
|
textPart = this.script.substring(token.start, token.stop + 1);
|
|
140
142
|
}
|
|
141
143
|
else {
|
|
142
|
-
textPart = token.text
|
|
144
|
+
textPart = token.text || '';
|
|
143
145
|
}
|
|
144
146
|
}
|
|
145
147
|
else if (this.lexer.literalNames[token.type] !== null && this.lexer.literalNames[token.type] !== undefined) {
|
|
146
|
-
stringValue = this.lexer.literalNames[token.type];
|
|
148
|
+
stringValue = this.lexer.literalNames[token.type] ?? '';
|
|
147
149
|
textPart = this.script.substring(token.start, token.stop + 1);
|
|
148
150
|
}
|
|
149
151
|
else {
|
|
150
|
-
stringValue = token.
|
|
152
|
+
stringValue = token.text ?? '';
|
|
153
|
+
textPart = token.text || '';
|
|
151
154
|
}
|
|
152
155
|
return {
|
|
153
156
|
line: token.line,
|
|
@@ -156,6 +159,7 @@ export class SemanticTokensVisitor extends BaseVisitor {
|
|
|
156
159
|
tokenType: tokenType !== null ? tokenType : stringValue,
|
|
157
160
|
tokenModifiers: modifiers,
|
|
158
161
|
textValue: textPart,
|
|
162
|
+
path: '',
|
|
159
163
|
};
|
|
160
164
|
}
|
|
161
165
|
dumpTokens() {
|
|
@@ -169,38 +173,39 @@ export class SemanticTokensVisitor extends BaseVisitor {
|
|
|
169
173
|
}
|
|
170
174
|
export function prepareTokens(tokens, lexer, script) {
|
|
171
175
|
const parsedTokens = [];
|
|
172
|
-
|
|
176
|
+
for (const item of tokens) {
|
|
173
177
|
if (item.type !== -1) {
|
|
174
178
|
let stringValue = "";
|
|
175
179
|
let textPart = "";
|
|
176
180
|
if (lexer.symbolicNames[item.type] !== null && lexer.symbolicNames[item.type] !== undefined) {
|
|
177
|
-
stringValue = lexer.symbolicNames[item.type];
|
|
181
|
+
stringValue = lexer.symbolicNames[item.type] ?? '';
|
|
178
182
|
if (stringValue !== "NEWLINE") {
|
|
179
183
|
textPart = script.substring(item.start, item.stop + 1);
|
|
180
184
|
}
|
|
181
185
|
else {
|
|
182
|
-
textPart = item.text
|
|
186
|
+
textPart = item.text || '';
|
|
183
187
|
}
|
|
184
188
|
}
|
|
185
|
-
else if (lexer.literalNames[item.type] !== null && lexer.literalNames[item.type] !== undefined) {
|
|
186
|
-
stringValue = lexer.literalNames[item.type];
|
|
187
|
-
textPart = script.substring(item.start, item.stop + 1);
|
|
188
|
-
}
|
|
189
189
|
else {
|
|
190
|
-
stringValue = item.
|
|
190
|
+
stringValue = item.text ?? '';
|
|
191
|
+
textPart = item.text || '';
|
|
191
192
|
}
|
|
192
|
-
if (textPart !==
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
193
|
+
if (textPart !== '') {
|
|
194
|
+
const tokenType = resolveTokenType(stringValue);
|
|
195
|
+
if (tokenType !== '') {
|
|
196
|
+
parsedTokens.push({
|
|
197
|
+
line: item.line,
|
|
198
|
+
column: item.column,
|
|
199
|
+
length: item.stop - item.start + 1,
|
|
200
|
+
tokenType: tokenType,
|
|
201
|
+
tokenModifiers: resolveTokenModifiers(stringValue),
|
|
202
|
+
textValue: textPart,
|
|
203
|
+
path: '',
|
|
204
|
+
});
|
|
205
|
+
}
|
|
201
206
|
}
|
|
202
207
|
}
|
|
203
|
-
}
|
|
208
|
+
}
|
|
204
209
|
return parsedTokens;
|
|
205
210
|
}
|
|
206
211
|
const languageKeywords = [
|
|
@@ -208,15 +213,10 @@ const languageKeywords = [
|
|
|
208
213
|
'graphic', 'wire', 'pin', 'add', 'at', 'to',
|
|
209
214
|
'point', 'join', 'parallel', 'return', 'def', 'from', 'import',
|
|
210
215
|
'true', 'false', 'nc', 'sheet', 'frame', 'if', 'else', 'for', 'in',
|
|
211
|
-
];
|
|
212
|
-
const operatorKeywords = [
|
|
213
216
|
'at', 'to', 'wire', 'add', 'frame', 'join', 'parallel', 'point'
|
|
214
217
|
];
|
|
215
218
|
function resolveTokenType(tokenType) {
|
|
216
|
-
if (
|
|
217
|
-
return 'graphKeyword';
|
|
218
|
-
}
|
|
219
|
-
else if (languageKeywords.indexOf(tokenType.toLowerCase()) !== -1) {
|
|
219
|
+
if (languageKeywords.indexOf(tokenType.toLowerCase()) !== -1) {
|
|
220
220
|
return 'keyword';
|
|
221
221
|
}
|
|
222
222
|
else {
|
|
@@ -236,7 +236,7 @@ function resolveTokenType(tokenType) {
|
|
|
236
236
|
case 'COMMENT':
|
|
237
237
|
return 'comment';
|
|
238
238
|
}
|
|
239
|
-
return
|
|
239
|
+
return '';
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
function resolveTokenModifiers(tokenType) {
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { Big } from 'big.js';
|
|
2
1
|
import { ParserRuleContext } from "antlr4ng";
|
|
3
2
|
import { ClassComponent } from "./objects/ClassComponent.js";
|
|
4
|
-
import { NumericValue } from "./objects/ParamDefinition.js";
|
|
5
3
|
import { SequenceAction } from './objects/ExecutionScope.js';
|
|
6
|
-
import { BlockTypes } from
|
|
4
|
+
import { BlockTypes } from "./objects/BlockTypes.js";
|
|
7
5
|
import { DeclaredReference, AnyReference } from './objects/types.js';
|
|
8
6
|
export class SimpleStopwatch {
|
|
9
7
|
startTime;
|
|
@@ -71,9 +69,6 @@ export function getPortType(component) {
|
|
|
71
69
|
});
|
|
72
70
|
return foundPinType;
|
|
73
71
|
}
|
|
74
|
-
export function roundValue(value) {
|
|
75
|
-
return resolveToNumericValue(new Big(value.toBigNumber().toFixed(7)));
|
|
76
|
-
}
|
|
77
72
|
export function throwWithContext(context, messageOrError) {
|
|
78
73
|
if (messageOrError instanceof BaseError) {
|
|
79
74
|
throw messageOrError;
|
|
@@ -93,67 +88,6 @@ export function combineMaps(map1, map2) {
|
|
|
93
88
|
});
|
|
94
89
|
return newMap;
|
|
95
90
|
}
|
|
96
|
-
export function getNumberExponential(value) {
|
|
97
|
-
value = value.trim();
|
|
98
|
-
switch (value) {
|
|
99
|
-
case 'G':
|
|
100
|
-
return 9;
|
|
101
|
-
case 'M':
|
|
102
|
-
return 6;
|
|
103
|
-
case 'k':
|
|
104
|
-
case 'K':
|
|
105
|
-
return 3;
|
|
106
|
-
case 'm':
|
|
107
|
-
return -3;
|
|
108
|
-
case 'u':
|
|
109
|
-
return -6;
|
|
110
|
-
case 'n':
|
|
111
|
-
return -9;
|
|
112
|
-
case 'p':
|
|
113
|
-
return -12;
|
|
114
|
-
case 'f':
|
|
115
|
-
return -15;
|
|
116
|
-
default:
|
|
117
|
-
return 0;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
export function getNumberExponentialText(value) {
|
|
121
|
-
switch (value) {
|
|
122
|
-
case -15:
|
|
123
|
-
return 'f';
|
|
124
|
-
case -12:
|
|
125
|
-
return 'p';
|
|
126
|
-
case -9:
|
|
127
|
-
return 'n';
|
|
128
|
-
case -6:
|
|
129
|
-
return 'u';
|
|
130
|
-
case -3:
|
|
131
|
-
return 'm';
|
|
132
|
-
case 3:
|
|
133
|
-
return 'k';
|
|
134
|
-
case 6:
|
|
135
|
-
return 'M';
|
|
136
|
-
case 9:
|
|
137
|
-
return 'G';
|
|
138
|
-
case 0:
|
|
139
|
-
default:
|
|
140
|
-
return '';
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
export function resolveToNumericValue(value) {
|
|
144
|
-
if (value.toNumber() === 0) {
|
|
145
|
-
return new NumericValue(0);
|
|
146
|
-
}
|
|
147
|
-
const isNeg = value.lt(0);
|
|
148
|
-
const positiveValue = isNeg ? value.neg() : value;
|
|
149
|
-
const prefixPart = Math.floor(Math.log10(positiveValue.toNumber()) / 3);
|
|
150
|
-
let useValue = value;
|
|
151
|
-
if (prefixPart !== 0) {
|
|
152
|
-
const tmpValue1 = positiveValue.div(Math.pow(10, prefixPart * 3));
|
|
153
|
-
useValue = isNeg ? tmpValue1.neg() : tmpValue1;
|
|
154
|
-
}
|
|
155
|
-
return new NumericValue(useValue, prefixPart * 3);
|
|
156
|
-
}
|
|
157
91
|
export function isPointWithinArea(point, bounds) {
|
|
158
92
|
const [xPt, yPt] = point;
|
|
159
93
|
const [xmin, ymin, xmax, ymax] = bounds;
|
|
@@ -276,18 +210,26 @@ export function getLinePositionAsString(ctx) {
|
|
|
276
210
|
if (ctx === null || ctx === undefined) {
|
|
277
211
|
return null;
|
|
278
212
|
}
|
|
279
|
-
const startToken = ctx
|
|
280
|
-
const endToken = ctx.stop;
|
|
213
|
+
const { start: startToken, stop: stopToken } = ctx;
|
|
281
214
|
let result = null;
|
|
282
215
|
if (startToken) {
|
|
283
216
|
const { line, column } = startToken;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
217
|
+
let stopLine = 0;
|
|
218
|
+
let stopCol = 0;
|
|
219
|
+
if (stopToken && (stopToken.line !== startToken.line || stopToken.column !== startToken.column)) {
|
|
220
|
+
stopLine = stopToken.line;
|
|
221
|
+
stopCol = stopToken.column + (stopToken.stop - stopToken.start);
|
|
222
|
+
}
|
|
223
|
+
else if (startToken === stopToken || startToken) {
|
|
224
|
+
stopLine = line;
|
|
225
|
+
stopCol = column + 1 + (startToken.stop - startToken.start);
|
|
288
226
|
}
|
|
289
227
|
else {
|
|
290
|
-
|
|
228
|
+
stopCol = -1;
|
|
229
|
+
}
|
|
230
|
+
result = ` at ${line}:${column + 1}`;
|
|
231
|
+
if (stopCol !== -1) {
|
|
232
|
+
result += `-${stopLine}:${stopCol + 1}`;
|
|
291
233
|
}
|
|
292
234
|
}
|
|
293
235
|
return result;
|
package/dist/esm/visitor.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { ClassComponent } from './objects/ClassComponent.js';
|
|
2
|
-
import { NumberOperator,
|
|
2
|
+
import { NumberOperator, NumericValue } from './objects/NumericValue.js';
|
|
3
|
+
import { ParamDefinition } from "./objects/ParamDefinition.js";
|
|
4
|
+
import { numeric } from "./objects/NumericValue.js";
|
|
3
5
|
import { PinDefinition, PinId, PinIdType } from './objects/PinDefinition.js';
|
|
4
6
|
import { PinTypes } from './objects/PinTypes.js';
|
|
5
7
|
import { DeclaredReference, UndeclaredReference } from './objects/types.js';
|
|
6
|
-
import {
|
|
8
|
+
import { ComponentTypes, Delimiter1, FrameType, GlobalDocumentName, ModuleContainsKeyword, NoNetText, ParamKeys, RefdesFileSuffix, ReferenceTypes, SymbolPinSide, ValidPinSides, WireAutoDirection } from './globals.js';
|
|
9
|
+
import { BlockTypes } from "./objects/BlockTypes.js";
|
|
7
10
|
import { unwrapValue } from "./utils.js";
|
|
8
11
|
import { PlaceHolderCommands, SymbolDrawingCommands } from './render/draw_symbols.js';
|
|
9
12
|
import { BaseVisitor } from './BaseVisitor.js';
|
|
@@ -663,7 +666,12 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
663
666
|
}
|
|
664
667
|
dataResult = unwrapValue(dataResult);
|
|
665
668
|
if (dataResult === null || dataResult === undefined) {
|
|
666
|
-
|
|
669
|
+
if (componentCtx) {
|
|
670
|
+
this.throwWithContext(componentCtx, "Could not find component: " + componentCtx.getText());
|
|
671
|
+
}
|
|
672
|
+
else {
|
|
673
|
+
this.throwWithContext(ctx, "Failed to parse");
|
|
674
|
+
}
|
|
667
675
|
}
|
|
668
676
|
if (dataResult instanceof ClassComponent
|
|
669
677
|
&& dataResult.copyProp) {
|
|
@@ -1009,7 +1017,13 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1009
1017
|
}
|
|
1010
1018
|
segments.push([value, new UnitDimension(useValue)]);
|
|
1011
1019
|
}
|
|
1020
|
+
else {
|
|
1021
|
+
this.throwWithContext(ctx, "Invalid wire expression");
|
|
1022
|
+
}
|
|
1012
1023
|
});
|
|
1024
|
+
if (segments.length === 0) {
|
|
1025
|
+
this.throwWithContext(ctx, "Invalid wire expression");
|
|
1026
|
+
}
|
|
1013
1027
|
const newWire = this.getExecutor().addWire(segments);
|
|
1014
1028
|
this.creationCtx.set(newWire, ctx);
|
|
1015
1029
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ParserRuleContext, CommonTokenStream } from 'antlr4ng';
|
|
2
|
-
import { Add_component_exprContext, At_block_headerContext, At_blockContext, At_component_exprContext, Component_select_exprContext, Frame_exprContext, Function_def_exprContext, Function_return_exprContext, ScriptContext, To_component_exprContext, TrailerContext } from '../antlr/CircuitScriptParser.js';
|
|
2
|
+
import { Add_component_exprContext, Assignment_exprContext, At_block_headerContext, At_blockContext, At_component_exprContext, Callable_exprContext, Component_select_exprContext, Frame_exprContext, Function_def_exprContext, Function_return_exprContext, ScriptContext, To_component_exprContext, TrailerContext } from '../antlr/CircuitScriptParser.js';
|
|
3
3
|
import { BaseVisitor } from '../BaseVisitor.js';
|
|
4
4
|
import { ClassComponent } from '../objects/ClassComponent.js';
|
|
5
5
|
import { RefdesModification } from './utils.js';
|
|
@@ -14,6 +14,8 @@ export declare class RefdesAnnotationVisitor extends BaseVisitor {
|
|
|
14
14
|
getModifications(): Map<ParserRuleContext, RefdesModification>;
|
|
15
15
|
private getOriginalText;
|
|
16
16
|
visitScript: (ctx: ScriptContext) => Promise<void>;
|
|
17
|
+
visitCallable_expr: (ctx: Callable_exprContext) => void;
|
|
18
|
+
visitAssignment_expr: (ctx: Assignment_exprContext) => void;
|
|
17
19
|
visitAdd_component_expr: (ctx: Add_component_exprContext) => void;
|
|
18
20
|
visitAt_component_expr: (ctx: At_component_exprContext) => void;
|
|
19
21
|
visitComponent_select_expr: (ctx: Component_select_exprContext) => void;
|
package/dist/types/execute.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FrameType, ReferenceTypes } from './globals.js';
|
|
2
|
+
import { BlockTypes } from "./objects/BlockTypes.js";
|
|
2
3
|
import { ExecutionWarning } from "./utils.js";
|
|
3
4
|
import { ClassComponent } from './objects/ClassComponent.js';
|
|
4
5
|
import { ExecutionScope } from './objects/ExecutionScope.js';
|
|
5
6
|
import { Net } from './objects/Net.js';
|
|
6
|
-
import { NumericValue
|
|
7
|
+
import { NumericValue } from './objects/NumericValue.js';
|
|
8
|
+
import { ParamDefinition } from "./objects/ParamDefinition.js";
|
|
7
9
|
import { PinDefinition, PinId } from './objects/PinDefinition.js';
|
|
8
10
|
import { AnyReference, CFunction, CFunctionEntry, CFunctionResult, CallableParameter, ComponentPin, ComponentUnitDefinition } from './objects/types.js';
|
|
9
11
|
import { Wire } from './objects/Wire.js';
|
package/dist/types/globals.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ export declare const displayUnits = LengthUnit.mils;
|
|
|
61
61
|
export declare const defaultFont = "Arial";
|
|
62
62
|
export declare const defaultFontBold = "Arial";
|
|
63
63
|
export declare const defaultFontSize = 10;
|
|
64
|
-
export declare const junctionSize: import("./objects/
|
|
64
|
+
export declare const junctionSize: import("./objects/NumericValue.js").NumericValue;
|
|
65
65
|
export declare const PortArrowSize: number;
|
|
66
66
|
export declare const PortPaddingHorizontal: number;
|
|
67
67
|
export declare const PortPaddingVertical: number;
|
|
@@ -88,12 +88,6 @@ export declare enum ReferenceTypes {
|
|
|
88
88
|
library = "library",
|
|
89
89
|
unknown = "unknown"
|
|
90
90
|
}
|
|
91
|
-
export declare enum BlockTypes {
|
|
92
|
-
Branch = 1,
|
|
93
|
-
Join = 2,
|
|
94
|
-
Parallel = 3,
|
|
95
|
-
Point = 4
|
|
96
|
-
}
|
|
97
91
|
export declare enum NetGraphicsParams {
|
|
98
92
|
Color = "color",
|
|
99
93
|
LineWidth = "lineWidth",
|
package/dist/types/helpers.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { BaseError } from "./utils.js";
|
|
2
1
|
import { ParserRuleContext } from "antlr4ng";
|
|
2
|
+
import { BaseError } from "./utils.js";
|
|
3
3
|
import { ATNSimulator, BaseErrorListener, CommonTokenStream, DefaultErrorStrategy, Parser, RecognitionException, Recognizer, Token } from "antlr4ng";
|
|
4
4
|
import { CircuitScriptParser, ScriptContext } from "./antlr/CircuitScriptParser.js";
|
|
5
5
|
import { CircuitScriptLexer } from "./antlr/CircuitScriptLexer.js";
|
|
6
6
|
import { LengthUnit } from "./globals.js";
|
|
7
7
|
export type SVGWindow = any;
|
|
8
|
-
import { NumericValue } from "./objects/
|
|
8
|
+
import { NumericValue } from "./objects/NumericValue.js";
|
|
9
9
|
import { NodeScriptEnvironment } from "./environment/environment.js";
|
|
10
10
|
import { ImportedLibrary } from "./objects/types.js";
|
|
11
11
|
export declare enum JSModuleType {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
export * from './render/draw_symbols.js';
|
|
2
2
|
export * from './execute.js';
|
|
3
|
-
export * from './export.js';
|
|
3
|
+
export * from './render/export.js';
|
|
4
4
|
export * from './render/geometry.js';
|
|
5
|
+
export * from './pipeline.js';
|
|
5
6
|
export * from './globals.js';
|
|
6
7
|
export * from './helpers.js';
|
|
7
8
|
export * from './render/layout.js';
|
|
9
|
+
export * from './render/render.js';
|
|
10
|
+
export * from './render/KiCadNetListOutputHandler.js';
|
|
8
11
|
export * from './lexer.js';
|
|
9
12
|
export * from './LexerDiagnosticListener.js';
|
|
10
13
|
export * from './logger.js';
|
|
11
14
|
export * from './parser.js';
|
|
12
|
-
export * from './render/render.js';
|
|
13
15
|
export * from './utils.js';
|
|
14
16
|
export * from './visitor.js';
|
|
15
17
|
export * from './sizing.js';
|
|
@@ -18,5 +20,7 @@ export * from './builtinMethods.js';
|
|
|
18
20
|
export * from './validate/SymbolTable.js';
|
|
19
21
|
export * from './validate/SymbolValidatorResolveVisitor.js';
|
|
20
22
|
export * from './validate/SymbolValidatorVisitor.js';
|
|
23
|
+
export * from './validate/validateScript.js';
|
|
21
24
|
export * from './environment/environment.js';
|
|
22
25
|
export * from './annotate/RefdesAnnotationVisitor.js';
|
|
26
|
+
export * from './semantic-tokens/getSemanticTokens.js';
|
package/dist/types/lexer.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare class MainLexer extends CircuitScriptLexer {
|
|
|
8
8
|
opened: number;
|
|
9
9
|
diagnosticCollector: LexerDiagnosticCollector;
|
|
10
10
|
lineOffset: number;
|
|
11
|
+
enableDiagnostics: boolean;
|
|
11
12
|
constructor(input: CharStream, enableDiagnostics?: boolean);
|
|
12
13
|
reset(): void;
|
|
13
14
|
emitToken(token: Token): void;
|
|
@@ -5,7 +5,7 @@ import { Net } from './Net.js';
|
|
|
5
5
|
import { PinDefinition, PinId } from './PinDefinition.js';
|
|
6
6
|
import { WireSegment } from './Wire.js';
|
|
7
7
|
import { ExecutionContext } from '../execute.js';
|
|
8
|
-
import { NumericValue } from './
|
|
8
|
+
import { NumericValue } from './NumericValue.js';
|
|
9
9
|
export declare class ComponentUnit {
|
|
10
10
|
parent: ClassComponent;
|
|
11
11
|
unitId: string;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ClassComponent } from './ClassComponent.js';
|
|
2
2
|
import { Net } from './Net.js';
|
|
3
3
|
import { CFunction, CFunctionEntry, ComponentPinNet, ComponentPinNetPair, ComponentPinWireId, ImportedLibrary, ValueType } from './types.js';
|
|
4
|
-
import {
|
|
4
|
+
import { LayoutDirection } from '../globals.js';
|
|
5
|
+
import { BlockTypes } from "./BlockTypes.js";
|
|
5
6
|
import { Wire, WireSegment } from './Wire.js';
|
|
6
7
|
import { Frame } from './Frame.js';
|
|
7
8
|
import { ParserRuleContext } from 'antlr4ng';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Big } from 'big.js';
|
|
2
|
+
import { PercentageValue } from "./PercentageValue.js";
|
|
3
|
+
import { WrappedNumber } from "./WrappedNumber.js";
|
|
4
|
+
export declare class NumericValue {
|
|
5
|
+
value: string | number | Big;
|
|
6
|
+
valuePart: Big;
|
|
7
|
+
prefixPart: number;
|
|
8
|
+
constructor(value: string | number | Big, prefix?: number);
|
|
9
|
+
toString(): string;
|
|
10
|
+
toDisplayString(): string;
|
|
11
|
+
toNumber(): number;
|
|
12
|
+
toBigNumber(): Big;
|
|
13
|
+
div(value: NumericValue | number): NumericValue;
|
|
14
|
+
half(): NumericValue;
|
|
15
|
+
mul(value: NumericValue | number): NumericValue;
|
|
16
|
+
add(value: NumericValue | number): NumericValue;
|
|
17
|
+
sub(value: NumericValue | number): NumericValue;
|
|
18
|
+
mod(value: NumericValue | number): NumericValue;
|
|
19
|
+
neg(): NumericValue;
|
|
20
|
+
eq(value: NumericValue): boolean;
|
|
21
|
+
}
|
|
22
|
+
export type NumberOperatorType = NumericValue | PercentageValue | WrappedNumber;
|
|
23
|
+
export declare class NumberOperator {
|
|
24
|
+
prepare(value: number | NumberOperatorType): NumberOperatorType;
|
|
25
|
+
multiply(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
|
|
26
|
+
divide(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
|
|
27
|
+
addition(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
|
|
28
|
+
subtraction(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
|
|
29
|
+
modulus(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
|
|
30
|
+
}
|
|
31
|
+
export declare function numeric(value: number | string): NumericValue;
|
|
32
|
+
export declare function getNumberExponentialText(value: number): string;
|
|
33
|
+
export declare function getNumberExponential(value: string): number;
|
|
34
|
+
export declare function resolveToNumericValue(value: Big): NumericValue;
|
|
35
|
+
export declare function roundValue(value: NumericValue): NumericValue;
|
|
@@ -1,46 +1,5 @@
|
|
|
1
|
-
import { Big } from 'big.js';
|
|
2
1
|
export declare class ParamDefinition {
|
|
3
2
|
paramName: string;
|
|
4
3
|
paramValue: string | number | any;
|
|
5
4
|
constructor(paramName: string, paramValue: any);
|
|
6
5
|
}
|
|
7
|
-
export declare class NumericValue {
|
|
8
|
-
value: string | number | Big;
|
|
9
|
-
valuePart: Big;
|
|
10
|
-
prefixPart: number;
|
|
11
|
-
constructor(value: string | number | Big, prefix?: number);
|
|
12
|
-
toString(): string;
|
|
13
|
-
toDisplayString(): string;
|
|
14
|
-
toNumber(): number;
|
|
15
|
-
toBigNumber(): Big;
|
|
16
|
-
div(value: NumericValue | number): NumericValue;
|
|
17
|
-
half(): NumericValue;
|
|
18
|
-
mul(value: NumericValue | number): NumericValue;
|
|
19
|
-
add(value: NumericValue | number): NumericValue;
|
|
20
|
-
sub(value: NumericValue | number): NumericValue;
|
|
21
|
-
mod(value: NumericValue | number): NumericValue;
|
|
22
|
-
neg(): NumericValue;
|
|
23
|
-
eq(value: NumericValue): boolean;
|
|
24
|
-
}
|
|
25
|
-
export declare function numeric(value: number | string): NumericValue;
|
|
26
|
-
export declare class PercentageValue {
|
|
27
|
-
value: string | number;
|
|
28
|
-
constructor(value: string | number);
|
|
29
|
-
toString(): string;
|
|
30
|
-
toNumber(): number;
|
|
31
|
-
}
|
|
32
|
-
export declare class WrappedNumber {
|
|
33
|
-
value: number;
|
|
34
|
-
constructor(value: number);
|
|
35
|
-
toString(): string;
|
|
36
|
-
toNumber(): number;
|
|
37
|
-
}
|
|
38
|
-
export type NumberOperatorType = NumericValue | PercentageValue | WrappedNumber;
|
|
39
|
-
export declare class NumberOperator {
|
|
40
|
-
prepare(value: number | NumberOperatorType): NumberOperatorType;
|
|
41
|
-
multiply(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
|
|
42
|
-
divide(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
|
|
43
|
-
addition(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
|
|
44
|
-
subtraction(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
|
|
45
|
-
modulus(value1: NumberOperatorType, value2: NumberOperatorType): NumberOperatorType;
|
|
46
|
-
}
|
|
@@ -2,7 +2,8 @@ import { CommonTokenStream, ParserRuleContext, Token } from 'antlr4ng';
|
|
|
2
2
|
import { ExecutionContext } from '../execute.js';
|
|
3
3
|
import { ClassComponent } from './ClassComponent.js';
|
|
4
4
|
import { Net } from './Net.js';
|
|
5
|
-
import { NumericValue
|
|
5
|
+
import { NumericValue } from './NumericValue.js';
|
|
6
|
+
import { PercentageValue } from "./PercentageValue.js";
|
|
6
7
|
import { ReferenceTypes } from '../globals.js';
|
|
7
8
|
import { PinDefinition, PinId } from './PinDefinition.js';
|
|
8
9
|
import { ScriptContext } from 'src/antlr/CircuitScriptParser.js';
|
|
@@ -3,7 +3,7 @@ import { Feature, GeometryProp, HorizontalAlign, LabelStyle, Textbox, VerticalAl
|
|
|
3
3
|
import { Logger } from "../logger.js";
|
|
4
4
|
import { PinTypes } from "../objects/PinTypes.js";
|
|
5
5
|
import { ParserRuleContext } from "antlr4ng";
|
|
6
|
-
import { NumericValue } from "../objects/
|
|
6
|
+
import { NumericValue } from "../objects/NumericValue.js";
|
|
7
7
|
import { PinId } from "../objects/PinDefinition.js";
|
|
8
8
|
export declare abstract class SymbolGraphic {
|
|
9
9
|
drawPortsName: boolean;
|