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:
parent
b52c98ac43
commit
f3c5f36317
@ -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()
|
||||
}
|
||||
|
@ -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}'
|
||||
}
|
Loading…
Reference in New Issue
Block a user