Sha256: 41796fcc066ea0d002591d7d74f4af42ced2af97d9d3dc546da3675b4e5d096e

Contents?: true

Size: 951 Bytes

Versions: 3

Compression:

Stored size: 951 Bytes

Contents

require "rly/parse/lr_table"
require "rly/version"
require "erb"

module Rly

  class PlyDump
    attr_reader :backlog

    def initialize(grammar)
      @grammar = grammar
      @backlog = ""
      if grammar
        @t = Rly::LRTable.new(grammar)
        @t.parse_table(self)
      end
    end

    def to_s
      fn = File.join(File.dirname(__FILE__), '..', '..', '..', 'assets', 'ply_dump.erb')
      e = ERB.new(open(fn).read)
      e.result(TinyContext.new(g: @grammar, backlog: @backlog, ver: Rly::VERSION).get_binding)
    end

    def self.stub
      PlyDump.new(nil)
    end

    def info(*args)
      s = sprintf(*args)
      @backlog += s + "\n"
    end

    def debug(*args)
      s = sprintf(*args)
      @backlog += s + "\n"
    end

    class TinyContext
      def initialize(ctx)
        @ctx = ctx
      end

      def get_binding
        binding()
      end

      def method_missing(m)
        @ctx[m]
      end
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rly-0.2.3 lib/rly/parse/ply_dump.rb
rly-0.2.2 lib/rly/parse/ply_dump.rb
rly-0.2.1 lib/rly/parse/ply_dump.rb