UNPKG

@maniascript/parser

Version:
40 lines (39 loc) 1.27 kB
import { Lexer } from 'antlr4ng'; import { api, generateFromFile } from '@maniascript/api'; export class ManiaScriptBaseLexer extends Lexer { static CHANNEL_NAME_DEFAULT = 'DEFAULT_TOKEN_CHANNEL'; static CHANNEL_NAME_HIDDEN = 'HIDDEN'; static CHANNEL_NAME_COMMENT = 'COMMENT'; static GAME_MANIAPLANET = 'maniaplanet'; static GAME_TRACKMANIA = 'trackmania'; interpolatedStringLevel; classes; constructor(input) { super(input); this.interpolatedStringLevel = 0; this.classes = new Set(api.trackmania.classNames); } setClasses(classes = []) { if (Array.isArray(classes)) { this.classes = new Set(classes); } else if (classes instanceof Set) { this.classes = classes; } else { throw new Error('classes parameter must be an Array or Set'); } } async setMSApi(path = '') { const api = await generateFromFile(path); this.setClasses(api.classNames); } setGame(game) { if (game === ManiaScriptBaseLexer.GAME_MANIAPLANET) { this.classes = new Set(api.maniaplanet.classNames); } else { this.classes = new Set(api.trackmania.classNames); } } }