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AmB,CAAC,CAAS;QACnC,IAAI,CAAC,GAAW,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QACxC,OAAO,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;IACtB,CAAC;IASM,OAAO,CAAC,EAAwB;QACtC,IAAI,EAAE,YAAY,qDAAyB,EAAE;YAC5C,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,qBAAS,CAAC,GAAG,EAAE;gBACxC,4BAA4B;gBAC5B,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;aACtC;SACD;aAAM;YACN,6EAA6E;YAC7E,uBAAuB;YACvB,2DAA2D;YAC3D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;SACtB;IACF,CAAC;;AA3YsB,kBAAY,GAAW,CAAC,CAAC;AACzB,UAAI,GAAW,CAAC,CAAC,CAAC;AAClB,UAAI,GAAW,CAAC,CAAC,CAAC;AAUlB,oBAAc,GAAW,MAAM,CAAC;AAChC,oBAAc,GAAW,QAAQ,CAAC;AAmFzD;IADC,qBAAQ;sCA6DR;AAwCD;IADC,qBAAQ;yCAGR;AAQD;IADC,qBAAQ;wCAGR;AAUD;IADC,qBAAQ;uCAGR;AAyCD;IADC,qBAAQ;iCAGR;AAOD;IADC,qBAAQ;+CAGR;AAlRF,sBA8YC","sourcesContent":["/*!\r\n * Copyright 2016 The ANTLR Project. All rights reserved.\r\n * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information.\r\n */\r\n\r\n// ConvertTo-TS run at 2016-10-04T11:26:51.7913318-07:00\r\n\r\nimport { ANTLRErrorListener } from \"./ANTLRErrorListener\";\r\nimport { CharStream } from \"./CharStream\";\r\nimport { CommonTokenFactory } from \"./CommonTokenFactory\";\r\nimport { IntegerStack } from \"./misc/IntegerStack\";\r\nimport { Interval } from \"./misc/Interval\";\r\nimport { IntStream } from \"./IntStream\";\r\nimport { LexerATNSimulator } from \"./atn/LexerATNSimulator\";\r\nimport { LexerNoViableAltException } from \"./LexerNoViableAltException\";\r\nimport { Override } from \"./Decorators\";\r\nimport { RecognitionException } from \"./RecognitionException\";\r\nimport { Recognizer } from \"./Recognizer\";\r\nimport { Token } from \"./Token\";\r\nimport { TokenFactory } from \"./TokenFactory\";\r\nimport { TokenSource } from \"./TokenSource\";\r\n\r\n/** A lexer is recognizer that draws input symbols from a character stream.\r\n * lexer grammars result in a subclass of this object. A Lexer object\r\n * uses simplified match() and error recovery mechanisms in the interest\r\n * of speed.\r\n */\r\nexport abstract class Lexer extends Recognizer<number, LexerATNSimulator>\r\n\timplements TokenSource {\r\n\tpublic static readonly DEFAULT_MODE: number = 0;\r\n\tpublic static readonly MORE: number = -2;\r\n\tpublic static readonly SKIP: number = -3;\r\n\r\n\tstatic get DEFAULT_TOKEN_CHANNEL(): number {\r\n\t\treturn Token.DEFAULT_CHANNEL;\r\n\t}\r\n\r\n\tstatic get HIDDEN(): number {\r\n\t\treturn Token.HIDDEN_CHANNEL;\r\n\t}\r\n\r\n\tpublic static readonly MIN_CHAR_VALUE: number = 0x0000;\r\n\tpublic static readonly MAX_CHAR_VALUE: number = 0x10FFFF;\r\n\r\n\tpublic _input: CharStream;\r\n\r\n\tprotected _tokenFactorySourcePair: { source: TokenSource, stream: CharStream };\r\n\r\n\t/** How to create token objects */\r\n\tprotected _factory: TokenFactory = CommonTokenFactory.DEFAULT;\r\n\r\n\t/** The goal of all lexer rules/methods is to create a token object.\r\n\t * This is an instance variable as multiple rules may collaborate to\r\n\t * create a single token. nextToken will return this object after\r\n\t * matching lexer rule(s). If you subclass to allow multiple token\r\n\t * emissions, then set this to the last token to be matched or\r\n\t * something non-undefined so that the auto token emit mechanism will not\r\n\t * emit another token.\r\n\t */\r\n\tpublic _token: Token | undefined;\r\n\r\n\t/** What character index in the stream did the current token start at?\r\n\t * Needed, for example, to get the text for current token. Set at\r\n\t * the start of nextToken.\r\n\t */\r\n\tpublic _tokenStartCharIndex: number = -1;\r\n\r\n\t/** The line on which the first character of the token resides */\r\n\tpublic _tokenStartLine: number = 0;\r\n\r\n\t/** The character position of first character within the line */\r\n\tpublic _tokenStartCharPositionInLine: number = 0;\r\n\r\n\t/** Once we see EOF on char stream, next token will be EOF.\r\n\t * If you have DONE : EOF ; then you see DONE EOF.\r\n\t */\r\n\tpublic _hitEOF: boolean = false;\r\n\r\n\t/** The channel number for the current token */\r\n\tpublic _channel: number = 0;\r\n\r\n\t/** The token type for the current token */\r\n\tpublic _type: number = 0;\r\n\r\n\tpublic readonly _modeStack: IntegerStack = new IntegerStack();\r\n\tpublic _mode: number = Lexer.DEFAULT_MODE;\r\n\r\n\t/** You can set the text for the current token to override what is in\r\n\t * the input char buffer. Set `text` or can set this instance var.\r\n\t */\r\n\tpublic _text: string | undefined;\r\n\r\n\tconstructor(input: CharStream) {\r\n\t\tsuper();\r\n\t\tthis._input = input;\r\n\t\tthis._tokenFactorySourcePair = { source: this, stream: input };\r\n\t}\r\n\r\n\tpublic reset(): void;\r\n\tpublic reset(resetInput: boolean): void;\r\n\tpublic reset(resetInput?: boolean): void {\r\n\t\t// wack Lexer state variables\r\n\t\tif (resetInput === undefined || resetInput) {\r\n\t\t\tthis._input.seek(0); // rewind the input\r\n\t\t}\r\n\r\n\t\tthis._token = undefined;\r\n\t\tthis._type = Token.INVALID_TYPE;\r\n\t\tthis._channel = Token.DEFAULT_CHANNEL;\r\n\t\tthis._tokenStartCharIndex = -1;\r\n\t\tthis._tokenStartCharPositionInLine = -1;\r\n\t\tthis._tokenStartLine = -1;\r\n\t\tthis._text = undefined;\r\n\r\n\t\tthis._hitEOF = false;\r\n\t\tthis._mode = Lexer.DEFAULT_MODE;\r\n\t\tthis._modeStack.clear();\r\n\r\n\t\tthis.interpreter.reset();\r\n\t}\r\n\r\n\t/** Return a token from this source; i.e., match a token on the char\r\n\t * stream.\r\n\t */\r\n\t@Override\r\n\tpublic nextToken(): Token {\r\n\t\tif (this._input == null) {\r\n\t\t\tthrow new Error(\"nextToken requires a non-null input stream.\");\r\n\t\t}\r\n\r\n\t\t// Mark start location in char stream so unbuffered streams are\r\n\t\t// guaranteed at least have text of current token\r\n\t\tlet tokenStartMarker: number = this._input.mark();\r\n\t\ttry {\r\n\t\t\touter:\r\n\t\t\twhile (true) {\r\n\t\t\t\tif (this._hitEOF) {\r\n\t\t\t\t\treturn this.emitEOF();\r\n\t\t\t\t}\r\n\r\n\t\t\t\tthis._token = undefined;\r\n\t\t\t\tthis._channel = Token.DEFAULT_CHANNEL;\r\n\t\t\t\tthis._tokenStartCharIndex = this._input.index;\r\n\t\t\t\tthis._tokenStartCharPositionInLine = this.interpreter.charPositionInLine;\r\n\t\t\t\tthis._tokenStartLine = this.interpreter.line;\r\n\t\t\t\tthis._text = undefined;\r\n\t\t\t\tdo {\r\n\t\t\t\t\tthis._type = Token.INVALID_TYPE;\r\n//\t\t\t\tSystem.out.println(\"nextToken line \"+tokenStartLine+\" at \"+((char)input.LA(1))+\r\n//\t\t\t\t\t\t\t\t \" in mode \"+mode+\r\n//\t\t\t\t\t\t\t\t \" at index \"+input.index);\r\n\t\t\t\t\tlet ttype: number;\r\n\t\t\t\t\ttry {\r\n\t\t\t\t\t\tttype = this.interpreter.match(this._input, this._mode);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcatch (e) {\r\n\t\t\t\t\t\tif (e instanceof LexerNoViableAltException) {\r\n\t\t\t\t\t\t\tthis.notifyListeners(e);\t\t// report error\r\n\t\t\t\t\t\t\tthis.recover(e);\r\n\t\t\t\t\t\t\tttype = Lexer.SKIP;\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tthrow e;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (this._input.LA(1) === IntStream.EOF) {\r\n\t\t\t\t\t\tthis._hitEOF = true;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (this._type === Token.INVALID_TYPE) {\r\n\t\t\t\t\t\tthis._type = ttype;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (this._type === Lexer.SKIP) {\r\n\t\t\t\t\t\tcontinue outer;\r\n\t\t\t\t\t}\r\n\t\t\t\t} while (this._type === Lexer.MORE);\r\n\t\t\t\tif (this._token == null) {\r\n\t\t\t\t\treturn this.emit();\r\n\t\t\t\t}\r\n\t\t\t\treturn this._token;\r\n\t\t\t}\r\n\t\t}\r\n\t\tfinally {\r\n\t\t\t// make sure we release marker after match or\r\n\t\t\t// unbuffered char stream will keep buffering\r\n\t\t\tthis._input.release(tokenStartMarker);\r\n\t\t}\r\n\t}\r\n\r\n\t/** Instruct the lexer to skip creating a token for current lexer rule\r\n\t * and look for another token. nextToken() knows to keep looking when\r\n\t * a lexer rule finishes with token set to SKIP_TOKEN. Recall that\r\n\t * if token==undefined at end of any token rule, it creates one for you\r\n\t * and emits it.\r\n\t */\r\n\tpublic skip(): void {\r\n\t\tthis._type = Lexer.SKIP;\r\n\t}\r\n\r\n\tpublic more(): void {\r\n\t\tthis._type = Lexer.MORE;\r\n\t}\r\n\r\n\tpublic mode(m: number): void {\r\n\t\tthis._mode = m;\r\n\t}\r\n\r\n\tpublic pushMode(m: number): void {\r\n\t\tif (LexerATNSimulator.debug) {\r\n\t\t\tconsole.log(\"pushMode \" + m);\r\n\t\t}\r\n\t\tthis._modeStack.push(this._mode);\r\n\t\tthis.mode(m);\r\n\t}\r\n\r\n\tpublic popMode(): number {\r\n\t\tif (this._modeStack.isEmpty) {\r\n\t\t\tthrow new Error(\"EmptyStackException\");\r\n\t\t}\r\n\t\tif (LexerATNSimulator.debug) {\r\n\t\t\tconsole.log(\"popMode back to \" + this._modeStack.peek());\r\n\t\t}\r\n\t\tthis.mode(this._modeStack.pop());\r\n\t\treturn this._mode;\r\n\t}\r\n\r\n\t@Override\r\n\tget tokenFactory(): TokenFactory {\r\n\t\treturn this._factory;\r\n\t}\r\n\r\n\t// @Override\r\n\tset tokenFactory(factory: TokenFactory) {\r\n\t\tthis._factory = factory;\r\n\t}\r\n\r\n\t@Override\r\n\tget inputStream(): CharStream {\r\n\t\treturn this._input;\r\n\t}\r\n\r\n\t/** Set the char stream and reset the lexer */\r\n\tset inputStream(input: CharStream) {\r\n\t\tthis.reset(false);\r\n\t\tthis._input = input;\r\n\t\tthis._tokenFactorySourcePair = { source: this, stream: this._input };\r\n\t}\r\n\r\n\t@Override\r\n\tget sourceName(): string {\r\n\t\treturn this._input.sourceName;\r\n\t}\r\n\r\n\r\n\t/** The standard method called to automatically emit a token at the\r\n\t * outermost lexical rule. The token object should point into the\r\n\t * char buffer start..stop. If there is a text override in 'text',\r\n\t * use that to set the token's text. Override this method to emit\r\n\t * custom Token objects or provide a new factory.\r\n\t */\r\n\tpublic emit(token: Token): Token;\r\n\r\n\t/** By default does not support multiple emits per nextToken invocation\r\n\t * for efficiency reasons. Subclass and override this method, nextToken,\r\n\t * and getToken (to push tokens into a list and pull from that list\r\n\t * rather than a single variable as this implementation does).\r\n\t */\r\n\tpublic emit(): Token;\r\n\r\n\tpublic emit(token?: Token): Token {\r\n\t\tif (!token) {\r\n\t\t\ttoken = this._factory.create(\r\n\t\t\t\tthis._tokenFactorySourcePair, this._type, this._text, this._channel,\r\n\t\t\t\tthis._tokenStartCharIndex, this.charIndex - 1, this._tokenStartLine,\r\n\t\t\t\tthis._tokenStartCharPositionInLine);\r\n\t\t}\r\n\t\tthis._token = token;\r\n\t\treturn token;\r\n\t}\r\n\r\n\tpublic emitEOF(): Token {\r\n\t\tlet cpos: number = this.charPositionInLine;\r\n\t\tlet line: number = this.line;\r\n\t\tlet eof: Token = this._factory.create(\r\n\t\t\tthis._tokenFactorySourcePair, Token.EOF, undefined,\r\n\t\t\tToken.DEFAULT_CHANNEL, this._input.index, this._input.index - 1,\r\n\t\t\tline, cpos);\r\n\t\tthis.emit(eof);\r\n\t\treturn eof;\r\n\t}\r\n\r\n\t@Override\r\n\tget line(): number {\r\n\t\treturn this.interpreter.line;\r\n\t}\r\n\r\n\tset line(line: number) {\r\n\t\tthis.interpreter.line = line;\r\n\t}\r\n\r\n\t@Override\r\n\tget charPositionInLine(): number {\r\n\t\treturn this.interpreter.charPositionInLine;\r\n\t}\r\n\r\n\tset charPositionInLine(charPositionInLine: number) {\r\n\t\tthis.interpreter.charPositionInLine = charPositionInLine;\r\n\t}\r\n\r\n\t/** What is the index of the current character of lookahead? */\r\n\tget charIndex(): number {\r\n\t\treturn this._input.index;\r\n\t}\r\n\r\n\t/** Return the text matched so far for the current token or any\r\n\t * text override.\r\n\t */\r\n\tget text(): string {\r\n\t\tif (this._text != null) {\r\n\t\t\treturn this._text;\r\n\t\t}\r\n\t\treturn this.interpreter.getText(this._input);\r\n\t}\r\n\r\n\t/** Set the complete text of this token; it wipes any previous\r\n\t * changes to the text.\r\n\t */\r\n\tset text(text: string) {\r\n\t\tthis._text = text;\r\n\t}\r\n\r\n\t/** Override if emitting multiple tokens. */\r\n\tget token(): Token | undefined { return this._token; }\r\n\r\n\tset token(_token: Token | undefined) {\r\n\t\tthis._token = _token;\r\n\t}\r\n\r\n\tset type(ttype: number) {\r\n\t\tthis._type = ttype;\r\n\t}\r\n\r\n\tget type(): number {\r\n\t\treturn this._type;\r\n\t}\r\n\r\n\tset channel(channel: number) {\r\n\t\tthis._channel = channel;\r\n\t}\r\n\r\n\tget channel(): number {\r\n\t\treturn this._channel;\r\n\t}\r\n\r\n\tpublic abstract readonly channelNames: string[];\r\n\r\n\tpublic abstract readonly modeNames: string[];\r\n\r\n\t/** Return a list of all Token objects in input char stream.\r\n\t * Forces load of all tokens. Does not include EOF token.\r\n\t */\r\n\tpublic getAllTokens(): Token[] {\r\n\t\tlet tokens: Token[] = [];\r\n\t\tlet t: Token = this.nextToken();\r\n\t\twhile (t.type !== Token.EOF) {\r\n\t\t\ttokens.push(t);\r\n\t\t\tt = this.nextToken();\r\n\t\t}\r\n\t\treturn tokens;\r\n\t}\r\n\r\n\tpublic notifyListeners(e: LexerNoViableAltException): void {\r\n\t\tlet text: string = this._input.getText(\r\n\t\t\tInterval.of(this._tokenStartCharIndex, this._input.index));\r\n\t\tlet msg: string = \"token recognition error at: '\" +\r\n\t\t\tthis.getErrorDisplay(text) + \"'\";\r\n\r\n\t\tlet listener: ANTLRErrorListener<number> = this.getErrorListenerDispatch();\r\n\t\tif (listener.syntaxError) {\r\n\t\t\tlistener.syntaxError(this, undefined, this._tokenStartLine, this._tokenStartCharPositionInLine, msg, e);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic getErrorDisplay(s: string | number): string {\r\n\t\tif (typeof s === \"number\") {\r\n\t\t\tswitch (s) {\r\n\t\t\tcase Token.EOF:\r\n\t\t\t\treturn \"<EOF>\";\r\n\t\t\tcase 0x0a:\r\n\t\t\t\treturn \"\\\\n\";\r\n\t\t\tcase 0x09:\r\n\t\t\t\treturn \"\\\\t\";\r\n\t\t\tcase 0x0d:\r\n\t\t\t\treturn \"\\\\r\";\r\n\t\t\t}\r\n\t\t\treturn String.fromCharCode(s);\r\n\t\t}\r\n\t\treturn s.replace(/\\n/g, \"\\\\n\")\r\n\t\t\t.replace(/\\t/g, \"\\\\t\")\r\n\t\t\t.replace(/\\r/g, \"\\\\r\");\r\n\t}\r\n\r\n\tpublic getCharErrorDisplay(c: number): string {\r\n\t\tlet s: string = this.getErrorDisplay(c);\r\n\t\treturn \"'\" + s + \"'\";\r\n\t}\r\n\r\n\t/** Lexers can normally match any char in it's vocabulary after matching\r\n\t * a token, so do the easy thing and just kill a character and hope\r\n\t * it all works out. You can instead use the rule invocation stack\r\n\t * to do sophisticated error recovery if you are in a fragment rule.\r\n\t */\r\n\tpublic recover(re: RecognitionException): void;\r\n\tpublic recover(re: LexerNoViableAltException): void;\r\n\tpublic recover(re: RecognitionException): void {\r\n\t\tif (re instanceof LexerNoViableAltException) {\r\n\t\t\tif (this._input.LA(1) !== IntStream.EOF) {\r\n\t\t\t\t// skip a char and try again\r\n\t\t\t\tthis.interpreter.consume(this._input);\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\t//System.out.println(\"consuming char \"+(char)input.LA(1)+\" during recovery\");\r\n\t\t\t//re.printStackTrace();\r\n\t\t\t// TODO: Do we lose character or line position information?\r\n\t\t\tthis._input.consume();\r\n\t\t}\r\n\t}\r\n}\r\n"]}
\No newline at end of file