4.12. kink/LOCATION

The companion mod for location vals.

4.12.1. type location

A location val represents a location in a program text.

A location val consists of (Program_name, Program_text, Pos), where Pos is the pos index in the runes of the Program_text.

Example:

:LOCATION.require_from('kink/')
:Loc <- LOCATION.new('foo.kn' "ping(Pong)\nfoo(Bar)\n" 15)
stdout.print_line(Loc.program_name.repr)  # => "foo.kn"
stdout.print_line(Loc.program_text.repr)  # => "ping(Pong)\nfoo(Bar)\n"
stdout.print_line(Loc.line_num.repr)      # => 2
stdout.print_line(Loc.col_offset.repr)    # => 4
stdout.print_line(Loc.col_num.repr)       # => 5
stdout.print_line(Loc.line.repr)          # => "foo(Bar)\n"
stdout.print_line(Loc.indicator.repr)     # => "foo(-->Bar)"
stdout.print_line(Loc.desc.repr)          # => "foo.kn L2 C5"

4.12.1.1. Loc.program_name

`program_name` returns `Program_name` attribute of `Loc`.

4.12.1.2. Loc.program_text

`program_name` returns `Program_text` attribute of `Loc`.

4.12.1.3. Loc.pos

`pos` returns `Pos` attribute of `Loc`.

The result is an int num, in the range [0, Program_text.size].

4.12.1.4. Loc.line_num

`line_num` returns the line number of `Loc` in the program.

The line number is the number of LF characters plus one in the program text before `Pos`.

4.12.1.5. Loc.col_offset

`col_offset` returns the column offset of `Loc`.

The column offset is the number of runes from the start pos of the line to `Pos`. The start pos of the line is the pos just after the nearest preceding LF character, or zero if there is no preceding LF character.

4.12.1.6. Loc.col_num

`col_num` returns the column number of the location.

The result is equal to Loc.col_offset + 1.

4.12.1.7. Loc.line

`line` returns the line str where the location resides.

`line` returns a slice of `Program_text` from the start pos of the line which the location resides, to the start pos of the next line or the end of the text. Thus, the result str may include an LF character as the last rune.

4.12.1.8. Loc.indicator

`indicator` returns a str indicating the pos of `Loc` in the line, such as "stdout.-->write(Bin)".

The result str does not contain LF characters.

4.12.1.9. Loc.desc

`desc` returns a str describing `Loc`.

`desc` returns a str such as "foo.kn L42 C9", when the program text is "foo.kn", the line number is 42, and the column number is 9.

4.12.1.10. Loc1.op_eq(Loc2)

`op_eq` returns whether two locs indicate the same pos in the same program.

Two locs are equal if and only if the program name, the program text and the pos are equal.

4.12.2. LOCATION.new(Program_name Program_text Pos)

`new` returns a location with the given attributes.

4.12.3. LOCATION.empty

`empty` returns a location with the empty Program_name, the empty Program_text, and Pos=0.

4.12.4. LOCATION.is?(Val)

`is?` returns whether `Val` is a location val.