Module: Qrb::Syntax::Constraints

Defined in:
lib/qrb/syntax/constraints.rb

Instance Method Summary collapse

Instance Method Details

#compile(var_name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/qrb/syntax/constraints.rb', line 5

def compile(var_name)
  constraints = {}
  captures[:named_constraint].each do |node|
    compiled = node.compile(var_name)
    constraints.merge!(compiled) do |k,_,_|
      raise Error, "Duplicate constraint name `#{k}`"
    end
  end
  constraints
end

#to_ast(var_name) ⇒ Object



16
17
18
# File 'lib/qrb/syntax/constraints.rb', line 16

def to_ast(var_name)
  captures[:named_constraint].map{|c| c.to_ast(var_name) }
end