UNPKG

antlr-ng

Version:

Next generation ANTLR Tool

59 lines (58 loc) 1.71 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); import { CommonToken } from "antlr4ng"; class GrammarToken extends CommonToken { static { __name(this, "GrammarToken"); } g; originalTokenIndex = -1; constructor(g, oldToken) { const source = [oldToken.tokenSource, oldToken.inputStream]; super({ ...oldToken, source }); this.g = g; } getCharPositionInLine() { if (this.originalTokenIndex >= 0) { return this.g.originalTokenStream.get(this.originalTokenIndex).column; } return this.column; } getLine() { if (this.originalTokenIndex >= 0) { return this.g.originalTokenStream.get(this.originalTokenIndex).line; } return this.line; } getTokenIndex() { return this.originalTokenIndex; } getStartIndex() { if (this.originalTokenIndex >= 0) { return this.g.originalTokenStream.get(this.originalTokenIndex).start; } return this.start; } getStopIndex() { const n = this.stop - this.start + 1; return this.getStartIndex() + n - 1; } toString() { let channelStr = ""; if (this.channel > 0) { channelStr = ",channel=" + this.channel; } let txt = this.text; if (txt != null) { txt = txt.replaceAll("\n", "\\\\n"); txt = txt.replaceAll("\r", "\\\\r"); txt = txt.replaceAll(" ", "\\\\t"); } else { txt = "<no text>"; } return "[@" + this.getTokenIndex() + "," + this.getStartIndex() + ":" + this.getStopIndex() + "='" + txt + "',<" + this.type + ">" + channelStr + "," + this.getLine() + ":" + this.getCharPositionInLine() + "]"; } } export { GrammarToken };