@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.
- package/README.md +3 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +44 -9
- package/dist/api.js.map +1 -1
- package/dist/lexer/lexer.d.ts.map +1 -1
- package/dist/lexer/lexer.js +8 -0
- package/dist/lexer/lexer.js.map +1 -1
- package/dist/lexer/tokens.d.ts +2 -0
- package/dist/lexer/tokens.d.ts.map +1 -1
- package/dist/lexer/tokens.js +6 -0
- package/dist/lexer/tokens.js.map +1 -1
- package/dist/parser/parser.d.ts +4 -0
- package/dist/parser/parser.d.ts.map +1 -1
- package/dist/parser/parser.js +224 -92
- package/dist/parser/parser.js.map +1 -1
- package/dist/profiles/aristotelian/syllogistic.d.ts +1 -1
- package/dist/profiles/aristotelian/syllogistic.d.ts.map +1 -1
- package/dist/profiles/aristotelian/syllogistic.js +26 -8
- package/dist/profiles/aristotelian/syllogistic.js.map +1 -1
- package/dist/profiles/arithmetic/index.d.ts +1 -1
- package/dist/profiles/arithmetic/index.d.ts.map +1 -1
- package/dist/profiles/arithmetic/index.js +29 -7
- package/dist/profiles/arithmetic/index.js.map +1 -1
- package/dist/profiles/classical/first-order.d.ts +1 -1
- package/dist/profiles/classical/first-order.d.ts.map +1 -1
- package/dist/profiles/classical/first-order.js +32 -8
- package/dist/profiles/classical/first-order.js.map +1 -1
- package/dist/profiles/classical/propositional.d.ts +1 -1
- package/dist/profiles/classical/propositional.d.ts.map +1 -1
- package/dist/profiles/classical/propositional.js +464 -69
- package/dist/profiles/classical/propositional.js.map +1 -1
- package/dist/profiles/intuitionistic/propositional.d.ts +1 -1
- package/dist/profiles/intuitionistic/propositional.d.ts.map +1 -1
- package/dist/profiles/intuitionistic/propositional.js +33 -5
- package/dist/profiles/intuitionistic/propositional.js.map +1 -1
- package/dist/profiles/paraconsistent/belnap.d.ts +1 -2
- package/dist/profiles/paraconsistent/belnap.d.ts.map +1 -1
- package/dist/profiles/paraconsistent/belnap.js +25 -11
- package/dist/profiles/paraconsistent/belnap.js.map +1 -1
- package/dist/profiles/probabilistic/basic.d.ts +1 -1
- package/dist/profiles/probabilistic/basic.d.ts.map +1 -1
- package/dist/profiles/probabilistic/basic.js +29 -5
- package/dist/profiles/probabilistic/basic.js.map +1 -1
- package/dist/profiles/shared/base-profile.d.ts +1 -1
- package/dist/profiles/shared/base-profile.d.ts.map +1 -1
- package/dist/profiles/shared/base-profile.js +20 -3
- package/dist/profiles/shared/base-profile.js.map +1 -1
- package/dist/profiles/shared/tableau-engine.d.ts +4 -3
- package/dist/profiles/shared/tableau-engine.d.ts.map +1 -1
- package/dist/profiles/shared/tableau-engine.js +107 -15
- package/dist/profiles/shared/tableau-engine.js.map +1 -1
- package/dist/protocol/handler.d.ts +4 -0
- package/dist/protocol/handler.d.ts.map +1 -1
- package/dist/protocol/handler.js +133 -41
- package/dist/protocol/handler.js.map +1 -1
- package/dist/repl/repl.d.ts +2 -0
- package/dist/repl/repl.d.ts.map +1 -1
- package/dist/repl/repl.js +44 -19
- package/dist/repl/repl.js.map +1 -1
- package/dist/runtime/compat.d.ts +29 -0
- package/dist/runtime/compat.d.ts.map +1 -0
- package/dist/runtime/compat.js +819 -0
- package/dist/runtime/compat.js.map +1 -0
- package/dist/runtime/interpreter.d.ts +3 -0
- package/dist/runtime/interpreter.d.ts.map +1 -1
- package/dist/runtime/interpreter.js +133 -30
- package/dist/runtime/interpreter.js.map +1 -1
- package/dist/tests/cli.test.js +5 -1
- package/dist/tests/cli.test.js.map +1 -1
- package/dist/tests/compat.test.d.ts +2 -0
- package/dist/tests/compat.test.d.ts.map +1 -0
- package/dist/tests/compat.test.js +247 -0
- package/dist/tests/compat.test.js.map +1 -0
- package/dist/tests/core.test.js +41 -1
- package/dist/tests/core.test.js.map +1 -1
- package/dist/tests/parser.test.js +38 -0
- package/dist/tests/parser.test.js.map +1 -1
- package/dist/tests/profiles.test.js +8 -0
- package/dist/tests/profiles.test.js.map +1 -1
- package/dist/tests/protocol-text-layer.test.d.ts +2 -0
- package/dist/tests/protocol-text-layer.test.d.ts.map +1 -0
- package/dist/tests/protocol-text-layer.test.js +54 -0
- package/dist/tests/protocol-text-layer.test.js.map +1 -0
- package/dist/tests/stress-exhaustive.test.js +5 -1
- package/dist/tests/stress-exhaustive.test.js.map +1 -1
- package/dist/text-layer/compiler.d.ts.map +1 -1
- package/dist/text-layer/compiler.js +35 -8
- package/dist/text-layer/compiler.js.map +1 -1
- package/dist/types/index.d.ts +37 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +42 -0
- package/dist/types/index.js.map +1 -1
- package/package.json +1 -3
package/dist/parser/parser.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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.
|
|
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 (
|
|
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
|
}
|