@stackpress/idea-parser
Version:
Parses ideas to AST and readable JSON.
36 lines (35 loc) • 1.06 kB
JavaScript
import { scan } from '../definitions.js';
import AbstractTree from './AbstractTree.js';
export default class UseTree extends AbstractTree {
static definitions(lexer) {
super.definitions(lexer);
lexer.define('UseWord', (code, index) => 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
}
};
}
}
;