Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tolerate missing field tags #246

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading