2020-01-23 21:04:46 +01:00
|
|
|
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
|
2020-01-18 23:26:14 +01:00
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
module token
|
|
|
|
|
|
|
|
pub struct Position {
|
|
|
|
pub:
|
2020-05-18 21:38:06 +02:00
|
|
|
len int // length of the literal in the source
|
2020-01-18 23:26:14 +01:00
|
|
|
line_nr int // the line number in the source where the token occured
|
2020-02-15 13:37:48 +01:00
|
|
|
pos int // the position of the token in scanner text
|
2020-01-18 23:26:14 +01:00
|
|
|
}
|
|
|
|
|
2020-04-10 21:00:54 +02:00
|
|
|
pub fn (pos Position) str() string {
|
|
|
|
return 'Position{ line_nr: $pos.line_nr, pos: $pos.pos, len: $pos.len }'
|
|
|
|
}
|
|
|
|
|
2020-04-19 00:07:57 +02:00
|
|
|
pub fn (pos Position) extend(end Position) Position {
|
|
|
|
return {
|
|
|
|
pos |
|
|
|
|
len: end.pos - pos.pos + end.len
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 23:26:14 +01:00
|
|
|
[inline]
|
|
|
|
pub fn (tok &Token) position() Position {
|
|
|
|
return Position{
|
2020-05-18 21:38:06 +02:00
|
|
|
len: tok.len
|
2020-01-22 21:34:38 +01:00
|
|
|
line_nr: tok.line_nr - 1
|
2020-02-15 13:37:48 +01:00
|
|
|
pos: tok.pos
|
2020-01-18 23:26:14 +01:00
|
|
|
}
|
|
|
|
}
|