@stevenvo780/st-lang 3.1.0 → 3.1.2

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.
Files changed (93) hide show
  1. package/README.md +3 -3
  2. package/dist/api.d.ts.map +1 -1
  3. package/dist/api.js +44 -9
  4. package/dist/api.js.map +1 -1
  5. package/dist/lexer/lexer.d.ts.map +1 -1
  6. package/dist/lexer/lexer.js +8 -0
  7. package/dist/lexer/lexer.js.map +1 -1
  8. package/dist/lexer/tokens.d.ts +2 -0
  9. package/dist/lexer/tokens.d.ts.map +1 -1
  10. package/dist/lexer/tokens.js +6 -0
  11. package/dist/lexer/tokens.js.map +1 -1
  12. package/dist/parser/parser.d.ts +4 -0
  13. package/dist/parser/parser.d.ts.map +1 -1
  14. package/dist/parser/parser.js +224 -92
  15. package/dist/parser/parser.js.map +1 -1
  16. package/dist/profiles/aristotelian/syllogistic.d.ts +1 -1
  17. package/dist/profiles/aristotelian/syllogistic.d.ts.map +1 -1
  18. package/dist/profiles/aristotelian/syllogistic.js +26 -8
  19. package/dist/profiles/aristotelian/syllogistic.js.map +1 -1
  20. package/dist/profiles/arithmetic/index.d.ts +1 -1
  21. package/dist/profiles/arithmetic/index.d.ts.map +1 -1
  22. package/dist/profiles/arithmetic/index.js +29 -7
  23. package/dist/profiles/arithmetic/index.js.map +1 -1
  24. package/dist/profiles/classical/first-order.d.ts +1 -1
  25. package/dist/profiles/classical/first-order.d.ts.map +1 -1
  26. package/dist/profiles/classical/first-order.js +32 -8
  27. package/dist/profiles/classical/first-order.js.map +1 -1
  28. package/dist/profiles/classical/propositional.d.ts +1 -1
  29. package/dist/profiles/classical/propositional.d.ts.map +1 -1
  30. package/dist/profiles/classical/propositional.js +464 -69
  31. package/dist/profiles/classical/propositional.js.map +1 -1
  32. package/dist/profiles/intuitionistic/propositional.d.ts +1 -1
  33. package/dist/profiles/intuitionistic/propositional.d.ts.map +1 -1
  34. package/dist/profiles/intuitionistic/propositional.js +33 -5
  35. package/dist/profiles/intuitionistic/propositional.js.map +1 -1
  36. package/dist/profiles/paraconsistent/belnap.d.ts +1 -2
  37. package/dist/profiles/paraconsistent/belnap.d.ts.map +1 -1
  38. package/dist/profiles/paraconsistent/belnap.js +25 -11
  39. package/dist/profiles/paraconsistent/belnap.js.map +1 -1
  40. package/dist/profiles/probabilistic/basic.d.ts +1 -1
  41. package/dist/profiles/probabilistic/basic.d.ts.map +1 -1
  42. package/dist/profiles/probabilistic/basic.js +29 -5
  43. package/dist/profiles/probabilistic/basic.js.map +1 -1
  44. package/dist/profiles/shared/base-profile.d.ts +1 -1
  45. package/dist/profiles/shared/base-profile.d.ts.map +1 -1
  46. package/dist/profiles/shared/base-profile.js +20 -3
  47. package/dist/profiles/shared/base-profile.js.map +1 -1
  48. package/dist/profiles/shared/tableau-engine.d.ts +4 -3
  49. package/dist/profiles/shared/tableau-engine.d.ts.map +1 -1
  50. package/dist/profiles/shared/tableau-engine.js +107 -15
  51. package/dist/profiles/shared/tableau-engine.js.map +1 -1
  52. package/dist/protocol/handler.d.ts +4 -0
  53. package/dist/protocol/handler.d.ts.map +1 -1
  54. package/dist/protocol/handler.js +133 -41
  55. package/dist/protocol/handler.js.map +1 -1
  56. package/dist/repl/repl.d.ts +2 -0
  57. package/dist/repl/repl.d.ts.map +1 -1
  58. package/dist/repl/repl.js +44 -19
  59. package/dist/repl/repl.js.map +1 -1
  60. package/dist/runtime/compat.d.ts +29 -0
  61. package/dist/runtime/compat.d.ts.map +1 -0
  62. package/dist/runtime/compat.js +819 -0
  63. package/dist/runtime/compat.js.map +1 -0
  64. package/dist/runtime/interpreter.d.ts +3 -0
  65. package/dist/runtime/interpreter.d.ts.map +1 -1
  66. package/dist/runtime/interpreter.js +133 -30
  67. package/dist/runtime/interpreter.js.map +1 -1
  68. package/dist/tests/cli.test.js +5 -1
  69. package/dist/tests/cli.test.js.map +1 -1
  70. package/dist/tests/compat.test.d.ts +2 -0
  71. package/dist/tests/compat.test.d.ts.map +1 -0
  72. package/dist/tests/compat.test.js +247 -0
  73. package/dist/tests/compat.test.js.map +1 -0
  74. package/dist/tests/core.test.js +41 -1
  75. package/dist/tests/core.test.js.map +1 -1
  76. package/dist/tests/parser.test.js +38 -0
  77. package/dist/tests/parser.test.js.map +1 -1
  78. package/dist/tests/profiles.test.js +8 -0
  79. package/dist/tests/profiles.test.js.map +1 -1
  80. package/dist/tests/protocol-text-layer.test.d.ts +2 -0
  81. package/dist/tests/protocol-text-layer.test.d.ts.map +1 -0
  82. package/dist/tests/protocol-text-layer.test.js +54 -0
  83. package/dist/tests/protocol-text-layer.test.js.map +1 -0
  84. package/dist/tests/stress-exhaustive.test.js +5 -1
  85. package/dist/tests/stress-exhaustive.test.js.map +1 -1
  86. package/dist/text-layer/compiler.d.ts.map +1 -1
  87. package/dist/text-layer/compiler.js +35 -8
  88. package/dist/text-layer/compiler.js.map +1 -1
  89. package/dist/types/index.d.ts +37 -3
  90. package/dist/types/index.d.ts.map +1 -1
  91. package/dist/types/index.js +42 -0
  92. package/dist/types/index.js.map +1 -1
  93. package/package.json +1 -3
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Parser = void 0;
7
7
  const tokens_1 = require("../lexer/tokens");
8
8
  const lexer_1 = require("../lexer/lexer");
9
+ const compat_1 = require("../runtime/compat");
9
10
  // Modal aliases per profile: maps identifier names to modal formula types
10
11
  const MODAL_ALIASES = {
11
12
  'deontic.standard': { O: 'box', P: 'diamond', F: 'box_not' },
@@ -21,6 +22,7 @@ class Parser {
21
22
  pos = 0;
22
23
  file;
23
24
  diagnostics = [];
25
+ contextStack = [];
24
26
  knownFunctionNames = new Set([
25
27
  'typeof',
26
28
  'is_valid',
@@ -40,10 +42,12 @@ class Parser {
40
42
  this.initialProfile = profile;
41
43
  }
42
44
  parse(source) {
43
- const lexer = new lexer_1.Lexer(source, this.file, this.initialProfile);
45
+ const normalizedSource = (0, compat_1.normalizeSTSource)(source);
46
+ const lexer = new lexer_1.Lexer(normalizedSource, this.file, this.initialProfile);
44
47
  this.tokens = lexer.tokenize();
45
48
  this.diagnostics.push(...lexer.diagnostics);
46
49
  this.pos = 0;
50
+ this.contextStack = [];
47
51
  const statements = [];
48
52
  while (!this.isAtEnd()) {
49
53
  this.skipNewlines();
@@ -75,93 +79,95 @@ class Parser {
75
79
  // Detección de llamada a función: nombre(...)
76
80
  if (this.peek(1) === tokens_1.TokenType.LPAREN &&
77
81
  (tok.type === tokens_1.TokenType.IDENTIFIER || this.knownFunctionNames.has(tok.value))) {
78
- return this.parseFnCall();
82
+ return this.withContext(`llamada a funcion '${tok.value}'`, () => this.parseFnCall());
79
83
  }
80
84
  // Detección de llamada a método: objeto.metodo(...)
81
85
  if (tok.type === tokens_1.TokenType.IDENTIFIER &&
82
86
  this.peek(1) === tokens_1.TokenType.DOT &&
83
87
  this.peek(2) === tokens_1.TokenType.IDENTIFIER &&
84
88
  this.peek(3) === tokens_1.TokenType.LPAREN) {
85
- return this.parseMemberFnCall();
86
- }
87
- switch (tok.type) {
88
- case tokens_1.TokenType.LOGIC:
89
- return this.parseLogicDecl();
90
- case tokens_1.TokenType.AXIOM:
91
- return this.parseAxiomDecl();
92
- case tokens_1.TokenType.THEOREM:
93
- return this.parseTheoremDecl();
94
- case tokens_1.TokenType.DERIVE:
95
- return this.parseDeriveCmd();
96
- case tokens_1.TokenType.CHECK:
97
- return this.parseCheckCmd();
98
- case tokens_1.TokenType.PROVE:
99
- return this.parseProveCmd();
100
- case tokens_1.TokenType.COUNTERMODEL:
101
- case tokens_1.TokenType.REFUTE:
102
- return this.parseCountermodelCmd();
103
- case tokens_1.TokenType.TRUTH_TABLE:
104
- return this.parseTruthTableCmd();
105
- case tokens_1.TokenType.LET:
106
- return this.parseLetDecl();
107
- case tokens_1.TokenType.CLAIM:
108
- return this.parseClaimDecl();
109
- case tokens_1.TokenType.SUPPORT:
110
- return this.parseSupportDecl();
111
- case tokens_1.TokenType.CONFIDENCE:
112
- return this.parseConfidenceDecl();
113
- case tokens_1.TokenType.CONTEXT:
114
- return this.parseContextDecl();
115
- case tokens_1.TokenType.RENDER:
116
- return this.parseRenderCmd();
117
- case tokens_1.TokenType.ANALYZE:
118
- return this.parseAnalyzeCmd();
119
- case tokens_1.TokenType.EXPLAIN:
120
- return this.parseExplainCmd();
121
- case tokens_1.TokenType.IMPORT:
122
- return this.parseImportDecl();
123
- case tokens_1.TokenType.ASSUME:
124
- return this.parseProofBlock();
125
- case tokens_1.TokenType.THEORY:
126
- return this.parseTheoryDecl();
127
- case tokens_1.TokenType.PRINT:
128
- return this.parsePrintCmd();
129
- case tokens_1.TokenType.SET:
130
- return this.parseSetCmd();
131
- case tokens_1.TokenType.IF:
132
- return this.parseIfStmt();
133
- case tokens_1.TokenType.FOR:
134
- return this.parseForStmt();
135
- case tokens_1.TokenType.WHILE:
136
- return this.parseWhileStmt();
137
- case tokens_1.TokenType.FN:
138
- return this.parseFnDecl();
139
- case tokens_1.TokenType.RETURN:
140
- return this.parseReturnStmt();
141
- case tokens_1.TokenType.EXPORT:
142
- return this.parseExportDecl();
143
- case tokens_1.TokenType.DEFINE:
144
- return this.parseDefineDecl();
145
- case tokens_1.TokenType.UNFOLD:
146
- return this.parseUnfoldCmd();
147
- case tokens_1.TokenType.FOLD:
148
- return this.parseFoldCmd();
149
- case tokens_1.TokenType.SOURCE_KW:
150
- return this.parseSourceDecl();
151
- case tokens_1.TokenType.INTERPRET:
152
- return this.parseInterpretCmd();
153
- case tokens_1.TokenType.GLOSSARY:
154
- return this.parseGlossaryCmd();
155
- case tokens_1.TokenType.IDENTIFIER:
156
- throw new Error(`Statement inesperado: '${tok.value}' (${tok.type})`);
157
- case tokens_1.TokenType.NEWLINE:
158
- this.advance();
159
- return null;
160
- case tokens_1.TokenType.EOF:
161
- return null;
162
- default:
163
- throw new Error(`Statement inesperado: '${tok.value}' (${tok.type})`);
164
- }
89
+ return this.withContext(`llamada a metodo '${tok.value}'`, () => this.parseMemberFnCall());
90
+ }
91
+ return this.withContext(this.describeStatementContext(tok), () => {
92
+ switch (tok.type) {
93
+ case tokens_1.TokenType.LOGIC:
94
+ return this.parseLogicDecl();
95
+ case tokens_1.TokenType.AXIOM:
96
+ return this.parseAxiomDecl();
97
+ case tokens_1.TokenType.THEOREM:
98
+ return this.parseTheoremDecl();
99
+ case tokens_1.TokenType.DERIVE:
100
+ return this.parseDeriveCmd();
101
+ case tokens_1.TokenType.CHECK:
102
+ return this.parseCheckCmd();
103
+ case tokens_1.TokenType.PROVE:
104
+ return this.parseProveCmd();
105
+ case tokens_1.TokenType.COUNTERMODEL:
106
+ case tokens_1.TokenType.REFUTE:
107
+ return this.parseCountermodelCmd();
108
+ case tokens_1.TokenType.TRUTH_TABLE:
109
+ return this.parseTruthTableCmd();
110
+ case tokens_1.TokenType.LET:
111
+ return this.parseLetDecl();
112
+ case tokens_1.TokenType.CLAIM:
113
+ return this.parseClaimDecl();
114
+ case tokens_1.TokenType.SUPPORT:
115
+ return this.parseSupportDecl();
116
+ case tokens_1.TokenType.CONFIDENCE:
117
+ return this.parseConfidenceDecl();
118
+ case tokens_1.TokenType.CONTEXT:
119
+ return this.parseContextDecl();
120
+ case tokens_1.TokenType.RENDER:
121
+ return this.parseRenderCmd();
122
+ case tokens_1.TokenType.ANALYZE:
123
+ return this.parseAnalyzeCmd();
124
+ case tokens_1.TokenType.EXPLAIN:
125
+ return this.parseExplainCmd();
126
+ case tokens_1.TokenType.IMPORT:
127
+ return this.parseImportDecl();
128
+ case tokens_1.TokenType.ASSUME:
129
+ return this.parseProofBlock();
130
+ case tokens_1.TokenType.THEORY:
131
+ return this.parseTheoryDecl();
132
+ case tokens_1.TokenType.PRINT:
133
+ return this.parsePrintCmd();
134
+ case tokens_1.TokenType.SET:
135
+ return this.parseSetCmd();
136
+ case tokens_1.TokenType.IF:
137
+ return this.parseIfStmt();
138
+ case tokens_1.TokenType.FOR:
139
+ return this.parseForStmt();
140
+ case tokens_1.TokenType.WHILE:
141
+ return this.parseWhileStmt();
142
+ case tokens_1.TokenType.FN:
143
+ return this.parseFnDecl();
144
+ case tokens_1.TokenType.RETURN:
145
+ return this.parseReturnStmt();
146
+ case tokens_1.TokenType.EXPORT:
147
+ return this.parseExportDecl();
148
+ case tokens_1.TokenType.DEFINE:
149
+ return this.parseDefineDecl();
150
+ case tokens_1.TokenType.UNFOLD:
151
+ return this.parseUnfoldCmd();
152
+ case tokens_1.TokenType.FOLD:
153
+ return this.parseFoldCmd();
154
+ case tokens_1.TokenType.SOURCE_KW:
155
+ return this.parseSourceDecl();
156
+ case tokens_1.TokenType.INTERPRET:
157
+ return this.parseInterpretCmd();
158
+ case tokens_1.TokenType.GLOSSARY:
159
+ return this.parseGlossaryCmd();
160
+ case tokens_1.TokenType.IDENTIFIER:
161
+ throw new Error(this.contextualize(`Statement inesperado: '${tok.value}' (${tok.type})`));
162
+ case tokens_1.TokenType.NEWLINE:
163
+ this.advance();
164
+ return null;
165
+ case tokens_1.TokenType.EOF:
166
+ return null;
167
+ default:
168
+ throw new Error(this.contextualize(`Statement inesperado: '${tok.value}' (${tok.type})`));
169
+ }
170
+ });
165
171
  }
166
172
  // logic classical.propositional
167
173
  parseLogicDecl() {
@@ -547,12 +553,14 @@ class Parser {
547
553
  if (this.checkType(tokens_1.TokenType.QED))
548
554
  break;
549
555
  try {
550
- const stmt = this.parseStatement();
556
+ const stmt = this.checkType(tokens_1.TokenType.ASSUME)
557
+ ? this.parseProofBlock()
558
+ : this.parseStatement();
551
559
  if (stmt)
552
560
  body.push(stmt);
553
561
  }
554
562
  catch (e) {
555
- const message = e instanceof Error ? e.message : 'Error de parseo';
563
+ const message = e instanceof Error ? e.message : 'Error de parseo en bloque de prueba';
556
564
  this.diagnostics.push({
557
565
  severity: 'error',
558
566
  message,
@@ -563,6 +571,9 @@ class Parser {
563
571
  this.advanceToNextStatement();
564
572
  }
565
573
  }
574
+ if (this.isAtEnd()) {
575
+ throw new Error(`Se esperaba 'qed' para cerrar el bloque de prueba abierto en linea ${src.line}, columna ${src.column}`);
576
+ }
566
577
  this.expect(tokens_1.TokenType.QED);
567
578
  return { kind: 'proof_block', assumptions, goal, body, source: src };
568
579
  }
@@ -1108,6 +1119,17 @@ class Parser {
1108
1119
  return this.parseAtom();
1109
1120
  }
1110
1121
  parseAtom() {
1122
+ // Constantes lógicas ⊤/⊥ (true/false/verdadero/falso)
1123
+ if (this.checkType(tokens_1.TokenType.TRUE_CONST)) {
1124
+ const tok = this.current();
1125
+ this.advance();
1126
+ return { kind: 'true', source: { line: tok.line, column: tok.column } };
1127
+ }
1128
+ if (this.checkType(tokens_1.TokenType.FALSE_CONST)) {
1129
+ const tok = this.current();
1130
+ this.advance();
1131
+ return { kind: 'false', source: { line: tok.line, column: tok.column } };
1132
+ }
1111
1133
  // Literal numérico
1112
1134
  if (this.checkType(tokens_1.TokenType.NUMBER)) {
1113
1135
  const tok = this.current();
@@ -1428,8 +1450,8 @@ class Parser {
1428
1450
  if (this.checkType(type)) {
1429
1451
  return this.advance();
1430
1452
  }
1431
- throw new Error(`Se esperaba ${type}, encontrado '${this.current().value}' (${this.current().type}) ` +
1432
- `en linea ${this.current().line}, columna ${this.current().column}`);
1453
+ throw new Error(this.contextualize(`Se esperaba ${type}, encontrado '${this.current().value}' (${this.current().type}) ` +
1454
+ `en linea ${this.current().line}, columna ${this.current().column}`));
1433
1455
  }
1434
1456
  expectOneOf(...types) {
1435
1457
  for (const type of types) {
@@ -1437,8 +1459,8 @@ class Parser {
1437
1459
  return this.advance();
1438
1460
  }
1439
1461
  }
1440
- throw new Error(`Se esperaba ${types.join(' o ')}, encontrado '${this.current().value}' (${this.current().type}) ` +
1441
- `en linea ${this.current().line}, columna ${this.current().column}`);
1462
+ throw new Error(this.contextualize(`Se esperaba ${types.join(' o ')}, encontrado '${this.current().value}' (${this.current().type}) ` +
1463
+ `en linea ${this.current().line}, columna ${this.current().column}`));
1442
1464
  }
1443
1465
  expectIdent() {
1444
1466
  const tok = this.expect(tokens_1.TokenType.IDENTIFIER);
@@ -1474,8 +1496,95 @@ class Parser {
1474
1496
  this.advance();
1475
1497
  return tok.value;
1476
1498
  }
1477
- throw new Error(`Se esperaba nombre/identificador, encontrado '${tok.value}' (${tok.type}) ` +
1478
- `en linea ${tok.line}, columna ${tok.column}`);
1499
+ throw new Error(this.contextualize(`Se esperaba nombre/identificador, encontrado '${tok.value}' (${tok.type}) ` +
1500
+ `en linea ${tok.line}, columna ${tok.column}`));
1501
+ }
1502
+ contextualize(message) {
1503
+ if (this.contextStack.length === 0)
1504
+ return message;
1505
+ return `${message} mientras se parseaba ${this.contextStack.join(' > ')}`;
1506
+ }
1507
+ withContext(context, fn) {
1508
+ this.contextStack.push(context);
1509
+ try {
1510
+ return fn();
1511
+ }
1512
+ finally {
1513
+ this.contextStack.pop();
1514
+ }
1515
+ }
1516
+ describeStatementContext(tok) {
1517
+ switch (tok.type) {
1518
+ case tokens_1.TokenType.LOGIC:
1519
+ return 'declaracion logic';
1520
+ case tokens_1.TokenType.AXIOM:
1521
+ return 'declaracion de axioma';
1522
+ case tokens_1.TokenType.THEOREM:
1523
+ return 'declaracion de teorema';
1524
+ case tokens_1.TokenType.DERIVE:
1525
+ return 'comando derive';
1526
+ case tokens_1.TokenType.CHECK:
1527
+ return 'comando check';
1528
+ case tokens_1.TokenType.PROVE:
1529
+ return 'comando prove';
1530
+ case tokens_1.TokenType.COUNTERMODEL:
1531
+ case tokens_1.TokenType.REFUTE:
1532
+ return 'comando countermodel';
1533
+ case tokens_1.TokenType.TRUTH_TABLE:
1534
+ return 'comando truth_table';
1535
+ case tokens_1.TokenType.LET:
1536
+ return 'declaracion let';
1537
+ case tokens_1.TokenType.CLAIM:
1538
+ return 'declaracion claim';
1539
+ case tokens_1.TokenType.SUPPORT:
1540
+ return 'declaracion support';
1541
+ case tokens_1.TokenType.CONFIDENCE:
1542
+ return 'declaracion confidence';
1543
+ case tokens_1.TokenType.CONTEXT:
1544
+ return 'declaracion context';
1545
+ case tokens_1.TokenType.RENDER:
1546
+ return 'comando render';
1547
+ case tokens_1.TokenType.ANALYZE:
1548
+ return 'comando analyze';
1549
+ case tokens_1.TokenType.EXPLAIN:
1550
+ return 'comando explain';
1551
+ case tokens_1.TokenType.IMPORT:
1552
+ return 'declaracion import';
1553
+ case tokens_1.TokenType.ASSUME:
1554
+ return 'bloque de prueba';
1555
+ case tokens_1.TokenType.THEORY:
1556
+ return 'declaracion theory';
1557
+ case tokens_1.TokenType.PRINT:
1558
+ return 'comando print';
1559
+ case tokens_1.TokenType.SET:
1560
+ return 'comando set';
1561
+ case tokens_1.TokenType.IF:
1562
+ return 'sentencia if';
1563
+ case tokens_1.TokenType.FOR:
1564
+ return 'sentencia for';
1565
+ case tokens_1.TokenType.WHILE:
1566
+ return 'sentencia while';
1567
+ case tokens_1.TokenType.FN:
1568
+ return 'declaracion fn';
1569
+ case tokens_1.TokenType.RETURN:
1570
+ return 'sentencia return';
1571
+ case tokens_1.TokenType.EXPORT:
1572
+ return 'declaracion export';
1573
+ case tokens_1.TokenType.DEFINE:
1574
+ return 'declaracion define';
1575
+ case tokens_1.TokenType.UNFOLD:
1576
+ return 'comando unfold';
1577
+ case tokens_1.TokenType.FOLD:
1578
+ return 'comando fold';
1579
+ case tokens_1.TokenType.SOURCE_KW:
1580
+ return 'declaracion source';
1581
+ case tokens_1.TokenType.INTERPRET:
1582
+ return 'comando interpret';
1583
+ case tokens_1.TokenType.GLOSSARY:
1584
+ return 'comando glossary';
1585
+ default:
1586
+ return `statement '${tok.value}'`;
1587
+ }
1479
1588
  }
1480
1589
  loc() {
1481
1590
  const tok = this.current();
@@ -1527,14 +1636,37 @@ class Parser {
1527
1636
  tokens_1.TokenType.INTERPRET,
1528
1637
  tokens_1.TokenType.GLOSSARY,
1529
1638
  ]);
1639
+ let parenDepth = 0;
1640
+ let braceDepth = 0;
1641
+ let bracketDepth = 0;
1530
1642
  while (!this.isAtEnd()) {
1531
- if (this.checkType(tokens_1.TokenType.NEWLINE)) {
1643
+ if (this.checkType(tokens_1.TokenType.NEWLINE) &&
1644
+ parenDepth === 0 &&
1645
+ braceDepth === 0 &&
1646
+ bracketDepth === 0) {
1532
1647
  this.skipNewlines();
1533
1648
  return;
1534
1649
  }
1535
- if (statementStarters.has(this.current().type)) {
1650
+ if (parenDepth === 0 &&
1651
+ braceDepth === 0 &&
1652
+ bracketDepth === 0 &&
1653
+ statementStarters.has(this.current().type)) {
1536
1654
  return; // Encontramos el inicio del siguiente statement
1537
1655
  }
1656
+ if (this.checkType(tokens_1.TokenType.LPAREN))
1657
+ parenDepth += 1;
1658
+ else if (this.checkType(tokens_1.TokenType.RPAREN))
1659
+ parenDepth = Math.max(0, parenDepth - 1);
1660
+ else if (this.checkType(tokens_1.TokenType.LBRACE))
1661
+ braceDepth += 1;
1662
+ else if (this.checkType(tokens_1.TokenType.RBRACE))
1663
+ braceDepth = Math.max(0, braceDepth - 1);
1664
+ else if (this.checkType(tokens_1.TokenType.LBRACKET) || this.checkType(tokens_1.TokenType.LBRACKET_DOUBLE)) {
1665
+ bracketDepth += 1;
1666
+ }
1667
+ else if (this.checkType(tokens_1.TokenType.RBRACKET) || this.checkType(tokens_1.TokenType.RBRACKET_DOUBLE)) {
1668
+ bracketDepth = Math.max(0, bracketDepth - 1);
1669
+ }
1538
1670
  this.advance();
1539
1671
  }
1540
1672
  }