6.86. kink/program/LOCATION

6.86.1. type location

`location` is a position index of Unicode code points in a program text.

A `location` consists of the following attributes:

• Program: a `program`

• Pos: a position index as an integer `num`.

Invariant

0 <= Pos <= Program.text.size

Example

6.86.1.1. Loc.program

`program` returns `Program` attribute of `Loc`.

6.86.1.2. Loc.pos

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

6.86.1.3. Loc.line_num

`line_num` returns the line number of `Loc` as an integer `num`.

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

Example

6.86.1.4. Loc.col_num

`col_num` returns the column number of `Loc` as an integer `num`.

The result is the number of code points plus one in the line before `Loc`.

Example

6.86.1.5. Loc.line

`line` returns the line of `Loc` as a `str`.

`line` returns a slice of the program text in the range [From, To), where `From` is the code point index of the beginning of the line, and `To` is the code point index of the beginning of the next line or the end of the text. Thus, the result `str` may include an LF character as the last code point.

Example

6.86.1.6. Loc.indicator

`indicator` returns a `str` which represents the position of `Loc` in the line.

The result `str` does not contain CR or LF characters.

Example

6.86.1.7. Loc.desc

`desc` returns a `str` which describes the program name, the line number, and the column number.

Example

6.86.1.8. Loc1 == Loc2

`==` operator, or `op_eq` method, returns whether two `location` values have the equal `Program` and `Pos` attributes.

6.86.1.9. Loc.repr

`repr` returns a `str` representation of `Loc` for debugging purposes.

Example

6.86.2. LOCATION.new(Program Pos)

`new` returns a `location` with the given attributes.

Preconditions

`Program` must be a `program`.

`Pos` must be an integer `num`.

0 <= Pos <= Program.text.size

6.86.3. LOCATION.empty

`empty` returns a `location` with the empty program name, the empty program text, and Pos=0.

6.86.4. LOCATION.is?(Val)

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