circuitscript 0.0.20 → 0.0.21

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.
@@ -223,6 +223,21 @@ R1.mpn = "res-12345"
223
223
  expect(item1.parameters.get('place')).toBe(false);
224
224
  expect(item1.parameters.get('mpn')).toBe('res-12345');
225
225
  });
226
+
227
+ test('unary minus operator', async () => {
228
+ const script = `
229
+ b = 20
230
+ print(b)
231
+ print(-b)
232
+ print(--b)
233
+ print(---b)
234
+ `;
235
+
236
+ const { hasError, visitor } = await runScript(script);
237
+ expect(hasError).toBe(false);
238
+
239
+ expect(visitor.printStream).toStrictEqual([20, -20, 20, -20]);
240
+ });
226
241
  });
227
242
 
228
243
  // This tests that an error is generated at the right position for
@@ -1715,67 +1715,66 @@ export default class CircuitScriptParser extends Parser {
1715
1715
  {
1716
1716
  this.state = 329;
1717
1717
  this._errHandler.sync(this);
1718
- switch (this._interp.adaptivePredict(this._input, 34, this._ctx)) {
1718
+ switch (this._interp.adaptivePredict(this._input, 33, this._ctx)) {
1719
1719
  case 1:
1720
1720
  {
1721
- localctx = new DataExprContext(this, localctx);
1721
+ localctx = new RoundedBracketsExprContext(this, localctx);
1722
1722
  this._ctx = localctx;
1723
1723
  _prevctx = localctx;
1724
- {
1725
- this.state = 317;
1726
- this._errHandler.sync(this);
1727
- switch (this._interp.adaptivePredict(this._input, 32, this._ctx)) {
1728
- case 1:
1729
- {
1730
- this.state = 316;
1731
- this.unary_operator();
1732
- }
1733
- break;
1734
- }
1735
- this.state = 321;
1736
- this._errHandler.sync(this);
1737
- switch (this._input.LA(1)) {
1738
- case 6:
1739
- case 30:
1740
- case 36:
1741
- case 38:
1742
- case 39:
1743
- case 40:
1744
- case 41:
1745
- case 42:
1746
- {
1747
- this.state = 319;
1748
- this.value_expr();
1749
- }
1750
- break;
1751
- case 29:
1752
- case 31:
1753
- case 37:
1754
- {
1755
- this.state = 320;
1756
- this.atom_expr();
1757
- }
1758
- break;
1759
- default:
1760
- throw new NoViableAltException(this);
1761
- }
1762
- }
1724
+ this.state = 316;
1725
+ this.match(CircuitScriptParser.OPEN_PAREN);
1726
+ this.state = 317;
1727
+ this.data_expr(0);
1728
+ this.state = 318;
1729
+ this.match(CircuitScriptParser.CLOSE_PAREN);
1763
1730
  }
1764
1731
  break;
1765
1732
  case 2:
1766
1733
  {
1767
- localctx = new RoundedBracketsExprContext(this, localctx);
1734
+ localctx = new ValueAtomExprContext(this, localctx);
1735
+ this._ctx = localctx;
1736
+ _prevctx = localctx;
1737
+ this.state = 322;
1738
+ this._errHandler.sync(this);
1739
+ switch (this._input.LA(1)) {
1740
+ case 6:
1741
+ case 30:
1742
+ case 36:
1743
+ case 38:
1744
+ case 39:
1745
+ case 40:
1746
+ case 41:
1747
+ case 42:
1748
+ {
1749
+ this.state = 320;
1750
+ this.value_expr();
1751
+ }
1752
+ break;
1753
+ case 29:
1754
+ case 31:
1755
+ case 37:
1756
+ {
1757
+ this.state = 321;
1758
+ this.atom_expr();
1759
+ }
1760
+ break;
1761
+ default:
1762
+ throw new NoViableAltException(this);
1763
+ }
1764
+ }
1765
+ break;
1766
+ case 3:
1767
+ {
1768
+ localctx = new UnaryOperatorExprContext(this, localctx);
1768
1769
  this._ctx = localctx;
1769
1770
  _prevctx = localctx;
1770
- this.state = 323;
1771
- this.match(CircuitScriptParser.OPEN_PAREN);
1772
1771
  this.state = 324;
1773
- this.data_expr(0);
1772
+ this.unary_operator();
1774
1773
  this.state = 325;
1775
- this.match(CircuitScriptParser.CLOSE_PAREN);
1774
+ this.data_expr(6);
1776
1775
  }
1777
1776
  break;
1778
- case 3:
1777
+ case 4:
1779
1778
  {
1780
1779
  localctx = new DataExprContext(this, localctx);
1781
1780
  this._ctx = localctx;
@@ -1784,7 +1783,7 @@ export default class CircuitScriptParser extends Parser {
1784
1783
  this.create_component_expr();
1785
1784
  }
1786
1785
  break;
1787
- case 4:
1786
+ case 5:
1788
1787
  {
1789
1788
  localctx = new DataExprContext(this, localctx);
1790
1789
  this._ctx = localctx;
@@ -1797,7 +1796,7 @@ export default class CircuitScriptParser extends Parser {
1797
1796
  this._ctx.stop = this._input.LT(-1);
1798
1797
  this.state = 343;
1799
1798
  this._errHandler.sync(this);
1800
- _alt = this._interp.adaptivePredict(this._input, 36, this._ctx);
1799
+ _alt = this._interp.adaptivePredict(this._input, 35, this._ctx);
1801
1800
  while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) {
1802
1801
  if (_alt === 1) {
1803
1802
  if (this._parseListeners != null) {
@@ -1807,7 +1806,7 @@ export default class CircuitScriptParser extends Parser {
1807
1806
  {
1808
1807
  this.state = 341;
1809
1808
  this._errHandler.sync(this);
1810
- switch (this._interp.adaptivePredict(this._input, 35, this._ctx)) {
1809
+ switch (this._interp.adaptivePredict(this._input, 34, this._ctx)) {
1811
1810
  case 1:
1812
1811
  {
1813
1812
  localctx = new MultiplyExprContext(this, new Data_exprContext(this, _parentctx, _parentState));
@@ -1869,7 +1868,7 @@ export default class CircuitScriptParser extends Parser {
1869
1868
  }
1870
1869
  this.state = 345;
1871
1870
  this._errHandler.sync(this);
1872
- _alt = this._interp.adaptivePredict(this._input, 36, this._ctx);
1871
+ _alt = this._interp.adaptivePredict(this._input, 35, this._ctx);
1873
1872
  }
1874
1873
  }
1875
1874
  }
@@ -2175,7 +2174,7 @@ export default class CircuitScriptParser extends Parser {
2175
2174
  let _alt;
2176
2175
  this.state = 408;
2177
2176
  this._errHandler.sync(this);
2178
- switch (this._interp.adaptivePredict(this._input, 46, this._ctx)) {
2177
+ switch (this._interp.adaptivePredict(this._input, 45, this._ctx)) {
2179
2178
  case 1:
2180
2179
  this.enterOuterAlt(localctx, 1);
2181
2180
  {
@@ -2183,7 +2182,7 @@ export default class CircuitScriptParser extends Parser {
2183
2182
  this.match(CircuitScriptParser.ID);
2184
2183
  this.state = 384;
2185
2184
  this._errHandler.sync(this);
2186
- _alt = this._interp.adaptivePredict(this._input, 43, this._ctx);
2185
+ _alt = this._interp.adaptivePredict(this._input, 42, this._ctx);
2187
2186
  while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) {
2188
2187
  if (_alt === 1) {
2189
2188
  {
@@ -2197,7 +2196,7 @@ export default class CircuitScriptParser extends Parser {
2197
2196
  }
2198
2197
  this.state = 386;
2199
2198
  this._errHandler.sync(this);
2200
- _alt = this._interp.adaptivePredict(this._input, 43, this._ctx);
2199
+ _alt = this._interp.adaptivePredict(this._input, 42, this._ctx);
2201
2200
  }
2202
2201
  this.state = 393;
2203
2202
  this._errHandler.sync(this);
@@ -2290,7 +2289,7 @@ export default class CircuitScriptParser extends Parser {
2290
2289
  this.match(CircuitScriptParser.ID);
2291
2290
  this.state = 417;
2292
2291
  this._errHandler.sync(this);
2293
- _alt = this._interp.adaptivePredict(this._input, 48, this._ctx);
2292
+ _alt = this._interp.adaptivePredict(this._input, 47, this._ctx);
2294
2293
  while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) {
2295
2294
  if (_alt === 1) {
2296
2295
  {
@@ -2302,7 +2301,7 @@ export default class CircuitScriptParser extends Parser {
2302
2301
  }
2303
2302
  this.state = 419;
2304
2303
  this._errHandler.sync(this);
2305
- _alt = this._interp.adaptivePredict(this._input, 48, this._ctx);
2304
+ _alt = this._interp.adaptivePredict(this._input, 47, this._ctx);
2306
2305
  }
2307
2306
  }
2308
2307
  }
@@ -2395,7 +2394,7 @@ export default class CircuitScriptParser extends Parser {
2395
2394
  this.match(CircuitScriptParser.Divide);
2396
2395
  this.state = 434;
2397
2396
  this._errHandler.sync(this);
2398
- switch (this._interp.adaptivePredict(this._input, 52, this._ctx)) {
2397
+ switch (this._interp.adaptivePredict(this._input, 51, this._ctx)) {
2399
2398
  case 1:
2400
2399
  {
2401
2400
  this.state = 433;
@@ -2598,7 +2597,7 @@ export default class CircuitScriptParser extends Parser {
2598
2597
  this.match(CircuitScriptParser.T__0);
2599
2598
  this.state = 472;
2600
2599
  this._errHandler.sync(this);
2601
- switch (this._interp.adaptivePredict(this._input, 57, this._ctx)) {
2600
+ switch (this._interp.adaptivePredict(this._input, 56, this._ctx)) {
2602
2601
  case 1:
2603
2602
  {
2604
2603
  this.state = 467;
@@ -2844,7 +2843,7 @@ export default class CircuitScriptParser extends Parser {
2844
2843
  this.match(CircuitScriptParser.ID);
2845
2844
  this.state = 508;
2846
2845
  this._errHandler.sync(this);
2847
- _alt = this._interp.adaptivePredict(this._input, 62, this._ctx);
2846
+ _alt = this._interp.adaptivePredict(this._input, 61, this._ctx);
2848
2847
  while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) {
2849
2848
  if (_alt === 1) {
2850
2849
  {
@@ -2863,7 +2862,7 @@ export default class CircuitScriptParser extends Parser {
2863
2862
  }
2864
2863
  this.state = 510;
2865
2864
  this._errHandler.sync(this);
2866
- _alt = this._interp.adaptivePredict(this._input, 62, this._ctx);
2865
+ _alt = this._interp.adaptivePredict(this._input, 61, this._ctx);
2867
2866
  }
2868
2867
  }
2869
2868
  }
@@ -3055,40 +3054,40 @@ export default class CircuitScriptParser extends Parser {
3055
3054
  1, 24, 1, 24, 1, 24, 5, 24, 285, 8, 24, 10, 24, 12, 24, 288, 9, 24, 1, 24, 1, 24, 5, 24, 292, 8,
3056
3055
  24, 10, 24, 12, 24, 295, 9, 24, 1, 24, 1, 24, 1, 24, 5, 24, 300, 8, 24, 10, 24, 12, 24, 303, 9,
3057
3056
  24, 3, 24, 305, 8, 24, 1, 25, 1, 25, 1, 25, 1, 25, 1, 26, 1, 26, 1, 26, 1, 26, 1, 26, 1, 27, 1, 27,
3058
- 3, 27, 318, 8, 27, 1, 27, 1, 27, 3, 27, 322, 8, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 3, 27,
3059
- 330, 8, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 5, 27, 342, 8, 27,
3060
- 10, 27, 12, 27, 345, 9, 27, 1, 28, 1, 28, 1, 29, 1, 29, 1, 30, 3, 30, 352, 8, 30, 1, 30, 1, 30, 3,
3061
- 30, 356, 8, 30, 1, 31, 1, 31, 1, 31, 1, 31, 3, 31, 362, 8, 31, 1, 31, 1, 31, 1, 31, 1, 31, 1, 31,
3062
- 1, 31, 4, 31, 370, 8, 31, 11, 31, 12, 31, 371, 1, 31, 1, 31, 1, 32, 1, 32, 3, 32, 378, 8, 32, 1,
3063
- 33, 1, 33, 1, 33, 5, 33, 383, 8, 33, 10, 33, 12, 33, 386, 9, 33, 1, 33, 1, 33, 1, 33, 1, 33, 5, 33,
3064
- 392, 8, 33, 10, 33, 12, 33, 395, 9, 33, 1, 33, 1, 33, 1, 33, 1, 33, 1, 33, 1, 33, 1, 33, 5, 33, 404,
3065
- 8, 33, 10, 33, 12, 33, 407, 9, 33, 3, 33, 409, 8, 33, 1, 34, 3, 34, 412, 8, 34, 1, 34, 1, 34, 5,
3066
- 34, 416, 8, 34, 10, 34, 12, 34, 419, 9, 34, 1, 35, 1, 35, 3, 35, 423, 8, 35, 1, 35, 1, 35, 1, 35,
3067
- 3, 35, 428, 8, 35, 1, 36, 3, 36, 431, 8, 36, 1, 36, 1, 36, 3, 36, 435, 8, 36, 1, 37, 1, 37, 1, 37,
3068
- 1, 38, 1, 38, 1, 38, 1, 38, 1, 38, 1, 38, 1, 38, 4, 38, 447, 8, 38, 11, 38, 12, 38, 448, 1, 38, 1,
3069
- 38, 1, 39, 1, 39, 1, 39, 1, 39, 1, 39, 1, 39, 1, 39, 4, 39, 460, 8, 39, 11, 39, 12, 39, 461, 1, 39,
3070
- 1, 39, 1, 40, 1, 40, 1, 40, 1, 40, 1, 40, 1, 40, 1, 40, 3, 40, 473, 8, 40, 1, 41, 1, 41, 1, 41, 1,
3071
- 41, 1, 42, 1, 42, 1, 43, 1, 43, 1, 43, 1, 43, 4, 43, 485, 8, 43, 11, 43, 12, 43, 486, 1, 43, 1, 43,
3072
- 1, 43, 1, 43, 5, 43, 493, 8, 43, 10, 43, 12, 43, 496, 9, 43, 3, 43, 498, 8, 43, 1, 44, 1, 44, 1,
3073
- 44, 1, 44, 1, 45, 1, 45, 1, 45, 5, 45, 507, 8, 45, 10, 45, 12, 45, 510, 9, 45, 1, 46, 1, 46, 1, 46,
3074
- 1, 47, 1, 47, 1, 47, 1, 48, 1, 48, 1, 48, 1, 48, 1, 48, 1, 48, 4, 48, 524, 8, 48, 11, 48, 12, 48,
3075
- 525, 1, 48, 1, 48, 1, 48, 0, 1, 54, 49, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
3076
- 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78,
3077
- 80, 82, 84, 86, 88, 90, 92, 94, 96, 0, 11, 2, 0, 10, 10, 19, 21, 1, 0, 37, 38, 2, 0, 38, 38, 41,
3078
- 41, 2, 0, 35, 35, 38, 38, 1, 0, 31, 32, 1, 0, 29, 30, 1, 0, 27, 28, 2, 0, 26, 26, 30, 30, 2, 0, 36,
3079
- 36, 38, 42, 2, 0, 15, 15, 37, 37, 2, 0, 37, 38, 41, 41, 562, 0, 100, 1, 0, 0, 0, 2, 122, 1, 0, 0,
3080
- 0, 4, 125, 1, 0, 0, 0, 6, 129, 1, 0, 0, 0, 8, 141, 1, 0, 0, 0, 10, 153, 1, 0, 0, 0, 12, 159, 1, 0, 0,
3081
- 0, 14, 164, 1, 0, 0, 0, 16, 171, 1, 0, 0, 0, 18, 173, 1, 0, 0, 0, 20, 176, 1, 0, 0, 0, 22, 178, 1,
3082
- 0, 0, 0, 24, 186, 1, 0, 0, 0, 26, 201, 1, 0, 0, 0, 28, 223, 1, 0, 0, 0, 30, 233, 1, 0, 0, 0, 32, 235,
3083
- 1, 0, 0, 0, 34, 249, 1, 0, 0, 0, 36, 251, 1, 0, 0, 0, 38, 259, 1, 0, 0, 0, 40, 261, 1, 0, 0, 0, 42,
3084
- 271, 1, 0, 0, 0, 44, 273, 1, 0, 0, 0, 46, 277, 1, 0, 0, 0, 48, 304, 1, 0, 0, 0, 50, 306, 1, 0, 0, 0,
3085
- 52, 310, 1, 0, 0, 0, 54, 329, 1, 0, 0, 0, 56, 346, 1, 0, 0, 0, 58, 348, 1, 0, 0, 0, 60, 355, 1, 0,
3086
- 0, 0, 62, 357, 1, 0, 0, 0, 64, 377, 1, 0, 0, 0, 66, 408, 1, 0, 0, 0, 68, 411, 1, 0, 0, 0, 70, 427,
3087
- 1, 0, 0, 0, 72, 430, 1, 0, 0, 0, 74, 436, 1, 0, 0, 0, 76, 439, 1, 0, 0, 0, 78, 452, 1, 0, 0, 0, 80,
3088
- 465, 1, 0, 0, 0, 82, 474, 1, 0, 0, 0, 84, 478, 1, 0, 0, 0, 86, 497, 1, 0, 0, 0, 88, 499, 1, 0, 0, 0,
3089
- 90, 503, 1, 0, 0, 0, 92, 511, 1, 0, 0, 0, 94, 514, 1, 0, 0, 0, 96, 517, 1, 0, 0, 0, 98, 101, 3, 2,
3090
- 1, 0, 99, 101, 5, 45, 0, 0, 100, 98, 1, 0, 0, 0, 100, 99, 1, 0, 0, 0, 101, 102, 1, 0, 0, 0, 102, 100,
3091
- 1, 0, 0, 0, 102, 103, 1, 0, 0, 0, 103, 104, 1, 0, 0, 0, 104, 105, 5, 0, 0, 1, 105, 1, 1, 0, 0, 0, 106,
3057
+ 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 3, 27, 323, 8, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 3, 27, 330,
3058
+ 8, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 5, 27, 342, 8, 27, 10,
3059
+ 27, 12, 27, 345, 9, 27, 1, 28, 1, 28, 1, 29, 1, 29, 1, 30, 3, 30, 352, 8, 30, 1, 30, 1, 30, 3, 30,
3060
+ 356, 8, 30, 1, 31, 1, 31, 1, 31, 1, 31, 3, 31, 362, 8, 31, 1, 31, 1, 31, 1, 31, 1, 31, 1, 31, 1, 31,
3061
+ 4, 31, 370, 8, 31, 11, 31, 12, 31, 371, 1, 31, 1, 31, 1, 32, 1, 32, 3, 32, 378, 8, 32, 1, 33, 1,
3062
+ 33, 1, 33, 5, 33, 383, 8, 33, 10, 33, 12, 33, 386, 9, 33, 1, 33, 1, 33, 1, 33, 1, 33, 5, 33, 392,
3063
+ 8, 33, 10, 33, 12, 33, 395, 9, 33, 1, 33, 1, 33, 1, 33, 1, 33, 1, 33, 1, 33, 1, 33, 5, 33, 404, 8,
3064
+ 33, 10, 33, 12, 33, 407, 9, 33, 3, 33, 409, 8, 33, 1, 34, 3, 34, 412, 8, 34, 1, 34, 1, 34, 5, 34,
3065
+ 416, 8, 34, 10, 34, 12, 34, 419, 9, 34, 1, 35, 1, 35, 3, 35, 423, 8, 35, 1, 35, 1, 35, 1, 35, 3,
3066
+ 35, 428, 8, 35, 1, 36, 3, 36, 431, 8, 36, 1, 36, 1, 36, 3, 36, 435, 8, 36, 1, 37, 1, 37, 1, 37, 1,
3067
+ 38, 1, 38, 1, 38, 1, 38, 1, 38, 1, 38, 1, 38, 4, 38, 447, 8, 38, 11, 38, 12, 38, 448, 1, 38, 1, 38,
3068
+ 1, 39, 1, 39, 1, 39, 1, 39, 1, 39, 1, 39, 1, 39, 4, 39, 460, 8, 39, 11, 39, 12, 39, 461, 1, 39, 1,
3069
+ 39, 1, 40, 1, 40, 1, 40, 1, 40, 1, 40, 1, 40, 1, 40, 3, 40, 473, 8, 40, 1, 41, 1, 41, 1, 41, 1, 41,
3070
+ 1, 42, 1, 42, 1, 43, 1, 43, 1, 43, 1, 43, 4, 43, 485, 8, 43, 11, 43, 12, 43, 486, 1, 43, 1, 43, 1,
3071
+ 43, 1, 43, 5, 43, 493, 8, 43, 10, 43, 12, 43, 496, 9, 43, 3, 43, 498, 8, 43, 1, 44, 1, 44, 1, 44,
3072
+ 1, 44, 1, 45, 1, 45, 1, 45, 5, 45, 507, 8, 45, 10, 45, 12, 45, 510, 9, 45, 1, 46, 1, 46, 1, 46, 1,
3073
+ 47, 1, 47, 1, 47, 1, 48, 1, 48, 1, 48, 1, 48, 1, 48, 1, 48, 4, 48, 524, 8, 48, 11, 48, 12, 48, 525,
3074
+ 1, 48, 1, 48, 1, 48, 0, 1, 54, 49, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32,
3075
+ 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80,
3076
+ 82, 84, 86, 88, 90, 92, 94, 96, 0, 11, 2, 0, 10, 10, 19, 21, 1, 0, 37, 38, 2, 0, 38, 38, 41, 41,
3077
+ 2, 0, 35, 35, 38, 38, 1, 0, 31, 32, 1, 0, 29, 30, 1, 0, 27, 28, 2, 0, 26, 26, 30, 30, 2, 0, 36, 36,
3078
+ 38, 42, 2, 0, 15, 15, 37, 37, 2, 0, 37, 38, 41, 41, 562, 0, 100, 1, 0, 0, 0, 2, 122, 1, 0, 0, 0, 4,
3079
+ 125, 1, 0, 0, 0, 6, 129, 1, 0, 0, 0, 8, 141, 1, 0, 0, 0, 10, 153, 1, 0, 0, 0, 12, 159, 1, 0, 0, 0, 14,
3080
+ 164, 1, 0, 0, 0, 16, 171, 1, 0, 0, 0, 18, 173, 1, 0, 0, 0, 20, 176, 1, 0, 0, 0, 22, 178, 1, 0, 0, 0,
3081
+ 24, 186, 1, 0, 0, 0, 26, 201, 1, 0, 0, 0, 28, 223, 1, 0, 0, 0, 30, 233, 1, 0, 0, 0, 32, 235, 1, 0,
3082
+ 0, 0, 34, 249, 1, 0, 0, 0, 36, 251, 1, 0, 0, 0, 38, 259, 1, 0, 0, 0, 40, 261, 1, 0, 0, 0, 42, 271,
3083
+ 1, 0, 0, 0, 44, 273, 1, 0, 0, 0, 46, 277, 1, 0, 0, 0, 48, 304, 1, 0, 0, 0, 50, 306, 1, 0, 0, 0, 52,
3084
+ 310, 1, 0, 0, 0, 54, 329, 1, 0, 0, 0, 56, 346, 1, 0, 0, 0, 58, 348, 1, 0, 0, 0, 60, 355, 1, 0, 0, 0,
3085
+ 62, 357, 1, 0, 0, 0, 64, 377, 1, 0, 0, 0, 66, 408, 1, 0, 0, 0, 68, 411, 1, 0, 0, 0, 70, 427, 1, 0,
3086
+ 0, 0, 72, 430, 1, 0, 0, 0, 74, 436, 1, 0, 0, 0, 76, 439, 1, 0, 0, 0, 78, 452, 1, 0, 0, 0, 80, 465,
3087
+ 1, 0, 0, 0, 82, 474, 1, 0, 0, 0, 84, 478, 1, 0, 0, 0, 86, 497, 1, 0, 0, 0, 88, 499, 1, 0, 0, 0, 90,
3088
+ 503, 1, 0, 0, 0, 92, 511, 1, 0, 0, 0, 94, 514, 1, 0, 0, 0, 96, 517, 1, 0, 0, 0, 98, 101, 3, 2, 1, 0,
3089
+ 99, 101, 5, 45, 0, 0, 100, 98, 1, 0, 0, 0, 100, 99, 1, 0, 0, 0, 101, 102, 1, 0, 0, 0, 102, 100, 1,
3090
+ 0, 0, 0, 102, 103, 1, 0, 0, 0, 103, 104, 1, 0, 0, 0, 104, 105, 5, 0, 0, 1, 105, 1, 1, 0, 0, 0, 106,
3092
3091
  123, 3, 14, 7, 0, 107, 123, 3, 24, 12, 0, 108, 123, 3, 22, 11, 0, 109, 123, 3, 44, 22, 0, 110,
3093
3092
  123, 3, 50, 25, 0, 111, 123, 3, 8, 4, 0, 112, 123, 3, 52, 26, 0, 113, 123, 3, 42, 21, 0, 114, 123,
3094
3093
  3, 62, 31, 0, 115, 123, 3, 90, 45, 0, 116, 123, 3, 94, 47, 0, 117, 123, 3, 96, 48, 0, 118, 123,
@@ -3146,11 +3145,11 @@ export default class CircuitScriptParser extends Parser {
3146
3145
  0, 0, 0, 302, 305, 1, 0, 0, 0, 303, 301, 1, 0, 0, 0, 304, 281, 1, 0, 0, 0, 304, 296, 1, 0, 0, 0, 305,
3147
3146
  49, 1, 0, 0, 0, 306, 307, 3, 68, 34, 0, 307, 308, 5, 3, 0, 0, 308, 309, 3, 54, 27, 0, 309, 51, 1,
3148
3147
  0, 0, 0, 310, 311, 5, 4, 0, 0, 311, 312, 5, 37, 0, 0, 312, 313, 5, 3, 0, 0, 313, 314, 3, 54, 27,
3149
- 0, 314, 53, 1, 0, 0, 0, 315, 317, 6, 27, -1, 0, 316, 318, 3, 58, 29, 0, 317, 316, 1, 0, 0, 0, 317,
3150
- 318, 1, 0, 0, 0, 318, 321, 1, 0, 0, 0, 319, 322, 3, 60, 30, 0, 320, 322, 3, 68, 34, 0, 321, 319,
3151
- 1, 0, 0, 0, 321, 320, 1, 0, 0, 0, 322, 330, 1, 0, 0, 0, 323, 324, 5, 33, 0, 0, 324, 325, 3, 54, 27,
3152
- 0, 325, 326, 5, 34, 0, 0, 326, 330, 1, 0, 0, 0, 327, 330, 3, 76, 38, 0, 328, 330, 3, 78, 39, 0,
3153
- 329, 315, 1, 0, 0, 0, 329, 323, 1, 0, 0, 0, 329, 327, 1, 0, 0, 0, 329, 328, 1, 0, 0, 0, 330, 343,
3148
+ 0, 314, 53, 1, 0, 0, 0, 315, 316, 6, 27, -1, 0, 316, 317, 5, 33, 0, 0, 317, 318, 3, 54, 27, 0, 318,
3149
+ 319, 5, 34, 0, 0, 319, 330, 1, 0, 0, 0, 320, 323, 3, 60, 30, 0, 321, 323, 3, 68, 34, 0, 322, 320,
3150
+ 1, 0, 0, 0, 322, 321, 1, 0, 0, 0, 323, 330, 1, 0, 0, 0, 324, 325, 3, 58, 29, 0, 325, 326, 3, 54,
3151
+ 27, 6, 326, 330, 1, 0, 0, 0, 327, 330, 3, 76, 38, 0, 328, 330, 3, 78, 39, 0, 329, 315, 1, 0, 0,
3152
+ 0, 329, 322, 1, 0, 0, 0, 329, 324, 1, 0, 0, 0, 329, 327, 1, 0, 0, 0, 329, 328, 1, 0, 0, 0, 330, 343,
3154
3153
  1, 0, 0, 0, 331, 332, 10, 5, 0, 0, 332, 333, 7, 4, 0, 0, 333, 342, 3, 54, 27, 6, 334, 335, 10, 4,
3155
3154
  0, 0, 335, 336, 7, 5, 0, 0, 336, 342, 3, 54, 27, 5, 337, 338, 10, 3, 0, 0, 338, 339, 3, 56, 28,
3156
3155
  0, 339, 340, 3, 54, 27, 4, 340, 342, 1, 0, 0, 0, 341, 331, 1, 0, 0, 0, 341, 334, 1, 0, 0, 0, 341,
@@ -3203,10 +3202,10 @@ export default class CircuitScriptParser extends Parser {
3203
3202
  5, 8, 0, 0, 518, 519, 5, 1, 0, 0, 519, 520, 5, 45, 0, 0, 520, 523, 5, 47, 0, 0, 521, 524, 5, 45,
3204
3203
  0, 0, 522, 524, 3, 2, 1, 0, 523, 521, 1, 0, 0, 0, 523, 522, 1, 0, 0, 0, 524, 525, 1, 0, 0, 0, 525,
3205
3204
  523, 1, 0, 0, 0, 525, 526, 1, 0, 0, 0, 526, 527, 1, 0, 0, 0, 527, 528, 5, 48, 0, 0, 528, 97, 1, 0,
3206
- 0, 0, 65, 100, 102, 122, 127, 135, 137, 147, 149, 159, 162, 167, 171, 181, 184, 192, 196,
3207
- 199, 209, 217, 219, 230, 241, 243, 249, 255, 259, 265, 267, 286, 293, 301, 304, 317, 321,
3208
- 329, 341, 343, 351, 355, 361, 369, 371, 377, 384, 393, 405, 408, 411, 417, 422, 427, 430,
3209
- 434, 446, 448, 459, 461, 472, 484, 486, 494, 497, 508, 523, 525];
3205
+ 0, 0, 64, 100, 102, 122, 127, 135, 137, 147, 149, 159, 162, 167, 171, 181, 184, 192, 196,
3206
+ 199, 209, 217, 219, 230, 241, 243, 249, 255, 259, 265, 267, 286, 293, 301, 304, 322, 329,
3207
+ 341, 343, 351, 355, 361, 369, 371, 377, 384, 393, 405, 408, 411, 417, 422, 427, 430, 434,
3208
+ 446, 448, 459, 461, 472, 484, 486, 494, 497, 508, 523, 525];
3210
3209
  static __ATN;
3211
3210
  static get _ATN() {
3212
3211
  if (!CircuitScriptParser.__ATN) {
@@ -4083,15 +4082,6 @@ export class DataExprContext extends Data_exprContext {
4083
4082
  super(parser, ctx.parentCtx, ctx.invokingState);
4084
4083
  super.copyFrom(ctx);
4085
4084
  }
4086
- value_expr() {
4087
- return this.getTypedRuleContext(Value_exprContext, 0);
4088
- }
4089
- atom_expr() {
4090
- return this.getTypedRuleContext(Atom_exprContext, 0);
4091
- }
4092
- unary_operator() {
4093
- return this.getTypedRuleContext(Unary_operatorContext, 0);
4094
- }
4095
4085
  create_component_expr() {
4096
4086
  return this.getTypedRuleContext(Create_component_exprContext, 0);
4097
4087
  }
@@ -4107,6 +4097,46 @@ export class DataExprContext extends Data_exprContext {
4107
4097
  }
4108
4098
  }
4109
4099
  }
4100
+ export class UnaryOperatorExprContext extends Data_exprContext {
4101
+ constructor(parser, ctx) {
4102
+ super(parser, ctx.parentCtx, ctx.invokingState);
4103
+ super.copyFrom(ctx);
4104
+ }
4105
+ unary_operator() {
4106
+ return this.getTypedRuleContext(Unary_operatorContext, 0);
4107
+ }
4108
+ data_expr() {
4109
+ return this.getTypedRuleContext(Data_exprContext, 0);
4110
+ }
4111
+ accept(visitor) {
4112
+ if (visitor.visitUnaryOperatorExpr) {
4113
+ return visitor.visitUnaryOperatorExpr(this);
4114
+ }
4115
+ else {
4116
+ return visitor.visitChildren(this);
4117
+ }
4118
+ }
4119
+ }
4120
+ export class ValueAtomExprContext extends Data_exprContext {
4121
+ constructor(parser, ctx) {
4122
+ super(parser, ctx.parentCtx, ctx.invokingState);
4123
+ super.copyFrom(ctx);
4124
+ }
4125
+ value_expr() {
4126
+ return this.getTypedRuleContext(Value_exprContext, 0);
4127
+ }
4128
+ atom_expr() {
4129
+ return this.getTypedRuleContext(Atom_exprContext, 0);
4130
+ }
4131
+ accept(visitor) {
4132
+ if (visitor.visitValueAtomExpr) {
4133
+ return visitor.visitValueAtomExpr(this);
4134
+ }
4135
+ else {
4136
+ return visitor.visitChildren(this);
4137
+ }
4138
+ }
4139
+ }
4110
4140
  export class BinaryOperatorExprContext extends Data_exprContext {
4111
4141
  constructor(parser, ctx) {
4112
4142
  super(parser, ctx.parentCtx, ctx.invokingState);
@@ -30,6 +30,8 @@ export default class CircuitScriptVisitor extends ParseTreeVisitor {
30
30
  visitAdditionExpr;
31
31
  visitMultiplyExpr;
32
32
  visitDataExpr;
33
+ visitUnaryOperatorExpr;
34
+ visitValueAtomExpr;
33
35
  visitBinaryOperatorExpr;
34
36
  visitRoundedBracketsExpr;
35
37
  visitBinary_operator;
@@ -393,7 +393,7 @@ export class MainVisitor extends ParseTreeVisitor {
393
393
  }
394
394
  return [component, pinValue];
395
395
  }
396
- visitDataExpr(ctx) {
396
+ visitValueAtomExpr(ctx) {
397
397
  let value;
398
398
  if (ctx.value_expr()) {
399
399
  value = this.visit(ctx.value_expr());
@@ -407,8 +407,13 @@ export class MainVisitor extends ParseTreeVisitor {
407
407
  value = reference.value;
408
408
  }
409
409
  }
410
- if (ctx.unary_operator()) {
411
- if (ctx.unary_operator().Not()) {
410
+ return value;
411
+ }
412
+ visitUnaryOperatorExpr(ctx) {
413
+ const value = this.visit(ctx.data_expr());
414
+ const unaryOp = ctx.unary_operator();
415
+ if (unaryOp) {
416
+ if (unaryOp.Not()) {
412
417
  if (typeof value === "boolean") {
413
418
  value = !value;
414
419
  }
@@ -416,7 +421,7 @@ export class MainVisitor extends ParseTreeVisitor {
416
421
  throw "Failed to do Not operator";
417
422
  }
418
423
  }
419
- else if (ctx.unary_operator().Minus()) {
424
+ else if (unaryOp.Minus()) {
420
425
  if (typeof value === 'number') {
421
426
  return -value;
422
427
  }
@@ -425,6 +430,10 @@ export class MainVisitor extends ParseTreeVisitor {
425
430
  }
426
431
  }
427
432
  }
433
+ return value;
434
+ }
435
+ visitDataExpr(ctx) {
436
+ let value;
428
437
  if (ctx.create_component_expr()) {
429
438
  value = this.visit(ctx.create_component_expr());
430
439
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "circuitscript",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "Interpreter for the circuitscript language",
5
5
  "homepage": "https://circuitscript.net",
6
6
  "engines": {
@@ -106,8 +106,9 @@ property_set_expr: atom_expr '=' data_expr;
106
106
  double_dot_property_set_expr: '..' ID '=' data_expr;
107
107
 
108
108
  data_expr:
109
- (unary_operator? (value_expr | atom_expr)) #DataExpr
110
- | '(' data_expr ')' #RoundedBracketsExpr
109
+ '(' data_expr ')' #RoundedBracketsExpr
110
+ | (value_expr | atom_expr) #ValueAtomExpr
111
+ | unary_operator data_expr #UnaryOperatorExpr
111
112
  | data_expr (Multiply | Divide) data_expr #MultiplyExpr
112
113
  | data_expr (Addition | Minus) data_expr #AdditionExpr
113
114
  | data_expr binary_operator data_expr #BinaryOperatorExpr
@@ -1744,25 +1744,27 @@ export default class CircuitScriptParser extends Parser {
1744
1744
  {
1745
1745
  this.state = 329;
1746
1746
  this._errHandler.sync(this);
1747
- switch ( this._interp.adaptivePredict(this._input, 34, this._ctx) ) {
1747
+ switch ( this._interp.adaptivePredict(this._input, 33, this._ctx) ) {
1748
1748
  case 1:
1749
1749
  {
1750
- localctx = new DataExprContext(this, localctx);
1750
+ localctx = new RoundedBracketsExprContext(this, localctx);
1751
1751
  this._ctx = localctx;
1752
1752
  _prevctx = localctx;
1753
1753
 
1754
- {
1754
+ this.state = 316;
1755
+ this.match(CircuitScriptParser.OPEN_PAREN);
1755
1756
  this.state = 317;
1756
- this._errHandler.sync(this);
1757
- switch ( this._interp.adaptivePredict(this._input, 32, this._ctx) ) {
1758
- case 1:
1759
- {
1760
- this.state = 316;
1761
- this.unary_operator();
1762
- }
1763
- break;
1757
+ this.data_expr(0);
1758
+ this.state = 318;
1759
+ this.match(CircuitScriptParser.CLOSE_PAREN);
1764
1760
  }
1765
- this.state = 321;
1761
+ break;
1762
+ case 2:
1763
+ {
1764
+ localctx = new ValueAtomExprContext(this, localctx);
1765
+ this._ctx = localctx;
1766
+ _prevctx = localctx;
1767
+ this.state = 322;
1766
1768
  this._errHandler.sync(this);
1767
1769
  switch (this._input.LA(1)) {
1768
1770
  case 6:
@@ -1774,7 +1776,7 @@ export default class CircuitScriptParser extends Parser {
1774
1776
  case 41:
1775
1777
  case 42:
1776
1778
  {
1777
- this.state = 319;
1779
+ this.state = 320;
1778
1780
  this.value_expr();
1779
1781
  }
1780
1782
  break;
@@ -1782,7 +1784,7 @@ export default class CircuitScriptParser extends Parser {
1782
1784
  case 31:
1783
1785
  case 37:
1784
1786
  {
1785
- this.state = 320;
1787
+ this.state = 321;
1786
1788
  this.atom_expr();
1787
1789
  }
1788
1790
  break;
@@ -1790,22 +1792,19 @@ export default class CircuitScriptParser extends Parser {
1790
1792
  throw new NoViableAltException(this);
1791
1793
  }
1792
1794
  }
1793
- }
1794
1795
  break;
1795
- case 2:
1796
+ case 3:
1796
1797
  {
1797
- localctx = new RoundedBracketsExprContext(this, localctx);
1798
+ localctx = new UnaryOperatorExprContext(this, localctx);
1798
1799
  this._ctx = localctx;
1799
1800
  _prevctx = localctx;
1800
- this.state = 323;
1801
- this.match(CircuitScriptParser.OPEN_PAREN);
1802
1801
  this.state = 324;
1803
- this.data_expr(0);
1802
+ this.unary_operator();
1804
1803
  this.state = 325;
1805
- this.match(CircuitScriptParser.CLOSE_PAREN);
1804
+ this.data_expr(6);
1806
1805
  }
1807
1806
  break;
1808
- case 3:
1807
+ case 4:
1809
1808
  {
1810
1809
  localctx = new DataExprContext(this, localctx);
1811
1810
  this._ctx = localctx;
@@ -1814,7 +1813,7 @@ export default class CircuitScriptParser extends Parser {
1814
1813
  this.create_component_expr();
1815
1814
  }
1816
1815
  break;
1817
- case 4:
1816
+ case 5:
1818
1817
  {
1819
1818
  localctx = new DataExprContext(this, localctx);
1820
1819
  this._ctx = localctx;
@@ -1827,7 +1826,7 @@ export default class CircuitScriptParser extends Parser {
1827
1826
  this._ctx.stop = this._input.LT(-1);
1828
1827
  this.state = 343;
1829
1828
  this._errHandler.sync(this);
1830
- _alt = this._interp.adaptivePredict(this._input, 36, this._ctx);
1829
+ _alt = this._interp.adaptivePredict(this._input, 35, this._ctx);
1831
1830
  while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) {
1832
1831
  if (_alt === 1) {
1833
1832
  if (this._parseListeners != null) {
@@ -1837,7 +1836,7 @@ export default class CircuitScriptParser extends Parser {
1837
1836
  {
1838
1837
  this.state = 341;
1839
1838
  this._errHandler.sync(this);
1840
- switch ( this._interp.adaptivePredict(this._input, 35, this._ctx) ) {
1839
+ switch ( this._interp.adaptivePredict(this._input, 34, this._ctx) ) {
1841
1840
  case 1:
1842
1841
  {
1843
1842
  localctx = new MultiplyExprContext(this, new Data_exprContext(this, _parentctx, _parentState));
@@ -1899,7 +1898,7 @@ export default class CircuitScriptParser extends Parser {
1899
1898
  }
1900
1899
  this.state = 345;
1901
1900
  this._errHandler.sync(this);
1902
- _alt = this._interp.adaptivePredict(this._input, 36, this._ctx);
1901
+ _alt = this._interp.adaptivePredict(this._input, 35, this._ctx);
1903
1902
  }
1904
1903
  }
1905
1904
  }
@@ -2207,7 +2206,7 @@ export default class CircuitScriptParser extends Parser {
2207
2206
  let _alt: number;
2208
2207
  this.state = 408;
2209
2208
  this._errHandler.sync(this);
2210
- switch ( this._interp.adaptivePredict(this._input, 46, this._ctx) ) {
2209
+ switch ( this._interp.adaptivePredict(this._input, 45, this._ctx) ) {
2211
2210
  case 1:
2212
2211
  this.enterOuterAlt(localctx, 1);
2213
2212
  {
@@ -2215,7 +2214,7 @@ export default class CircuitScriptParser extends Parser {
2215
2214
  this.match(CircuitScriptParser.ID);
2216
2215
  this.state = 384;
2217
2216
  this._errHandler.sync(this);
2218
- _alt = this._interp.adaptivePredict(this._input, 43, this._ctx);
2217
+ _alt = this._interp.adaptivePredict(this._input, 42, this._ctx);
2219
2218
  while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) {
2220
2219
  if (_alt === 1) {
2221
2220
  {
@@ -2229,7 +2228,7 @@ export default class CircuitScriptParser extends Parser {
2229
2228
  }
2230
2229
  this.state = 386;
2231
2230
  this._errHandler.sync(this);
2232
- _alt = this._interp.adaptivePredict(this._input, 43, this._ctx);
2231
+ _alt = this._interp.adaptivePredict(this._input, 42, this._ctx);
2233
2232
  }
2234
2233
  this.state = 393;
2235
2234
  this._errHandler.sync(this);
@@ -2323,7 +2322,7 @@ export default class CircuitScriptParser extends Parser {
2323
2322
  this.match(CircuitScriptParser.ID);
2324
2323
  this.state = 417;
2325
2324
  this._errHandler.sync(this);
2326
- _alt = this._interp.adaptivePredict(this._input, 48, this._ctx);
2325
+ _alt = this._interp.adaptivePredict(this._input, 47, this._ctx);
2327
2326
  while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) {
2328
2327
  if (_alt === 1) {
2329
2328
  {
@@ -2335,7 +2334,7 @@ export default class CircuitScriptParser extends Parser {
2335
2334
  }
2336
2335
  this.state = 419;
2337
2336
  this._errHandler.sync(this);
2338
- _alt = this._interp.adaptivePredict(this._input, 48, this._ctx);
2337
+ _alt = this._interp.adaptivePredict(this._input, 47, this._ctx);
2339
2338
  }
2340
2339
  }
2341
2340
  }
@@ -2430,7 +2429,7 @@ export default class CircuitScriptParser extends Parser {
2430
2429
  this.match(CircuitScriptParser.Divide);
2431
2430
  this.state = 434;
2432
2431
  this._errHandler.sync(this);
2433
- switch ( this._interp.adaptivePredict(this._input, 52, this._ctx) ) {
2432
+ switch ( this._interp.adaptivePredict(this._input, 51, this._ctx) ) {
2434
2433
  case 1:
2435
2434
  {
2436
2435
  this.state = 433;
@@ -2633,7 +2632,7 @@ export default class CircuitScriptParser extends Parser {
2633
2632
  this.match(CircuitScriptParser.T__0);
2634
2633
  this.state = 472;
2635
2634
  this._errHandler.sync(this);
2636
- switch ( this._interp.adaptivePredict(this._input, 57, this._ctx) ) {
2635
+ switch ( this._interp.adaptivePredict(this._input, 56, this._ctx) ) {
2637
2636
  case 1:
2638
2637
  {
2639
2638
  this.state = 467;
@@ -2879,7 +2878,7 @@ export default class CircuitScriptParser extends Parser {
2879
2878
  this.match(CircuitScriptParser.ID);
2880
2879
  this.state = 508;
2881
2880
  this._errHandler.sync(this);
2882
- _alt = this._interp.adaptivePredict(this._input, 62, this._ctx);
2881
+ _alt = this._interp.adaptivePredict(this._input, 61, this._ctx);
2883
2882
  while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) {
2884
2883
  if (_alt === 1) {
2885
2884
  {
@@ -2898,7 +2897,7 @@ export default class CircuitScriptParser extends Parser {
2898
2897
  }
2899
2898
  this.state = 510;
2900
2899
  this._errHandler.sync(this);
2901
- _alt = this._interp.adaptivePredict(this._input, 62, this._ctx);
2900
+ _alt = this._interp.adaptivePredict(this._input, 61, this._ctx);
2902
2901
  }
2903
2902
  }
2904
2903
  }
@@ -3091,40 +3090,40 @@ export default class CircuitScriptParser extends Parser {
3091
3090
  1,24,1,24,1,24,5,24,285,8,24,10,24,12,24,288,9,24,1,24,1,24,5,24,292,8,
3092
3091
  24,10,24,12,24,295,9,24,1,24,1,24,1,24,5,24,300,8,24,10,24,12,24,303,9,
3093
3092
  24,3,24,305,8,24,1,25,1,25,1,25,1,25,1,26,1,26,1,26,1,26,1,26,1,27,1,27,
3094
- 3,27,318,8,27,1,27,1,27,3,27,322,8,27,1,27,1,27,1,27,1,27,1,27,1,27,3,27,
3095
- 330,8,27,1,27,1,27,1,27,1,27,1,27,1,27,1,27,1,27,1,27,1,27,5,27,342,8,27,
3096
- 10,27,12,27,345,9,27,1,28,1,28,1,29,1,29,1,30,3,30,352,8,30,1,30,1,30,3,
3097
- 30,356,8,30,1,31,1,31,1,31,1,31,3,31,362,8,31,1,31,1,31,1,31,1,31,1,31,
3098
- 1,31,4,31,370,8,31,11,31,12,31,371,1,31,1,31,1,32,1,32,3,32,378,8,32,1,
3099
- 33,1,33,1,33,5,33,383,8,33,10,33,12,33,386,9,33,1,33,1,33,1,33,1,33,5,33,
3100
- 392,8,33,10,33,12,33,395,9,33,1,33,1,33,1,33,1,33,1,33,1,33,1,33,5,33,404,
3101
- 8,33,10,33,12,33,407,9,33,3,33,409,8,33,1,34,3,34,412,8,34,1,34,1,34,5,
3102
- 34,416,8,34,10,34,12,34,419,9,34,1,35,1,35,3,35,423,8,35,1,35,1,35,1,35,
3103
- 3,35,428,8,35,1,36,3,36,431,8,36,1,36,1,36,3,36,435,8,36,1,37,1,37,1,37,
3104
- 1,38,1,38,1,38,1,38,1,38,1,38,1,38,4,38,447,8,38,11,38,12,38,448,1,38,1,
3105
- 38,1,39,1,39,1,39,1,39,1,39,1,39,1,39,4,39,460,8,39,11,39,12,39,461,1,39,
3106
- 1,39,1,40,1,40,1,40,1,40,1,40,1,40,1,40,3,40,473,8,40,1,41,1,41,1,41,1,
3107
- 41,1,42,1,42,1,43,1,43,1,43,1,43,4,43,485,8,43,11,43,12,43,486,1,43,1,43,
3108
- 1,43,1,43,5,43,493,8,43,10,43,12,43,496,9,43,3,43,498,8,43,1,44,1,44,1,
3109
- 44,1,44,1,45,1,45,1,45,5,45,507,8,45,10,45,12,45,510,9,45,1,46,1,46,1,46,
3110
- 1,47,1,47,1,47,1,48,1,48,1,48,1,48,1,48,1,48,4,48,524,8,48,11,48,12,48,
3111
- 525,1,48,1,48,1,48,0,1,54,49,0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,
3112
- 32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,
3113
- 80,82,84,86,88,90,92,94,96,0,11,2,0,10,10,19,21,1,0,37,38,2,0,38,38,41,
3114
- 41,2,0,35,35,38,38,1,0,31,32,1,0,29,30,1,0,27,28,2,0,26,26,30,30,2,0,36,
3115
- 36,38,42,2,0,15,15,37,37,2,0,37,38,41,41,562,0,100,1,0,0,0,2,122,1,0,0,
3116
- 0,4,125,1,0,0,0,6,129,1,0,0,0,8,141,1,0,0,0,10,153,1,0,0,0,12,159,1,0,0,
3117
- 0,14,164,1,0,0,0,16,171,1,0,0,0,18,173,1,0,0,0,20,176,1,0,0,0,22,178,1,
3118
- 0,0,0,24,186,1,0,0,0,26,201,1,0,0,0,28,223,1,0,0,0,30,233,1,0,0,0,32,235,
3119
- 1,0,0,0,34,249,1,0,0,0,36,251,1,0,0,0,38,259,1,0,0,0,40,261,1,0,0,0,42,
3120
- 271,1,0,0,0,44,273,1,0,0,0,46,277,1,0,0,0,48,304,1,0,0,0,50,306,1,0,0,0,
3121
- 52,310,1,0,0,0,54,329,1,0,0,0,56,346,1,0,0,0,58,348,1,0,0,0,60,355,1,0,
3122
- 0,0,62,357,1,0,0,0,64,377,1,0,0,0,66,408,1,0,0,0,68,411,1,0,0,0,70,427,
3123
- 1,0,0,0,72,430,1,0,0,0,74,436,1,0,0,0,76,439,1,0,0,0,78,452,1,0,0,0,80,
3124
- 465,1,0,0,0,82,474,1,0,0,0,84,478,1,0,0,0,86,497,1,0,0,0,88,499,1,0,0,0,
3125
- 90,503,1,0,0,0,92,511,1,0,0,0,94,514,1,0,0,0,96,517,1,0,0,0,98,101,3,2,
3126
- 1,0,99,101,5,45,0,0,100,98,1,0,0,0,100,99,1,0,0,0,101,102,1,0,0,0,102,100,
3127
- 1,0,0,0,102,103,1,0,0,0,103,104,1,0,0,0,104,105,5,0,0,1,105,1,1,0,0,0,106,
3093
+ 1,27,1,27,1,27,1,27,1,27,3,27,323,8,27,1,27,1,27,1,27,1,27,1,27,3,27,330,
3094
+ 8,27,1,27,1,27,1,27,1,27,1,27,1,27,1,27,1,27,1,27,1,27,5,27,342,8,27,10,
3095
+ 27,12,27,345,9,27,1,28,1,28,1,29,1,29,1,30,3,30,352,8,30,1,30,1,30,3,30,
3096
+ 356,8,30,1,31,1,31,1,31,1,31,3,31,362,8,31,1,31,1,31,1,31,1,31,1,31,1,31,
3097
+ 4,31,370,8,31,11,31,12,31,371,1,31,1,31,1,32,1,32,3,32,378,8,32,1,33,1,
3098
+ 33,1,33,5,33,383,8,33,10,33,12,33,386,9,33,1,33,1,33,1,33,1,33,5,33,392,
3099
+ 8,33,10,33,12,33,395,9,33,1,33,1,33,1,33,1,33,1,33,1,33,1,33,5,33,404,8,
3100
+ 33,10,33,12,33,407,9,33,3,33,409,8,33,1,34,3,34,412,8,34,1,34,1,34,5,34,
3101
+ 416,8,34,10,34,12,34,419,9,34,1,35,1,35,3,35,423,8,35,1,35,1,35,1,35,3,
3102
+ 35,428,8,35,1,36,3,36,431,8,36,1,36,1,36,3,36,435,8,36,1,37,1,37,1,37,1,
3103
+ 38,1,38,1,38,1,38,1,38,1,38,1,38,4,38,447,8,38,11,38,12,38,448,1,38,1,38,
3104
+ 1,39,1,39,1,39,1,39,1,39,1,39,1,39,4,39,460,8,39,11,39,12,39,461,1,39,1,
3105
+ 39,1,40,1,40,1,40,1,40,1,40,1,40,1,40,3,40,473,8,40,1,41,1,41,1,41,1,41,
3106
+ 1,42,1,42,1,43,1,43,1,43,1,43,4,43,485,8,43,11,43,12,43,486,1,43,1,43,1,
3107
+ 43,1,43,5,43,493,8,43,10,43,12,43,496,9,43,3,43,498,8,43,1,44,1,44,1,44,
3108
+ 1,44,1,45,1,45,1,45,5,45,507,8,45,10,45,12,45,510,9,45,1,46,1,46,1,46,1,
3109
+ 47,1,47,1,47,1,48,1,48,1,48,1,48,1,48,1,48,4,48,524,8,48,11,48,12,48,525,
3110
+ 1,48,1,48,1,48,0,1,54,49,0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,
3111
+ 34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,
3112
+ 82,84,86,88,90,92,94,96,0,11,2,0,10,10,19,21,1,0,37,38,2,0,38,38,41,41,
3113
+ 2,0,35,35,38,38,1,0,31,32,1,0,29,30,1,0,27,28,2,0,26,26,30,30,2,0,36,36,
3114
+ 38,42,2,0,15,15,37,37,2,0,37,38,41,41,562,0,100,1,0,0,0,2,122,1,0,0,0,4,
3115
+ 125,1,0,0,0,6,129,1,0,0,0,8,141,1,0,0,0,10,153,1,0,0,0,12,159,1,0,0,0,14,
3116
+ 164,1,0,0,0,16,171,1,0,0,0,18,173,1,0,0,0,20,176,1,0,0,0,22,178,1,0,0,0,
3117
+ 24,186,1,0,0,0,26,201,1,0,0,0,28,223,1,0,0,0,30,233,1,0,0,0,32,235,1,0,
3118
+ 0,0,34,249,1,0,0,0,36,251,1,0,0,0,38,259,1,0,0,0,40,261,1,0,0,0,42,271,
3119
+ 1,0,0,0,44,273,1,0,0,0,46,277,1,0,0,0,48,304,1,0,0,0,50,306,1,0,0,0,52,
3120
+ 310,1,0,0,0,54,329,1,0,0,0,56,346,1,0,0,0,58,348,1,0,0,0,60,355,1,0,0,0,
3121
+ 62,357,1,0,0,0,64,377,1,0,0,0,66,408,1,0,0,0,68,411,1,0,0,0,70,427,1,0,
3122
+ 0,0,72,430,1,0,0,0,74,436,1,0,0,0,76,439,1,0,0,0,78,452,1,0,0,0,80,465,
3123
+ 1,0,0,0,82,474,1,0,0,0,84,478,1,0,0,0,86,497,1,0,0,0,88,499,1,0,0,0,90,
3124
+ 503,1,0,0,0,92,511,1,0,0,0,94,514,1,0,0,0,96,517,1,0,0,0,98,101,3,2,1,0,
3125
+ 99,101,5,45,0,0,100,98,1,0,0,0,100,99,1,0,0,0,101,102,1,0,0,0,102,100,1,
3126
+ 0,0,0,102,103,1,0,0,0,103,104,1,0,0,0,104,105,5,0,0,1,105,1,1,0,0,0,106,
3128
3127
  123,3,14,7,0,107,123,3,24,12,0,108,123,3,22,11,0,109,123,3,44,22,0,110,
3129
3128
  123,3,50,25,0,111,123,3,8,4,0,112,123,3,52,26,0,113,123,3,42,21,0,114,123,
3130
3129
  3,62,31,0,115,123,3,90,45,0,116,123,3,94,47,0,117,123,3,96,48,0,118,123,
@@ -3182,11 +3181,11 @@ export default class CircuitScriptParser extends Parser {
3182
3181
  0,0,0,302,305,1,0,0,0,303,301,1,0,0,0,304,281,1,0,0,0,304,296,1,0,0,0,305,
3183
3182
  49,1,0,0,0,306,307,3,68,34,0,307,308,5,3,0,0,308,309,3,54,27,0,309,51,1,
3184
3183
  0,0,0,310,311,5,4,0,0,311,312,5,37,0,0,312,313,5,3,0,0,313,314,3,54,27,
3185
- 0,314,53,1,0,0,0,315,317,6,27,-1,0,316,318,3,58,29,0,317,316,1,0,0,0,317,
3186
- 318,1,0,0,0,318,321,1,0,0,0,319,322,3,60,30,0,320,322,3,68,34,0,321,319,
3187
- 1,0,0,0,321,320,1,0,0,0,322,330,1,0,0,0,323,324,5,33,0,0,324,325,3,54,27,
3188
- 0,325,326,5,34,0,0,326,330,1,0,0,0,327,330,3,76,38,0,328,330,3,78,39,0,
3189
- 329,315,1,0,0,0,329,323,1,0,0,0,329,327,1,0,0,0,329,328,1,0,0,0,330,343,
3184
+ 0,314,53,1,0,0,0,315,316,6,27,-1,0,316,317,5,33,0,0,317,318,3,54,27,0,318,
3185
+ 319,5,34,0,0,319,330,1,0,0,0,320,323,3,60,30,0,321,323,3,68,34,0,322,320,
3186
+ 1,0,0,0,322,321,1,0,0,0,323,330,1,0,0,0,324,325,3,58,29,0,325,326,3,54,
3187
+ 27,6,326,330,1,0,0,0,327,330,3,76,38,0,328,330,3,78,39,0,329,315,1,0,0,
3188
+ 0,329,322,1,0,0,0,329,324,1,0,0,0,329,327,1,0,0,0,329,328,1,0,0,0,330,343,
3190
3189
  1,0,0,0,331,332,10,5,0,0,332,333,7,4,0,0,333,342,3,54,27,6,334,335,10,4,
3191
3190
  0,0,335,336,7,5,0,0,336,342,3,54,27,5,337,338,10,3,0,0,338,339,3,56,28,
3192
3191
  0,339,340,3,54,27,4,340,342,1,0,0,0,341,331,1,0,0,0,341,334,1,0,0,0,341,
@@ -3239,10 +3238,10 @@ export default class CircuitScriptParser extends Parser {
3239
3238
  5,8,0,0,518,519,5,1,0,0,519,520,5,45,0,0,520,523,5,47,0,0,521,524,5,45,
3240
3239
  0,0,522,524,3,2,1,0,523,521,1,0,0,0,523,522,1,0,0,0,524,525,1,0,0,0,525,
3241
3240
  523,1,0,0,0,525,526,1,0,0,0,526,527,1,0,0,0,527,528,5,48,0,0,528,97,1,0,
3242
- 0,0,65,100,102,122,127,135,137,147,149,159,162,167,171,181,184,192,196,
3243
- 199,209,217,219,230,241,243,249,255,259,265,267,286,293,301,304,317,321,
3244
- 329,341,343,351,355,361,369,371,377,384,393,405,408,411,417,422,427,430,
3245
- 434,446,448,459,461,472,484,486,494,497,508,523,525];
3241
+ 0,0,64,100,102,122,127,135,137,147,149,159,162,167,171,181,184,192,196,
3242
+ 199,209,217,219,230,241,243,249,255,259,265,267,286,293,301,304,322,329,
3243
+ 341,343,351,355,361,369,371,377,384,393,405,408,411,417,422,427,430,434,
3244
+ 446,448,459,461,472,484,486,494,497,508,523,525];
3246
3245
 
3247
3246
  private static __ATN: ATN;
3248
3247
  public static get _ATN(): ATN {
@@ -4179,15 +4178,6 @@ export class DataExprContext extends Data_exprContext {
4179
4178
  super(parser, ctx.parentCtx, ctx.invokingState);
4180
4179
  super.copyFrom(ctx);
4181
4180
  }
4182
- public value_expr(): Value_exprContext {
4183
- return this.getTypedRuleContext(Value_exprContext, 0) as Value_exprContext;
4184
- }
4185
- public atom_expr(): Atom_exprContext {
4186
- return this.getTypedRuleContext(Atom_exprContext, 0) as Atom_exprContext;
4187
- }
4188
- public unary_operator(): Unary_operatorContext {
4189
- return this.getTypedRuleContext(Unary_operatorContext, 0) as Unary_operatorContext;
4190
- }
4191
4181
  public create_component_expr(): Create_component_exprContext {
4192
4182
  return this.getTypedRuleContext(Create_component_exprContext, 0) as Create_component_exprContext;
4193
4183
  }
@@ -4203,6 +4193,46 @@ export class DataExprContext extends Data_exprContext {
4203
4193
  }
4204
4194
  }
4205
4195
  }
4196
+ export class UnaryOperatorExprContext extends Data_exprContext {
4197
+ constructor(parser: CircuitScriptParser, ctx: Data_exprContext) {
4198
+ super(parser, ctx.parentCtx, ctx.invokingState);
4199
+ super.copyFrom(ctx);
4200
+ }
4201
+ public unary_operator(): Unary_operatorContext {
4202
+ return this.getTypedRuleContext(Unary_operatorContext, 0) as Unary_operatorContext;
4203
+ }
4204
+ public data_expr(): Data_exprContext {
4205
+ return this.getTypedRuleContext(Data_exprContext, 0) as Data_exprContext;
4206
+ }
4207
+ // @Override
4208
+ public accept<Result>(visitor: CircuitScriptVisitor<Result>): Result {
4209
+ if (visitor.visitUnaryOperatorExpr) {
4210
+ return visitor.visitUnaryOperatorExpr(this);
4211
+ } else {
4212
+ return visitor.visitChildren(this);
4213
+ }
4214
+ }
4215
+ }
4216
+ export class ValueAtomExprContext extends Data_exprContext {
4217
+ constructor(parser: CircuitScriptParser, ctx: Data_exprContext) {
4218
+ super(parser, ctx.parentCtx, ctx.invokingState);
4219
+ super.copyFrom(ctx);
4220
+ }
4221
+ public value_expr(): Value_exprContext {
4222
+ return this.getTypedRuleContext(Value_exprContext, 0) as Value_exprContext;
4223
+ }
4224
+ public atom_expr(): Atom_exprContext {
4225
+ return this.getTypedRuleContext(Atom_exprContext, 0) as Atom_exprContext;
4226
+ }
4227
+ // @Override
4228
+ public accept<Result>(visitor: CircuitScriptVisitor<Result>): Result {
4229
+ if (visitor.visitValueAtomExpr) {
4230
+ return visitor.visitValueAtomExpr(this);
4231
+ } else {
4232
+ return visitor.visitChildren(this);
4233
+ }
4234
+ }
4235
+ }
4206
4236
  export class BinaryOperatorExprContext extends Data_exprContext {
4207
4237
  constructor(parser: CircuitScriptParser, ctx: Data_exprContext) {
4208
4238
  super(parser, ctx.parentCtx, ctx.invokingState);
@@ -35,6 +35,8 @@ import { Double_dot_property_set_exprContext } from "./CircuitScriptParser";
35
35
  import { AdditionExprContext } from "./CircuitScriptParser";
36
36
  import { MultiplyExprContext } from "./CircuitScriptParser";
37
37
  import { DataExprContext } from "./CircuitScriptParser";
38
+ import { UnaryOperatorExprContext } from "./CircuitScriptParser";
39
+ import { ValueAtomExprContext } from "./CircuitScriptParser";
38
40
  import { BinaryOperatorExprContext } from "./CircuitScriptParser";
39
41
  import { RoundedBracketsExprContext } from "./CircuitScriptParser";
40
42
  import { Binary_operatorContext } from "./CircuitScriptParser";
@@ -252,6 +254,20 @@ export default class CircuitScriptVisitor<Result> extends ParseTreeVisitor<Resul
252
254
  * @return the visitor result
253
255
  */
254
256
  visitDataExpr?: (ctx: DataExprContext) => Result;
257
+ /**
258
+ * Visit a parse tree produced by the `UnaryOperatorExpr`
259
+ * labeled alternative in `CircuitScriptParser.data_expr`.
260
+ * @param ctx the parse tree
261
+ * @return the visitor result
262
+ */
263
+ visitUnaryOperatorExpr?: (ctx: UnaryOperatorExprContext) => Result;
264
+ /**
265
+ * Visit a parse tree produced by the `ValueAtomExpr`
266
+ * labeled alternative in `CircuitScriptParser.data_expr`.
267
+ * @param ctx the parse tree
268
+ * @return the visitor result
269
+ */
270
+ visitValueAtomExpr?: (ctx: ValueAtomExprContext) => Result;
255
271
  /**
256
272
  * Visit a parse tree produced by the `BinaryOperatorExpr`
257
273
  * labeled alternative in `CircuitScriptParser.data_expr`.
package/src/visitor.ts CHANGED
@@ -47,6 +47,8 @@ import {
47
47
  To_component_exprContext,
48
48
  Value_exprContext,
49
49
  Wire_exprContext,
50
+ ValueAtomExprContext,
51
+ UnaryOperatorExprContext,
50
52
  } from './antlr/CircuitScriptParser.js';
51
53
  import { ExecutionContext } from './execute.js';
52
54
  import { ClassComponent } from './objects/ClassComponent.js';
@@ -576,8 +578,8 @@ export class MainVisitor extends ParseTreeVisitor<any> {
576
578
  return [component, pinValue];
577
579
  }
578
580
 
579
- visitDataExpr(ctx: DataExprContext): ComplexType {
580
- let value : ComplexType;
581
+ visitValueAtomExpr(ctx: ValueAtomExprContext): ComplexType {
582
+ let value: ComplexType;
581
583
 
582
584
  if (ctx.value_expr()) {
583
585
  value = this.visit(ctx.value_expr()) as ValueType;
@@ -585,7 +587,7 @@ export class MainVisitor extends ParseTreeVisitor<any> {
585
587
  } else if (ctx.atom_expr()) {
586
588
  const reference = this.visit(ctx.atom_expr());
587
589
 
588
- if (!reference.found){
590
+ if (!reference.found) {
589
591
  value = new UndeclaredReference(reference);
590
592
  } else {
591
593
  // This is the returned component from the function call
@@ -593,26 +595,39 @@ export class MainVisitor extends ParseTreeVisitor<any> {
593
595
  }
594
596
  }
595
597
 
596
- if (ctx.unary_operator()){
597
- if(ctx.unary_operator().Not()){
598
- if(typeof value === "boolean"){
598
+ return value;
599
+ }
600
+
601
+ visitUnaryOperatorExpr(ctx: UnaryOperatorExprContext): ComplexType {
602
+ const value = this.visit(ctx.data_expr());
603
+
604
+ const unaryOp = ctx.unary_operator();
605
+ if (unaryOp) {
606
+ if (unaryOp.Not()) {
607
+ if (typeof value === "boolean") {
599
608
  value = !value;
600
609
  } else {
601
610
  throw "Failed to do Not operator";
602
611
  }
603
- } else if (ctx.unary_operator().Minus()){
604
- if (typeof value === 'number'){
612
+ } else if (unaryOp.Minus()) {
613
+ if (typeof value === 'number') {
605
614
  return -value;
606
615
  } else {
607
616
  throw "Failed to do Negation operator";
608
617
  }
609
618
  }
610
619
  }
611
-
620
+
621
+ return value;
622
+ }
623
+
624
+ visitDataExpr(ctx: DataExprContext): ComplexType {
625
+ let value: ComplexType;
626
+
612
627
  if (ctx.create_component_expr()) {
613
628
  value = this.visit(ctx.create_component_expr()) as ClassComponent;
614
629
 
615
- } else if (ctx.create_graphic_expr()){
630
+ } else if (ctx.create_graphic_expr()) {
616
631
  value = this.visit(ctx.create_graphic_expr()) as ClassComponent;
617
632
  }
618
633
 
@@ -1086,7 +1101,8 @@ export class MainVisitor extends ParseTreeVisitor<any> {
1086
1101
  const propertyName = ctx.ID().getText();
1087
1102
  this.getExecutor().setProperty('..' + propertyName, result);
1088
1103
  }
1089
- visitRoundedBracketsExpr(ctx: RoundedBracketsExprContext){
1104
+
1105
+ visitRoundedBracketsExpr(ctx: RoundedBracketsExprContext) {
1090
1106
  return this.visit(ctx.data_expr());
1091
1107
  }
1092
1108