@intend-it/parser 1.1.4 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +23 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9331,6 +9331,14 @@ class IntendParser extends CstParser {
|
|
|
9331
9331
|
{ ALT: () => this.CONSUME(Let) }
|
|
9332
9332
|
]);
|
|
9333
9333
|
this.CONSUME(Identifier, { LABEL: "ResultVar" });
|
|
9334
|
+
this.OPTION2(() => {
|
|
9335
|
+
this.CONSUME(Colon);
|
|
9336
|
+
this.CONSUME2(Identifier, { LABEL: "ResultType" });
|
|
9337
|
+
this.OPTION3(() => {
|
|
9338
|
+
this.CONSUME(LBracket);
|
|
9339
|
+
this.CONSUME(RBracket);
|
|
9340
|
+
});
|
|
9341
|
+
});
|
|
9334
9342
|
});
|
|
9335
9343
|
});
|
|
9336
9344
|
ensureStatement = this.RULE("ensureStatement", () => {
|
|
@@ -9462,11 +9470,18 @@ class IntendASTVisitor extends BaseIntendVisitor {
|
|
|
9462
9470
|
const instruction = this.unquoteString(rawString);
|
|
9463
9471
|
const resultVariable = ctx.ResultVar ? ctx.ResultVar[0].image : undefined;
|
|
9464
9472
|
const variableKind = ctx.Let && ctx.Let.length > 0 ? "let" : "const";
|
|
9473
|
+
let resultType;
|
|
9474
|
+
if (ctx.ResultType) {
|
|
9475
|
+
const base = ctx.ResultType[0].image;
|
|
9476
|
+
const isArray2 = ctx.LBracket && ctx.LBracket.length > 0;
|
|
9477
|
+
resultType = isArray2 ? `${base}[]` : base;
|
|
9478
|
+
}
|
|
9465
9479
|
return {
|
|
9466
9480
|
type: "Step",
|
|
9467
9481
|
instruction,
|
|
9468
9482
|
resultVariable,
|
|
9469
|
-
variableKind
|
|
9483
|
+
variableKind,
|
|
9484
|
+
resultType
|
|
9470
9485
|
};
|
|
9471
9486
|
}
|
|
9472
9487
|
returnStatement(ctx) {
|
|
@@ -9539,7 +9554,13 @@ function parse(text) {
|
|
|
9539
9554
|
function parseToAST(text) {
|
|
9540
9555
|
const result = parse(text);
|
|
9541
9556
|
if (result.lexingErrors.length > 0 || result.parsingErrors.length > 0) {
|
|
9542
|
-
|
|
9557
|
+
const errors = [
|
|
9558
|
+
...result.lexingErrors.map((e) => `Lexing Error: ${e.message} at line ${e.line}:${e.column}`),
|
|
9559
|
+
...result.parsingErrors.map((e) => `Parsing Error: ${e.message} at line ${e.token.startLine}:${e.token.startColumn}`)
|
|
9560
|
+
].join(`
|
|
9561
|
+
`);
|
|
9562
|
+
throw new Error(`Cannot generate AST: parsing failed
|
|
9563
|
+
${errors}`);
|
|
9543
9564
|
}
|
|
9544
9565
|
const ast = astVisitor.visit(result.cst);
|
|
9545
9566
|
return {
|