Class: Aurum::Grammar::LexicalRules::CharacterSet::Interval
- Inherits:
-
Struct
- Object
- Struct
- Aurum::Grammar::LexicalRules::CharacterSet::Interval
- Includes:
- Comparable
- Defined in:
- lib/aurum/grammar/lexical_rules.rb
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #include?(char) ⇒ Boolean
-
#initialize(first, last = first) ⇒ Interval
constructor
A new instance of Interval.
- #inspect ⇒ Object
- #merge!(other) ⇒ Object
- #to_char_set ⇒ Object
Constructor Details
#initialize(first, last = first) ⇒ Interval
Returns a new instance of Interval.
171 172 173 |
# File 'lib/aurum/grammar/lexical_rules.rb', line 171 def initialize first, last = first super first, last end |
Instance Method Details
#<=>(other) ⇒ Object
185 186 187 188 |
# File 'lib/aurum/grammar/lexical_rules.rb', line 185 def <=> other return first <=> other.first unless first == other.first (last - first) <=> (other.last - other.first) end |
#include?(char) ⇒ Boolean
174 175 176 177 |
# File 'lib/aurum/grammar/lexical_rules.rb', line 174 def include? char char = char[0] if char.kind_of? String first <= char && char <= last end |
#inspect ⇒ Object
194 195 196 |
# File 'lib/aurum/grammar/lexical_rules.rb', line 194 def inspect first == last ? chr_of(first) : "#{chr_of(first)}-#{chr_of(last)}" end |
#merge!(other) ⇒ Object
179 180 181 182 183 |
# File 'lib/aurum/grammar/lexical_rules.rb', line 179 def merge! other return nil unless include?(other.first) || include?(other.last) || other.first - last == 1 || first - other.last == 1 self.first, self.last = [first, other.first].min, [last, other.last].max self end |
#to_char_set ⇒ Object
190 191 192 |
# File 'lib/aurum/grammar/lexical_rules.rb', line 190 def to_char_set CharacterSet.new([self]) end |