File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -153,7 +153,8 @@ pub enum AttributeKind {
153153 plain // [name]
154154 string // ['name']
155155 number // [123]
156- comptime_define // [if name]
156+ bool // [true] || [false]
157+ comptime_define // [if name]
157158}
158159
159160pub struct VAttribute {
Original file line number Diff line number Diff line change @@ -2045,7 +2045,7 @@ fn (mut p Parser) parse_attr(is_at bool) ast.Attr {
20452045 if p.tok.kind == .colon {
20462046 has_arg = true
20472047 p.next ()
2048- if p.tok.kind == .name || (p.tok.kind != .string && token. is_key (p.tok.lit)) { // `name: arg`
2048+ if p.tok.kind == .name { // `name: arg`
20492049 kind = .plain
20502050 arg = p.check_name ()
20512051 } else if p.tok.kind == .number { // `name: 123`
@@ -2060,6 +2060,9 @@ fn (mut p Parser) parse_attr(is_at bool) ast.Attr {
20602060 kind = .bool
20612061 arg = p.tok.kind.str ()
20622062 p.next ()
2063+ } else if token.is_key (p.tok.lit) { // // `name: keyword`
2064+ kind = .plain
2065+ arg = p.check_name ()
20632066 } else {
20642067 p.unexpected (additional_msg: 'an argument is expected after `:`' )
20652068 }
Original file line number Diff line number Diff line change 1+ @[foo: true ]
12@[name: 'abc' ]
23@[amount: 2 ]
34@[abc]
@@ -26,8 +27,19 @@ fn test_attributes() {
2627 } else if attr.has_arg && attr.kind == .number {
2728 assert attr.name == 'amount'
2829 assert attr.arg == '2'
29- } else {
30+ } else if attr.kind != .bool {
3031 assert attr.name == 'abc'
3132 }
3233 }
3334}
35+
36+ fn test_attr_boolean () {
37+ mut bool_fields := []string {}
38+ $for attr in Abc.attributes {
39+ if attr.kind == .bool {
40+ bool_fields << attr.name
41+ }
42+ }
43+ assert bool_fields.len == 1
44+ assert bool_fields[0 ] == 'foo'
45+ }
You can’t perform that action at this time.
0 commit comments