Class: ABNF::Compiler::Rule::ValueRange

Inherits:
Object
  • Object
show all
Includes:
ABNF::Compiler::Rule
Defined in:
lib/abnf/compiler/rule/value_range.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ABNF::Compiler::Rule

#parse?

Constructor Details

#initialize(start_character, end_character) ⇒ ValueRange

Returns a new instance of ValueRange.



10
11
12
13
# File 'lib/abnf/compiler/rule/value_range.rb', line 10

def initialize start_character, end_character
  @start_character = start_character
  @end_character = end_character
end

Instance Attribute Details

#end_characterObject (readonly)

Returns the value of attribute end_character.



8
9
10
# File 'lib/abnf/compiler/rule/value_range.rb', line 8

def end_character
  @end_character
end

#start_characterObject (readonly)

Returns the value of attribute start_character.



7
8
9
# File 'lib/abnf/compiler/rule/value_range.rb', line 7

def start_character
  @start_character
end

Instance Method Details

#parse(stream) ⇒ Object



15
16
17
18
19
# File 'lib/abnf/compiler/rule/value_range.rb', line 15

def parse stream
  match_data = stream.match regexp
  return unless match_data
  AST.leaf match_data.to_s
end

#regexpObject



21
22
23
24
25
26
27
28
29
# File 'lib/abnf/compiler/rule/value_range.rb', line 21

def regexp
  @regexp ||=
    begin
      start_char = Regexp.escape start_character
      end_char = Regexp.escape end_character

      Regexp.new "[#{start_char}-#{end_char}]", false, 'n'.freeze
    end
end