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

all: remove comp time '@' expansion from scanner (#6746)

This commit is contained in:
Larpon
2020-11-05 09:12:32 +01:00
committed by GitHub
parent 1b1d17cfb5
commit 785bf40f67
13 changed files with 251 additions and 249 deletions

View File

@@ -79,18 +79,7 @@ pub fn formatted_error(kind string, omsg string, filepath string, pos token.Posi
}
}
//
source := read_file(filepath) or {
''
}
mut p := imax(0, imin(source.len - 1, pos.pos))
if source.len > 0 {
for ; p >= 0; p-- {
if source[p] == `\r` || source[p] == `\n` {
break
}
}
}
column := imax(0, pos.pos - p - 1)
source, column := filepath_pos_to_source_and_column(filepath, pos)
position := '$path:${pos.line_nr + 1}:${imax(1, column + 1)}:'
scontext := source_context(kind, source, column, pos).join('\n')
final_position := bold(position)
@@ -101,6 +90,24 @@ pub fn formatted_error(kind string, omsg string, filepath string, pos token.Posi
return '$final_position $final_kind $final_msg$final_context'.trim_space()
}
pub fn filepath_pos_to_source_and_column(filepath string, pos token.Position) (string, int) {
// TODO: optimize this; may be use a cache.
// The column should not be so computationally hard to get.
source := read_file(filepath) or {
''
}
mut p := imax(0, imin(source.len - 1, pos.pos))
if source.len > 0 {
for ; p >= 0; p-- {
if source[p] == `\n` || source[p] == `\r` {
break
}
}
}
column := imax(0, pos.pos - p - 1)
return source, column
}
pub fn source_context(kind string, source string, column int, pos token.Position) []string {
mut clines := []string{}
if source.len == 0 {