parser: fix parsing new attribute syntax in struct decl field (stage 1) (#19682)

This commit is contained in:
Joe C 2023-10-28 10:05:47 +11:00 committed by GitHub
parent b3b68e418d
commit 22e57d2f41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -267,7 +267,8 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
// Comments after type (same line) // Comments after type (same line)
prev_attrs := p.attrs prev_attrs := p.attrs
p.attrs = [] p.attrs = []
if p.tok.kind == .lsbr || p.tok.kind == .at { // TODO: remove once old syntax is no longer supported
if p.tok.kind == .lsbr {
p.inside_struct_attr_decl = true p.inside_struct_attr_decl = true
// attrs are stored in `p.attrs` // attrs are stored in `p.attrs`
p.attributes() p.attributes()
@ -294,6 +295,17 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
has_default_expr = true has_default_expr = true
comments << p.eat_comments() comments << p.eat_comments()
} }
if p.tok.kind == .at {
p.inside_struct_attr_decl = true
// attrs are stored in `p.attrs`
p.attributes()
for fa in p.attrs {
if fa.name == 'deprecated' {
is_field_deprecated = true
}
}
p.inside_struct_attr_decl = false
}
ast_fields << ast.StructField{ ast_fields << ast.StructField{
name: field_name name: field_name
typ: typ typ: typ