Class: Antlr4::Runtime::Recognizer
- Inherits:
-
Object
- Object
- Antlr4::Runtime::Recognizer
- Defined in:
- lib/antlr4/runtime/recognizer.rb
Constant Summary collapse
- EOF =
-1
Instance Attribute Summary collapse
-
#_interp ⇒ Object
Returns the value of attribute _interp.
-
#_state_number ⇒ Object
Returns the value of attribute _state_number.
Instance Method Summary collapse
- #action(_localctx, _rule_index, _action_index) ⇒ Object
- #add_error_listener(listener) ⇒ Object
- #error_header(e) ⇒ Object
- #error_listener_dispatch ⇒ Object
- #get_rule_index_map ⇒ Object
- #get_serialized_atn ⇒ Object
- #get_token_type(token_name) ⇒ Object
- #get_token_type_map ⇒ Object
- #get_vocabulary ⇒ Object
-
#initialize ⇒ Recognizer
constructor
A new instance of Recognizer.
- #parse_info ⇒ Object
- #precpred(_localctx, _precedence) ⇒ Object
- #remove_error_listener(listener) ⇒ Object
- #remove_error_listeners ⇒ Object
- #rule_names ⇒ Object
- #sempred(_localctx, _rule_index, _action_index) ⇒ Object
- #token_error_display(t) ⇒ Object
- #token_names ⇒ Object
Constructor Details
#initialize ⇒ Recognizer
Returns a new instance of Recognizer.
9 10 11 12 13 14 15 16 |
# File 'lib/antlr4/runtime/recognizer.rb', line 9 def initialize @token_type_map_cache = [] @rule_index_map_cache = [] @_listeners = [] @_listeners << ConsoleErrorListener.instance @_interp = nil @_state_number = -1 end |
Instance Attribute Details
#_interp ⇒ Object
Returns the value of attribute _interp.
6 7 8 |
# File 'lib/antlr4/runtime/recognizer.rb', line 6 def _interp @_interp end |
#_state_number ⇒ Object
Returns the value of attribute _state_number.
7 8 9 |
# File 'lib/antlr4/runtime/recognizer.rb', line 7 def _state_number @_state_number end |
Instance Method Details
#action(_localctx, _rule_index, _action_index) ⇒ Object
130 131 |
# File 'lib/antlr4/runtime/recognizer.rb', line 130 def action(_localctx, _rule_index, _action_index) end |
#add_error_listener(listener) ⇒ Object
104 105 106 107 108 |
# File 'lib/antlr4/runtime/recognizer.rb', line 104 def add_error_listener(listener) raise NullPointerException, 'listener cannot be nil.' if listener.nil? @_listeners << listener end |
#error_header(e) ⇒ Object
81 82 83 84 85 |
# File 'lib/antlr4/runtime/recognizer.rb', line 81 def error_header(e) line = e.getOffendingToken.line charPositionInLine = e.getOffendingToken.char_position_in_line 'line ' + line + ':' + charPositionInLine end |
#error_listener_dispatch ⇒ Object
118 119 120 |
# File 'lib/antlr4/runtime/recognizer.rb', line 118 def error_listener_dispatch ProxyErrorListener.new(@_listeners) end |
#get_rule_index_map ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/antlr4/runtime/recognizer.rb', line 52 def get_rule_index_map if rule_names.nil? raise UnsupportedOperationException, 'The current recognizer does not provide a list of rule names.' end result = @rule_index_map_cache[rule_names] if result.nil? result = Utils.toMap(rule_names) @rule_index_map_cache[rule_names] = result end result end |
#get_serialized_atn ⇒ Object
73 74 75 |
# File 'lib/antlr4/runtime/recognizer.rb', line 73 def get_serialized_atn raise UnsupportedOperationException, 'there is no serialized ATN' end |
#get_token_type(token_name) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/antlr4/runtime/recognizer.rb', line 66 def get_token_type(token_name) ttype = get_token_type_map[token_name] return ttype unless ttype.nil? Token::INVALID_TYPE end |
#get_token_type_map ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/antlr4/runtime/recognizer.rb', line 30 def get_token_type_map vocab = get_vocabulary result = @token_type_map_cache[vocab] if result.nil? result = {} i = 0 while i <= getATN.max_token_type literal_name = vocab.literal_name(i) result[literal_name] = i unless literal_name.nil? symbolic_name = vocab.symbolic_name(i) result[symbolic_name] = i unless symbolic_name.nil? i += 1 end result['EOF'] = Token::EOF @token_type_map_cache[vocab] = result end result end |
#get_vocabulary ⇒ Object
18 19 20 |
# File 'lib/antlr4/runtime/recognizer.rb', line 18 def get_vocabulary VocabularyImpl.from_token_names(token_names) end |
#parse_info ⇒ Object
77 78 79 |
# File 'lib/antlr4/runtime/recognizer.rb', line 77 def parse_info nil end |
#precpred(_localctx, _precedence) ⇒ Object
126 127 128 |
# File 'lib/antlr4/runtime/recognizer.rb', line 126 def precpred(_localctx, _precedence) true end |
#remove_error_listener(listener) ⇒ Object
110 111 112 |
# File 'lib/antlr4/runtime/recognizer.rb', line 110 def remove_error_listener(listener) @_listeners.delete(listener) end |
#remove_error_listeners ⇒ Object
114 115 116 |
# File 'lib/antlr4/runtime/recognizer.rb', line 114 def remove_error_listeners @_listeners.clear end |
#rule_names ⇒ Object
26 27 28 |
# File 'lib/antlr4/runtime/recognizer.rb', line 26 def rule_names nil end |
#sempred(_localctx, _rule_index, _action_index) ⇒ Object
122 123 124 |
# File 'lib/antlr4/runtime/recognizer.rb', line 122 def sempred(_localctx, _rule_index, _action_index) true end |
#token_error_display(t) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/antlr4/runtime/recognizer.rb', line 87 def token_error_display(t) return '<no token>' if t.nil? s = t.text if s.nil? s = if t.type == Token::EOF '<EOF>' else '<' + t.type + '>' end end s = s.tr_s!("\n", '\\n') s = s.tr_s!("\r", '\\r') s = s.tr_s!("\t", '\\t') "'" + s + "'" end |
#token_names ⇒ Object
22 23 24 |
# File 'lib/antlr4/runtime/recognizer.rb', line 22 def token_names nil end |