class ABNF::Parser::Compiler::Repetition

Attributes

abnf[W]
element[RW]
range[RW]

Public Instance Methods

abnf() click to toggle source
# File lib/abnf/parser/compiler/repetition.rb, line 9
def abnf
  @abnf ||= ''
end
finished(element) click to toggle source
# File lib/abnf/parser/compiler/repetition.rb, line 13
def finished element
  abnf << element.abnf

  if range
    rule = Rules::Repetition.new element, range, abnf
  else
    rule = element
  end

  compiler.pop rule
end
repeat_exact(token) click to toggle source
# File lib/abnf/parser/compiler/repetition.rb, line 25
def repeat_exact token
  number = token.lexeme.to_i

  self.abnf = token.abnf
  self.range = (number..number)
end
repeat_range(token) click to toggle source
# File lib/abnf/parser/compiler/repetition.rb, line 32
def repeat_range token
  minimum, maximum = token.lexeme.split '*'

  if minimum then minimum = minimum.to_i else minimum = 0 end
  if maximum then maximum = maximum.to_i else maximum = Float::INFINITY end

  self.abnf = token.abnf
  self.range = (minimum..maximum)
end
start_rule(token) click to toggle source
# File lib/abnf/parser/compiler/repetition.rb, line 42
def start_rule token
  compiler.push Element do |element|
    finished element
  end
end