antlr4-runtime 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/Gemfile.lock +35 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +65 -0
  10. data/Rakefile +6 -0
  11. data/antlr4-runtime.gemspec +30 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  14. data/ext/rumourhash/Makefile +264 -0
  15. data/ext/rumourhash/extconf.rb +3 -0
  16. data/ext/rumourhash/rumourhash.c +59 -0
  17. data/lib/antlr4/runtime.rb +37 -0
  18. data/lib/antlr4/runtime/abstract_parse_tree_visitor.rb +43 -0
  19. data/lib/antlr4/runtime/abstract_predicate_transition.rb +11 -0
  20. data/lib/antlr4/runtime/action_transition.rb +29 -0
  21. data/lib/antlr4/runtime/ambiguity_info.rb +10 -0
  22. data/lib/antlr4/runtime/antlr_error_listener.rb +15 -0
  23. data/lib/antlr4/runtime/antlr_error_strategy.rb +24 -0
  24. data/lib/antlr4/runtime/antlr_file_stream.rb +17 -0
  25. data/lib/antlr4/runtime/antlr_input_stream.rb +6 -0
  26. data/lib/antlr4/runtime/array_2d_hash_set.rb +471 -0
  27. data/lib/antlr4/runtime/array_prediction_context.rb +76 -0
  28. data/lib/antlr4/runtime/atn.rb +100 -0
  29. data/lib/antlr4/runtime/atn_config.rb +140 -0
  30. data/lib/antlr4/runtime/atn_config_set.rb +150 -0
  31. data/lib/antlr4/runtime/atn_deserialization_options.rb +48 -0
  32. data/lib/antlr4/runtime/atn_deserializer.rb +737 -0
  33. data/lib/antlr4/runtime/atn_simulator.rb +69 -0
  34. data/lib/antlr4/runtime/atn_state.rb +118 -0
  35. data/lib/antlr4/runtime/atn_type.rb +8 -0
  36. data/lib/antlr4/runtime/atom_transition.rb +27 -0
  37. data/lib/antlr4/runtime/bail_error_strategy.rb +31 -0
  38. data/lib/antlr4/runtime/base_error_listener.rb +18 -0
  39. data/lib/antlr4/runtime/basic_block_start_state.rb +12 -0
  40. data/lib/antlr4/runtime/basic_state.rb +11 -0
  41. data/lib/antlr4/runtime/bit_set.rb +54 -0
  42. data/lib/antlr4/runtime/block_end_state.rb +15 -0
  43. data/lib/antlr4/runtime/block_start_state.rb +12 -0
  44. data/lib/antlr4/runtime/buffered_token_stream.rb +335 -0
  45. data/lib/antlr4/runtime/char_stream.rb +6 -0
  46. data/lib/antlr4/runtime/char_streams.rb +12 -0
  47. data/lib/antlr4/runtime/chunk.rb +4 -0
  48. data/lib/antlr4/runtime/code_point_char_stream.rb +83 -0
  49. data/lib/antlr4/runtime/common_token.rb +125 -0
  50. data/lib/antlr4/runtime/common_token_factory.rb +30 -0
  51. data/lib/antlr4/runtime/common_token_stream.rb +63 -0
  52. data/lib/antlr4/runtime/console_error_listener.rb +12 -0
  53. data/lib/antlr4/runtime/context_sensitivity_info.rb +7 -0
  54. data/lib/antlr4/runtime/decision_event_info.rb +19 -0
  55. data/lib/antlr4/runtime/decision_info.rb +36 -0
  56. data/lib/antlr4/runtime/decision_state.rb +15 -0
  57. data/lib/antlr4/runtime/default_error_strategy.rb +314 -0
  58. data/lib/antlr4/runtime/dfa.rb +97 -0
  59. data/lib/antlr4/runtime/dfa_serializer.rb +62 -0
  60. data/lib/antlr4/runtime/dfa_state.rb +109 -0
  61. data/lib/antlr4/runtime/diagnostic_error_listener.rb +58 -0
  62. data/lib/antlr4/runtime/double_key_map.rb +49 -0
  63. data/lib/antlr4/runtime/empty_prediction_context.rb +35 -0
  64. data/lib/antlr4/runtime/epsilon_transition.rb +27 -0
  65. data/lib/antlr4/runtime/equality_comparator.rb +4 -0
  66. data/lib/antlr4/runtime/error_info.rb +7 -0
  67. data/lib/antlr4/runtime/error_node.rb +5 -0
  68. data/lib/antlr4/runtime/error_node_impl.rb +12 -0
  69. data/lib/antlr4/runtime/failed_predicate_exception.rb +33 -0
  70. data/lib/antlr4/runtime/flexible_hash_map.rb +232 -0
  71. data/lib/antlr4/runtime/input_mismatch_exception.rb +20 -0
  72. data/lib/antlr4/runtime/int_stream.rb +31 -0
  73. data/lib/antlr4/runtime/integer.rb +14 -0
  74. data/lib/antlr4/runtime/interval.rb +111 -0
  75. data/lib/antlr4/runtime/interval_set.rb +540 -0
  76. data/lib/antlr4/runtime/lexer.rb +257 -0
  77. data/lib/antlr4/runtime/lexer_action.rb +12 -0
  78. data/lib/antlr4/runtime/lexer_action_executor.rb +75 -0
  79. data/lib/antlr4/runtime/lexer_action_type.rb +12 -0
  80. data/lib/antlr4/runtime/lexer_atn_config.rb +50 -0
  81. data/lib/antlr4/runtime/lexer_atn_simulator.rb +522 -0
  82. data/lib/antlr4/runtime/lexer_channel_action.rb +51 -0
  83. data/lib/antlr4/runtime/lexer_custom_action.rb +49 -0
  84. data/lib/antlr4/runtime/lexer_dfa_serializer.rb +12 -0
  85. data/lib/antlr4/runtime/lexer_indexed_custom_action.rb +49 -0
  86. data/lib/antlr4/runtime/lexer_mode_action.rb +51 -0
  87. data/lib/antlr4/runtime/lexer_more_action.rb +41 -0
  88. data/lib/antlr4/runtime/lexer_no_viable_alt_exception.rb +4 -0
  89. data/lib/antlr4/runtime/lexer_pop_mode_action.rb +41 -0
  90. data/lib/antlr4/runtime/lexer_push_mode_action.rb +51 -0
  91. data/lib/antlr4/runtime/lexer_skip_action.rb +43 -0
  92. data/lib/antlr4/runtime/lexer_type_action.rb +51 -0
  93. data/lib/antlr4/runtime/ll1_analyzer.rb +133 -0
  94. data/lib/antlr4/runtime/lookahead_event_info.rb +10 -0
  95. data/lib/antlr4/runtime/loop_end_state.rb +15 -0
  96. data/lib/antlr4/runtime/murmur_hash.rb +99 -0
  97. data/lib/antlr4/runtime/no_viable_alt_exception.rb +7 -0
  98. data/lib/antlr4/runtime/not_set_transition.rb +20 -0
  99. data/lib/antlr4/runtime/object_equality_comparator.rb +18 -0
  100. data/lib/antlr4/runtime/ordered_atn_config_set.rb +15 -0
  101. data/lib/antlr4/runtime/parse_cancellation_exception.rb +5 -0
  102. data/lib/antlr4/runtime/parse_tree.rb +7 -0
  103. data/lib/antlr4/runtime/parse_tree_listener.rb +4 -0
  104. data/lib/antlr4/runtime/parse_tree_visitor.rb +4 -0
  105. data/lib/antlr4/runtime/parser.rb +522 -0
  106. data/lib/antlr4/runtime/parser_atn_simulator.rb +1171 -0
  107. data/lib/antlr4/runtime/parser_rule_context.rb +186 -0
  108. data/lib/antlr4/runtime/plus_block_start_state.rb +11 -0
  109. data/lib/antlr4/runtime/plus_loopback_state.rb +12 -0
  110. data/lib/antlr4/runtime/precedence_predicate_transition.rb +31 -0
  111. data/lib/antlr4/runtime/predicate.rb +6 -0
  112. data/lib/antlr4/runtime/predicate_eval_info.rb +16 -0
  113. data/lib/antlr4/runtime/predicate_transition.rb +35 -0
  114. data/lib/antlr4/runtime/prediction_context.rb +103 -0
  115. data/lib/antlr4/runtime/prediction_context_cache.rb +28 -0
  116. data/lib/antlr4/runtime/prediction_context_utils.rb +407 -0
  117. data/lib/antlr4/runtime/prediction_mode.rb +213 -0
  118. data/lib/antlr4/runtime/profiling_atn_simulator.rb +149 -0
  119. data/lib/antlr4/runtime/proxy_error_listener.rb +33 -0
  120. data/lib/antlr4/runtime/range_transition.rb +29 -0
  121. data/lib/antlr4/runtime/recognition_exception.rb +17 -0
  122. data/lib/antlr4/runtime/recognizer.rb +136 -0
  123. data/lib/antlr4/runtime/rule_context.rb +131 -0
  124. data/lib/antlr4/runtime/rule_context_with_alt_num.rb +11 -0
  125. data/lib/antlr4/runtime/rule_node.rb +8 -0
  126. data/lib/antlr4/runtime/rule_start_state.rb +17 -0
  127. data/lib/antlr4/runtime/rule_stop_state.rb +12 -0
  128. data/lib/antlr4/runtime/rule_tag_token.rb +64 -0
  129. data/lib/antlr4/runtime/rule_transition.rb +29 -0
  130. data/lib/antlr4/runtime/semantic_context.rb +313 -0
  131. data/lib/antlr4/runtime/set_transition.rb +29 -0
  132. data/lib/antlr4/runtime/singleton_prediction_context.rb +56 -0
  133. data/lib/antlr4/runtime/star_block_start_state.rb +12 -0
  134. data/lib/antlr4/runtime/star_loop_entry_state.rb +17 -0
  135. data/lib/antlr4/runtime/star_loopback_state.rb +16 -0
  136. data/lib/antlr4/runtime/syntax_tree.rb +6 -0
  137. data/lib/antlr4/runtime/tag_chunk.rb +22 -0
  138. data/lib/antlr4/runtime/terminal_node.rb +5 -0
  139. data/lib/antlr4/runtime/terminal_node_impl.rb +50 -0
  140. data/lib/antlr4/runtime/text_chunk.rb +16 -0
  141. data/lib/antlr4/runtime/token.rb +13 -0
  142. data/lib/antlr4/runtime/token_stream.rb +13 -0
  143. data/lib/antlr4/runtime/token_tag_token.rb +22 -0
  144. data/lib/antlr4/runtime/tokens_start_state.rb +14 -0
  145. data/lib/antlr4/runtime/transition.rb +51 -0
  146. data/lib/antlr4/runtime/tree.rb +4 -0
  147. data/lib/antlr4/runtime/trees.rb +195 -0
  148. data/lib/antlr4/runtime/triple.rb +40 -0
  149. data/lib/antlr4/runtime/utils.rb +117 -0
  150. data/lib/antlr4/runtime/uuid.rb +46 -0
  151. data/lib/antlr4/runtime/version.rb +5 -0
  152. data/lib/antlr4/runtime/vocabulary.rb +12 -0
  153. data/lib/antlr4/runtime/vocabulary_impl.rb +82 -0
  154. data/lib/antlr4/runtime/wildcard_transition.rb +20 -0
  155. data/lib/antlr4/runtime/writable_token.rb +7 -0
  156. metadata +243 -0
@@ -0,0 +1,51 @@
1
+ module Antlr4::Runtime
2
+
3
+ class LexerChannelAction < LexerAction
4
+ attr_reader :channel
5
+
6
+ def initialize(channel)
7
+ @channel = channel
8
+ end
9
+
10
+ def action_type
11
+ LexerActionType::CHANNEL
12
+ end
13
+
14
+ def position_dependent?
15
+ false
16
+ end
17
+
18
+ def execute(lexer)
19
+ lexer.setChannel(@channel)
20
+ end
21
+
22
+ def hash
23
+ return @_hash unless @_hash.nil?
24
+
25
+ hash_code = MurmurHash.hash_int_int(action_type.ordinal, channel)
26
+
27
+ if !@_hash.nil?
28
+ if hash_code == @_hash
29
+ puts 'Same hash_code for LexerChannelAction'
30
+ else
31
+ puts 'Different hash_code for LexerChannelAction'
32
+ end
33
+ end
34
+ @_hash = hash_code
35
+ end
36
+
37
+ def eql?(other)
38
+ if other == self
39
+ return true
40
+ else
41
+ return false unless other.is_a? LexerChannelAction
42
+ end
43
+
44
+ @channel == other.channel
45
+ end
46
+
47
+ def to_s
48
+ 'channel(' << @channel.to_s << ')'
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,49 @@
1
+ module Antlr4::Runtime
2
+
3
+ class LexerCustomAction < LexerAction
4
+ attr_reader :ruleIndex
5
+ attr_reader :action_index
6
+
7
+ def initialize(rule_index, action_index)
8
+ @rule_index = rule_index
9
+ @action_index = action_index
10
+ end
11
+
12
+ def action_type
13
+ LexerActionType::CUSTOM
14
+ end
15
+
16
+ def position_dependent?
17
+ true
18
+ end
19
+
20
+ def execute(lexer)
21
+ lexer.action(nil, @rule_index, @action_index)
22
+ end
23
+
24
+ def hash
25
+ return @_hash unless @_hash.nil?
26
+
27
+ hash_code = MurmurHash.hash_ints([action_type, rule_index, action_index])
28
+
29
+ if !@_hash.nil?
30
+ if hash_code == @_hash
31
+ puts 'Same hash_code for LexerCustomAction'
32
+ else
33
+ puts 'Different hash_code for LexerCustomAction'
34
+ end
35
+ end
36
+ @_hash = hash_code
37
+ end
38
+
39
+ def eql?(other)
40
+ if other == self
41
+ return true
42
+ else
43
+ return false unless other.is_a? LexerCustomAction
44
+ end
45
+
46
+ @rule_index == other.rule_index && @action_index == other.action_index
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,12 @@
1
+ module Antlr4::Runtime
2
+
3
+ class LexerDFASerializer < DFASerializer
4
+ def initialize(dfa)
5
+ init_from_vocabulary(dfa, VocabularyImpl::EMPTY_VOCABULARY)
6
+ end
7
+
8
+ def edge_label(i)
9
+ "'" << i.to_s << "'"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,49 @@
1
+ module Antlr4::Runtime
2
+
3
+ class LexerIndexedCustomAction < LexerAction
4
+ attr_reader :action
5
+ attr_reader :offset
6
+
7
+ def initialize(offset, action)
8
+ @offset = offset
9
+ @action = action
10
+ end
11
+
12
+ def action_type
13
+ @action.action_type
14
+ end
15
+
16
+ def position_dependent?
17
+ true
18
+ end
19
+
20
+ def execute(lexer) # assume the input stream position was properly set by the calling code
21
+ @action.execute(lexer)
22
+ end
23
+
24
+ def hash
25
+ return @_hash unless @_hash.nil?
26
+
27
+ hash_code = MurmurHash.hash_int_obj(offset, action)
28
+
29
+ if !@_hash.nil?
30
+ if hash_code == @_hash
31
+ puts 'Same hash_code for LexerIndexedCustomAction'
32
+ else
33
+ puts 'Different hash_code for LexerIndexedCustomAction'
34
+ end
35
+ end
36
+ @_hash = hash_code
37
+ end
38
+
39
+ def eql?(other)
40
+ if other == self
41
+ return true
42
+ else
43
+ return false unless other.is_a? LexerIndexedCustomAction
44
+ end
45
+
46
+ @offset == other.offset && @action == other.action
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,51 @@
1
+ module Antlr4::Runtime
2
+
3
+ class LexerModeAction < LexerAction
4
+ attr_reader :mode
5
+
6
+ def initialize(mode)
7
+ @mode = mode
8
+ end
9
+
10
+ def action_type
11
+ LexerActionType::MODE
12
+ end
13
+
14
+ def position_dependent?
15
+ false
16
+ end
17
+
18
+ def execute(lexer)
19
+ lexer.mode(@mode)
20
+ end
21
+
22
+ def hash
23
+ return @_hash unless @_hash.nil?
24
+
25
+ hash_code = MurmurHash.hash_int_int(action_type, mode)
26
+
27
+ if !@_hash.nil?
28
+ if hash_code == @_hash
29
+ puts 'Same hash_code for LexerModeAction'
30
+ else
31
+ puts 'Different hash_code for LexerModeAction'
32
+ end
33
+ end
34
+ @_hash = hash_code
35
+ end
36
+
37
+ def eql?(other)
38
+ if other == self
39
+ return true
40
+ else
41
+ return false unless other.is_a? LexerModeAction
42
+ end
43
+
44
+ @mode == other.mode
45
+ end
46
+
47
+ def to_s
48
+ 'mode(' << @mode << ')'
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,41 @@
1
+ module Antlr4::Runtime
2
+
3
+ class LexerMoreAction < LexerAction
4
+ include Singleton
5
+
6
+ def action_type
7
+ LexerActionType::MORE
8
+ end
9
+
10
+ def position_dependent?
11
+ false
12
+ end
13
+
14
+ def execute(lexer)
15
+ lexer.more
16
+ end
17
+
18
+ def hash
19
+ return @_hash unless @_hash.nil?
20
+
21
+ hash_code = MurmurHash.hash_int(action_type)
22
+
23
+ if !@_hash.nil?
24
+ if hash_code == @_hash
25
+ puts 'Same hash_code for LexerMoreAction'
26
+ else
27
+ puts 'Different hash_code for LexerMoreAction'
28
+ end
29
+ end
30
+ @_hash = hash_code
31
+ end
32
+
33
+ def eql?(other)
34
+ other == self
35
+ end
36
+
37
+ def to_s
38
+ 'more'
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,4 @@
1
+ module Antlr4::Runtime
2
+ class LexerNoViableAltException < StandardError
3
+ end
4
+ end
@@ -0,0 +1,41 @@
1
+ module Antlr4::Runtime
2
+
3
+ class LexerPopModeAction < LexerAction
4
+ include Singleton
5
+
6
+ def action_type
7
+ LexerActionType::POP_MODE
8
+ end
9
+
10
+ def position_dependent?
11
+ false
12
+ end
13
+
14
+ def execute(lexer)
15
+ lexer.pop_mode
16
+ end
17
+
18
+ def hash
19
+ return @_hash unless @_hash.nil?
20
+
21
+ hash_code = MurmurHash.hash_int(action_type)
22
+
23
+ if !@_hash.nil?
24
+ if hash_code == @_hash
25
+ puts 'Same hash_code for LexerPopModeAction'
26
+ else
27
+ puts 'Different hash_code for LexerPopModeAction'
28
+ end
29
+ end
30
+ @_hash = hash_code
31
+ end
32
+
33
+ def equals(other)
34
+ other == self
35
+ end
36
+
37
+ def to_s
38
+ 'popMode'
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,51 @@
1
+ module Antlr4::Runtime
2
+
3
+ class LexerPushModeAction < LexerAction
4
+ attr_reader :mode
5
+
6
+ def initialize(mode)
7
+ @mode = mode
8
+ end
9
+
10
+ def action_type
11
+ LexerActionType::PUSH_MODE
12
+ end
13
+
14
+ def position_dependent?
15
+ false
16
+ end
17
+
18
+ def execute(lexer)
19
+ lexer.push_mode(@mode)
20
+ end
21
+
22
+ def hash
23
+ return @_hash unless @_hash.nil?
24
+
25
+ hash_code = MurmurHash.hash_int_int(action_type, mode)
26
+
27
+ if !@_hash.nil?
28
+ if hash_code == @_hash
29
+ puts 'Same hash_code for LexerPushModeAction'
30
+ else
31
+ puts 'Different hash_code for LexerPushModeAction'
32
+ end
33
+ end
34
+ @_hash = hash_code
35
+ end
36
+
37
+ def eql?(other)
38
+ if other == self
39
+ return true
40
+ else
41
+ return false unless other.is_a? LexerPushModeAction
42
+ end
43
+
44
+ @mode == other.mode
45
+ end
46
+
47
+ def to_s
48
+ 'pushMode(' << @mode << ')'
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,43 @@
1
+ require 'antlr4/runtime/lexer_action'
2
+
3
+ module Antlr4::Runtime
4
+
5
+ class LexerSkipAction < LexerAction
6
+ include Singleton
7
+
8
+ def action_type
9
+ LexerActionType::SKIP
10
+ end
11
+
12
+ def position_dependent?
13
+ false
14
+ end
15
+
16
+ def execute(lexer)
17
+ lexer.skip
18
+ end
19
+
20
+ def hash
21
+ return @_hash unless @_hash.nil?
22
+
23
+ hash_code = MurmurHash.hash_int(action_type)
24
+
25
+ if !@_hash.nil?
26
+ if hash_code == @_hash
27
+ puts 'Same hash_code for LexerSkipAction'
28
+ else
29
+ puts 'Different hash_code for LexerSkipAction'
30
+ end
31
+ end
32
+ @_hash = hash_code
33
+ end
34
+
35
+ def eql?(other)
36
+ other == self
37
+ end
38
+
39
+ def to_s
40
+ 'skip'
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,51 @@
1
+ module Antlr4::Runtime
2
+
3
+ class LexerTypeAction < LexerAction
4
+ attr_reader :type
5
+
6
+ def initialize(type)
7
+ @type = type
8
+ end
9
+
10
+ def action_type
11
+ LexerActionType::TYPE
12
+ end
13
+
14
+ def position_dependent?
15
+ false
16
+ end
17
+
18
+ def execute(lexer)
19
+ lexer._type = @type
20
+ end
21
+
22
+ def hash
23
+ return @_hash unless @_hash.nil?
24
+
25
+ hash_code = MurmurHash.hash_int_int(action_type, @type)
26
+
27
+ if !@_hash.nil?
28
+ if hash_code == @_hash
29
+ puts 'Same hash_code for LexerTypeAction'
30
+ else
31
+ puts 'Different hash_code for LexerTypeAction'
32
+ end
33
+ end
34
+ @_hash = hash_code
35
+ end
36
+
37
+ def eql?(other)
38
+ if other == self
39
+ return true
40
+ else
41
+ return false unless other.is_a? LexerTypeAction
42
+ end
43
+
44
+ @type == other.type
45
+ end
46
+
47
+ def to_s
48
+ 'type(' << @type << ')'
49
+ end
50
+ end
51
+ end