Class: Kumi::Syntax::Location

Inherits:
Struct
  • Object
show all
Defined in:
lib/kumi/syntax/location.rb

Overview

The single source of truth for how a source location is rendered. Every error message and code frame formats locations through here so the codebase speaks one dialect: the editor-clickable ‘file:line:col` form. Do not hand-roll `“at file line=N column=M”` strings elsewhere — call #to_s.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#columnObject

Returns the value of attribute column

Returns:

  • (Object)

    the current value of column



7
8
9
# File 'lib/kumi/syntax/location.rb', line 7

def column
  @column
end

#fileObject

Returns the value of attribute file

Returns:

  • (Object)

    the current value of file



7
8
9
# File 'lib/kumi/syntax/location.rb', line 7

def file
  @file
end

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



7
8
9
# File 'lib/kumi/syntax/location.rb', line 7

def line
  @line
end

Instance Method Details

#to_sObject

Canonical ‘file:line:col` rendering. A zero/nil column is omitted (the column is unknown rather than column 0), giving a clean `file:line`.



10
11
12
13
14
# File 'lib/kumi/syntax/location.rb', line 10

def to_s
  return "#{file}:#{line}:#{column}" if column&.positive?

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

#usable?Boolean

True when there is enough to point a user at a real spot in their source.

Returns:

  • (Boolean)


17
18
19
# File 'lib/kumi/syntax/location.rb', line 17

def usable?
  !file.nil? && !line.nil? && line.positive?
end