UNPKG

antlr-ng

Version:

Next generation ANTLR Tool

67 lines (66 loc) 2.6 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); import { Lexer, Token } from "antlr4ng"; import { ANTLRv4Lexer } from "../generated/ANTLRv4Lexer.js"; class LexerAdaptor extends Lexer { static { __name(this, "LexerAdaptor"); } /** Generic type for OPTIONS, TOKENS and CHANNELS */ static PREQUEL_CONSTRUCT = -10; static OPTIONS_CONSTRUCT = -11; currentRuleType = Token.INVALID_TYPE; constructor(input) { super(input); this.currentRuleType = Token.INVALID_TYPE; } reset() { this.currentRuleType = Token.INVALID_TYPE; super.reset(); } emit() { if ((this.type === ANTLRv4Lexer.OPTIONS || this.type === ANTLRv4Lexer.TOKENS || this.type === ANTLRv4Lexer.CHANNELS) && this.currentRuleType === Token.INVALID_TYPE) { this.currentRuleType = LexerAdaptor.PREQUEL_CONSTRUCT; } else if (this.type === ANTLRv4Lexer.OPTIONS && this.currentRuleType === ANTLRv4Lexer.TOKEN_REF) { this.currentRuleType = LexerAdaptor.OPTIONS_CONSTRUCT; } else if (this.type === ANTLRv4Lexer.RBRACE && this.currentRuleType === LexerAdaptor.PREQUEL_CONSTRUCT) { this.currentRuleType = Token.INVALID_TYPE; } else if (this.type === ANTLRv4Lexer.RBRACE && this.currentRuleType === LexerAdaptor.OPTIONS_CONSTRUCT) { this.currentRuleType = ANTLRv4Lexer.TOKEN_REF; } else if (this.type === ANTLRv4Lexer.AT && this.currentRuleType === Token.INVALID_TYPE) { this.currentRuleType = ANTLRv4Lexer.AT; } else if (this.type === ANTLRv4Lexer.SEMI && this.currentRuleType === LexerAdaptor.OPTIONS_CONSTRUCT) { } else if (this.type === ANTLRv4Lexer.ID) { const firstChar = this.inputStream.getTextFromRange(this.tokenStartCharIndex, this.tokenStartCharIndex); const c = firstChar.charAt(0); if (c === c.toUpperCase()) { this.type = ANTLRv4Lexer.TOKEN_REF; } else { this.type = ANTLRv4Lexer.RULE_REF; } if (this.currentRuleType === Token.INVALID_TYPE) { this.currentRuleType = this.type; } } else if (this.type === ANTLRv4Lexer.SEMI) { this.currentRuleType = Token.INVALID_TYPE; } return super.emit(); } handleBeginArgument() { if (this.currentRuleType === ANTLRv4Lexer.TOKEN_REF) { this.pushMode(ANTLRv4Lexer.LexerCharSet); this.more(); } else { this.pushMode(ANTLRv4Lexer.Argument); } } handleEndArgument() { this.popMode(); if (this.modeStack.length > 0) { this.type = ANTLRv4Lexer.ARGUMENT_CONTENT; } } } export { LexerAdaptor };