Class: Aurum::CharacterSet

Inherits:
Object
  • Object
show all
Defined in:
lib/aurum/lexical_table_generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*intervals) ⇒ CharacterSet

Returns a new instance of CharacterSet.



341
342
343
# File 'lib/aurum/lexical_table_generator.rb', line 341

def initialize *intervals
    @intervals = intervals
end

Instance Attribute Details

#intervalsObject (readonly)

Returns the value of attribute intervals.



308
309
310
# File 'lib/aurum/lexical_table_generator.rb', line 308

def intervals
  @intervals
end

Class Method Details

.anyObject



309
310
311
# File 'lib/aurum/lexical_table_generator.rb', line 309

def self.any
    Interval.new(0, 65535).to_char_set
end

Instance Method Details

#+(other) ⇒ Object



313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/aurum/lexical_table_generator.rb', line 313

def + other
    result = self.dup
    if (other.kind_of? CharacterSet)
        for interval in other.intervals
            result.add_interval interval.first, interval.last
        end
    else
        other.to_s.each_byte do |byte|
            result.add_interval byte
        end
    end
    result
end

#-(other) ⇒ Object



327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/aurum/lexical_table_generator.rb', line 327

def - other
    result = self.dup
    if (other.kind_of? CharacterSet)
        for interval in other.intervals
            result.delete_interval interval.first, interval.last
        end
    else
        other.to_s.each_byte do |byte|
            result.delete_interval byte
        end
    end
    result
end

#<<(obj) ⇒ Object



345
346
347
# File 'lib/aurum/lexical_table_generator.rb', line 345

def << obj
    obj.kind_of?(Range) ? add_interval(obj.first, obj.last) : obj.to_s.each_byte {|x| add_interval x}
end

#delete(obj) ⇒ Object



349
350
351
352
353
354
355
356
357
358
# File 'lib/aurum/lexical_table_generator.rb', line 349

def delete obj
    case obj
    when Range
        delete_interval obj.first, obj.last
    when Aurum::CharacterSet
        obj.intervals.each {|interval| delete_interval interval.first, interval.last}
    else
        obj.to_s.each_byte {|x| delete_interval x}
    end
end

#dupObject



375
376
377
378
379
380
381
# File 'lib/aurum/lexical_table_generator.rb', line 375

def dup
    intervals = []
    for interval in @intervals
        intervals << interval.dup
    end
    CharacterSet.new *intervals
end

#empty?Boolean

Returns:

  • (Boolean)


364
365
366
# File 'lib/aurum/lexical_table_generator.rb', line 364

def empty?
    return @intervals.empty?
end

#include?(char) ⇒ Boolean

Returns:

  • (Boolean)


360
361
362
# File 'lib/aurum/lexical_table_generator.rb', line 360

def include? char
    @intervals.any? {|x| x.include? char}
end

#to_points(destination) ⇒ Object



368
369
370
371
372
373
# File 'lib/aurum/lexical_table_generator.rb', line 368

def to_points destination
    @intervals.inject [] do |points, interval|
        points << Point.new(interval.first, true, destination)
        points << Point.new(interval.last, false, destination)
    end
end