Class: Recognizer
Direct Known Subclasses
Instance Attribute Summary collapse
-
#interp ⇒ Object
, :stateNumber.
-
#listeners ⇒ Object
, :stateNumber.
-
#ruleIndexMapCache ⇒ Object
Returns the value of attribute ruleIndexMapCache.
-
#state ⇒ Object
Returns the value of attribute state.
-
#tokenTypeMapCache ⇒ Object
Returns the value of attribute tokenTypeMapCache.
Instance Method Summary collapse
- #addErrorListener(listener) ⇒ Object
- #checkVersion(toolVersion) ⇒ Object
- #extractVersion(version) ⇒ Object
-
#getErrorHeader(e) ⇒ Object
What is the error header, normally line/character position information?#.
- #getErrorListenerDispatch ⇒ Object
-
#getRuleIndexMap ⇒ Object
Get a map from rule names to rule indexes.
- #getState ⇒ Object
-
#getTokenErrorDisplay(t) ⇒ Object
deprecated
Deprecated.
This method is not called by the ANTLR 4 Runtime. Specific
- #getTokenType(tokenName) ⇒ Object
- #getTokenTypeMap ⇒ Object
-
#initialize ⇒ Recognizer
constructor
A new instance of Recognizer.
- #precpred(localctx, precedence) ⇒ Object
-
#sempred(localctx, ruleIndex, actionIndex) ⇒ Object
subclass needs to override these if there are sempreds or actions that the ATN interp needs to execute.
Constructor Details
#initialize ⇒ Recognizer
Returns a new instance of Recognizer.
7 8 9 10 11 12 13 |
# File 'lib/antlr4/Recognizer.rb', line 7 def initialize @listeners = [ ConsoleErrorListener.INSTANCE ] @interp = nil @state = -1 @tokenTypeMapCache = Hash.new @ruleIndexMapCache = Hash.new end |
Instance Attribute Details
#interp ⇒ Object
, :stateNumber
4 5 6 |
# File 'lib/antlr4/Recognizer.rb', line 4 def interp @interp end |
#listeners ⇒ Object
, :stateNumber
4 5 6 |
# File 'lib/antlr4/Recognizer.rb', line 4 def listeners @listeners end |
#ruleIndexMapCache ⇒ Object
Returns the value of attribute ruleIndexMapCache.
5 6 7 |
# File 'lib/antlr4/Recognizer.rb', line 5 def ruleIndexMapCache @ruleIndexMapCache end |
#state ⇒ Object
Returns the value of attribute state.
6 7 8 |
# File 'lib/antlr4/Recognizer.rb', line 6 def state @state end |
#tokenTypeMapCache ⇒ Object
Returns the value of attribute tokenTypeMapCache.
5 6 7 |
# File 'lib/antlr4/Recognizer.rb', line 5 def tokenTypeMapCache @tokenTypeMapCache end |
Instance Method Details
#addErrorListener(listener) ⇒ Object
42 43 44 |
# File 'lib/antlr4/Recognizer.rb', line 42 def addErrorListener(listener) self.listeners.push(listener) end |
#checkVersion(toolVersion) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/antlr4/Recognizer.rb', line 33 def checkVersion(toolVersion) runtimeVersion = "4.4.1" rvmajor, rvminor = self.extractVersion(runtimeVersion) tvmajor, tvminor = self.extractVersion(toolVersion) if rvmajor!=tvmajor or rvminor!=tvminor puts "ANTLR runtime and generated code versions disagree: #{runtimeVersion}!=#{toolVersion}" end end |
#extractVersion(version) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/antlr4/Recognizer.rb', line 18 def extractVersion(version) pos = version.index(".") major = version[0..pos-1] version = version[pos+1..version.length] pos = version.index(".") if pos.nil? pos = version.index("-") end if pos.nil? pos = version.length end minor = version[0..pos-1] return major, minor end |
#getErrorHeader(e) ⇒ Object
What is the error header, normally line/character position information?#
85 86 87 88 89 |
# File 'lib/antlr4/Recognizer.rb', line 85 def getErrorHeader(e) # :RecognitionException): line = e.getOffendingToken().line column = e.getOffendingToken().column return "line #{line}:#{column}" end |
#getErrorListenerDispatch ⇒ Object
121 122 123 |
# File 'lib/antlr4/Recognizer.rb', line 121 def getErrorListenerDispatch return ProxyErrorListener.new(self.listeners) end |
#getRuleIndexMap ⇒ Object
Get a map from rule names to rule indexes.
<p>Used for XPath and tree pattern compilation.</p>
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/antlr4/Recognizer.rb', line 62 def getRuleIndexMap ruleNames = self.ruleNames if ruleNames.nil? then raise UnsupportedOperationException.new("The current recognizer does not provide a list of rule names.") end result = self.ruleIndexMapCache.get(ruleNames) if result.nil? result = ruleNames.zip( 0..ruleNames.length) self.ruleIndexMapCache[ruleNames] = result end return result end |
#getState ⇒ Object
15 16 17 |
# File 'lib/antlr4/Recognizer.rb', line 15 def getState @state end |
#getTokenErrorDisplay(t) ⇒ Object
This method is not called by the ANTLR 4 Runtime. Specific
How should a token be displayed in an error message? The default
is to display just the text, but during development you might
want to have a lot of information spit out. Override in that case
to use t.toString() (which, for CommonToken, dumps everything about
the token). This is better than forcing you to override a method in
your token objects because you don't have to go modify your lexer
so that it creates a new Java type.
implementations of ANTLRErrorStrategy may provide a similar feature when necessary. For example, see DefaultErrorStrategy#getTokenErrorDisplay.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/antlr4/Recognizer.rb', line 105 def getTokenErrorDisplay(t) return "<no token>" if t.nil? s = t.text if s.nil? if t.type==Token::EOF s = "<EOF>" else s = "<" + str(t.type) + ">" end end s = s.gsub("\n","\\n") s = s.gsub("\r","\\r") s = s.gsub("\t","\\t") return "'" + s + "'" end |
#getTokenType(tokenName) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/antlr4/Recognizer.rb', line 75 def getTokenType(tokenName) ttype = self.getTokenTypeMap().get(tokenName) if not ttype.nil? then return ttype else return Token::INVALID_TYPE end end |
#getTokenTypeMap ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/antlr4/Recognizer.rb', line 45 def getTokenTypeMap tokenNames = self.getTokenNames() if tokenNames.nil? then raise UnsupportedOperationException.new("The current recognizer does not provide a list of token names.") end result = self.tokenTypeMapCache.get(tokenNames) if result.nil? result = tokenNames.zip(0..tokenNames.length) result["EOF"] = Token::EOF self.tokenTypeMapCache[tokenNames] = result end return result end |
#precpred(localctx, precedence) ⇒ Object
131 132 133 |
# File 'lib/antlr4/Recognizer.rb', line 131 def precpred(localctx, precedence) return true end |
#sempred(localctx, ruleIndex, actionIndex) ⇒ Object
subclass needs to override these if there are sempreds or actions that the ATN interp needs to execute
127 128 129 |
# File 'lib/antlr4/Recognizer.rb', line 127 def sempred(localctx, ruleIndex, actionIndex) return true end |