Module: Pione::Util::Positionable

Included in:
Lang::ConditionalBranch, Lang::Declaration, Lang::Expr, Lang::LiteralContext, Lang::Piece, Lang::Sequence
Defined in:
lib/pione/util/positionable.rb

Overview

Positionable provides the function that stores its source position information to objects.

Instance Method Summary collapse

Instance Method Details

#line_and_columnObject

Return the line and column. If source position isn't established, return nil simply.



30
31
32
33
34
# File 'lib/pione/util/positionable.rb', line 30

def line_and_column
  if @__source_position__
    return @__source_position__.line, @__source_position__.column
  end
end

#posObject

Return the source position.



24
25
26
# File 'lib/pione/util/positionable.rb', line 24

def pos
  @__source_position__ || SourcePosition.unknown
end

#set_source_position(*args) ⇒ Object

Set source position informations of the object.

Examples:

Specify package name, filename, line number, and column number

obj = Object.new.tap {|x| x.extend Positionable}
obj.set_source_position("HelloWorld", "HelloWorld.pione", 1, 1)

SourcePosition object

obj = Object.new.tap {|x| x.extend Positionable}
obj.set_source_position(other.pos)


15
16
17
18
19
20
21
# File 'lib/pione/util/positionable.rb', line 15

def set_source_position(*args)
  if args.size == 1 and args[0].is_a?(SourcePosition)
    @__source_position__ = args[0]
  elsif args.size > 0
    @__source_position__ = SourcePosition.new(*args)
  end
end