@@ -24,6 +24,7 @@ pub struct Scanner {
2424pub mut :
2525 file_path string // '/path/to/file.v'
2626 file_base string // 'file.v'
27+ file_idx int = - 1 // file idx in the global table `filelist`
2728 text string // the whole text of the file
2829 pos int = - 1 // current position in the file, first character is s.text[0]
2930 line_nr int // current line number
@@ -107,7 +108,7 @@ pub enum CommentsMode {
107108}
108109
109110// new scanner from file.
110- pub fn new_scanner_file (file_path string , comments_mode CommentsMode, pref_ & pref.Preferences) ! & Scanner {
111+ pub fn new_scanner_file (file_path string , file_idx int , comments_mode CommentsMode, pref_ & pref.Preferences) ! & Scanner {
111112 if ! os.is_file (file_path) {
112113 return error ('${file_path } is not a .v file' )
113114 }
@@ -123,6 +124,7 @@ pub fn new_scanner_file(file_path string, comments_mode CommentsMode, pref_ &pre
123124 comments_mode: comments_mode
124125 file_path: file_path
125126 file_base: os.base (file_path)
127+ file_idx: file_idx
126128 }
127129 s.scan_all_tokens_in_buffer ()
128130 return s
@@ -186,26 +188,28 @@ fn (mut s Scanner) new_token(tok_kind token.Kind, lit string, len int) token.Tok
186188 max_column = 1
187189 }
188190 return token.Token{
189- kind: tok_kind
190- lit: lit
191- line_nr: s.line_nr + line_offset
192- col: max_column
193- pos: s.pos - len + 1
194- len: len
195- tidx: cidx
191+ kind: tok_kind
192+ lit: lit
193+ line_nr: s.line_nr + line_offset
194+ col: max_column
195+ pos: s.pos - len + 1
196+ len: len
197+ tidx: cidx
198+ file_idx: s.file_idx
196199 }
197200}
198201
199202@[inline]
200203fn (s &Scanner) new_eof_token () token.Token {
201204 return token.Token{
202- kind: .eof
203- lit: ''
204- line_nr: s.line_nr + 1
205- col: s.current_column ()
206- pos: s.pos
207- len: 1
208- tidx: s.tidx
205+ kind: .eof
206+ lit: ''
207+ line_nr: s.line_nr + 1
208+ col: s.current_column ()
209+ pos: s.pos
210+ len: 1
211+ tidx: s.tidx
212+ file_idx: s.file_idx
209213 }
210214}
211215
@@ -218,13 +222,14 @@ fn (mut s Scanner) new_multiline_token(tok_kind token.Kind, lit string, len int,
218222 max_column = 1
219223 }
220224 return token.Token{
221- kind: tok_kind
222- lit: lit
223- line_nr: start_line + 1
224- col: max_column
225- pos: s.pos - len + 1
226- len: len
227- tidx: cidx
225+ kind: tok_kind
226+ lit: lit
227+ line_nr: start_line + 1
228+ col: max_column
229+ pos: s.pos - len + 1
230+ len: len
231+ tidx: cidx
232+ file_idx: s.file_idx
228233 }
229234}
230235
@@ -945,10 +950,11 @@ pub fn (mut s Scanner) text_scan() token.Token {
945950 comment := s.text[start - 1 ..s.pos].trim_space ()
946951 if s.line_nr != 1 {
947952 comment_pos := token.Pos{
948- line_nr: s.line_nr - 1
949- len: comment.len
950- pos: start
951- col: s.current_column () - comment.len
953+ line_nr: s.line_nr - 1
954+ len: comment.len
955+ pos: start
956+ col: s.current_column () - comment.len
957+ file_idx: s.file_idx
952958 }
953959 s.error_with_pos ('a shebang is only valid at the top of the file' ,
954960 comment_pos)
@@ -1122,10 +1128,11 @@ pub fn (mut s Scanner) text_scan() token.Token {
11221128 mut comment := s.text[start..(s.pos - 1 )]
11231129 if ! comment.contains ('\n ' ) {
11241130 comment_pos := token.Pos{
1125- line_nr: start_line
1126- len: comment.len + 4
1127- pos: start
1128- col: s.current_column () - comment.len - 4
1131+ line_nr: start_line
1132+ len: comment.len + 4
1133+ pos: start
1134+ col: s.current_column () - comment.len - 4
1135+ file_idx: s.file_idx
11291136 }
11301137 s.error_with_pos ('inline comment is deprecated, please use line comment' ,
11311138 comment_pos)
@@ -1193,9 +1200,10 @@ pub fn (mut s Scanner) ident_string() string {
11931200 s.is_nested_string = false
11941201 }
11951202 lspos := token.Pos{
1196- line_nr: s.line_nr
1197- pos: s.pos
1198- col: s.pos - s.last_nl_pos - 1
1203+ line_nr: s.line_nr
1204+ pos: s.pos
1205+ col: s.pos - s.last_nl_pos - 1
1206+ file_idx: s.file_idx
11991207 }
12001208 q := s.text[s.pos]
12011209 is_quote := q in [single_quote, double_quote]
@@ -1511,9 +1519,10 @@ fn trim_slash_line_break(s string) string {
15111519// / escaped utf8 runes in octal like `\342\230\205` => (★)
15121520pub fn (mut s Scanner) ident_char () string {
15131521 lspos := token.Pos{
1514- line_nr: s.line_nr
1515- pos: s.pos
1516- col: s.pos - s.last_nl_pos - 1
1522+ line_nr: s.line_nr
1523+ pos: s.pos
1524+ col: s.pos - s.last_nl_pos - 1
1525+ file_idx: s.file_idx
15171526 }
15181527
15191528 start := s.pos // the string position of the first backtick char
@@ -1669,9 +1678,10 @@ fn (mut s Scanner) inc_line_number() {
16691678
16701679pub fn (mut s Scanner) current_pos () token.Pos {
16711680 return token.Pos{
1672- line_nr: s.line_nr
1673- pos: s.pos
1674- col: s.current_column () - 1
1681+ line_nr: s.line_nr
1682+ pos: s.pos
1683+ col: s.current_column () - 1
1684+ file_idx: s.file_idx
16751685 }
16761686}
16771687
@@ -1681,8 +1691,9 @@ pub fn (mut s Scanner) note(msg string) {
16811691 return
16821692 }
16831693 pos := token.Pos{
1684- line_nr: s.line_nr
1685- pos: s.pos
1694+ line_nr: s.line_nr
1695+ pos: s.pos
1696+ file_idx: s.file_idx
16861697 }
16871698 if s.pref.output_mode == .stdout && ! s.pref.check_only {
16881699 util.show_compiler_message ('notice:' , pos: pos, file_path: s.file_path, message: msg)
0 commit comments