@graffiticode/parser 0.1.4 → 0.2.0
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/package.json +1 -1
- package/src/parse.js +19 -6
package/package.json
CHANGED
package/src/parse.js
CHANGED
|
@@ -469,14 +469,27 @@ export const parse = (function () {
|
|
|
469
469
|
});
|
|
470
470
|
}
|
|
471
471
|
function binding(ctx, cc) {
|
|
472
|
+
// Save the current lexeme before bindingName consumes it
|
|
473
|
+
const savedLexeme = lexeme;
|
|
474
|
+
const savedCoord = getCoord(ctx);
|
|
472
475
|
return bindingName(ctx, function (ctx) {
|
|
473
|
-
|
|
474
|
-
|
|
476
|
+
// Check if we have a colon for full syntax, otherwise use shorthand
|
|
477
|
+
if (match(ctx, TK_COLON)) {
|
|
478
|
+
eat(ctx, TK_COLON);
|
|
479
|
+
const ret = function (ctx) {
|
|
480
|
+
countCounter(ctx);
|
|
481
|
+
return expr(ctx, cc);
|
|
482
|
+
};
|
|
483
|
+
ret.cls = "punc";
|
|
484
|
+
return ret;
|
|
485
|
+
} else {
|
|
486
|
+
// Shorthand syntax - create a name reference for the value
|
|
487
|
+
// The binding name was already pushed as a string by bindingName
|
|
488
|
+
// Now we need to push a name reference (identifier) as the value
|
|
489
|
+
Ast.name(ctx, savedLexeme, savedCoord);
|
|
475
490
|
countCounter(ctx);
|
|
476
|
-
return
|
|
477
|
-
}
|
|
478
|
-
ret.cls = "punc";
|
|
479
|
-
return ret;
|
|
491
|
+
return cc;
|
|
492
|
+
}
|
|
480
493
|
});
|
|
481
494
|
}
|
|
482
495
|
function lambda(ctx, cc) {
|