1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: allow for struct Abc { f [skip] = -1 }

This commit is contained in:
Delyan Angelov 2020-05-29 12:44:49 +03:00
parent b52c98ac43
commit f3c5f36317
2 changed files with 30 additions and 7 deletions

View File

@ -114,6 +114,13 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
println('XXXX' + s.str())
}
*/
mut attrs := []string{}
if p.tok.kind == .lsbr {
parsed_attrs := p.attributes()
for attr in parsed_attrs {
attrs << attr.name
}
}
mut default_expr := ast.Expr{}
mut has_default_expr := false
if p.tok.kind == .assign {
@ -129,13 +136,6 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
}
has_default_expr = true
}
mut attrs := []string{}
if p.tok.kind == .lsbr {
parsed_attrs := p.attributes()
for attr in parsed_attrs {
attrs << attr.name
}
}
if p.tok.kind == .comment {
comment = p.comment()
}

View File

@ -0,0 +1,23 @@
import json
struct Foo {
x int = 123
bar int [skip] = -112233
y int = 456
}
fn test_check_field_default_expr() {
f := Foo{}
//eprintln('f: $f')
assert f.bar == -112233
assert f.x == 123
assert f.y == 456
}
fn test_check_field_skip_attribute() {
f := Foo{}
s := json.encode(f)
//eprintln('f: $f')
//eprintln('s: $s')
assert s == '{"x":123,"y":456}'
}