class Calyx::Rule

Represents a named rule connected to a tree of productions that can be evaluated and a trace which represents where the rule was declared.

Attributes

name[R]
trace[R]
tree[R]

Public Class Methods

build_ast(productions, registry) click to toggle source
# File lib/calyx/rule.rb, line 5
def self.build_ast(productions, registry)
  if productions.first.is_a?(Hash)
    # TODO: test that key is a string

    if productions.first.first.last.is_a?(String)
      # If value of the production is a strings then this is a
      # paired mapping production.
      Production::AffixTable.parse(productions.first, registry)
    else
      # Otherwise, we assume this is a weighted choice declaration and
      # convert the hash to an array
      Syntax::WeightedChoices.parse(productions.first.to_a, registry)
    end
  elsif productions.first.is_a?(Enumerable)
    # TODO: this needs to change to support attributed/tagged grammars
    Syntax::WeightedChoices.parse(productions, registry)
  else
    Syntax::Choices.parse(productions, registry)
  end
end
new(name, productions, trace) click to toggle source
# File lib/calyx/rule.rb, line 28
def initialize(name, productions, trace)
  @name = name.to_sym
  @tree = productions
  @trace = trace
end

Public Instance Methods

evaluate(options) click to toggle source
# File lib/calyx/rule.rb, line 38
def evaluate(options)
  tree.evaluate(options)
end
size() click to toggle source
# File lib/calyx/rule.rb, line 34
def size
  tree.size
end