(www.gnu.org) PEG Parsing (Guile Reference Manual)
ROAM_REFS: https://www.gnu.org/software/guile/manual/html_node/PEG-Parsing.html
* 6.15 PEG Parsing ΒΆ
Parsing Expression Grammars (PEGs) are a way of specifying formal languages for text processing. They can be used either for matching (like regular expressions) or for building recursive descent parsers (like lex/yacc). Guile uses a superset of PEG syntax that allows more control over what information is preserved during parsing.
Wikipedia has a clear and concise introduction to PEGs if you want to familiarize yourself with the syntax: http://en.wikipedia.org/wiki/Parsing_expression_grammar.
The
(ice-9 peg)module works by compiling PEGs down to lambda expressions. These can either be stored in variables at compile-time by the define macros (define-peg-patternanddefine-peg-string-patterns) or calculated explicitly at runtime with the compile functions (compile-peg-patternandpeg-string-compile).They can then be used for either parsing (
match-pattern) or searching (search-for-pattern). For convenience,search-for-patternalso takes pattern literals in case you want to inline a simple search (people often use regular expressions this way).The rest of this documentation consists of a syntax reference, an API reference, and a tutorial.