diff options
author | Adam Scarr <adam@vektah.net> | 2017-08-09 21:18:14 +1000 |
---|---|---|
committer | Adam Scarr <adam@vektah.net> | 2017-08-09 21:19:41 +1000 |
commit | 47badae641b9cd8862f327864d2143a57b8e30af (patch) | |
tree | 930e6621051ec4da5e4fd028f98447e88978837d /html | |
parent | 8b2f10f2384c1efe4492f68b055415be6ead3f0e (diff) |
Add godoc
Diffstat (limited to 'html')
-rw-r--r-- | html/html.go | 20 | ||||
-rw-r--r-- | html/html_test.go | 2 |
2 files changed, 11 insertions, 11 deletions
diff --git a/html/html.go b/html/html.go index 6d1a2d3..01ae9c4 100644 --- a/html/html.go +++ b/html/html.go @@ -4,8 +4,8 @@ import ( . "github.com/vektah/goparsify" ) -func Parse(input string) (result interface{}, remaining string, err error) { - return ParseString(tag, input) +func Parse(input string) (result interface{}, err error) { + return Run(tag, input) } type Tag struct { @@ -18,28 +18,28 @@ var ( tag Parser identifier = NoAutoWS(Merge(Seq(WS(), Chars("a-zA-Z", 1), Chars("a-zA-Z0-9", 0)))) - text = Map(NotChars("<>"), func(n Node) Node { - return Node{Result: n.Token} + text = Map(NotChars("<>"), func(n Result) Result { + return Result{Result: n.Token} }) element = Any(text, &tag) - elements = Map(Some(element), func(n Node) Node { + elements = Map(Some(element), func(n Result) Result { ret := []interface{}{} for _, child := range n.Child { ret = append(ret, child.Result) } - return Node{Result: ret} + return Result{Result: ret} }) attr = Seq(identifier, "=", StringLit(`"'`)) - attrs = Map(Some(attr), func(node Node) Node { + attrs = Map(Some(attr), func(node Result) Result { attr := map[string]string{} for _, attrNode := range node.Child { attr[attrNode.Child[0].Token] = attrNode.Child[2].Result.(string) } - return Node{Result: attr} + return Result{Result: attr} }) tstart = Seq("<", identifier, attrs, ">") @@ -47,9 +47,9 @@ var ( ) func init() { - tag = Map(Seq(tstart, elements, tend), func(node Node) Node { + tag = Map(Seq(tstart, elements, tend), func(node Result) Result { openTag := node.Child[0] - return Node{Result: Tag{ + return Result{Result: Tag{ Name: openTag.Child[1].Token, Attributes: openTag.Child[2].Result.(map[string]string), Body: node.Child[1].Result.([]interface{}), diff --git a/html/html_test.go b/html/html_test.go index f2f8e6f..f614b4d 100644 --- a/html/html_test.go +++ b/html/html_test.go @@ -7,7 +7,7 @@ import ( ) func TestParse(t *testing.T) { - result, _, err := Parse(`<body>hello <p color="blue">world</p></body>`) + result, err := Parse(`<body>hello <p color="blue">world</p></body>`) require.NoError(t, err) require.Equal(t, Tag{Name: "body", Attributes: map[string]string{}, Body: []interface{}{ "hello ", |