diff options
author | Adam Scarr <adam@vektah.net> | 2017-08-06 23:32:10 +1000 |
---|---|---|
committer | Adam Scarr <adam@vektah.net> | 2017-08-06 23:32:10 +1000 |
commit | 666ea93dba377f267a2c8ecf97378a420db18383 (patch) | |
tree | 5efee0b6e4ccf44b854d9bb65e4e6fa5e7f86548 /html/html.go | |
parent | 9d7779e8ca5404f26abbd8cce0314d9cee967bba (diff) |
Eliminate a bunch of allocations
Diffstat (limited to 'html/html.go')
-rw-r--r-- | html/html.go | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/html/html.go b/html/html.go index adee935..847af96 100644 --- a/html/html.go +++ b/html/html.go @@ -2,32 +2,32 @@ package html import . "github.com/vektah/goparsify" -func Parse(input string) (result Node, remaining string, err error) { +func Parse(input string) (result interface{}, remaining string, err error) { return ParseString(tag, input) } type Tag struct { Name string Attributes map[string]string - Body []Node + Body []interface{} } var ( tag Parser - identifier = Merge(And(Range("a-z", 1, 1), Range("a-zA-Z0-9", 0))) - text = CharRunUntil("<>") + identifier = Merge(And(Chars("a-z", 1, 1), Chars("a-zA-Z0-9", 0))) + text = NotChars("<>") element = Any(text, &tag) elements = Kleene(element) //attr := And(identifier, equal, String()) attr = And(WS, identifier, WS, "=", WS, Any(String('"'), String('\''))) - attrs = Map(Kleene(attr, WS), func(node Node) Node { - nodes := node.([]Node) + attrs = Map(Kleene(attr, WS), func(node interface{}) interface{} { + nodes := node.([]interface{}) attr := map[string]string{} for _, attrNode := range nodes { - attrNodes := attrNode.([]Node) + attrNodes := attrNode.([]interface{}) attr[attrNodes[0].(string)] = attrNodes[2].(string) } @@ -39,13 +39,13 @@ var ( ) func init() { - tag = Map(And(tstart, elements, tend), func(node Node) Node { - nodes := node.([]Node) - openTag := nodes[0].([]Node) + tag = Map(And(tstart, elements, tend), func(node interface{}) interface{} { + nodes := node.([]interface{}) + openTag := nodes[0].([]interface{}) return Tag{ Name: openTag[1].(string), Attributes: openTag[2].(map[string]string), - Body: nodes[1].([]Node), + Body: nodes[1].([]interface{}), } }) |