diff options
author | Noah Lavine <nlavine@haverford.edu> | 2011-09-21 15:46:44 -0400 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2013-01-16 10:11:48 +0100 |
commit | ecaa261a2006a51a510c640b544350ce895fc2f3 (patch) | |
tree | 3c219db55d722833a8a0e1ae939a8943adfe5da9 /doc/ref/api-peg.texi | |
parent | e0d140251a1385ba88abd631d62e317ffab3487f (diff) | |
download | guile-ecaa261a2006a51a510c640b544350ce895fc2f3.tar.gz |
Document PEGs at Runtime
doc/ref/api-peg.texi: suggest a cleaner method of generating PEG parsers
at runtime.
Diffstat (limited to 'doc/ref/api-peg.texi')
-rw-r--r-- | doc/ref/api-peg.texi | 26 |
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 |