Sha256: 1d800af47949835e7024b7255dc82bdb510290c28e079a88755b705585788419

Contents?: true

Size: 971 Bytes

Versions: 12

Compression:

Stored size: 971 Bytes

Contents

#
# bitclust/parseutils.rb
#
# Copyright (c) 2006-2007 Minero Aoki
#
# This program is free software.
# You can distribute/modify this program under the Ruby License.
#

require 'bitclust/exception'

class String   # reopen
  attr_accessor :location
end

module BitClust

  class LineStream
    def initialize(f)
      @f = f
    end

    def gets
      line = @f.gets
      return nil unless line
      if @f.respond_to?(:path)
        path = @f.path
      else
        path = nil
      end
      line.location = Location.new(path, @f.lineno)
      line
    end
  end

  class Location
    def initialize(file, line)
      @file = file
      @line = line
    end

    attr_reader :file
    attr_reader :line

    def to_s
      "#{@file}:#{@line}"
    end

    def inspect
      "\#<#{self.class} #{@file}:#{@line}>"
    end
  end

  module ParseUtils
    def parse_error(msg, line)
      raise ParseError, "#{line.location}: #{msg}: #{line.inspect}"
    end
  end

end

Version data entries

12 entries across 8 versions & 1 rubygems

Version Path
bitclust-core-0.7.0 lib/bitclust/parseutils.rb
bitclust-core-0.6.0 lib/bitclust/parseutils.rb
bitclust-core-0.5.5 lib/bitclust/parseutils.rb
bitclust-core-0.5.4 lib/bitclust/parseutils.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.3/vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/lib/bitclust/parseutils.rb
bitclust-core-0.5.3 lib/bitclust/parseutils.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/lib/bitclust/parseutils.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.3/lib/bitclust/parseutils.rb
bitclust-core-0.5.2 lib/bitclust/parseutils.rb
bitclust-core-0.5.2 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/lib/bitclust/parseutils.rb
bitclust-core-0.5.1 lib/bitclust/parseutils.rb
bitclust-core-0.5.0 lib/bitclust/parseutils.rb