mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-29 19:30:36 +02:00
PEG Renames
* module/ice-9/peg.scm: rename 'define-grammar' to 'define-peg-string-patterns' * module/ice-9/peg/string-peg.scm: same * doc/ref/api-peg.texi: same * test-suite/tests/peg.bench: same * test-suite/tests/peg.test: same
This commit is contained in:
parent
40ebbd64c4
commit
3ebd578616
5 changed files with 20 additions and 20 deletions
|
@ -19,7 +19,7 @@ familiarize yourself with the syntax:
|
|||
|
||||
The module works by compiling PEGs down to lambda expressions. These
|
||||
can either be stored in variables at compile-time by the define macros
|
||||
(@code{define-peg-pattern} and @code{define-grammar}) or calculated
|
||||
(@code{define-peg-pattern} and @code{define-peg-string-patterns}) or calculated
|
||||
explicitly at runtime with the compile functions
|
||||
(@code{peg-sexp-compile} and @code{peg-string-compile}).
|
||||
|
||||
|
@ -206,11 +206,11 @@ retrieved from this record with the PEG match deconstructor functions.
|
|||
More complicated (and perhaps enlightening) examples can be found in the
|
||||
tutorial.
|
||||
|
||||
@deffn {Scheme Macro} define-grammar peg-string
|
||||
@deffn {Scheme Macro} define-peg-string-patterns peg-string
|
||||
Defines all the nonterminals in the PEG @var{peg-string}. More
|
||||
precisely, @code{define-grammar} takes a superset of PEGs. A normal PEG
|
||||
precisely, @code{define-peg-string-patterns} takes a superset of PEGs. A normal PEG
|
||||
has a @code{<-} between the nonterminal and the pattern.
|
||||
@code{define-grammar} uses this symbol to determine what information it
|
||||
@code{define-peg-string-patterns} uses this symbol to determine what information it
|
||||
should propagate up the parse tree. The normal @code{<-} propagates the
|
||||
matched text up the parse tree, @code{<--} propagates the matched text
|
||||
up the parse tree tagged with the name of the nonterminal, and @code{<}
|
||||
|
@ -220,11 +220,11 @@ character (in normal PEGs nonterminals can only be alphabetic).
|
|||
|
||||
For example, if we:
|
||||
@lisp
|
||||
(define-grammar
|
||||
(define-peg-string-patterns
|
||||
"as <- 'a'+
|
||||
bs <- 'b'+
|
||||
as-or-bs <- as/bs")
|
||||
(define-grammar
|
||||
(define-peg-string-patterns
|
||||
"as-tag <-- 'a'+
|
||||
bs-tag <-- 'b'+
|
||||
as-or-bs-tag <-- as-tag/bs-tag")
|
||||
|
@ -513,7 +513,7 @@ As a first pass at this, we might want to have all the entries in
|
|||
|
||||
Doing this with string-based PEG syntax would look like this:
|
||||
@lisp
|
||||
(define-grammar
|
||||
(define-peg-string-patterns
|
||||
"passwd <- entry* !.
|
||||
entry <-- (! NL .)* NL*
|
||||
NL < '\n'")
|
||||
|
@ -644,7 +644,7 @@ Let's extend this example a bit more and actually pull some useful
|
|||
information out of the passwd file:
|
||||
|
||||
@lisp
|
||||
(define-grammar
|
||||
(define-peg-string-patterns
|
||||
"passwd <-- entry* !.
|
||||
entry <-- login C pass C uid C gid C nameORcomment C homedir C shell NL*
|
||||
login <-- text
|
||||
|
@ -732,7 +732,7 @@ continue because it didn't have to match the nameORcomment to continue.
|
|||
We can parse simple mathematical expressions with the following PEG:
|
||||
|
||||
@lisp
|
||||
(define-grammar
|
||||
(define-peg-string-patterns
|
||||
"expr <- sum
|
||||
sum <-- (product ('+' / '-') sum) / product
|
||||
product <-- (value ('*' / '/') product) / value
|
||||
|
@ -822,7 +822,7 @@ a good choice:
|
|||
@lisp
|
||||
(use-modules (srfi srfi-1))
|
||||
|
||||
(define-grammar
|
||||
(define-peg-string-patterns
|
||||
"expr <- sum
|
||||
sum <-- (product ('+' / '-'))* product
|
||||
product <-- (value ('*' / '/'))* value
|
||||
|
@ -881,7 +881,7 @@ For a more tantalizing example, consider the following grammar that
|
|||
parses (highly) simplified C functions:
|
||||
|
||||
@lisp
|
||||
(define-grammar
|
||||
(define-peg-string-patterns
|
||||
"cfunc <-- cSP ctype cSP cname cSP cargs cLB cSP cbody cRB
|
||||
ctype <-- cidentifier
|
||||
cname <-- cidentifier
|
||||
|
|
|
@ -27,10 +27,10 @@
|
|||
#:use-module (ice-9 peg using-parsers)
|
||||
#:use-module (ice-9 peg cache)
|
||||
#:re-export (define-peg-pattern
|
||||
define-peg-string-patterns
|
||||
match-pattern
|
||||
search-for-pattern
|
||||
peg-sexp-compile
|
||||
define-grammar
|
||||
define-grammar-f
|
||||
keyword-flatten
|
||||
context-flatten
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
(define-module (ice-9 peg string-peg)
|
||||
#:export (peg-as-peg
|
||||
define-grammar
|
||||
define-peg-string-patterns
|
||||
define-grammar-f
|
||||
peg-grammar)
|
||||
#:use-module (ice-9 peg using-parsers)
|
||||
|
@ -118,7 +118,7 @@ RB < ']'
|
|||
|
||||
;; Macro wrapper for PEG-PARSER. Parses PEG grammars expressed as strings and
|
||||
;; defines all the appropriate nonterminals.
|
||||
(define-syntax define-grammar
|
||||
(define-syntax define-peg-string-patterns
|
||||
(lambda (x)
|
||||
(syntax-case x ()
|
||||
((_ str)
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
(define (eq-parse str) (apply parse-expr (peg:tree (match-pattern expr str))))
|
||||
|
||||
;; PEG for parsing equations (see tutorial).
|
||||
(define-grammar
|
||||
(define-peg-string-patterns
|
||||
"expr <- sum
|
||||
sum <-- (product ('+' / '-'))* product
|
||||
product <-- (value ('*' / '/'))* value
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
(with-test-prefix "PEG Grammar"
|
||||
(pass-if
|
||||
"defining PEGs with PEG"
|
||||
(and (eeval `(define-grammar ,(@@ (ice-9 peg) peg-as-peg))) #t))
|
||||
(and (eeval `(define-peg-string-patterns ,(@@ (ice-9 peg) peg-as-peg))) #t))
|
||||
(pass-if
|
||||
"equivalence of definitions"
|
||||
(equal?
|
||||
|
@ -90,7 +90,7 @@ messagebus:x:103:107::/var/run/dbus:/bin/false
|
|||
")
|
||||
|
||||
;; A grammar for parsing /etc/passwd files.
|
||||
(define-grammar
|
||||
(define-peg-string-patterns
|
||||
"passwd <-- entry* !.
|
||||
entry <-- login CO pass CO uid CO gid CO nameORcomment CO homedir CO shell NL*
|
||||
login <-- text
|
||||
|
@ -109,7 +109,7 @@ SLASH < '/'")
|
|||
|
||||
;; Tests some actual parsing using PEGs.
|
||||
(with-test-prefix "Parsing"
|
||||
(eeval `(define-grammar ,comment-grammar))
|
||||
(eeval `(define-peg-string-patterns ,comment-grammar))
|
||||
(pass-if
|
||||
;; Pascal-style comment parsing
|
||||
"simple comment"
|
||||
|
@ -164,7 +164,7 @@ SLASH < '/'")
|
|||
(record? #t)))))
|
||||
|
||||
;; PEG for parsing right-associative equations.
|
||||
(define-grammar
|
||||
(define-peg-string-patterns
|
||||
"expr <- sum
|
||||
sum <-- (product ('+' / '-') sum) / product
|
||||
product <-- (value ('*' / '/') product) / value
|
||||
|
@ -217,7 +217,7 @@ number <-- [0-9]+")
|
|||
'(+ 1 (+ (/ 1 (* 2 3)) (/ (+ 1 1) 2))))))
|
||||
|
||||
;; PEG for parsing left-associative equations (normal ones).
|
||||
(define-grammar
|
||||
(define-peg-string-patterns
|
||||
"expr <- sum
|
||||
sum <-- (product ('+' / '-'))* product
|
||||
product <-- (value ('*' / '/'))* value
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue