diff options
author | Noah Lavine <noah.b.lavine@gmail.com> | 2012-01-22 15:03:13 -0500 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2013-01-16 10:11:50 +0100 |
commit | fee87b821f6ed644c77cee4b3f5a02836f3d974f (patch) | |
tree | 142c7d56a01e8d089edbeba91bac6c780c19bfa5 | |
parent | 3ebd5786160226df4dd4bb2abf610105d156653a (diff) | |
download | guile-fee87b821f6ed644c77cee4b3f5a02836f3d974f.tar.gz |
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
-rw-r--r-- | doc/ref/api-peg.texi | 10 | ||||
-rw-r--r-- | module/ice-9/peg.scm | 2 | ||||
-rw-r--r-- | module/ice-9/peg/codegen.scm | 26 | ||||
-rw-r--r-- | module/ice-9/peg/string-peg.scm | 4 | ||||
-rw-r--r-- | module/ice-9/peg/using-parsers.scm | 4 |
5 files changed, 23 insertions, 23 deletions
diff --git a/doc/ref/api-peg.texi b/doc/ref/api-peg.texi index fa1e29e30..0e16aab7e 100644 --- a/doc/ref/api-peg.texi +++ b/doc/ref/api-peg.texi @@ -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 diff --git a/module/ice-9/peg.scm b/module/ice-9/peg.scm index e5798dd2c..f572277b9 100644 --- a/module/ice-9/peg.scm +++ b/module/ice-9/peg.scm @@ -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 diff --git a/module/ice-9/peg/codegen.scm b/module/ice-9/peg/codegen.scm index 372f7eb49..d80c3e849 100644 --- a/module/ice-9/peg/codegen.scm +++ b/module/ice-9/peg/codegen.scm @@ -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))) diff --git a/module/ice-9/peg/string-peg.scm b/module/ice-9/peg/string-peg.scm index 7859f6fdd..6b1efa982 100644 --- a/module/ice-9/peg/string-peg.scm +++ b/module/ice-9/peg/string-peg.scm @@ -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) diff --git a/module/ice-9/peg/using-parsers.scm b/module/ice-9/peg/using-parsers.scm index e9bd3728b..076de2999 100644 --- a/module/ice-9/peg/using-parsers.scm +++ b/module/ice-9/peg/using-parsers.scm @@ -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 |