circuitscript 0.1.10 → 0.1.11

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.
@@ -100,6 +100,11 @@ class SemanticTokensVisitor extends BaseVisitor_js_1.BaseVisitor {
100
100
  this.visitImport_expr = (ctx) => {
101
101
  this.addSemanticToken(ctx.ID(), [], 'namespace');
102
102
  };
103
+ this.visitFor_expr = (ctx) => {
104
+ ctx.ID().forEach(item => {
105
+ this.addSemanticToken(item, [], 'variable');
106
+ });
107
+ };
103
108
  this.lexer = lexer;
104
109
  this.script = script;
105
110
  }
@@ -187,7 +192,7 @@ const languageKeywords = [
187
192
  'break', 'branch', 'create', 'component',
188
193
  'graphic', 'wire', 'pin', 'add', 'at', 'to',
189
194
  'point', 'join', 'parallel', 'return', 'def', 'import',
190
- 'true', 'false', 'nc', 'sheet', 'frame', 'if', 'for',
195
+ 'true', 'false', 'nc', 'sheet', 'frame', 'if', 'else', 'for', 'in',
191
196
  ];
192
197
  const operatorKeywords = [
193
198
  'at', 'to', 'wire', 'add', 'frame', 'join', 'parallel', 'point'
@@ -577,21 +577,13 @@ class CircuitScriptParser extends antlr.Parser {
577
577
  pin_select_expr() {
578
578
  let localContext = new Pin_select_exprContext(this.context, this.state);
579
579
  this.enterRule(localContext, 14, CircuitScriptParser.RULE_pin_select_expr);
580
- let _la;
581
580
  try {
582
581
  this.enterOuterAlt(localContext, 1);
583
582
  {
584
583
  this.state = 202;
585
584
  this.match(CircuitScriptParser.Pin);
586
585
  this.state = 203;
587
- _la = this.tokenStream.LA(1);
588
- if (!(_la === 57 || _la === 60)) {
589
- this.errorHandler.recoverInline(this);
590
- }
591
- else {
592
- this.errorHandler.reportMatch(this);
593
- this.consume();
594
- }
586
+ this.data_expr(0);
595
587
  }
596
588
  }
597
589
  catch (re) {
@@ -3805,7 +3797,7 @@ CircuitScriptParser._serializedATN = [
3805
3797
  191, 1, 0, 0, 0, 193, 194, 1, 0, 0, 0, 194, 192, 1, 0, 0, 0, 194, 195, 1, 0, 0, 0, 195,
3806
3798
  196, 1, 0, 0, 0, 196, 197, 5, 67, 0, 0, 197, 11, 1, 0, 0, 0, 198, 199, 7, 1, 0, 0, 199,
3807
3799
  200, 5, 1, 0, 0, 200, 201, 3, 68, 34, 0, 201, 13, 1, 0, 0, 0, 202, 203, 5, 15, 0, 0, 203,
3808
- 204, 7, 2, 0, 0, 204, 15, 1, 0, 0, 0, 205, 206, 5, 56, 0, 0, 206, 209, 5, 1, 0, 0, 207,
3800
+ 204, 3, 62, 31, 0, 204, 15, 1, 0, 0, 0, 205, 206, 5, 56, 0, 0, 206, 209, 5, 1, 0, 0, 207,
3809
3801
  210, 3, 68, 34, 0, 208, 210, 5, 56, 0, 0, 209, 207, 1, 0, 0, 0, 209, 208, 1, 0, 0, 0, 210,
3810
3802
  17, 1, 0, 0, 0, 211, 214, 3, 62, 31, 0, 212, 214, 3, 50, 25, 0, 213, 211, 1, 0, 0, 0, 213,
3811
3803
  212, 1, 0, 0, 0, 214, 218, 1, 0, 0, 0, 215, 217, 3, 16, 8, 0, 216, 215, 1, 0, 0, 0, 217,
@@ -4241,11 +4233,8 @@ class Pin_select_exprContext extends antlr.ParserRuleContext {
4241
4233
  Pin() {
4242
4234
  return this.getToken(CircuitScriptParser.Pin, 0);
4243
4235
  }
4244
- INTEGER_VALUE() {
4245
- return this.getToken(CircuitScriptParser.INTEGER_VALUE, 0);
4246
- }
4247
- STRING_VALUE() {
4248
- return this.getToken(CircuitScriptParser.STRING_VALUE, 0);
4236
+ data_expr() {
4237
+ return this.getRuleContext(0, Data_exprContext);
4249
4238
  }
4250
4239
  get ruleIndex() {
4251
4240
  return CircuitScriptParser.RULE_pin_select_expr;
@@ -427,7 +427,8 @@ class SymbolPlaceholder extends SymbolGraphic {
427
427
  drawing.addArc(...positionParams);
428
428
  break;
429
429
  case PlaceHolderCommands.circle:
430
- drawing.addArc(...positionParams, (0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(360));
430
+ drawing.addArc(...positionParams, (0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(180));
431
+ drawing.addArc(...positionParams, (0, ParamDefinition_js_1.numeric)(180), (0, ParamDefinition_js_1.numeric)(360));
431
432
  break;
432
433
  case PlaceHolderCommands.triangle:
433
434
  drawing.addTriangle(...positionParams);
@@ -266,17 +266,12 @@ class Geometry {
266
266
  const x = item.center.x;
267
267
  const y = item.center.y;
268
268
  const radius = item.r;
269
- let useEndAngle = item.endAngle;
270
269
  let extraEnd = '';
271
- if (item.startAngle === 0 && item.endAngle === Geometry.FullCircleRadians) {
272
- useEndAngle = 359.9999 * Math.PI / 180;
273
- isClosedPolygon = true;
274
- extraEnd = ' Z';
275
- }
276
- const startPoint = getArcPointRadians(x, y, radius, item.startAngle);
270
+ const { startAngle: useStartAngle, endAngle: useEndAngle } = item;
271
+ const startPoint = getArcPointRadians(x, y, radius, useStartAngle);
277
272
  const endPoint = getArcPointRadians(x, y, radius, useEndAngle);
278
273
  let largeArcSweepFlag = 0;
279
- if (useEndAngle - item.startAngle > Math.PI) {
274
+ if (useEndAngle - useStartAngle > Math.PI) {
280
275
  largeArcSweepFlag = 1;
281
276
  }
282
277
  let sweepFlag = 1;
@@ -428,7 +423,6 @@ class Geometry {
428
423
  }
429
424
  }
430
425
  exports.Geometry = Geometry;
431
- Geometry.FullCircleRadians = 2 * Math.PI;
432
426
  function replaceSegments(segments, index, replacedSegments) {
433
427
  if (replacedSegments.length > 0) {
434
428
  segments.splice(index, 1);
@@ -103,6 +103,11 @@ class SymbolValidatorVisitor extends BaseVisitor_js_1.BaseVisitor {
103
103
  this.runExpressions(newExecutor, ctx.function_expr());
104
104
  this.executionStack.pop();
105
105
  };
106
+ this.visitFor_expr = (ctx) => {
107
+ ctx.ID().forEach(item => {
108
+ this.addSymbolVariable(item.getSymbol(), item.getText(), null);
109
+ });
110
+ };
106
111
  }
107
112
  enterFile(filePath) {
108
113
  this.filePathStack.push(filePath);
@@ -22,13 +22,16 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
22
22
  };
23
23
  this.visitPin_select_expr = (ctx) => {
24
24
  let value = null;
25
- const ctxIntegerValue = ctx.INTEGER_VALUE();
26
- const ctxStringValue = ctx.STRING_VALUE();
27
- if (ctxIntegerValue) {
28
- value = Number(ctxIntegerValue.getText());
25
+ const ctxData = ctx.data_expr();
26
+ const result = this.visitResult(ctxData);
27
+ if (result instanceof ParamDefinition_js_1.NumericValue) {
28
+ value = result.toNumber();
29
29
  }
30
- else if (ctxStringValue) {
31
- value = this.prepareStringValue(ctxStringValue.getText());
30
+ else if (typeof result === 'string') {
31
+ value = result;
32
+ }
33
+ else {
34
+ throw new utils_js_1.RuntimeExecutionError("Invalid value for pin", ctx);
32
35
  }
33
36
  this.setResult(ctx, value);
34
37
  };
@@ -102,6 +102,11 @@ export class SemanticTokensVisitor extends BaseVisitor {
102
102
  visitImport_expr = (ctx) => {
103
103
  this.addSemanticToken(ctx.ID(), [], 'namespace');
104
104
  };
105
+ visitFor_expr = (ctx) => {
106
+ ctx.ID().forEach(item => {
107
+ this.addSemanticToken(item, [], 'variable');
108
+ });
109
+ };
105
110
  addSemanticToken(node, modifiers, tokenType = null) {
106
111
  const parsedToken = this.parseToken(node, modifiers, tokenType);
107
112
  this.semanticTokens.set(parsedToken.line + "_" + parsedToken.column, parsedToken);
@@ -184,7 +189,7 @@ const languageKeywords = [
184
189
  'break', 'branch', 'create', 'component',
185
190
  'graphic', 'wire', 'pin', 'add', 'at', 'to',
186
191
  'point', 'join', 'parallel', 'return', 'def', 'import',
187
- 'true', 'false', 'nc', 'sheet', 'frame', 'if', 'for',
192
+ 'true', 'false', 'nc', 'sheet', 'frame', 'if', 'else', 'for', 'in',
188
193
  ];
189
194
  const operatorKeywords = [
190
195
  'at', 'to', 'wire', 'add', 'frame', 'join', 'parallel', 'point'
@@ -724,21 +724,13 @@ export class CircuitScriptParser extends antlr.Parser {
724
724
  pin_select_expr() {
725
725
  let localContext = new Pin_select_exprContext(this.context, this.state);
726
726
  this.enterRule(localContext, 14, CircuitScriptParser.RULE_pin_select_expr);
727
- let _la;
728
727
  try {
729
728
  this.enterOuterAlt(localContext, 1);
730
729
  {
731
730
  this.state = 202;
732
731
  this.match(CircuitScriptParser.Pin);
733
732
  this.state = 203;
734
- _la = this.tokenStream.LA(1);
735
- if (!(_la === 57 || _la === 60)) {
736
- this.errorHandler.recoverInline(this);
737
- }
738
- else {
739
- this.errorHandler.reportMatch(this);
740
- this.consume();
741
- }
733
+ this.data_expr(0);
742
734
  }
743
735
  }
744
736
  catch (re) {
@@ -3767,7 +3759,7 @@ export class CircuitScriptParser extends antlr.Parser {
3767
3759
  191, 1, 0, 0, 0, 193, 194, 1, 0, 0, 0, 194, 192, 1, 0, 0, 0, 194, 195, 1, 0, 0, 0, 195,
3768
3760
  196, 1, 0, 0, 0, 196, 197, 5, 67, 0, 0, 197, 11, 1, 0, 0, 0, 198, 199, 7, 1, 0, 0, 199,
3769
3761
  200, 5, 1, 0, 0, 200, 201, 3, 68, 34, 0, 201, 13, 1, 0, 0, 0, 202, 203, 5, 15, 0, 0, 203,
3770
- 204, 7, 2, 0, 0, 204, 15, 1, 0, 0, 0, 205, 206, 5, 56, 0, 0, 206, 209, 5, 1, 0, 0, 207,
3762
+ 204, 3, 62, 31, 0, 204, 15, 1, 0, 0, 0, 205, 206, 5, 56, 0, 0, 206, 209, 5, 1, 0, 0, 207,
3771
3763
  210, 3, 68, 34, 0, 208, 210, 5, 56, 0, 0, 209, 207, 1, 0, 0, 0, 209, 208, 1, 0, 0, 0, 210,
3772
3764
  17, 1, 0, 0, 0, 211, 214, 3, 62, 31, 0, 212, 214, 3, 50, 25, 0, 213, 211, 1, 0, 0, 0, 213,
3773
3765
  212, 1, 0, 0, 0, 214, 218, 1, 0, 0, 0, 215, 217, 3, 16, 8, 0, 216, 215, 1, 0, 0, 0, 217,
@@ -4207,11 +4199,8 @@ export class Pin_select_exprContext extends antlr.ParserRuleContext {
4207
4199
  Pin() {
4208
4200
  return this.getToken(CircuitScriptParser.Pin, 0);
4209
4201
  }
4210
- INTEGER_VALUE() {
4211
- return this.getToken(CircuitScriptParser.INTEGER_VALUE, 0);
4212
- }
4213
- STRING_VALUE() {
4214
- return this.getToken(CircuitScriptParser.STRING_VALUE, 0);
4202
+ data_expr() {
4203
+ return this.getRuleContext(0, Data_exprContext);
4215
4204
  }
4216
4205
  get ruleIndex() {
4217
4206
  return CircuitScriptParser.RULE_pin_select_expr;
@@ -424,7 +424,8 @@ export class SymbolPlaceholder extends SymbolGraphic {
424
424
  drawing.addArc(...positionParams);
425
425
  break;
426
426
  case PlaceHolderCommands.circle:
427
- drawing.addArc(...positionParams, numeric(0), numeric(360));
427
+ drawing.addArc(...positionParams, numeric(0), numeric(180));
428
+ drawing.addArc(...positionParams, numeric(180), numeric(360));
428
429
  break;
429
430
  case PlaceHolderCommands.triangle:
430
431
  drawing.addTriangle(...positionParams);
@@ -254,7 +254,6 @@ export class Geometry {
254
254
  height: maxY - minY,
255
255
  };
256
256
  }
257
- static FullCircleRadians = 2 * Math.PI;
258
257
  static featuresToPath(items, flipX, flipY) {
259
258
  const paths = [];
260
259
  let isClosedPolygon = false;
@@ -267,17 +266,12 @@ export class Geometry {
267
266
  const x = item.center.x;
268
267
  const y = item.center.y;
269
268
  const radius = item.r;
270
- let useEndAngle = item.endAngle;
271
269
  let extraEnd = '';
272
- if (item.startAngle === 0 && item.endAngle === Geometry.FullCircleRadians) {
273
- useEndAngle = 359.9999 * Math.PI / 180;
274
- isClosedPolygon = true;
275
- extraEnd = ' Z';
276
- }
277
- const startPoint = getArcPointRadians(x, y, radius, item.startAngle);
270
+ const { startAngle: useStartAngle, endAngle: useEndAngle } = item;
271
+ const startPoint = getArcPointRadians(x, y, radius, useStartAngle);
278
272
  const endPoint = getArcPointRadians(x, y, radius, useEndAngle);
279
273
  let largeArcSweepFlag = 0;
280
- if (useEndAngle - item.startAngle > Math.PI) {
274
+ if (useEndAngle - useStartAngle > Math.PI) {
281
275
  largeArcSweepFlag = 1;
282
276
  }
283
277
  let sweepFlag = 1;
@@ -154,6 +154,11 @@ export class SymbolValidatorVisitor extends BaseVisitor {
154
154
  this.runExpressions(newExecutor, ctx.function_expr());
155
155
  this.executionStack.pop();
156
156
  };
157
+ visitFor_expr = (ctx) => {
158
+ ctx.ID().forEach(item => {
159
+ this.addSymbolVariable(item.getSymbol(), item.getText(), null);
160
+ });
161
+ };
157
162
  getSymbols() {
158
163
  return this.symbolTable;
159
164
  }
@@ -17,13 +17,16 @@ export class ParserVisitor extends BaseVisitor {
17
17
  };
18
18
  visitPin_select_expr = (ctx) => {
19
19
  let value = null;
20
- const ctxIntegerValue = ctx.INTEGER_VALUE();
21
- const ctxStringValue = ctx.STRING_VALUE();
22
- if (ctxIntegerValue) {
23
- value = Number(ctxIntegerValue.getText());
20
+ const ctxData = ctx.data_expr();
21
+ const result = this.visitResult(ctxData);
22
+ if (result instanceof NumericValue) {
23
+ value = result.toNumber();
24
24
  }
25
- else if (ctxStringValue) {
26
- value = this.prepareStringValue(ctxStringValue.getText());
25
+ else if (typeof result === 'string') {
26
+ value = result;
27
+ }
28
+ else {
29
+ throw new RuntimeExecutionError("Invalid value for pin", ctx);
27
30
  }
28
31
  this.setResult(ctx, value);
29
32
  };
@@ -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 } 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 } 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 {
@@ -20,6 +20,7 @@ export declare class SemanticTokensVisitor extends BaseVisitor {
20
20
  visitAssignment_expr: (ctx: Assignment_exprContext) => void;
21
21
  visitAtom_expr: (ctx: Atom_exprContext) => void;
22
22
  visitImport_expr: (ctx: Import_exprContext) => void;
23
+ visitFor_expr: (ctx: For_exprContext) => void;
23
24
  addSemanticToken(node: TerminalNode, modifiers: string[], tokenType?: string | null): void;
24
25
  parseToken(node: TerminalNode, modifiers: string[], tokenType?: string | null): IParsedToken;
25
26
  dumpTokens(): void;
@@ -307,8 +307,7 @@ export declare class Assignment_expr2Context extends antlr.ParserRuleContext {
307
307
  export declare class Pin_select_exprContext extends antlr.ParserRuleContext {
308
308
  constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
309
309
  Pin(): antlr.TerminalNode;
310
- INTEGER_VALUE(): antlr.TerminalNode | null;
311
- STRING_VALUE(): antlr.TerminalNode | null;
310
+ data_expr(): Data_exprContext;
312
311
  get ruleIndex(): number;
313
312
  accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
314
313
  }
@@ -64,7 +64,6 @@ export declare class Geometry {
64
64
  width: number;
65
65
  height: number;
66
66
  };
67
- static FullCircleRadians: number;
68
67
  static featuresToPath(items: Feature[], flipX: number, flipY: number): {
69
68
  path: string;
70
69
  isClosedPolygon: boolean;
@@ -1,5 +1,5 @@
1
1
  import { TerminalNode, Token } from "antlr4ng";
2
- import { Import_exprContext, Assignment_exprContext, Atom_exprContext, Function_call_exprContext, ValueAtomExprContext, UnaryOperatorExprContext, MultiplyExprContext, AdditionExprContext, BinaryOperatorExprContext, DataExprContext, Function_def_exprContext } from "src/antlr/CircuitScriptParser";
2
+ import { Import_exprContext, Assignment_exprContext, Atom_exprContext, Function_call_exprContext, ValueAtomExprContext, UnaryOperatorExprContext, MultiplyExprContext, AdditionExprContext, BinaryOperatorExprContext, DataExprContext, Function_def_exprContext, For_exprContext } from "src/antlr/CircuitScriptParser";
3
3
  import { ExecutionContext } from "../execute.js";
4
4
  import { ComplexType, FunctionDefinedParameter } from "../objects/types.js";
5
5
  import { SymbolTableItem } from "./SymbolTable.js";
@@ -27,6 +27,7 @@ export declare class SymbolValidatorVisitor extends BaseVisitor {
27
27
  visitBinaryOperatorExpr: (ctx: BinaryOperatorExprContext) => void;
28
28
  visitDataExpr: (ctx: DataExprContext) => void;
29
29
  visitFunction_def_expr: (ctx: Function_def_exprContext) => void;
30
+ visitFor_expr: (ctx: For_exprContext) => void;
30
31
  getSymbols(): SymbolTable;
31
32
  dumpSymbols(): void;
32
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "circuitscript",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Interpreter for the circuitscript language",
5
5
  "homepage": "https://circuitscript.net",
6
6
  "engines": {
@@ -69,7 +69,8 @@
69
69
  "profile": "node --prof build/src/main.js examples/example_garden_pump.cst",
70
70
  "profile-flame": "node --prof-process --preprocess -j isolate*.log | flamebearer",
71
71
  "server": "node server.js",
72
- "pack-local": "npm run build; npm pack; rm circuitscript-install.tgz; mv `ls | grep circuitscript-` circuitscript-install.tgz; cp circuitscript-install.tgz ../circuitscript-vscode/client; cp circuitscript-install.tgz ../circuitscript-vscode/server && echo 'OK'",
72
+ "_old_pack-local": "npm run build; npm pack; rm circuitscript-install.tgz; mv `ls | grep circuitscript-` circuitscript-install.tgz; cp circuitscript-install.tgz ../circuitscript-vscode/client; cp circuitscript-install.tgz ../circuitscript-vscode/server && echo 'OK'",
73
+ "pack-language-server": "npm run build:release; npm pack; rm circuitscript-install.tgz; mv `ls | grep circuitscript-` circuitscript-install.tgz; cp circuitscript-install.tgz ../circuitscript-ide/language-server",
73
74
  "changelog": "auto-changelog --handlebars-setup ../changelog/helper.js -p",
74
75
  "preversion": "npm run test",
75
76
  "version": "npm run changelog && git add CHANGELOG.md",