UNPKG

@stackpress/idea-parser

Version:

Parses ideas to AST and readable JSON.

40 lines (39 loc) 1.19 kB
import { scan } from '../definitions.js'; import AbstractTree from './AbstractTree.js'; export default class PropTree extends AbstractTree { static definitions(lexer) { super.definitions(lexer); lexer.define('PropWord', (code, index) => 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 } ] }; } } ;