antlr4-runtime 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +65 -0
- data/Rakefile +6 -0
- data/antlr4-runtime.gemspec +30 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ext/rumourhash/Makefile +264 -0
- data/ext/rumourhash/extconf.rb +3 -0
- data/ext/rumourhash/rumourhash.c +59 -0
- data/lib/antlr4/runtime.rb +37 -0
- data/lib/antlr4/runtime/abstract_parse_tree_visitor.rb +43 -0
- data/lib/antlr4/runtime/abstract_predicate_transition.rb +11 -0
- data/lib/antlr4/runtime/action_transition.rb +29 -0
- data/lib/antlr4/runtime/ambiguity_info.rb +10 -0
- data/lib/antlr4/runtime/antlr_error_listener.rb +15 -0
- data/lib/antlr4/runtime/antlr_error_strategy.rb +24 -0
- data/lib/antlr4/runtime/antlr_file_stream.rb +17 -0
- data/lib/antlr4/runtime/antlr_input_stream.rb +6 -0
- data/lib/antlr4/runtime/array_2d_hash_set.rb +471 -0
- data/lib/antlr4/runtime/array_prediction_context.rb +76 -0
- data/lib/antlr4/runtime/atn.rb +100 -0
- data/lib/antlr4/runtime/atn_config.rb +140 -0
- data/lib/antlr4/runtime/atn_config_set.rb +150 -0
- data/lib/antlr4/runtime/atn_deserialization_options.rb +48 -0
- data/lib/antlr4/runtime/atn_deserializer.rb +737 -0
- data/lib/antlr4/runtime/atn_simulator.rb +69 -0
- data/lib/antlr4/runtime/atn_state.rb +118 -0
- data/lib/antlr4/runtime/atn_type.rb +8 -0
- data/lib/antlr4/runtime/atom_transition.rb +27 -0
- data/lib/antlr4/runtime/bail_error_strategy.rb +31 -0
- data/lib/antlr4/runtime/base_error_listener.rb +18 -0
- data/lib/antlr4/runtime/basic_block_start_state.rb +12 -0
- data/lib/antlr4/runtime/basic_state.rb +11 -0
- data/lib/antlr4/runtime/bit_set.rb +54 -0
- data/lib/antlr4/runtime/block_end_state.rb +15 -0
- data/lib/antlr4/runtime/block_start_state.rb +12 -0
- data/lib/antlr4/runtime/buffered_token_stream.rb +335 -0
- data/lib/antlr4/runtime/char_stream.rb +6 -0
- data/lib/antlr4/runtime/char_streams.rb +12 -0
- data/lib/antlr4/runtime/chunk.rb +4 -0
- data/lib/antlr4/runtime/code_point_char_stream.rb +83 -0
- data/lib/antlr4/runtime/common_token.rb +125 -0
- data/lib/antlr4/runtime/common_token_factory.rb +30 -0
- data/lib/antlr4/runtime/common_token_stream.rb +63 -0
- data/lib/antlr4/runtime/console_error_listener.rb +12 -0
- data/lib/antlr4/runtime/context_sensitivity_info.rb +7 -0
- data/lib/antlr4/runtime/decision_event_info.rb +19 -0
- data/lib/antlr4/runtime/decision_info.rb +36 -0
- data/lib/antlr4/runtime/decision_state.rb +15 -0
- data/lib/antlr4/runtime/default_error_strategy.rb +314 -0
- data/lib/antlr4/runtime/dfa.rb +97 -0
- data/lib/antlr4/runtime/dfa_serializer.rb +62 -0
- data/lib/antlr4/runtime/dfa_state.rb +109 -0
- data/lib/antlr4/runtime/diagnostic_error_listener.rb +58 -0
- data/lib/antlr4/runtime/double_key_map.rb +49 -0
- data/lib/antlr4/runtime/empty_prediction_context.rb +35 -0
- data/lib/antlr4/runtime/epsilon_transition.rb +27 -0
- data/lib/antlr4/runtime/equality_comparator.rb +4 -0
- data/lib/antlr4/runtime/error_info.rb +7 -0
- data/lib/antlr4/runtime/error_node.rb +5 -0
- data/lib/antlr4/runtime/error_node_impl.rb +12 -0
- data/lib/antlr4/runtime/failed_predicate_exception.rb +33 -0
- data/lib/antlr4/runtime/flexible_hash_map.rb +232 -0
- data/lib/antlr4/runtime/input_mismatch_exception.rb +20 -0
- data/lib/antlr4/runtime/int_stream.rb +31 -0
- data/lib/antlr4/runtime/integer.rb +14 -0
- data/lib/antlr4/runtime/interval.rb +111 -0
- data/lib/antlr4/runtime/interval_set.rb +540 -0
- data/lib/antlr4/runtime/lexer.rb +257 -0
- data/lib/antlr4/runtime/lexer_action.rb +12 -0
- data/lib/antlr4/runtime/lexer_action_executor.rb +75 -0
- data/lib/antlr4/runtime/lexer_action_type.rb +12 -0
- data/lib/antlr4/runtime/lexer_atn_config.rb +50 -0
- data/lib/antlr4/runtime/lexer_atn_simulator.rb +522 -0
- data/lib/antlr4/runtime/lexer_channel_action.rb +51 -0
- data/lib/antlr4/runtime/lexer_custom_action.rb +49 -0
- data/lib/antlr4/runtime/lexer_dfa_serializer.rb +12 -0
- data/lib/antlr4/runtime/lexer_indexed_custom_action.rb +49 -0
- data/lib/antlr4/runtime/lexer_mode_action.rb +51 -0
- data/lib/antlr4/runtime/lexer_more_action.rb +41 -0
- data/lib/antlr4/runtime/lexer_no_viable_alt_exception.rb +4 -0
- data/lib/antlr4/runtime/lexer_pop_mode_action.rb +41 -0
- data/lib/antlr4/runtime/lexer_push_mode_action.rb +51 -0
- data/lib/antlr4/runtime/lexer_skip_action.rb +43 -0
- data/lib/antlr4/runtime/lexer_type_action.rb +51 -0
- data/lib/antlr4/runtime/ll1_analyzer.rb +133 -0
- data/lib/antlr4/runtime/lookahead_event_info.rb +10 -0
- data/lib/antlr4/runtime/loop_end_state.rb +15 -0
- data/lib/antlr4/runtime/murmur_hash.rb +99 -0
- data/lib/antlr4/runtime/no_viable_alt_exception.rb +7 -0
- data/lib/antlr4/runtime/not_set_transition.rb +20 -0
- data/lib/antlr4/runtime/object_equality_comparator.rb +18 -0
- data/lib/antlr4/runtime/ordered_atn_config_set.rb +15 -0
- data/lib/antlr4/runtime/parse_cancellation_exception.rb +5 -0
- data/lib/antlr4/runtime/parse_tree.rb +7 -0
- data/lib/antlr4/runtime/parse_tree_listener.rb +4 -0
- data/lib/antlr4/runtime/parse_tree_visitor.rb +4 -0
- data/lib/antlr4/runtime/parser.rb +522 -0
- data/lib/antlr4/runtime/parser_atn_simulator.rb +1171 -0
- data/lib/antlr4/runtime/parser_rule_context.rb +186 -0
- data/lib/antlr4/runtime/plus_block_start_state.rb +11 -0
- data/lib/antlr4/runtime/plus_loopback_state.rb +12 -0
- data/lib/antlr4/runtime/precedence_predicate_transition.rb +31 -0
- data/lib/antlr4/runtime/predicate.rb +6 -0
- data/lib/antlr4/runtime/predicate_eval_info.rb +16 -0
- data/lib/antlr4/runtime/predicate_transition.rb +35 -0
- data/lib/antlr4/runtime/prediction_context.rb +103 -0
- data/lib/antlr4/runtime/prediction_context_cache.rb +28 -0
- data/lib/antlr4/runtime/prediction_context_utils.rb +407 -0
- data/lib/antlr4/runtime/prediction_mode.rb +213 -0
- data/lib/antlr4/runtime/profiling_atn_simulator.rb +149 -0
- data/lib/antlr4/runtime/proxy_error_listener.rb +33 -0
- data/lib/antlr4/runtime/range_transition.rb +29 -0
- data/lib/antlr4/runtime/recognition_exception.rb +17 -0
- data/lib/antlr4/runtime/recognizer.rb +136 -0
- data/lib/antlr4/runtime/rule_context.rb +131 -0
- data/lib/antlr4/runtime/rule_context_with_alt_num.rb +11 -0
- data/lib/antlr4/runtime/rule_node.rb +8 -0
- data/lib/antlr4/runtime/rule_start_state.rb +17 -0
- data/lib/antlr4/runtime/rule_stop_state.rb +12 -0
- data/lib/antlr4/runtime/rule_tag_token.rb +64 -0
- data/lib/antlr4/runtime/rule_transition.rb +29 -0
- data/lib/antlr4/runtime/semantic_context.rb +313 -0
- data/lib/antlr4/runtime/set_transition.rb +29 -0
- data/lib/antlr4/runtime/singleton_prediction_context.rb +56 -0
- data/lib/antlr4/runtime/star_block_start_state.rb +12 -0
- data/lib/antlr4/runtime/star_loop_entry_state.rb +17 -0
- data/lib/antlr4/runtime/star_loopback_state.rb +16 -0
- data/lib/antlr4/runtime/syntax_tree.rb +6 -0
- data/lib/antlr4/runtime/tag_chunk.rb +22 -0
- data/lib/antlr4/runtime/terminal_node.rb +5 -0
- data/lib/antlr4/runtime/terminal_node_impl.rb +50 -0
- data/lib/antlr4/runtime/text_chunk.rb +16 -0
- data/lib/antlr4/runtime/token.rb +13 -0
- data/lib/antlr4/runtime/token_stream.rb +13 -0
- data/lib/antlr4/runtime/token_tag_token.rb +22 -0
- data/lib/antlr4/runtime/tokens_start_state.rb +14 -0
- data/lib/antlr4/runtime/transition.rb +51 -0
- data/lib/antlr4/runtime/tree.rb +4 -0
- data/lib/antlr4/runtime/trees.rb +195 -0
- data/lib/antlr4/runtime/triple.rb +40 -0
- data/lib/antlr4/runtime/utils.rb +117 -0
- data/lib/antlr4/runtime/uuid.rb +46 -0
- data/lib/antlr4/runtime/version.rb +5 -0
- data/lib/antlr4/runtime/vocabulary.rb +12 -0
- data/lib/antlr4/runtime/vocabulary_impl.rb +82 -0
- data/lib/antlr4/runtime/wildcard_transition.rb +20 -0
- data/lib/antlr4/runtime/writable_token.rb +7 -0
- metadata +243 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
require 'antlr4/runtime/dfa_serializer'
|
|
2
|
+
require 'antlr4/runtime/lexer_dfa_serializer'
|
|
3
|
+
|
|
4
|
+
module Antlr4::Runtime
|
|
5
|
+
|
|
6
|
+
class DFA
|
|
7
|
+
attr_accessor :states
|
|
8
|
+
attr_accessor :s0
|
|
9
|
+
attr_reader :decision
|
|
10
|
+
attr_reader :atn_start_state
|
|
11
|
+
attr_reader :precedence_dfa
|
|
12
|
+
|
|
13
|
+
def initialize(atn_start_state, decision = 0)
|
|
14
|
+
@atn_start_state = atn_start_state
|
|
15
|
+
@decision = decision
|
|
16
|
+
@states = {}
|
|
17
|
+
|
|
18
|
+
@precedence_dfa = false
|
|
19
|
+
if atn_start_state.is_a? StarLoopEntryState
|
|
20
|
+
if atn_start_state.is_precedence_pecision
|
|
21
|
+
@precedence_dfa = true
|
|
22
|
+
precedence_state = DFAState.new(ATNConfigSet.new)
|
|
23
|
+
precedence_state.edges = []
|
|
24
|
+
precedence_state.is_accept_state = false
|
|
25
|
+
precedence_state.requires_full_context = false
|
|
26
|
+
@s0 = precedence_state
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def precedence_dfa?
|
|
33
|
+
@precedence_dfa
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def precedence_start_state(precedence)
|
|
37
|
+
unless @precedence_dfa
|
|
38
|
+
raise IllegalStateException, 'Only precedence DFAs may contain a precedence start state.'
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# s0.edges is never nil for a precedence DFA
|
|
42
|
+
return nil if precedence < 0 || precedence >= @s0.edges.length
|
|
43
|
+
|
|
44
|
+
@s0.edges[precedence]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def precedence_start_state2(precedence, start_state)
|
|
48
|
+
unless @precedence_dfa
|
|
49
|
+
raise IllegalStateException, 'Only precedence DFAs may contain a precedence start state.'
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
return if precedence < 0
|
|
53
|
+
|
|
54
|
+
@s0.edges[precedence] = start_state
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def precedence_dfa(precedence_dfa)
|
|
58
|
+
if precedence_dfa != @precedence_dfa
|
|
59
|
+
raise UnsupportedOperationException, 'The precedence_dfa field cannot change after a DFA is constructed.'
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def get_states
|
|
64
|
+
result = @states.keys
|
|
65
|
+
result.sort! {|i, j| i.state_number - j.state_number}
|
|
66
|
+
|
|
67
|
+
result
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def to_s
|
|
71
|
+
to_s2(VocabularyImpl.EMPTY_VOCABULARY)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def to_s1(token_names)
|
|
75
|
+
return '' if @s0.nil?
|
|
76
|
+
|
|
77
|
+
serializer = DFASerializer.new
|
|
78
|
+
serializer.init_from_token_names(self, token_names)
|
|
79
|
+
serializer.to_s
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def to_s2(vocabulary)
|
|
83
|
+
return '' if @s0.nil?
|
|
84
|
+
|
|
85
|
+
serializer = DFASerializer.new
|
|
86
|
+
serializer.init_from_vocabulary(self, vocabulary)
|
|
87
|
+
serializer.to_s
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def to_lexer_string
|
|
91
|
+
return '' if @s0.nil?
|
|
92
|
+
|
|
93
|
+
serializer = LexerDFASerializer.new(self)
|
|
94
|
+
serializer.to_s
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module Antlr4::Runtime
|
|
2
|
+
|
|
3
|
+
class DFASerializer
|
|
4
|
+
def init_from_token_names(dfa, token_names)
|
|
5
|
+
init_from_vocabulary(dfa, VocabularyImpl.from_token_names(token_names))
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def init_from_vocabulary(dfa, vocabulary)
|
|
9
|
+
@dfa = dfa
|
|
10
|
+
@vocabulary = vocabulary
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def to_s
|
|
14
|
+
return nil if @dfa.s0.nil?
|
|
15
|
+
|
|
16
|
+
buf = ''
|
|
17
|
+
states = @dfa.get_states
|
|
18
|
+
states.each do |s|
|
|
19
|
+
n = 0
|
|
20
|
+
n = s.edges.length unless s.edges.nil?
|
|
21
|
+
i = 0
|
|
22
|
+
while i < n
|
|
23
|
+
t = s.edges[i]
|
|
24
|
+
if !t.nil? && t.state_number != Integer::MAX
|
|
25
|
+
buf << state_string(s)
|
|
26
|
+
label = edge_label(i)
|
|
27
|
+
buf << '-' << label << '->' << state_string(t) << '\n'
|
|
28
|
+
end
|
|
29
|
+
i += 1
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
output = buf
|
|
34
|
+
return '' if output.empty?
|
|
35
|
+
|
|
36
|
+
# return Utils.sortLinesInString(output)
|
|
37
|
+
output
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def edge_label(i)
|
|
41
|
+
@vocabulary.display_name(i - 1)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def state_string(s)
|
|
45
|
+
n = s.state_number
|
|
46
|
+
base_state_str = (s.is_accept_state ? ':' : '') << 's' << n.to_s << (s.requires_full_context ? '^' : '')
|
|
47
|
+
if s.is_accept_state
|
|
48
|
+
if !s.predicates.nil?
|
|
49
|
+
preds = ''
|
|
50
|
+
s.predicates.each do |p|
|
|
51
|
+
preds << p.to_s
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
return base_state_str << '=>' << preds
|
|
55
|
+
else
|
|
56
|
+
return base_state_str << '=>' << @vocabulary.symbolic_name(s.prediction)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
base_state_str
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
require 'antlr4/runtime/atn_config_set'
|
|
2
|
+
|
|
3
|
+
module Antlr4::Runtime
|
|
4
|
+
class DFAState
|
|
5
|
+
attr_accessor :state_number
|
|
6
|
+
|
|
7
|
+
attr_accessor :configs
|
|
8
|
+
|
|
9
|
+
attr_accessor :edges
|
|
10
|
+
|
|
11
|
+
attr_accessor :is_accept_state
|
|
12
|
+
|
|
13
|
+
attr_accessor :prediction
|
|
14
|
+
|
|
15
|
+
attr_accessor :lexer_action_executor
|
|
16
|
+
|
|
17
|
+
attr_accessor :requires_full_context
|
|
18
|
+
|
|
19
|
+
attr_accessor :predicates
|
|
20
|
+
|
|
21
|
+
def initialize(x = nil)
|
|
22
|
+
@is_accept_state = false
|
|
23
|
+
@edges = []
|
|
24
|
+
@state_number = -1
|
|
25
|
+
|
|
26
|
+
if x.nil?
|
|
27
|
+
@configs = ATNConfigSet.new
|
|
28
|
+
elsif x.is_a?(ATNConfigSet)
|
|
29
|
+
@configs = x
|
|
30
|
+
else
|
|
31
|
+
@state_number = x
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class PredPrediction
|
|
36
|
+
attr_accessor :pred # never null at least SemanticContext::NONE
|
|
37
|
+
attr_accessor :alt
|
|
38
|
+
|
|
39
|
+
def initiailize(pred, alt)
|
|
40
|
+
@alt = alt
|
|
41
|
+
@pred = pred
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def to_s
|
|
45
|
+
'(' + @pred.to_s + ', ' + @alt.to_s + ')'
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def initialize_state_number(stateNumber)
|
|
50
|
+
@state_number = stateNumber
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def initialize_configs(configs)
|
|
54
|
+
@configs = configs
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def alt_set
|
|
58
|
+
alts = Set.new
|
|
59
|
+
unless @configs.nil?
|
|
60
|
+
i = 0
|
|
61
|
+
while i < @configs.length
|
|
62
|
+
c = @configs[i]
|
|
63
|
+
alts.add(c.alt)
|
|
64
|
+
i += 1
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
return nil if alts.empty?
|
|
68
|
+
|
|
69
|
+
alts
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def hash
|
|
73
|
+
return @_hash unless @_hash.nil?
|
|
74
|
+
|
|
75
|
+
hash_code = MurmurHash.hash_int(configs.hash)
|
|
76
|
+
|
|
77
|
+
if !@_hash.nil?
|
|
78
|
+
if hash_code == @_hash
|
|
79
|
+
puts 'Same hash_code for DFAState'
|
|
80
|
+
else
|
|
81
|
+
puts 'Different hash_code for DFAState'
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
@_hash = hash_code
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def equals?(o) # compare set of ATN configurations in this set with other
|
|
88
|
+
return true if self == o
|
|
89
|
+
return false unless o.is_a? DFAState
|
|
90
|
+
|
|
91
|
+
@configs.eql?(o.configs)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def to_s
|
|
95
|
+
buf = ''
|
|
96
|
+
buf << @state_number.to_s << ':' << @configs.to_s
|
|
97
|
+
if @is_accept_state
|
|
98
|
+
buf << '=>'
|
|
99
|
+
buf << if !@predicates.nil?
|
|
100
|
+
@predicates.to_s
|
|
101
|
+
else
|
|
102
|
+
@prediction.to_s
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
buf.to_s
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module Antlr4::Runtime
|
|
2
|
+
class DiagnosticErrorListener < BaseErrorListener
|
|
3
|
+
def initialize(exact_only = true)
|
|
4
|
+
@exact_only = exact_only
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def report_ambiguity(recognizer, dfa, start_index, stop_index, exact, ambig_alts, configs)
|
|
8
|
+
return if @exact_only && !exact
|
|
9
|
+
|
|
10
|
+
format = "reportAmbiguity d=%s: ambig_alts=%s, input='%s'"
|
|
11
|
+
decision = decision_description(recognizer, dfa)
|
|
12
|
+
conflicting_alts = conflicting_alts(ambig_alts, configs)
|
|
13
|
+
text = recognizer.getTokenStream.text(Interval.of(start_index, stop_index))
|
|
14
|
+
message = String.format(format, decision, conflicting_alts, text)
|
|
15
|
+
recognizer.notify_error_listeners(message)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def report_attempting_full_context(recognizer, dfa, start_index, stop_index, _conflicting_alts, _configs)
|
|
19
|
+
format = "reportAttemptingFullContext d=%s, input='%s'"
|
|
20
|
+
decision = decision_description(recognizer, dfa)
|
|
21
|
+
text = recognizer.getTokenStream.text(Interval.of(start_index, stop_index))
|
|
22
|
+
message = String.format(format, decision, text)
|
|
23
|
+
recognizer.notify_error_listeners(message)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def report_context_sensitivity(recognizer, dfa, start_index, stop_index, _prediction, _configs)
|
|
27
|
+
format = "reportContextSensitivity d=%s, input='%s'"
|
|
28
|
+
decision = decision_description(recognizer, dfa)
|
|
29
|
+
text = recognizer.getTokenStream.text(Interval.of(start_index, stop_index))
|
|
30
|
+
message = String.format(format, decision, text)
|
|
31
|
+
recognizer.notify_error_listeners(message)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def decision_description(recognizer, dfa)
|
|
35
|
+
decision = dfa.decision
|
|
36
|
+
rule_index = dfa.atn_start_state.rule_index
|
|
37
|
+
|
|
38
|
+
rule_names = recognizer.rule_names
|
|
39
|
+
return decision.to_s if rule_index < 0 || rule_index >= rule_names.length
|
|
40
|
+
|
|
41
|
+
rule_name = rule_names[rule_index]
|
|
42
|
+
return decision.to_s if rule_name.nil? || rule_name.empty?
|
|
43
|
+
|
|
44
|
+
String.format('%d (%s)', decision, rule_name)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def conflicting_alts(reported_alts, configs)
|
|
48
|
+
return reported_alts unless reported_alts.nil?
|
|
49
|
+
|
|
50
|
+
result = BitSet.new
|
|
51
|
+
configs.each do |config|
|
|
52
|
+
result.set(config.alt)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
result
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module Antlr4::Runtime
|
|
2
|
+
class DoubleKeyMap
|
|
3
|
+
def initialize
|
|
4
|
+
@data = {}
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def put(k1, k2, v)
|
|
8
|
+
data2 = @data[k1]
|
|
9
|
+
prev = nil
|
|
10
|
+
if data2.nil?
|
|
11
|
+
data2 = {}
|
|
12
|
+
@data[k1] = data2
|
|
13
|
+
else
|
|
14
|
+
prev = data2[k2]
|
|
15
|
+
end
|
|
16
|
+
data2[k2] = v
|
|
17
|
+
prev
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def get2(k1, k2)
|
|
21
|
+
data2 = @data[k1]
|
|
22
|
+
return nil if data2.nil?
|
|
23
|
+
|
|
24
|
+
data2[k2]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def get1(k1)
|
|
28
|
+
@data[k1]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def values(k1)
|
|
32
|
+
data2 = @data[k1]
|
|
33
|
+
return nil if data2.nil?
|
|
34
|
+
|
|
35
|
+
data2.values
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def key_set0
|
|
39
|
+
@data.keys
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def key_set1(k1)
|
|
43
|
+
data2 = @data[k1]
|
|
44
|
+
return nil if data2.nil?
|
|
45
|
+
|
|
46
|
+
data2.keys
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'antlr4/runtime/singleton_prediction_context'
|
|
2
|
+
module Antlr4::Runtime
|
|
3
|
+
|
|
4
|
+
class EmptyPredictionContext < SingletonPredictionContext
|
|
5
|
+
def initialize(return_state)
|
|
6
|
+
super(nil, return_state)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
EMPTY = EmptyPredictionContext.new(PredictionContextUtils::EMPTY_RETURN_STATE)
|
|
10
|
+
|
|
11
|
+
def isEmpty
|
|
12
|
+
true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def size
|
|
16
|
+
1
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def parent(_index=nil)
|
|
20
|
+
nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def return_state(_index=nil)
|
|
24
|
+
@return_state
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def equals(o)
|
|
28
|
+
self == o
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def to_s
|
|
32
|
+
'$'
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Antlr4::Runtime
|
|
2
|
+
|
|
3
|
+
class EpsilonTransition < Transition
|
|
4
|
+
def initialize(target, outermost_precedence_return = -1)
|
|
5
|
+
super(target)
|
|
6
|
+
@outermost_precedence_return = outermost_precedence_return
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
attr_reader :outermost_precedence_return
|
|
10
|
+
|
|
11
|
+
def serialization_type
|
|
12
|
+
EPSILON
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def epsilon?
|
|
16
|
+
true
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def matches(_symbol, _min_vocab_symbol, _max_vocab_symbol)
|
|
20
|
+
false
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def to_s
|
|
24
|
+
'epsilon'
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|