Sha256: e7a67b8c68ea59d792938463dad143cafc9206c350dcb4c763f8c7e9c0862037

Contents?: true

Size: 820 Bytes

Versions: 14

Compression:

Stored size: 820 Bytes

Contents

module Lucid
  module AST

    class Location
      attr_reader :file, :line

      def initialize(file, line)
        @file = file || raise(ArgumentError, "file is mandatory")
        @line = line || raise(ArgumentError, "line is mandatory")
      end

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

      def on_line(new_line)
        Location.new(file, new_line)
      end
    end

    module HasLocation
      def file_colon_line
        location.to_s
      end

      def file
        location.file
      end

      def line
        location.line
      end

      def location
        raise('Please set @location in the constructor') unless @location
        raise("@location must be an AST::Location but is a #{@location.class}") unless @location.is_a?(Location)
        @location
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
lucid-0.5.1 lib/lucid/ast/location.rb
lucid-0.4.1 lib/lucid/ast/location.rb
lucid-0.4.0 lib/lucid/ast/location.rb
lucid-0.3.3 lib/lucid/ast/location.rb
lucid-0.3.0 lib/lucid/ast/location.rb
lucid-0.2.1 lib/lucid/ast/location.rb
lucid-0.2.0 lib/lucid/ast/location.rb
lucid-0.1.1 lib/lucid/ast/location.rb
lucid-0.1.0 lib/lucid/ast/location.rb
lucid-0.0.9 lib/lucid/ast/location.rb
lucid-0.0.8 lib/lucid/ast/location.rb
lucid-0.0.7 lib/lucid/ast/location.rb
lucid-0.0.6 lib/lucid/ast/location.rb
lucid-0.0.5 lib/lucid/ast/location.rb