v/vlib/v/token/position.v

32 lines
752 B
V
Raw Normal View History

2020-01-23 21:04:46 +01:00
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
// 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
line_nr int // the line number in the source where the token occured
pos int // the position of the token in scanner text
}
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
}
}
[inline]
pub fn (tok &Token) position() Position {
return Position{
2020-05-18 21:38:06 +02:00
len: tok.len
line_nr: tok.line_nr - 1
pos: tok.pos
}
}