Class: Fabulator::Grammar::Actions::Lib

Inherits:
TagLib
  • Object
show all
Defined in:
lib/fabulator/grammar/actions.rb

Instance Method Summary collapse

Instance Method Details

#matchObject

reference a grammar name



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fabulator/grammar/actions.rb', line 26

function 'match' do |ctx, args|
  # first arg is the regex or <rule name>
  regex = args[0].to_s
  parser = Fabulator::Grammar::TokenParser.new
  compiled = parser.parse(regex).to_regex
  if args[1].is_a?(Array)
    args[1].collect{|a|
      if a.to_s =~ compiled
        ctx.root.anon_node(true)
      else
        ctx.root.anon_node(false)
      end
    }
  elsif args[1].to_s =~ compiled
    [ ctx.root.anon_node(true) ]
  else
    [ ctx.root.anon_node(false) ]
  end
end