Class: ABNF::Parser::Compiler::Concatenation

Inherits:
RuleBuilder
  • Object
show all
Defined in:
lib/abnf/parser/compiler/concatenation.rb

Instance Attribute Summary

Attributes inherited from RuleBuilder

#compiler

Instance Method Summary collapse

Methods inherited from RuleBuilder

#call, #initialize

Constructor Details

This class inherits a constructor from ABNF::Parser::Compiler::RuleBuilder

Instance Method Details

#alternation_slash(_) ⇒ Object



5
6
7
# File 'lib/abnf/parser/compiler/concatenation.rb', line 5

def alternation_slash _
  finished
end

#c_nl(token) ⇒ Object



9
10
11
12
# File 'lib/abnf/parser/compiler/concatenation.rb', line 9

def c_nl token
  finished
  compiler.handle token
end

#c_wsp(_) ⇒ Object



14
15
# File 'lib/abnf/parser/compiler/concatenation.rb', line 14

def c_wsp _
end

#finishedObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/abnf/parser/compiler/concatenation.rb', line 22

def finished
  if repetitions.size == 1
    rule = repetitions.first
  else
    abnf = repetitions.map &:abnf
    abnf *= ' '
    rule = Rules::Concatenation.new repetitions, abnf
  end

  compiler.pop rule
end

#group_stop(token) ⇒ Object



17
18
19
20
# File 'lib/abnf/parser/compiler/concatenation.rb', line 17

def group_stop token
  finished
  compiler.handle token
end

#option_stop(token) ⇒ Object



34
35
36
37
# File 'lib/abnf/parser/compiler/concatenation.rb', line 34

def option_stop token
  finished
  compiler.handle token
end

#repetition(repetition) ⇒ Object



39
40
41
# File 'lib/abnf/parser/compiler/concatenation.rb', line 39

def repetition repetition
  repetitions << repetition
end

#repetitionsObject



43
44
45
# File 'lib/abnf/parser/compiler/concatenation.rb', line 43

def repetitions
  @repetitions ||= []
end

#start_rule(token) ⇒ Object



47
48
49
50
51
# File 'lib/abnf/parser/compiler/concatenation.rb', line 47

def start_rule token
  compiler.push Repetition do |element|
    repetition element
  end
end