@stackpress/idea-parser
Version:
Parses ideas to AST and readable JSON.
42 lines (41 loc) • 1.36 kB
JavaScript
;
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 UseTree extends AbstractTree_js_1.default {
static definitions(lexer) {
super.definitions(lexer);
lexer.define('UseWord', (code, index) => (0, definitions_js_1.scan)('_UseWord', /^use/, 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.use();
}
use() {
const type = this._lexer.expect('UseWord');
this._lexer.expect('whitespace');
const imported = this._lexer.expect('String');
return {
type: 'ImportDeclaration',
start: type.start,
end: this._lexer.index,
specifiers: [],
source: {
type: 'Literal',
start: imported.start,
end: imported.end,
value: imported.value,
raw: imported.raw
}
};
}
}
exports.default = UseTree;
;