vls,parser: fix an eof error in parsing invalid const declarations (#7115)
parent
15ffce1317
commit
6c100a0bc3
|
@ -95,11 +95,14 @@ pub fn parse_comptime(text string, table &table.Table, pref &pref.Preferences, s
|
||||||
return p.parse()
|
return p.parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_text(text string, table &table.Table, comments_mode scanner.CommentsMode, pref &pref.Preferences, global_scope &ast.Scope) ast.File {
|
pub fn parse_text(text string, path string, table &table.Table, comments_mode scanner.CommentsMode, pref &pref.Preferences, global_scope &ast.Scope) ast.File {
|
||||||
s := scanner.new_scanner(text, comments_mode, pref)
|
s := scanner.new_scanner(text, comments_mode, pref)
|
||||||
mut p := Parser{
|
mut p := Parser{
|
||||||
scanner: s
|
scanner: s
|
||||||
comments_mode: comments_mode
|
comments_mode: comments_mode
|
||||||
|
file_name: path
|
||||||
|
file_base: os.base(path)
|
||||||
|
file_name_dir: os.dir(path)
|
||||||
table: table
|
table: table
|
||||||
pref: pref
|
pref: pref
|
||||||
scope: &ast.Scope{
|
scope: &ast.Scope{
|
||||||
|
@ -1708,14 +1711,20 @@ fn (mut p Parser) const_decl() ast.ConstDecl {
|
||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
end_pos := p.tok.position()
|
end_pos := p.tok.position()
|
||||||
|
const_pos := p.tok.position()
|
||||||
p.check(.key_const)
|
p.check(.key_const)
|
||||||
if p.tok.kind != .lpar {
|
if p.tok.kind != .lpar {
|
||||||
p.error('consts must be grouped, e.g.\nconst (\n\ta = 1\n)')
|
p.error_with_pos('const declaration is missing parentheses `( ... )`', const_pos)
|
||||||
|
return ast.ConstDecl{}
|
||||||
}
|
}
|
||||||
p.next() // (
|
p.next() // (
|
||||||
mut fields := []ast.ConstField{}
|
mut fields := []ast.ConstField{}
|
||||||
mut comments := []ast.Comment{}
|
mut comments := []ast.Comment{}
|
||||||
for {
|
for {
|
||||||
|
if p.tok.kind == .eof {
|
||||||
|
p.error_with_pos('const declaration is missing closing `)`', const_pos)
|
||||||
|
return ast.ConstDecl{}
|
||||||
|
}
|
||||||
comments = p.eat_comments()
|
comments = p.eat_comments()
|
||||||
if p.tok.kind == .rpar {
|
if p.tok.kind == .rpar {
|
||||||
break
|
break
|
||||||
|
|
|
@ -231,10 +231,13 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if p.tok.kind != .eof {
|
||||||
|
// eof should be handled where it happens
|
||||||
p.error_with_pos('invalid expression: unexpected $p.tok.kind.str() token',
|
p.error_with_pos('invalid expression: unexpected $p.tok.kind.str() token',
|
||||||
p.tok.position())
|
p.tok.position())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return p.expr_with_left(node, precedence, is_stmt_ident)
|
return p.expr_with_left(node, precedence, is_stmt_ident)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue