UNPKG

mframejs

Version:
173 lines 4.91 kB
export function addSymbols(astInstance) { const ast = astInstance; ast.symbol('(literal)').nud = function () { return this; }; ast.symbol('(variable)').nud = function () { return this; }; ast.symbol('(function)').nud = function () { return this; }; ast.symbol('(end)'); ast.symbol('(name)'); ast.symbol(':'); ast.symbol(';'); ast.symbol(')'); ast.symbol(']'); ast.symbol('}'); ast.symbol(','); ast.infix('+', 50); ast.infix('-', 50); ast.infix('*', 60); ast.infix('%', 60); ast.infix('/', 60); ast.infix('===', 40); ast.infix('!==', 40); ast.infix('==', 40); ast.infix('!=', 40); ast.infix('<', 40); ast.infix('<=', 40); ast.infix('>', 40); ast.infix('^', 70); ast.infix('>=', 40); ast.infix('?', 20, function (left) { this.first = left; this.second = ast.expression(0); ast.advance(':'); this.third = ast.expression(0); this.arity = 'ternary'; return this; }); ast.infix('.', 80, function (left) { this.first = left; if (ast.currentToken.arity !== 'variable') { ast.currentToken.error('Expected a property name.'); } ast.currentToken.arity = 'variable'; this.second = ast.currentToken; this.arity = 'binary'; this.isObject = true; ast.advance(); return this; }); ast.infix('[', 80, function (left) { this.first = left; this.second = ast.expression(0); this.arity = 'binary'; this.isObject = true; this.contextReset = true; ast.advance(']'); return this; }); ast.infix('(', 80, function (left) { if (!left) { return ast.expression(0); } const a = []; this.arity = 'binary'; this.isFunction = true; this.first = left; this.second = a; if (ast.currentToken.id !== ')') { while (true) { a.push(ast.expression(0)); if (ast.currentToken.id !== ',') { break; } ast.advance(','); } } ast.advance(')'); return this; }); ast.prefix('-'); ast.prefix('!'); ast.prefix('(', function () { const e = ast.expression(0); if (ast.currentToken.value === '|') { ast.valueConverter = ast.expression(0); } if (ast.currentToken.value === '&') { ast.behavior = ast.expression(0); } else { ast.advance(')'); } return e; }); ast.prefix('{', function () { const a = []; if (ast.currentToken.value !== '}') { while (true) { const n = ast.currentToken; ast.advance(); ast.advance(':'); const v = ast.expression(0); v.key = n.value; a.push(v); if (ast.currentToken.value !== ',') { break; } ast.advance(','); } } ast.advance('}'); this.first = a; this.arity = 'unary'; return this; }); ast.assignment('='); ast.assignment('+='); ast.assignment('-='); ast.assignment('*='); ast.assignment('/='); ast.prefix('|', function () { this.arity = 'valueConverter'; const value = ast.expression(0); this.value = value.value; const a = []; this.args = a; while (true) { if (ast.currentToken.id !== ':') { break; } ast.advance(','); a.push(ast.expression(0)); } this.args.unshift(ast.statementsArray.pop()); ast.currentStatement = this; return this; }); ast.prefix('&', function () { this.arity = 'behavior'; const value = ast.expression(0); this.value = value.value; const a = []; this.args = a; while (true) { if (ast.currentToken.id !== ':') { break; } ast.advance(','); a.push(ast.expression(0)); } return this; }); ast.prefix('${', function () { this.e = ast.expression(0); ast.advance('}'); return this.e; }); ast.prefix('@{', function () { const e = ast.expression(0); ast.advance('}'); return e; }); ast.infixr('&&', 30); ast.infixr('||', 30); ast.symbol(';').nud = function () { return null; }; } //# sourceMappingURL=addSymbols.js.map