summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Lavine <nlavine@haverford.edu>2011-09-21 15:46:44 -0400
committerNoah Lavine <nlavine@haverford.edu>2011-09-21 15:46:44 -0400
commit265ac5640a79d5536b9664f70a921fadbed093ad (patch)
treebd0cffd01c8d49476c0a4ba2a237920983ff1264
parentc9502660c5259a06ccc16fb882f2ac71ce101bfa (diff)
downloadguile-wip-peg-fixed.tar.gz
Document PEGs at Runtimewip-peg-fixed
doc/ref/api-peg.texi: suggest a cleaner method of generating PEG parsers at runtime.
-rw-r--r--doc/ref/api-peg.texi26
1 files changed, 15 insertions, 11 deletions
diff --git a/doc/ref/api-peg.texi b/doc/ref/api-peg.texi
index a489268a9..89444411c 100644
--- a/doc/ref/api-peg.texi
+++ b/doc/ref/api-peg.texi
@@ -281,17 +281,6 @@ Note that in doing this, we have bound 6 variables at the toplevel
@var{as-or-bs-tag}).
@end deffn
-These are macros, with all that entails. If you've built up a list at
-runtime and want to define a new PEG from it, you should e.g.:
-@lisp
-(define exp '(+ "a"))
-(eval `(define-nonterm as body ,exp) (interaction-environment))
-@end lisp
-The @code{eval} function has a bad reputation with regard to efficiency,
-but this is mostly because of the extra work that has to be done
-compiling the expressions, which has to be done anyway when compiling
-the PEGs at runtime.
-
@subsubheading Compile Functions
It is sometimes useful to be able to compile anonymous PEG patterns at
runtime. These functions let you do that using either syntax.
@@ -309,6 +298,21 @@ Compiles the PEG pattern in @var{peg-sexp} propagating according to
@code{define-nonterm}).
@end deffn
+The functions return syntax objects, which can be useful if you want to
+use them in macros. If all you want is to define a new nonterminal, you
+can do the following:
+
+@lisp
+(define exp '(+ "a"))
+(define as (compile (peg-sexp-compile exp 'body)))
+@end lisp
+
+You can use this nonterminal with all of the regular PEG functions:
+
+@lisp
+(peg-parse as "aaaaa") @result{}
+#<peg start: 0 end: 5 string: bbbbb tree: bbbbb>
+@end lisp
@subsubheading Parsing & Matching Functions