antlr4-runtime 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,33 @@
|
|
1
|
+
module Antlr4::Runtime
|
2
|
+
|
3
|
+
class FailedPredicateException < RecognitionException
|
4
|
+
attr_reader :predicate
|
5
|
+
attr_reader :predicate_index
|
6
|
+
attr_reader :rule_index
|
7
|
+
|
8
|
+
def initialize(recognizer, predicate = nil, message = nil)
|
9
|
+
super(format_message(predicate, message))
|
10
|
+
@recognizer = recognizer
|
11
|
+
@input = recognizer.input_stream
|
12
|
+
@context = recognizer._ctx
|
13
|
+
|
14
|
+
s = recognizer._interp.atn.states.get(recognizer.getState)
|
15
|
+
|
16
|
+
trans = s.transition(0)
|
17
|
+
if trans.is_a? PredicateTransition
|
18
|
+
@rule_index = trans.rule_index
|
19
|
+
@predicate_index = trans.pred_index
|
20
|
+
else
|
21
|
+
@rule_index = 0
|
22
|
+
@predicate_index = 0
|
23
|
+
end
|
24
|
+
|
25
|
+
@predicate = predicate
|
26
|
+
@offending_token = recognizer.current_token
|
27
|
+
end
|
28
|
+
|
29
|
+
def format_message(predicate, message)
|
30
|
+
message.nil? ? message : "failed predicate: {" + predicate + "}?"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,232 @@
|
|
1
|
+
module Antlr4::Runtime
|
2
|
+
class FlexibleHashMap
|
3
|
+
INITIAL_CAPACITY = 16 # must be power of 2
|
4
|
+
INITIAL_BUCKET_CAPACITY = 8
|
5
|
+
LOAD_FACTOR = 0.75
|
6
|
+
|
7
|
+
class Entry
|
8
|
+
attr_accessor :key
|
9
|
+
attr_accessor :value
|
10
|
+
|
11
|
+
def initialize(key, value)
|
12
|
+
@key = key
|
13
|
+
@value = value
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
@key.to_s << ':' << @value.to_s
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(comparator = nil, initial_capacity = nil, initial_bucket_capacity = nil)
|
22
|
+
comparator = ObjectEqualityComparator.INSTANCE if comparator.nil?
|
23
|
+
|
24
|
+
initial_capacity = INITIAL_CAPACITY if initial_capacity.nil?
|
25
|
+
initial_bucket_capacity = INITIAL_BUCKET_CAPACITY if initial_bucket_capacity.nil?
|
26
|
+
|
27
|
+
@n_items = 0
|
28
|
+
@threshold = initial_capacity * LOAD_FACTOR # when to expand
|
29
|
+
@current_prime = 1 # jump by 4 primes each expand or whatever
|
30
|
+
@initial_bucket_capacity = initial_bucket_capacity
|
31
|
+
@comparator = comparator
|
32
|
+
@buckets = create_entry_list_array(initial_bucket_capacity)
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_entry_list_array(length)
|
36
|
+
Array.new(length)
|
37
|
+
end
|
38
|
+
|
39
|
+
def bucket(key)
|
40
|
+
hash = @comparator.hash(key)
|
41
|
+
hash & (@buckets.length - 1) # assumes len is power of 2
|
42
|
+
end
|
43
|
+
|
44
|
+
def get(key)
|
45
|
+
typed_key = key
|
46
|
+
return nil if key.nil?
|
47
|
+
|
48
|
+
b = bucket(typed_key)
|
49
|
+
bucket = @buckets[b]
|
50
|
+
if bucket.nil?
|
51
|
+
return nil # no bucket
|
52
|
+
end
|
53
|
+
|
54
|
+
i = 0
|
55
|
+
while i < bucket.length
|
56
|
+
e = bucket[i]
|
57
|
+
return e.value if @comparator.equals(e.key, typed_key)
|
58
|
+
i += 1
|
59
|
+
end
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def put(key, value)
|
64
|
+
return nil if key.nil?
|
65
|
+
|
66
|
+
expand if @n_items > @threshold
|
67
|
+
b = bucket(key)
|
68
|
+
bucket = @buckets[b]
|
69
|
+
bucket = @buckets[b] = [] if bucket.nil?
|
70
|
+
i = 0
|
71
|
+
while i < bucket.length
|
72
|
+
e = bucket[i]
|
73
|
+
unless @comparator.equals(e.key, key)
|
74
|
+
i += 1
|
75
|
+
next
|
76
|
+
end
|
77
|
+
|
78
|
+
prev = e.value
|
79
|
+
e.value = value
|
80
|
+
@n_items += 1
|
81
|
+
return prev
|
82
|
+
end
|
83
|
+
# not there
|
84
|
+
bucket << Entry.new(key, value)
|
85
|
+
@n_items += 1
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
|
89
|
+
def values
|
90
|
+
a = []
|
91
|
+
i = 0
|
92
|
+
while i < @buckets.length
|
93
|
+
bucket = @buckets[i]
|
94
|
+
if bucket.nil?
|
95
|
+
i += 1
|
96
|
+
next
|
97
|
+
end
|
98
|
+
|
99
|
+
j = 0
|
100
|
+
while j < bucket.length
|
101
|
+
e = bucket[j]
|
102
|
+
a << e.value
|
103
|
+
j += 1
|
104
|
+
end
|
105
|
+
i += 1
|
106
|
+
end
|
107
|
+
a
|
108
|
+
end
|
109
|
+
|
110
|
+
def contains_key(key)
|
111
|
+
!get(key).nil?
|
112
|
+
end
|
113
|
+
|
114
|
+
def hash
|
115
|
+
objs = []
|
116
|
+
i = 0
|
117
|
+
while i < @buckets.length
|
118
|
+
bucket = @buckets[i]
|
119
|
+
if bucket.nil?
|
120
|
+
i += 1
|
121
|
+
next
|
122
|
+
end
|
123
|
+
|
124
|
+
j = 0
|
125
|
+
while j < bucket.length
|
126
|
+
e = bucket[j]
|
127
|
+
break if e.nil?
|
128
|
+
|
129
|
+
objs << e.key
|
130
|
+
j += 1
|
131
|
+
end
|
132
|
+
i += 1
|
133
|
+
end
|
134
|
+
|
135
|
+
hash_code = MurmurHash.hash_objs(objs)
|
136
|
+
|
137
|
+
if !@_hash.nil?
|
138
|
+
if hash_code == @_hash
|
139
|
+
puts 'Same hash_code for FlexibleHashMap'
|
140
|
+
else
|
141
|
+
puts 'Different hash_code for FlexibleHashMap'
|
142
|
+
end
|
143
|
+
end
|
144
|
+
@_hash = hash_code
|
145
|
+
end
|
146
|
+
|
147
|
+
def expand
|
148
|
+
old = @buckets
|
149
|
+
@current_prime += 4
|
150
|
+
new_capacity = @buckets.length * 2
|
151
|
+
new_table = create_entry_list_array(new_capacity)
|
152
|
+
@buckets = new_table
|
153
|
+
@threshold = new_capacity * LOAD_FACTOR
|
154
|
+
|
155
|
+
old_size = size
|
156
|
+
i = 0
|
157
|
+
while i < old.length
|
158
|
+
bucket = old[i]
|
159
|
+
if bucket.nil?
|
160
|
+
i += 1
|
161
|
+
next
|
162
|
+
end
|
163
|
+
|
164
|
+
j = 0
|
165
|
+
while j < bucket.length
|
166
|
+
e = bucket[j]
|
167
|
+
break if e.nil?
|
168
|
+
|
169
|
+
put(e.key, e.value)
|
170
|
+
j += 1
|
171
|
+
end
|
172
|
+
i += 1
|
173
|
+
end
|
174
|
+
@n_items = old_size
|
175
|
+
end
|
176
|
+
|
177
|
+
def size
|
178
|
+
@n_items
|
179
|
+
end
|
180
|
+
|
181
|
+
def empty?
|
182
|
+
@n_items == 0
|
183
|
+
end
|
184
|
+
|
185
|
+
def clear
|
186
|
+
@buckets = create_entry_list_array(INITIAL_CAPACITY)
|
187
|
+
@n_items = 0
|
188
|
+
end
|
189
|
+
|
190
|
+
def to_s
|
191
|
+
return 'end' if size == 0
|
192
|
+
|
193
|
+
buf = ''
|
194
|
+
buf << ''
|
195
|
+
first = true
|
196
|
+
@buckets.each do |bucket|
|
197
|
+
next if bucket.nil?
|
198
|
+
|
199
|
+
bucket.each do |e|
|
200
|
+
break if e.nil?
|
201
|
+
|
202
|
+
if first
|
203
|
+
first = false
|
204
|
+
else
|
205
|
+
buf << ', '
|
206
|
+
end
|
207
|
+
buf << e.to_s
|
208
|
+
end
|
209
|
+
end
|
210
|
+
buf << 'end'
|
211
|
+
buf.to_s
|
212
|
+
end
|
213
|
+
|
214
|
+
def to_table_string
|
215
|
+
buf = ''
|
216
|
+
@buckets.each do |bucket|
|
217
|
+
if bucket.nil?
|
218
|
+
buf << "nil\n"
|
219
|
+
next
|
220
|
+
end
|
221
|
+
buf << '['
|
222
|
+
first = true
|
223
|
+
bucket.each do |e|
|
224
|
+
first ? first = false : buf << ' '
|
225
|
+
buf << (e.nil? ? '_' : e.to_s)
|
226
|
+
end
|
227
|
+
buf << "]\n"
|
228
|
+
end
|
229
|
+
buf.to_s
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'antlr4/runtime/recognition_exception'
|
2
|
+
|
3
|
+
module Antlr4::Runtime
|
4
|
+
|
5
|
+
class InputMismatchException < RecognitionException
|
6
|
+
def self.create(recog, state = nil)
|
7
|
+
result = InputMismatchException.new
|
8
|
+
|
9
|
+
result.offending_state = -1
|
10
|
+
result.context = recog._ctx
|
11
|
+
result.input = recog._input
|
12
|
+
result.recognizer = recog
|
13
|
+
result.offending_state = recog._state_number unless recog.nil?
|
14
|
+
|
15
|
+
result.offending_token = recog.current_token unless recog.nil?
|
16
|
+
result.offending_state = state unless state.nil?
|
17
|
+
result
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Antlr4::Runtime
|
2
|
+
class IntStream
|
3
|
+
EOF = -1
|
4
|
+
|
5
|
+
UNKNOWN_SOURCE_NAME = '<unknown>'.freeze
|
6
|
+
|
7
|
+
def consume
|
8
|
+
end
|
9
|
+
|
10
|
+
def la(i)
|
11
|
+
end
|
12
|
+
|
13
|
+
def mark
|
14
|
+
end
|
15
|
+
|
16
|
+
def release(marker)
|
17
|
+
end
|
18
|
+
|
19
|
+
def index
|
20
|
+
end
|
21
|
+
|
22
|
+
def seek(index)
|
23
|
+
end
|
24
|
+
|
25
|
+
def size
|
26
|
+
end
|
27
|
+
|
28
|
+
def source_name
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module Antlr4::Runtime
|
2
|
+
class Interval
|
3
|
+
INTERVAL_POOL_MAX_VALUE = 1000
|
4
|
+
|
5
|
+
|
6
|
+
attr_accessor :a
|
7
|
+
attr_accessor :b
|
8
|
+
|
9
|
+
def initialize(a, b)
|
10
|
+
@a = a
|
11
|
+
@b = b
|
12
|
+
end
|
13
|
+
|
14
|
+
class << self
|
15
|
+
attr_accessor :creates
|
16
|
+
attr_accessor :misses
|
17
|
+
attr_accessor :hits
|
18
|
+
attr_accessor :outOfRange
|
19
|
+
attr_accessor :invalid
|
20
|
+
|
21
|
+
@@cache = []
|
22
|
+
@@creates = 0
|
23
|
+
@@misses = 0
|
24
|
+
@@hits = 0
|
25
|
+
@@outOfRange = 0
|
26
|
+
@@invalid = Interval.new(-1, -2)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.of(a, b)
|
30
|
+
return Interval.new(a, b) if a != b || a < 0 || a > INTERVAL_POOL_MAX_VALUE
|
31
|
+
|
32
|
+
@@cache[a] = Interval.new(a, a) if @@cache[a].nil?
|
33
|
+
@@cache[a]
|
34
|
+
end
|
35
|
+
|
36
|
+
def length
|
37
|
+
return 0 if @b < @a
|
38
|
+
|
39
|
+
@b - @a + 1
|
40
|
+
end
|
41
|
+
|
42
|
+
def ==(o)
|
43
|
+
return false if o.nil? || !(o.is_a? Interval)
|
44
|
+
|
45
|
+
@a == o.a && @b == o.b
|
46
|
+
end
|
47
|
+
|
48
|
+
def hash
|
49
|
+
hash = 23
|
50
|
+
hash = hash * 31 + @a
|
51
|
+
hash * 31 + @b
|
52
|
+
end
|
53
|
+
|
54
|
+
def starts_before_disjoint(other)
|
55
|
+
@a < other.a && @b < other.a
|
56
|
+
end
|
57
|
+
|
58
|
+
def starts_before_non_disjoint(other)
|
59
|
+
@a <= other.a && @b >= other.a
|
60
|
+
end
|
61
|
+
|
62
|
+
def startsAfter(other)
|
63
|
+
@a > other.a
|
64
|
+
end
|
65
|
+
|
66
|
+
def startsAfterDisjoint(other)
|
67
|
+
@a > other.b
|
68
|
+
end
|
69
|
+
|
70
|
+
def startsAfterNonDisjoint(other)
|
71
|
+
@a > other.a && @a <= other.b
|
72
|
+
end
|
73
|
+
|
74
|
+
def disjoint(other)
|
75
|
+
starts_before_disjoint(other) || startsAfterDisjoint(other)
|
76
|
+
end
|
77
|
+
|
78
|
+
def adjacent(other)
|
79
|
+
@a == other.b + 1 || @b == other.a - 1
|
80
|
+
end
|
81
|
+
|
82
|
+
def properlyContains(other)
|
83
|
+
other.a >= @a && other.b <= @b
|
84
|
+
end
|
85
|
+
|
86
|
+
def union(other)
|
87
|
+
Interval.of([a, other.a].min, [b, other.b].max)
|
88
|
+
end
|
89
|
+
|
90
|
+
def intersection(other)
|
91
|
+
Interval.of([a, other.a].max, [b, other.b].min)
|
92
|
+
end
|
93
|
+
|
94
|
+
def difference_not_properly_contained(other)
|
95
|
+
diff = null
|
96
|
+
if other.starts_before_non_disjoint(this)
|
97
|
+
|
98
|
+
diff = Interval.of([@a, other.b + 1].max, @b)
|
99
|
+
|
100
|
+
elsif other.startsAfterNonDisjoint(this)
|
101
|
+
|
102
|
+
diff = Interval.of(@a, other.a - 1)
|
103
|
+
end
|
104
|
+
diff
|
105
|
+
end
|
106
|
+
|
107
|
+
def to_s
|
108
|
+
@a.to_s + '..' + @b.to_s
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|