zclwrite: populate EOLTokens when parsing attributes

This commit is contained in:
Martin Atkins 2017-06-10 16:06:09 -07:00
parent 1565d4f906
commit 948b2e0b7b
2 changed files with 23 additions and 3 deletions

View File

@ -194,8 +194,6 @@ func parseBodyItem(nativeItem zclsyntax.Node, from inputTokens) (inputTokens, No
switch tItem := nativeItem.(type) {
case *zclsyntax.Attribute:
item = parseAttribute(tItem, within, leadComments, lineComments, newline)
// TODO: Grab the newline and any line comment from "after" and
// write them into the attribute object.
case *zclsyntax.Block:
// TODO: implement this
panic("block parsing not yet implemented")
@ -243,7 +241,8 @@ func parseAttribute(nativeAttr *zclsyntax.Attribute, from, leadComments, lineCom
}
if newline.Len() > 0 {
allTokens = append(allTokens, newline.Seq())
attr.EOLTokens = newline.Seq()
allTokens = append(allTokens, attr.EOLTokens)
}
// Collect any stragglers, though there shouldn't be any

View File

@ -89,6 +89,13 @@ func TestParse(t *testing.T) {
},
}},
},
EOLTokens: &TokenSeq{Tokens{
{
Type: zclsyntax.TokenNewline,
Bytes: []byte{'\n'},
SpacesBefore: 0,
},
}},
},
},
AllTokens: &TokenSeq{
@ -215,6 +222,13 @@ func TestParse(t *testing.T) {
},
}},
},
EOLTokens: &TokenSeq{Tokens{
{
Type: zclsyntax.TokenNewline,
Bytes: []byte{'\n'},
SpacesBefore: 0,
},
}},
},
},
AllTokens: &TokenSeq{
@ -451,6 +465,13 @@ func TestParse(t *testing.T) {
},
}},
},
EOLTokens: &TokenSeq{Tokens{
{
Type: zclsyntax.TokenNewline,
Bytes: []byte{'\n'},
SpacesBefore: 0,
},
}},
},
},
AllTokens: &TokenSeq{