1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: add information about the ending line for a few elements (#7414)

This commit is contained in:
Lukas Neubert
2020-12-22 14:45:12 +01:00
committed by GitHub
parent fb0c4556fd
commit d1fc65c260
5 changed files with 30 additions and 9 deletions

View File

@@ -8,10 +8,12 @@ pub:
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 mut:
last_line int // the line number where the ast object ends (used by vfmt)
}
pub fn (pos Position) str() string {
return 'Position{ line_nr: $pos.line_nr, pos: $pos.pos, len: $pos.len }'
return 'Position{ line_nr: $pos.line_nr, last_line: $pos.last_line, pos: $pos.pos, len: $pos.len }'
}
pub fn (pos Position) extend(end Position) Position {
@@ -21,6 +23,15 @@ pub fn (pos Position) extend(end Position) Position {
}
}
pub fn (pos Position) extend_with_last_line(end Position, last_line int) Position {
return {
len: end.pos - pos.pos + end.len
line_nr: pos.line_nr
last_line: last_line - 1
pos: pos.pos
}
}
[inline]
pub fn (tok &Token) position() Position {
return Position{