From b9cbb4f177eb373a8c633a3f7c4b27aa39e3d65e Mon Sep 17 00:00:00 2001 From: Ned Palacios <7358345+nedpals@users.noreply.github.com> Date: Tue, 23 Mar 2021 15:51:09 +0800 Subject: [PATCH] scanner: fix eof token position (#9432) --- vlib/v/parser/tests/fn_decl_unexpected_eof.out | 3 +++ vlib/v/parser/tests/fn_decl_unexpected_eof.vv | 1 + vlib/v/scanner/scanner.v | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 vlib/v/parser/tests/fn_decl_unexpected_eof.out create mode 100644 vlib/v/parser/tests/fn_decl_unexpected_eof.vv diff --git a/vlib/v/parser/tests/fn_decl_unexpected_eof.out b/vlib/v/parser/tests/fn_decl_unexpected_eof.out new file mode 100644 index 0000000000..aef33f63c2 --- /dev/null +++ b/vlib/v/parser/tests/fn_decl_unexpected_eof.out @@ -0,0 +1,3 @@ +vlib/v/parser/tests/fn_decl_unexpected_eof.vv:1:12: error: unexpected eof, expecting `}` + 1 | fn main() { + | ^ diff --git a/vlib/v/parser/tests/fn_decl_unexpected_eof.vv b/vlib/v/parser/tests/fn_decl_unexpected_eof.vv new file mode 100644 index 0000000000..fd74173764 --- /dev/null +++ b/vlib/v/parser/tests/fn_decl_unexpected_eof.vv @@ -0,0 +1 @@ +fn main() { \ No newline at end of file diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 4768171747..73e37c18f2 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -191,7 +191,7 @@ fn (s &Scanner) new_eof_token() token.Token { kind: .eof lit: '' line_nr: s.line_nr + 1 - col: 1 + col: s.current_column() pos: s.pos len: 1 tidx: s.tidx @@ -576,7 +576,7 @@ pub fn (mut s Scanner) buffer_scan() token.Token { } return s.all_tokens[cidx] } - return s.new_token(.eof, '', 1) + return s.new_eof_token() } [inline]