Sha256: c478335708d74fff57e644fb653a92dc81780a5d53f001db270a4515f897232f

Contents?: true

Size: 524 Bytes

Versions: 1

Compression:

Stored size: 524 Bytes

Contents

module Sexpr
  class Rule
    include Element

    attr_reader :name
    attr_reader :defn

    def initialize(name, defn)
      @name = name
      @defn = defn
    end

    def match?(sexp)
      return nil unless sexp.is_a?(Array)
      return false unless sexp.first && (sexp.first == name)
      defn.match?(sexp[1..-1])
    end

    def eat(sexp)
      return nil unless match?(sexp.first)
      sexp[1..-1]
    end

    def inspect
      "(rule #{name}, #{defn.inspect})"
    end

  end # class Rule
end # module Sexpr

Version data entries

1 entries across 1 versions & 1 rubygems

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