parser: update p.inside_or_expr consistently (fix `v fmt -w vls/analyzer/symbol_registration.v`)

pull/12236/head
Delyan Angelov 2021-10-19 13:33:02 +03:00
parent 6aca360507
commit f2cda1a529
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,40 @@
module analyzer
import os
const (
mut_struct_keyword = 'mut:'
pub_struct_keyword = 'pub:'
pub_mut_struct_keyword = 'pub mut:'
global_struct_keyword = '__global:'
)
struct SymbolRegistration {
mut:
store &Store = &Store(0)
cursor TreeCursor
module_name string
src_text []byte
// skips the local scopes and registers only
// the top-level ones regardless of its
// visibility
is_import bool
is_script bool
first_var_decl_pos C.TSRange
}
fn (mut sr SymbolRegistration) struct_field_decl(field_access SymbolAccess, field_decl_node C.TSNode) &Symbol {
field_type_node := field_decl_node.child_by_field_name('type')
field_name_node := field_decl_node.child_by_field_name('name')
field_typ := sr.store.find_symbol_by_type_node(field_type_node, sr.src_text) or { void_type }
return &Symbol{
name: field_name_node.get_text(sr.src_text)
kind: .field
range: field_name_node.range()
access: field_access
return_type: field_typ
is_top_level: true
file_path: sr.store.cur_file_path
file_version: sr.store.cur_version
}
}

View File

@ -492,6 +492,8 @@ fn (mut p Parser) infix_expr(left ast.Expr) ast.Expr {
// allow `x := <-ch or {...}` to handle closed channel // allow `x := <-ch or {...}` to handle closed channel
if op == .arrow { if op == .arrow {
if p.tok.kind == .key_orelse { if p.tok.kind == .key_orelse {
was_inside_or_expr := p.inside_or_expr
p.inside_or_expr = true
p.next() p.next()
p.open_scope() p.open_scope()
p.scope.register(ast.Var{ p.scope.register(ast.Var{
@ -505,6 +507,7 @@ fn (mut p Parser) infix_expr(left ast.Expr) ast.Expr {
or_stmts = p.parse_block_no_scope(false) or_stmts = p.parse_block_no_scope(false)
or_pos = or_pos.extend(p.prev_tok.position()) or_pos = or_pos.extend(p.prev_tok.position())
p.close_scope() p.close_scope()
p.inside_or_expr = was_inside_or_expr
} }
if p.tok.kind == .question { if p.tok.kind == .question {
p.next() p.next()
@ -595,6 +598,8 @@ fn (mut p Parser) prefix_expr() ast.Expr {
// allow `x := <-ch or {...}` to handle closed channel // allow `x := <-ch or {...}` to handle closed channel
if op == .arrow { if op == .arrow {
if p.tok.kind == .key_orelse { if p.tok.kind == .key_orelse {
was_inside_or_expr := p.inside_or_expr
p.inside_or_expr = true
p.next() p.next()
p.open_scope() p.open_scope()
p.scope.register(ast.Var{ p.scope.register(ast.Var{
@ -608,6 +613,7 @@ fn (mut p Parser) prefix_expr() ast.Expr {
or_stmts = p.parse_block_no_scope(false) or_stmts = p.parse_block_no_scope(false)
or_pos = or_pos.extend(p.prev_tok.position()) or_pos = or_pos.extend(p.prev_tok.position())
p.close_scope() p.close_scope()
p.inside_or_expr = was_inside_or_expr
} }
if p.tok.kind == .question { if p.tok.kind == .question {
p.next() p.next()

View File

@ -2338,6 +2338,7 @@ fn (mut p Parser) index_expr(left ast.Expr) ast.IndexExpr {
// a[i] or { ... } // a[i] or { ... }
if p.tok.kind == .key_orelse { if p.tok.kind == .key_orelse {
was_inside_or_expr := p.inside_or_expr was_inside_or_expr := p.inside_or_expr
p.inside_or_expr = true
or_pos = p.tok.position() or_pos = p.tok.position()
p.next() p.next()
p.open_scope() p.open_scope()
@ -2442,6 +2443,8 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr {
mut or_kind := ast.OrKind.absent mut or_kind := ast.OrKind.absent
mut or_pos := p.tok.position() mut or_pos := p.tok.position()
if p.tok.kind == .key_orelse { if p.tok.kind == .key_orelse {
was_inside_or_expr := p.inside_or_expr
p.inside_or_expr = true
p.next() p.next()
p.open_scope() p.open_scope()
p.scope.register(ast.Var{ p.scope.register(ast.Var{
@ -2455,6 +2458,7 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr {
or_stmts = p.parse_block_no_scope(false) or_stmts = p.parse_block_no_scope(false)
or_pos = or_pos.extend(p.prev_tok.position()) or_pos = or_pos.extend(p.prev_tok.position())
p.close_scope() p.close_scope()
p.inside_or_expr = was_inside_or_expr
} }
// `foo()?` // `foo()?`
if p.tok.kind == .question { if p.tok.kind == .question {