mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: clean up parse_ident() (#18138)
This commit is contained in:
parent
3a06b55388
commit
87623b367c
@ -35,7 +35,7 @@ pub fn (mut p Parser) check_expr(precedence int) !ast.Expr {
|
|||||||
// Prefix
|
// Prefix
|
||||||
match p.tok.kind {
|
match p.tok.kind {
|
||||||
.key_mut, .key_shared, .key_atomic, .key_static, .key_volatile {
|
.key_mut, .key_shared, .key_atomic, .key_static, .key_volatile {
|
||||||
ident := p.parse_ident(ast.Language.v)
|
ident := p.ident(ast.Language.v)
|
||||||
node = ident
|
node = ident
|
||||||
if p.inside_defer {
|
if p.inside_defer {
|
||||||
if !p.defer_vars.any(it.name == ident.name && it.mod == ident.mod)
|
if !p.defer_vars.any(it.name == ident.name && it.mod == ident.mod)
|
||||||
|
@ -2119,7 +2119,7 @@ fn (mut p Parser) parse_multi_expr(is_top_level bool) ast.Stmt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut p Parser) parse_ident(language ast.Language) ast.Ident {
|
pub fn (mut p Parser) ident(language ast.Language) ast.Ident {
|
||||||
is_option := p.tok.kind == .question && p.peek_tok.kind == .lsbr
|
is_option := p.tok.kind == .question && p.peek_tok.kind == .lsbr
|
||||||
if is_option {
|
if is_option {
|
||||||
p.next()
|
p.next()
|
||||||
@ -2537,7 +2537,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
|
|||||||
} else if p.peek_tok.kind == .dot && p.peek_token(2).kind != .eof
|
} else if p.peek_tok.kind == .dot && p.peek_token(2).kind != .eof
|
||||||
&& p.peek_token(2).lit.len == 0 {
|
&& p.peek_token(2).lit.len == 0 {
|
||||||
// incomplete module selector must be handled by dot_expr instead
|
// incomplete module selector must be handled by dot_expr instead
|
||||||
ident := p.parse_ident(language)
|
ident := p.ident(language)
|
||||||
node = ident
|
node = ident
|
||||||
if p.inside_defer {
|
if p.inside_defer {
|
||||||
if !p.defer_vars.any(it.name == ident.name && it.mod == ident.mod)
|
if !p.defer_vars.any(it.name == ident.name && it.mod == ident.mod)
|
||||||
@ -2568,7 +2568,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
|
|||||||
same_line := p.tok.line_nr == p.peek_tok.line_nr
|
same_line := p.tok.line_nr == p.peek_tok.line_nr
|
||||||
// `(` must be on same line as name token otherwise it's a ParExpr
|
// `(` must be on same line as name token otherwise it's a ParExpr
|
||||||
if !same_line && p.peek_tok.kind == .lpar {
|
if !same_line && p.peek_tok.kind == .lpar {
|
||||||
ident := p.parse_ident(language)
|
ident := p.ident(language)
|
||||||
node = ident
|
node = ident
|
||||||
if p.inside_defer {
|
if p.inside_defer {
|
||||||
if !p.defer_vars.any(it.name == ident.name && it.mod == ident.mod)
|
if !p.defer_vars.any(it.name == ident.name && it.mod == ident.mod)
|
||||||
@ -2774,7 +2774,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
|
|||||||
} else if is_option && p.tok.kind == .lsbr {
|
} else if is_option && p.tok.kind == .lsbr {
|
||||||
return p.array_init(is_option)
|
return p.array_init(is_option)
|
||||||
}
|
}
|
||||||
ident := p.parse_ident(language)
|
ident := p.ident(language)
|
||||||
node = ident
|
node = ident
|
||||||
if p.inside_defer {
|
if p.inside_defer {
|
||||||
if !p.defer_vars.any(it.name == ident.name && it.mod == ident.mod)
|
if !p.defer_vars.any(it.name == ident.name && it.mod == ident.mod)
|
||||||
|
Loading…
Reference in New Issue
Block a user