Sha256: c27a6691721f3f4b170b624fa07976552756b76e696d9e5583b039d9eaf636fa

Contents?: true

Size: 631 Bytes

Versions: 3

Compression:

Stored size: 631 Bytes

Contents

module Sexpr
  module Matcher
    class NonTerminal
      include Matcher

      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
        "(non-terminal #{name}, #{defn.inspect})"
      end

    end # class NonTerminal
  end # module Matcher
end # module Sexpr

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sexpr-1.1.0 lib/sexpr/matcher/non_terminal.rb
sexpr-1.0.0 lib/sexpr/matcher/non_terminal.rb
sexpr-0.6.0 lib/sexpr/matcher/non_terminal.rb