mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
PEG Renames
* module/ice-9/peg.scm: rename 'peg-sexp-compile' to 'compile-peg-pattern' * module/ice-9/peg/codegen.scm: same * module/ice-9/peg/string-peg.scm: same * module/ice-9/peg/using-parsers.scm: same * doc/ref/api-peg.texi: same
This commit is contained in:
parent
3ebd578616
commit
fee87b821f
5 changed files with 23 additions and 23 deletions
|
@ -21,7 +21,7 @@ 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-peg-string-patterns}) or calculated
|
||||
explicitly at runtime with the compile functions
|
||||
(@code{peg-sexp-compile} and @code{peg-string-compile}).
|
||||
(@code{compile-peg-pattern} and @code{peg-string-compile}).
|
||||
|
||||
They can then be used for either parsing (@code{match-pattern}) or searching
|
||||
(@code{search-for-pattern}). For convenience, @code{search-for-pattern}
|
||||
|
@ -292,7 +292,7 @@ Compiles the PEG pattern in @var{peg-string} propagating according to
|
|||
@end deffn
|
||||
|
||||
|
||||
@deffn {Scheme Procedure} peg-sexp-compile peg-sexp capture-type
|
||||
@deffn {Scheme Procedure} compile-peg-pattern peg-sexp capture-type
|
||||
Compiles the PEG pattern in @var{peg-sexp} propagating according to
|
||||
@var{capture-type} (capture-type can be any of the values from
|
||||
@code{define-peg-pattern}).
|
||||
|
@ -304,7 +304,7 @@ can do the following:
|
|||
|
||||
@lisp
|
||||
(define exp '(+ "a"))
|
||||
(define as (compile (peg-sexp-compile exp 'body)))
|
||||
(define as (compile (compile-peg-pattern exp 'body)))
|
||||
@end lisp
|
||||
|
||||
You can use this nonterminal with all of the regular PEG functions:
|
||||
|
@ -1013,10 +1013,10 @@ in the @code{(ice-9 peg string-peg)} module.
|
|||
|
||||
Then, then s-expression PEG that results is compiled into a parsing
|
||||
function by the @code{(ice-9 peg codegen)} module. In particular, the
|
||||
function @code{peg-sexp-compile} is called on the s-expression. It then
|
||||
function @code{compile-peg-pattern} is called on the s-expression. It then
|
||||
decides what to do based on the form it is passed.
|
||||
|
||||
The PEG syntax can be expanded by providing @code{peg-sexp-compile} more
|
||||
The PEG syntax can be expanded by providing @code{compile-peg-pattern} more
|
||||
options for what to do with its forms. The extended syntax will be
|
||||
associated with a symbol, for instance @code{my-parsing-form}, and will
|
||||
be called on all PEG expressions of the form
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
define-peg-string-patterns
|
||||
match-pattern
|
||||
search-for-pattern
|
||||
peg-sexp-compile
|
||||
compile-peg-pattern
|
||||
define-grammar-f
|
||||
keyword-flatten
|
||||
context-flatten
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
;;;;
|
||||
|
||||
(define-module (ice-9 peg codegen)
|
||||
#:export (peg-sexp-compile wrap-parser-for-users add-peg-compiler!)
|
||||
#:export (compile-peg-pattern wrap-parser-for-users add-peg-compiler!)
|
||||
#:use-module (ice-9 pretty-print)
|
||||
#:use-module (system base pmatch))
|
||||
|
||||
|
@ -144,14 +144,14 @@ return EXP."
|
|||
(define (cg-ignore pat accum)
|
||||
(syntax-case pat ()
|
||||
((inner)
|
||||
(peg-sexp-compile #'inner 'none))))
|
||||
(compile-peg-pattern #'inner 'none))))
|
||||
|
||||
(define (cg-capture pat accum)
|
||||
(syntax-case pat ()
|
||||
((inner)
|
||||
(peg-sexp-compile #'inner 'body))))
|
||||
(compile-peg-pattern #'inner 'body))))
|
||||
|
||||
;; Filters the accum argument to peg-sexp-compile for buildings like string
|
||||
;; Filters the accum argument to compile-peg-pattern for buildings like string
|
||||
;; literals (since we don't want to tag them with their name if we're doing an
|
||||
;; "all" accum).
|
||||
(define (builtin-accum-filter accum)
|
||||
|
@ -174,7 +174,7 @@ return EXP."
|
|||
(()
|
||||
(cggr accum 'cg-and #`(reverse #,body) at))
|
||||
((first rest ...)
|
||||
#`(let ((res (#,(peg-sexp-compile #'first accum) #,str #,strlen #,at)))
|
||||
#`(let ((res (#,(compile-peg-pattern #'first accum) #,str #,strlen #,at)))
|
||||
(and res
|
||||
;; update AT and BODY then recurse
|
||||
(let ((newat (car res))
|
||||
|
@ -194,7 +194,7 @@ return EXP."
|
|||
(()
|
||||
#f)
|
||||
((first rest ...)
|
||||
#`(or (#,(peg-sexp-compile #'first accum) #,str #,strlen #,at)
|
||||
#`(or (#,(compile-peg-pattern #'first accum) #,str #,strlen #,at)
|
||||
#,(cg-or-int #'(rest ...) accum str strlen at)))))
|
||||
|
||||
(define (cg-* args accum)
|
||||
|
@ -203,7 +203,7 @@ return EXP."
|
|||
#`(lambda (str strlen at)
|
||||
(let ((body '()))
|
||||
(let lp ((end at) (count 0))
|
||||
(let* ((match (#,(peg-sexp-compile #'pat (baf accum))
|
||||
(let* ((match (#,(compile-peg-pattern #'pat (baf accum))
|
||||
str strlen end))
|
||||
(new-end (if match (car match) end))
|
||||
(count (if (> new-end end) (1+ count) count)))
|
||||
|
@ -223,7 +223,7 @@ return EXP."
|
|||
#`(lambda (str strlen at)
|
||||
(let ((body '()))
|
||||
(let lp ((end at) (count 0))
|
||||
(let* ((match (#,(peg-sexp-compile #'pat (baf accum))
|
||||
(let* ((match (#,(compile-peg-pattern #'pat (baf accum))
|
||||
str strlen end))
|
||||
(new-end (if match (car match) end))
|
||||
(count (if (> new-end end) (1+ count) count)))
|
||||
|
@ -243,7 +243,7 @@ return EXP."
|
|||
#`(lambda (str strlen at)
|
||||
(let ((body '()))
|
||||
(let lp ((end at) (count 0))
|
||||
(let* ((match (#,(peg-sexp-compile #'pat (baf accum))
|
||||
(let* ((match (#,(compile-peg-pattern #'pat (baf accum))
|
||||
str strlen end))
|
||||
(new-end (if match (car match) end))
|
||||
(count (if (> new-end end) (1+ count) count)))
|
||||
|
@ -263,7 +263,7 @@ return EXP."
|
|||
#`(lambda (str strlen at)
|
||||
(let ((body '()))
|
||||
(let lp ((end at) (count 0))
|
||||
(let* ((match (#,(peg-sexp-compile #'pat (baf accum))
|
||||
(let* ((match (#,(compile-peg-pattern #'pat (baf accum))
|
||||
str strlen end))
|
||||
(new-end (if match (car match) end))
|
||||
(count (if (> new-end end) (1+ count) count)))
|
||||
|
@ -282,7 +282,7 @@ return EXP."
|
|||
#`(lambda (str strlen at)
|
||||
(let ((body '()))
|
||||
(let lp ((end at) (count 0))
|
||||
(let* ((match (#,(peg-sexp-compile #'pat (baf accum))
|
||||
(let* ((match (#,(compile-peg-pattern #'pat (baf accum))
|
||||
str strlen end))
|
||||
(new-end (if match (car match) end))
|
||||
(count (if (> new-end end) (1+ count) count)))
|
||||
|
@ -315,8 +315,8 @@ return EXP."
|
|||
(add-peg-compiler! 'not-followed-by cg-not-followed-by)
|
||||
|
||||
;; Takes an arbitrary expressions and accumulation variable, then parses it.
|
||||
;; E.g.: (peg-sexp-compile syntax '(and "abc" (or "-" (range #\a #\z))) 'all)
|
||||
(define (peg-sexp-compile pat accum)
|
||||
;; E.g.: (compile-peg-pattern syntax '(and "abc" (or "-" (range #\a #\z))) 'all)
|
||||
(define (compile-peg-pattern pat accum)
|
||||
(syntax-case pat (peg-any)
|
||||
(peg-any
|
||||
(cg-peg-any (baf accum)))
|
||||
|
|
|
@ -59,7 +59,7 @@ RB < ']'
|
|||
(lambda (x)
|
||||
(syntax-case x ()
|
||||
((_ sym accum pat)
|
||||
(let* ((matchf (peg-sexp-compile #'pat (syntax->datum #'accum)))
|
||||
(let* ((matchf (compile-peg-pattern #'pat (syntax->datum #'accum)))
|
||||
(accumsym (syntax->datum #'accum))
|
||||
(syn (wrap-parser-for-users x matchf accumsym #'sym)))
|
||||
#`(define sym #,syn))))))
|
||||
|
@ -262,7 +262,7 @@ RB < ']'
|
|||
(syntax-case args ()
|
||||
((str-stx) (string? (syntax->datum #'str-stx))
|
||||
(let ((string (syntax->datum #'str-stx)))
|
||||
(peg-sexp-compile
|
||||
(compile-peg-pattern
|
||||
(compressor
|
||||
(peg-pattern->defn
|
||||
(peg:tree (match-pattern peg-pattern string)) #'str-stx)
|
||||
|
|
|
@ -57,7 +57,7 @@ execute the STMTs and try again."
|
|||
(lambda (x)
|
||||
(syntax-case x ()
|
||||
((_ sym accum pat)
|
||||
(let ((matchf (peg-sexp-compile #'pat (syntax->datum #'accum)))
|
||||
(let ((matchf (compile-peg-pattern #'pat (syntax->datum #'accum)))
|
||||
(accumsym (syntax->datum #'accum)))
|
||||
;; CODE is the code to parse the string if the result isn't cached.
|
||||
(let ((syn (wrap-parser-for-users x matchf accumsym #'sym)))
|
||||
|
@ -75,7 +75,7 @@ execute the STMTs and try again."
|
|||
(syntax-case x ()
|
||||
((_ pattern string-uncopied)
|
||||
(let ((pmsym (syntax->datum #'pattern)))
|
||||
(let ((matcher (peg-sexp-compile (peg-like->peg #'pattern) 'body)))
|
||||
(let ((matcher (compile-peg-pattern (peg-like->peg #'pattern) 'body)))
|
||||
;; We copy the string before using it because it might have been
|
||||
;; modified in-place since the last time it was parsed, which would
|
||||
;; invalidate the cache. Guile uses copy-on-write for strings, so
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue