parser: improve syntax errors in module declarations
parent
6a7ef4f5b2
commit
5a231326d7
|
@ -1,5 +0,0 @@
|
|||
vlib/v/checker/tests/module_multiple_names_err.vv:1:13: error: `module x` can only declare one module
|
||||
1 | module main os
|
||||
| ~~
|
||||
2 | fn main() {
|
||||
3 | println('hello, world')
|
|
@ -1,5 +0,0 @@
|
|||
vlib/v/checker/tests/module_syntax_err.vv:1:12: error: `module x` syntax error
|
||||
1 | module main.os
|
||||
| ^
|
||||
2 | fn main() {
|
||||
3 | println('hello, world')
|
|
@ -1835,12 +1835,14 @@ fn (mut p Parser) module_decl() ast.Module {
|
|||
// as it creates a wrong position when extended
|
||||
// to module_pos
|
||||
n_pos := p.tok.position()
|
||||
if module_pos.line_nr == n_pos.line_nr && p.tok.kind != .comment {
|
||||
if p.tok.kind != .name {
|
||||
p.error_with_pos('`module x` syntax error', n_pos)
|
||||
if module_pos.line_nr == n_pos.line_nr && p.tok.kind != .comment && p.tok.kind != .eof {
|
||||
if p.tok.kind == .name {
|
||||
p.error_with_pos('`module $name`, you can only declare one module, unexpected `$p.tok.lit`',
|
||||
n_pos)
|
||||
return mod_node
|
||||
} else {
|
||||
p.error_with_pos('`module x` can only declare one module', n_pos)
|
||||
p.error_with_pos('`module $name`, unexpected `$p.tok.kind` after module name',
|
||||
n_pos)
|
||||
return mod_node
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
vlib/v/parser/tests/module_multiple_names_err.vv:1:13: error: `module main`, you can only declare one module, unexpected `os`
|
||||
1 | module main os
|
||||
| ~~
|
||||
2 | fn main() {
|
||||
3 | println('hello, world')
|
|
@ -0,0 +1,5 @@
|
|||
vlib/v/parser/tests/module_syntax_err.vv:1:12: error: `module main`, unexpected `.` after module name
|
||||
1 | module main.os
|
||||
| ^
|
||||
2 | fn main() {
|
||||
3 | println('hello, world')
|
Loading…
Reference in New Issue