@bablr/language-en-es6
Version:
A BABLR language for ES6 (JavaScript)
142 lines (140 loc) • 5.13 kB
JavaScript
/* @macrome
* @generatedby @bablr/macrome-generator-bablr
* @generatedfrom ./function.macro.js#131fa920ecc7aa38c83fd989fbfe47e749a55217
* This file is autogenerated. Please do not edit it directly.
* When editing run `npx macrome watch` then change the file this is generated from.
*/
import _applyDecs from "@babel/runtime/helpers/applyDecs2305";
import { spam as m, re } from '@bablr/boot';
import { CoveredBy, Node } from '@bablr/helpers/decorators';
import { o, eat, eatMatch, fail, match, shiftMatch } from '@bablr/helpers/grammar';
export const mixin = Base => {
let _initProto, _FunctionExpressionDecs;
return class es6FunctionGrammar extends Base {
static {
[] = _applyDecs(this, [[_FunctionExpressionDecs, 2, "FunctionExpression"], [Node, 2, "YieldStatement"], [Node, 2, "ObjectPattern"], [Node, 2, "PropertyPattern"], [Node, 2, "AssignmentPattern"], [Node, 2, "ArrayPattern"], [Node, 2, "ArrowFunctionExpression"]], [], 0, void 0, Base).e;
}
constructor(...args) {
super(...args);
_initProto(this);
}
*[(_FunctionExpressionDecs = [CoveredBy('Expression'), Node], "FunctionExpression")]({
props: {
shorthand
}
}) {
if (!shorthand) {
yield eat(m`sigilToken: <*Keyword 'function' />`);
} else {
yield eat(m`sigilToken: null`);
}
let a = yield eatMatch(m`asyncToken: <*Keyword 'async' />`);
let gen = yield eatMatch(m`starToken: <*Punctuator '*' />`);
if (a && gen) yield fail();
if (!shorthand) {
yield eatMatch(m`id: <Identifier />`, o({}), o({
bind: true
}));
} else {
yield eat(m`id: null`);
}
yield eat(m`openParamsToken: <*Punctuator '(' { balanced: ')' } />`);
yield eat(m`params[]+: <__List />`, o({
element: m`<_CapturePattern />`,
allowTrailingSeparator: false,
separator: m`#separatorTokens[]: <*Punctuator ',' />`
}));
yield eat(m`closeParamsToken: <*Punctuator ')' { balancer: true } />`);
yield eat(m`body: <BlockStatement />`);
}
*YieldStatement() {
yield eat(m`sigilToken: <*Keyword 'yield' />`);
yield eat(m`expression+$: <_Expression />`);
yield eatMatch(m`endToken: <*Punctuator ';' />`, null, o({
bind: true
}));
}
// (type = null, { prop, value: name = {} }) => {};
*CapturePattern({
ctx
}) {
let pn;
if (pn = yield match(re`/[[{]/`)) {
switch (ctx.sourceTextFor(pn).trim()) {
case '{':
yield eat(m`<ObjectPattern />`);
break;
case '[':
yield eat(m`<ArrayPattern />`);
break;
}
} else {
yield eat(m`<Identifier />`);
return shiftMatch(m`<AssignmentPattern '=' />`);
}
}
*ObjectPattern() {
yield eat(m`openToken: <*Punctuator '{' { balanced: '}' } />`);
yield eat(m`params[]+$: <__List />`, o({
element: m`<PropertyPattern />`,
allowTrailingSeparator: true,
separator: m`#separatorTokens[]: <*Punctuator ',' />`
}));
yield eat(m`closeToken: <*Punctuator '}' { balancer: true } />`);
}
*PropertyPattern() {
if (yield eatMatch(m`key$: <Identifier />`)) {
let cn = yield eatMatch(m`mapOperator: <*Punctuator ':' />`, null, o({
bind: true
}));
if (cn) {
yield eat(m`value+$: <_CapturePattern />`);
}
} else {
yield eat(m`key$: <Identifier />`, o({
scoped: false
}));
yield eat(m`mapOperator: <*Punctuator ':' />`);
yield eat(m`value+$: <_CapturePattern />`);
}
}
*AssignmentPattern() {
yield eat(m`source+$: <Identifier />`);
yield eat(m`assignmentOperator: <*Punctuator '=' />`);
yield eat(m`defaultValue+$: <_Expression />`, o({
power: 32
}));
}
*ArrayPattern() {
yield eat(m`openToken: <*Punctuator '[' { balanced: ']' } />`);
yield eat(m`params[]+$: <__List />`, o({
element: m`<_CapturePattern />`,
allowTrailingSeparator: true,
separator: m`#separatorTokens[]: <*Punctuator ',' />`
}));
yield eat(m`closeToken: <*Punctuator ']' { balancer: true } />`);
}
*ArrowFunctionExpression() {
// yield eat(m`params[]+: []`);
if (yield match('(')) {
yield eat(m`openParamsToken: <*Punctuator '(' { balanced: ')' } />`);
yield eat(m`params[]+$: <__List />`, o({
element: m`<_CapturePattern />`,
allowTrailingSeparator: false,
separator: m`#separatorTokens[]: <*Punctuator ',' />`
}));
yield eat(m`closeParamsToken: <*Punctuator ')' { balancer: true } />`);
} else {
yield eat(m`params[]+$: <Identifier />`);
yield eat(m`openParamsToken: null`);
yield eat(m`closeParamsToken: null`);
}
yield eat(m`sigilToken: <*Keyword '=>' />`);
if (yield match('{')) {
yield eat(m`body+$: <BlockStatement />`);
} else {
yield eat(m`body+$: <_Expression />`);
}
}
};
};