Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | /* * This file is released under the MIT license. * Copyright (c) 2016, 2020, Mike Lischke * * See LICENSE file for more info. */ import { Lexer, Token } from "antlr4ts"; import { Interval } from "antlr4ts/misc"; import { ANTLRv4Lexer } from "./ANTLRv4Lexer"; export abstract class LexerAdaptor extends Lexer { private currentRuleType : number = Token.INVALID_TYPE; public emit(): Token { if (this.type === ANTLRv4Lexer.ID) { const firstChar = this.inputStream.getText( new Interval(this._tokenStartCharIndex, this._tokenStartCharIndex), ); if (firstChar.charAt(0) === firstChar.charAt(0).toUpperCase()) { this.type = ANTLRv4Lexer.TOKEN_REF; } else { this.type = ANTLRv4Lexer.RULE_REF; } Iif (this.currentRuleType === Token.INVALID_TYPE) { // if outside of rule def this.currentRuleType = this.type; // set to inside lexer or parser rule } } else Iif (this.type === ANTLRv4Lexer.SEMI) { // exit rule def this.currentRuleType = Token.INVALID_TYPE; } return super.emit(); } protected handleBeginArgument(): void { if (this.currentRuleType === ANTLRv4Lexer.TOKEN_REF) { this.pushMode(ANTLRv4Lexer.LexerCharSet); this.more(); } else { this.pushMode(ANTLRv4Lexer.Argument); } } protected handleEndArgument(): void { this.popMode(); // eslint-disable-next-line no-underscore-dangle Iif (this._modeStack.size > 0) { this.type = ANTLRv4Lexer.ARGUMENT_CONTENT; } } protected handleEndAction(): void { this.popMode(); // eslint-disable-next-line no-underscore-dangle Iif (this._modeStack.size > 0) { this.type = ANTLRv4Lexer.ACTION_CONTENT; } } } |