1// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
2// Use of this source code is governed by an MIT license
3// that can be found in the LICENSE file.
4module token
5
6pub struct Position {
7pub:
8	len     int // length of the literal in the source
9	line_nr int // the line number in the source where the token occured
10	pos     int // the position of the token in scanner text
11}
12
13pub fn (pos Position) str() string {
14	return 'Position{ line_nr: $pos.line_nr, pos: $pos.pos, len: $pos.len }'
15}
16
17pub fn (pos Position) extend(end Position) Position {
18	return {
19		pos |
20		len: end.pos - pos.pos + end.len
21	}
22}
23
24[inline]
25pub fn (tok &Token) position() Position {
26	return Position{
27		len: tok.len
28		line_nr: tok.line_nr - 1
29		pos: tok.pos
30	}
31}
32