Sha256: 9f522855e05ba2c271f6f6ac5666050e9d5a04bc923c725a1ef7e10cd9bfec5b

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

module Pione::Model
  # CallRule represents the application of a rule.
  # @example
  #   # simple rule calling:
  #   rule r1
  #   #=> CallRule.new(RuleExpr.new('r1'))
  # @example
  #   # with absolute path:
  #   rule /abc:a
  #   #=> CallRule.new(RuleExpr.new('/abc:a'))
  # @example
  #   # with variable:
  #   rule $X
  #   #=> CallRule.new(Variable.new('X'))
  class CallRule < BasicModel
    attr_reader :expr

    # Creates a callee rule.
    # @param [BasicModel] expr
    #   callee rule
    def initialize(expr)
      @expr = expr
      super()
    end

    # Returns a rule path string with expanding variables.
    # @return [String]
    #   rule path(package name and rule name)
    def rule_path
      if @expr.include_variable?
        raise UnboundVariableError.new(@expr)
      end
      @expr.rule_path
    end

    # Returns true if the expression has variables.
    # @return [Boolean]
    #   true if the expression has variables
    def include_variable?
      @expr.include_variable?
    end

    # Evaluates the expression.
    # @param [VariableTable] vtable
    #   variable table for evaluation
    # @return [BasicModel]
    #   evaluation result
    def eval(vtable)
      self.class.new(@expr.eval(vtable))
    end

    # @api private
    def textize
      "call_rule(%s)" % [@expr.textize]
    end

    # @api private
    def ==(other)
      @expr == other.expr
    end

    alias :eql? :==

    # @api private
    def hash
      @expr.hash
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pione-0.1.1 lib/pione/model/call-rule.rb
pione-0.1.0 lib/pione/model/call-rule.rb