Sha256: b0562108ee4d3a36518c292b87597bb25ab7046022f56302f8b7daefc40a9402

Contents?: true

Size: 802 Bytes

Versions: 2

Compression:

Stored size: 802 Bytes

Contents

require "rly/lex"

module Rly
  class FileLex < Lex
    def initialize(fn=nil)
      @inputstack = []
      push_file(fn) if fn
    end
    
    def push_file(fn)
      @inputstack.push([@input, @pos, @filename]) if @filename

      @filename = fn
      @input = open(fn).read
      @pos = 0
    end

    def pop_file
      (@input, @pos, @filename) = @inputstack.pop
    end

    def next
      begin
        tok = super

        if tok
          return tok
        else
          if @inputstack.empty?
            return nil
          else
            pop_file
            redo
          end
        end
      end until tok
    end

    def build_token(type, value)
      tok = LexToken.new(type, value, self, @pos, @lineno)
      tok.location_info[:filename] = @filename
      tok
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rly-0.2.3 lib/rly/file_lex.rb
rly-0.2.2 lib/rly/file_lex.rb