summaryrefslogtreecommitdiff
path: root/examples_test.go
diff options
context:
space:
mode:
authorAdam Scarr <adam@vektah.net>2017-08-10 21:58:14 +1000
committerAdam Scarr <adam@vektah.net>2017-08-10 22:01:06 +1000
commita0e66b1c46ec57218f8a95a21ace7cbbceb29ec2 (patch)
tree630056d07ca6b44f7a747b7872ba422c6c301d85 /examples_test.go
parentaf542eff9e1e51561a9efa37685ee07b1d01b53e (diff)
Document cuts
Diffstat (limited to 'examples_test.go')
-rw-r--r--examples_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/examples_test.go b/examples_test.go
new file mode 100644
index 0000000..a1de129
--- /dev/null
+++ b/examples_test.go
@@ -0,0 +1,24 @@
+package goparsify_test
+
+import (
+ "fmt"
+
+ . "github.com/vektah/goparsify"
+)
+
+func ExampleCuts() {
+ // without a cut if the close tag is left out the parser will backtrack and ignore the rest of the string
+ alpha := Chars("a-z")
+ nocut := Many(Any(Seq("<", alpha, ">"), alpha))
+ _, err := Run(nocut, "asdf <foo")
+ fmt.Println(err.Error())
+
+ // with a cut, once we see the open tag we know there must be a close tag that matches it, so the parser will error
+ cut := Many(Any(Seq("<", Cut, alpha, ">"), alpha))
+ _, err = Run(cut, "asdf <foo")
+ fmt.Println(err.Error())
+
+ // Output:
+ // left unparsed: <foo
+ // offset 9: expected >
+}