Skip to content

Commit

Permalink
Tolerate missing field tags (#246)
Browse files Browse the repository at this point in the history
While still returning an error. See
#200
Note that the error occurs during validation instead of parsing to
eventually allow algorithmic field tag assignments.
  • Loading branch information
Alfus authored Mar 1, 2024
1 parent 31b173d commit f4c4a6f
Show file tree
Hide file tree
Showing 6 changed files with 869 additions and 522 deletions.
70 changes: 50 additions & 20 deletions ast/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ func NewFieldNode(label *KeywordNode, fieldType IdentValueNode, name *IdentNode,
if name == nil {
panic("name is nil")
}
if equals == nil {
panic("equals is nil")
numChildren := 2
if equals != nil {
numChildren++
}
if tag == nil {
panic("tag is nil")
if tag != nil {
numChildren++
}
numChildren := 4
if semicolon != nil {
numChildren++
}
Expand All @@ -104,7 +104,13 @@ func NewFieldNode(label *KeywordNode, fieldType IdentValueNode, name *IdentNode,
if label != nil {
children = append(children, label)
}
children = append(children, fieldType, name, equals, tag)
children = append(children, fieldType, name)
if equals != nil {
children = append(children, equals)
}
if tag != nil {
children = append(children, tag)
}
if opts != nil {
children = append(children, opts)
}
Expand Down Expand Up @@ -145,6 +151,9 @@ func (n *FieldNode) FieldType() Node {
}

func (n *FieldNode) FieldTag() Node {
if n.Tag == nil {
return n
}
return n.Tag
}

Expand Down Expand Up @@ -237,30 +246,36 @@ func NewGroupNode(label *KeywordNode, keyword *KeywordNode, name *IdentNode, equ
if name == nil {
panic("name is nil")
}
if equals == nil {
panic("equals is nil")
}
if tag == nil {
panic("tag is nil")
}
if openBrace == nil {
panic("openBrace is nil")
}
if closeBrace == nil {
panic("closeBrace is nil")
}
numChildren := 6 + len(decls)
numChildren := 4 + len(decls)
if label != nil {
numChildren++
}
if equals != nil {
numChildren++
}
if tag != nil {
numChildren++
}
if opts != nil {
numChildren++
}
children := make([]Node, 0, numChildren)
if label != nil {
children = append(children, label)
}
children = append(children, keyword, name, equals, tag)
children = append(children, keyword, name)
if equals != nil {
children = append(children, equals)
}
if tag != nil {
children = append(children, tag)
}
if opts != nil {
children = append(children, opts)
}
Expand Down Expand Up @@ -302,6 +317,9 @@ func (n *GroupNode) FieldType() Node {
}

func (n *GroupNode) FieldTag() Node {
if n.Tag == nil {
return n
}
return n.Tag
}

Expand Down Expand Up @@ -537,21 +555,27 @@ func NewMapFieldNode(mapType *MapTypeNode, name *IdentNode, equals *RuneNode, ta
if name == nil {
panic("name is nil")
}
if equals == nil {
panic("equals is nil")
numChildren := 2
if equals != nil {
numChildren++
}
if tag == nil {
panic("tag is nil")
if tag != nil {
numChildren++
}
numChildren := 4
if opts != nil {
numChildren++
}
if semicolon != nil {
numChildren++
}
children := make([]Node, 0, numChildren)
children = append(children, mapType, name, equals, tag)
children = append(children, mapType, name)
if equals != nil {
children = append(children, equals)
}
if tag != nil {
children = append(children, tag)
}
if opts != nil {
children = append(children, opts)
}
Expand Down Expand Up @@ -585,6 +609,9 @@ func (n *MapFieldNode) FieldType() Node {
}

func (n *MapFieldNode) FieldTag() Node {
if n.Tag == nil {
return n
}
return n.Tag
}

Expand Down Expand Up @@ -660,6 +687,9 @@ func (n *SyntheticMapField) FieldType() Node {
}

func (n *SyntheticMapField) FieldTag() Node {
if n.Tag == nil {
return n
}
return n.Tag
}

Expand Down
Loading

0 comments on commit f4c4a6f

Please sign in to comment.