UNPKG

@stackpress/idea-parser

Version:

Parses ideas to AST and readable JSON.

46 lines (45 loc) 1.49 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const definitions_js_1 = require("../definitions.js"); const AbstractTree_js_1 = __importDefault(require("./AbstractTree.js")); class PropTree extends AbstractTree_js_1.default { static definitions(lexer) { super.definitions(lexer); lexer.define('PropWord', (code, index) => (0, definitions_js_1.scan)('_PropWord', /^prop/, code, index)); return lexer; } static parse(code, start = 0) { return new this().parse(code, start); } parse(code, start = 0) { this._lexer.load(code, start); return this.prop(); } prop() { const type = this._lexer.expect('PropWord'); this._lexer.expect('whitespace'); const id = this._lexer.expect('CapitalIdentifier'); this._lexer.expect('whitespace'); const init = this._lexer.expect('Object'); return { type: 'VariableDeclaration', kind: 'prop', start: type.start, end: init.end, declarations: [ { type: 'VariableDeclarator', start: id.start, end: init.end, id, init } ] }; } } exports.default = PropTree; ;