Skip to content

Commit

Permalink
Implement comment tag
Browse files Browse the repository at this point in the history
  • Loading branch information
osteele committed Jun 27, 2017
1 parent c4bd99b commit eb7a18e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -14,7 +14,7 @@
- [x] Arrays
- [ ] Whitespace Control
- [ ] Tags
- [ ] Comment
- [x] Comment
- [ ] Control Flow
- [x] if/else/elsif
- [x] unless
Expand Down
25 changes: 16 additions & 9 deletions chunks/parser.go
Expand Up @@ -12,21 +12,28 @@ func Parse(chunks []Chunk) (ASTNode, error) {
ap *[]ASTNode
}
var (
root = &ASTSeq{}
ap = &root.Children // pointer to current node accumulation slice
ccd *controlTagDefinition
ccn *ASTControlTag
stack []frame // stack of control structures
root = &ASTSeq{}
ap = &root.Children // pointer to current node accumulation slice
ccd *controlTagDefinition
ccn *ASTControlTag
stack []frame // stack of control structures
inComment = false
)
for _, c := range chunks {
switch c.Type {
case ObjChunkType:
switch {
case inComment:
if c.Type == TagChunkType && c.Tag == "endcomment" {
inComment = false
}
case c.Type == ObjChunkType:
*ap = append(*ap, &ASTObject{Chunk: c})
case TextChunkType:
case c.Type == TextChunkType:
*ap = append(*ap, &ASTText{Chunk: c})
case TagChunkType:
case c.Type == TagChunkType:
if cd, ok := findControlTagDefinition(c.Tag); ok {
switch {
case c.Tag == "comment":
inComment = true
case cd.requiresParent() && !cd.compatibleParent(ccd):
suffix := ""
if ccd != nil {
Expand Down
3 changes: 3 additions & 0 deletions tags/tags_test.go
Expand Up @@ -16,6 +16,9 @@ var parseErrorTests = []struct{ in, expected string }{
}

var tagTests = []struct{ in, expected string }{
// TODO test whether this requires matching interior tags
{"{%comment%}{{a}}{%unknown%}{%endcomment%}", ""},

{"{%if true%}true{%endif%}", "true"},
{"{%if false%}false{%endif%}", ""},
{"{%if 0%}true{%endif%}", "true"},
Expand Down

0 comments on commit eb7a18e

Please sign in to comment.