antlr-ng
Version:
Next generation ANTLR Tool
98 lines (97 loc) • 2.7 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
class TreePatternLexer {
static {
__name(this, "TreePatternLexer");
}
static EOF = -1;
static BEGIN = 1;
static END = 2;
static ID = 3;
static ARG = 4;
static PERCENT = 5;
static COLON = 6;
static DOT = 7;
/** Set when token type is ID or ARG. */
stringValue = "";
/** Index into input string */
currentPosition = -1;
/** Current char */
c;
/** The input pattern as a sequence of code points. */
input;
constructor(pattern) {
this.input = new Uint16Array(pattern.length);
for (let i = 0; i < pattern.length; ++i) {
this.input[i] = pattern.charCodeAt(i);
}
this.consume();
}
nextToken() {
this.stringValue = "";
while (this.currentPosition < this.input.length) {
if (this.c === 32 || this.c === 13 || this.c === 10 || this.c === 9) {
this.consume();
continue;
}
if (this.c >= 97 && this.c <= 122 || this.c >= 65 && this.c <= 90 || this.c === 95) {
this.stringValue += String.fromCodePoint(this.c);
this.consume();
while (this.c >= 97 && this.c <= 122 || this.c >= 65 && this.c <= 90 || this.c >= 48 && this.c <= 57 || this.c === 95) {
this.stringValue += String.fromCodePoint(this.c);
this.consume();
}
return TreePatternLexer.ID;
}
if (this.c === 40) {
this.consume();
return TreePatternLexer.BEGIN;
}
if (this.c === 41) {
this.consume();
return TreePatternLexer.END;
}
if (this.c === 37) {
this.consume();
return TreePatternLexer.PERCENT;
}
if (this.c === 58) {
this.consume();
return TreePatternLexer.COLON;
}
if (this.c === 46) {
this.consume();
return TreePatternLexer.DOT;
}
if (this.c === 91) {
this.consume();
while (this.c !== 93) {
if (this.c === 92) {
this.consume();
this.stringValue += "\\";
this.stringValue += String.fromCodePoint(this.c);
} else {
this.stringValue += String.fromCodePoint(this.c);
}
this.consume();
}
this.consume();
return TreePatternLexer.ARG;
}
this.consume();
return TreePatternLexer.EOF;
}
return TreePatternLexer.EOF;
}
consume() {
++this.currentPosition;
if (this.currentPosition >= this.input.length) {
this.c = TreePatternLexer.EOF;
} else {
this.c = this.input[this.currentPosition];
}
}
}
export {
TreePatternLexer
};