Skip to content

Commit 294be97

Browse files
doc/terml: More doc.
1 parent 9b1005f commit 294be97

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

doc/terml.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,20 @@ That's it! We've created an empty term, `Term`, with nothing inside.
2929
We can see that terms are not just `namedtuple` lookalikes. They have their
3030
own internals and store data in a slightly different and more structured way
3131
than a normal tuple.
32+
33+
Parsing Terms
34+
=============
35+
36+
Parsley can parse terms from streams. Terms can contain any kind of parseable
37+
data, including other terms. Returning to the ubiquitous calculator example::
38+
39+
add = Add(:x, :y) -> x + y
40+
41+
Here this rule matches a term called `Add` which has two components, bind
42+
those components to a couple of names (`x` and `y`), and return their sum. If
43+
this rule were applied to a term like `Add(3, 5)`, it would return 8.
44+
45+
Terms can be nested, too. Here's an example that performs a slightly contrived
46+
match on a negated term inside an addition::
47+
48+
add_negate = Add(:x, Negate(:y)) -> x - y

0 commit comments

Comments
 (0)