Module: Fop::Parser

Defined in:
lib/fop/parser.rb

Constant Summary collapse

Error =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.parse!(tokens) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fop/parser.rb', line 7

def self.parse!(tokens)
  stack = []
  current_el = nil

  tokens.each { |token|
    case current_el
    when nil
      current_el = new_element token
    when :wildcard
      current_el = new_element token, true
      raise Error, "Unexpected * after wildcard" if current_el == :wildcard
    when Nodes::Text
      current_el = parse_text stack, current_el, token
    when Nodes::Match
      current_el = parse_match stack, current_el, token
    else
      raise Error, "Unexpected token #{token} in #{current_el}"
    end
  }

  case current_el
  when nil
    # noop
  when :wildcard
    stack << Nodes::Text.new(true, "")
  when Nodes::Text
    stack << current_el
  when Nodes::Match
    raise Error, "Unclosed match"
  end

  stack
end