UNPKG

@stackpress/idea-parser

Version:

Parses ideas to AST and readable JSON.

51 lines (50 loc) 1.7 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 PluginTree extends AbstractTree_js_1.default { static definitions(lexer) { super.definitions(lexer); lexer.define('PluginWord', (code, index) => (0, definitions_js_1.scan)('_PluginWord', /^plugin/, 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.plugin(); } plugin() { const type = this._lexer.expect('PluginWord'); this._lexer.expect('whitespace'); const id = this._lexer.expect('String'); this._lexer.expect('whitespace'); const init = this._lexer.expect('Object'); return { type: 'VariableDeclaration', kind: 'plugin', start: type.start, end: this._lexer.index, declarations: [ { type: 'VariableDeclarator', start: id.start, end: this._lexer.index, id: { type: 'Identifier', start: id.start, end: id.end, name: id.value }, init } ] }; } } exports.default = PluginTree; ;