3.10. kink/LOC

The companion mod for loc vals.

3.10.1. type loc

A loc val represents a location in a program text.

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


:Loc <- LOC.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"


Loc.program_name returns the program name str.


Loc.program_name returns the program text str.


Loc.pos returns the pos in the program text str.

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


Loc.line_num returns the line number of the loc.

The line number is the number of LF characters plus one in the program text before the Loc.pos.


Loc.col_offset returns the column offset of the loc.

The column offset is the number of runes from the start pos of the line to the Loc.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.


Loc.col_num returns the column number of the loc.

The result is equal to Loc.col_offset + 1.


Loc.line returns the line str where the loc resides.

Loc.line returns the slice of the program text from the start pos of the line which the loc 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.


Loc.indicator returns a str indicating the loc in the line, such as ":Foo = stdout.-->write(Bin)".

The result str does not contain LF characters.


Loc.desc returns a str describing the loc in the program text.

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.

Loc.op_eq(Arg_loc) Loc.op_ne(Arg_loc)

loc.op_eq and Loc.op_ne return whether or not 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.

3.10.2. LOC.loc?(Val)

LOC.loc? returns whether the Val is a loc val.

3.10.3. LOC.new(Program_name Program_text Pos)

LOC.new makes a loc of the Program_name, Program_text and the Pos.

TODO maybe it has to be renamed to LOC.new.