Sha256: 2ade04b49247967ac82f5f3bb774c6b0ab2b918ad49868b42507861d3f6e7368

Contents?: true

Size: 497 Bytes

Versions: 1

Compression:

Stored size: 497 Bytes

Contents

module Sexpr
  class Reference
    include Element

    attr_reader :rule_name
    attr_reader :grammar

    def initialize(rule_name, grammar)
      @rule_name = rule_name
      @grammar   = grammar
    end

    def rule
      @rule ||= @grammar[@rule_name]
    end

    def match?(sexp)
      rule && rule.match?(sexp)
    end

    def eat(sexp)
      rule && rule.eat(sexp)
    end

    def inspect
      "(ref #{rule_name}, #{rule.inspect})"
    end

  end # class Reference
end # module Sexpr

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sexpr-0.2.0 lib/sexpr/reference.rb