Class: Emfrp::OpParser

Inherits:
ParserCombinator
  • Object
show all
Defined in:
lib/emfrp/parser/operator.rb

Class Method Summary collapse

Class Method Details

.make_op_parser(priority_list) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/emfrp/parser/operator.rb', line 5

def self.make_op_parser(priority_list)
  priority_list.reverse.inject(item.map(&:item)) do |contp, x|
    op = sat{|i| i.item.is_a?(SSymbol) && i.item[:desc] == x[:sym]}
    if x[:dir] == "left"
      opp = x[:op].map do |op|
        proc{|l, r| FuncCall.new(:name => op, :args => [l, r])}
      end
      binopl_fail(contp, opp)
    elsif x[:dir] == "right"
      sp = contp >> proc{|l|
        x[:op] >> proc{|op|
          sp >> proc{|r|
            ok(FuncCall.new(:name => op, :args => [l, r]))
          }}} | contp
    else
      raise "invalid direction"
    end
  end
end