mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-29 22:40:34 +02:00
Factor PEG Structure
* modules/ice-9/peg.scm: remove the part that defines a match structure * modules/ice-9/peg/match-record.scm: and put it here
This commit is contained in:
parent
f3f41b9226
commit
44bd21ae7b
2 changed files with 52 additions and 29 deletions
|
@ -21,23 +21,24 @@
|
|||
#:export (peg-parse
|
||||
; define-nonterm
|
||||
; define-nonterm-f
|
||||
peg-match
|
||||
peg:start
|
||||
peg:end
|
||||
peg:string
|
||||
peg:tree
|
||||
peg:substring
|
||||
peg-record?)
|
||||
peg-match)
|
||||
; #:export-syntax (define-nonterm)
|
||||
#:use-module (ice-9 peg codegen)
|
||||
#:use-module (ice-9 peg string-peg)
|
||||
#:use-module (ice-9 peg simplify-tree)
|
||||
#:use-module (ice-9 peg match-record)
|
||||
#:re-export (peg-sexp-compile
|
||||
define-grammar
|
||||
define-grammar-f
|
||||
define-nonterm
|
||||
keyword-flatten
|
||||
context-flatten))
|
||||
context-flatten
|
||||
peg:start
|
||||
peg:end
|
||||
peg:string
|
||||
peg:tree
|
||||
peg:substring
|
||||
peg-record?))
|
||||
|
||||
;;;
|
||||
;;; Helper Macros
|
||||
|
@ -96,26 +97,5 @@ execute the STMTs and try again."
|
|||
at end string
|
||||
(string-collapse match))))))))))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;; PMATCH STRUCTURE MUNGING
|
||||
;; Pretty self-explanatory.
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(define prec
|
||||
(make-record-type "peg" '(start end string tree)))
|
||||
(define make-prec
|
||||
(record-constructor prec '(start end string tree)))
|
||||
(define (peg:start pm)
|
||||
(if pm ((record-accessor prec 'start) pm) #f))
|
||||
(define (peg:end pm)
|
||||
(if pm ((record-accessor prec 'end) pm) #f))
|
||||
(define (peg:string pm)
|
||||
(if pm ((record-accessor prec 'string) pm) #f))
|
||||
(define (peg:tree pm)
|
||||
(if pm ((record-accessor prec 'tree) pm) #f))
|
||||
(define (peg:substring pm)
|
||||
(if pm (substring (peg:string pm) (peg:start pm) (peg:end pm)) #f))
|
||||
(define peg-record? (record-predicate prec))
|
||||
|
||||
)
|
||||
|
||||
|
|
43
module/ice-9/peg/match-record.scm
Normal file
43
module/ice-9/peg/match-record.scm
Normal file
|
@ -0,0 +1,43 @@
|
|||
;;;; match-record.scm --- records to hold PEG parser results
|
||||
;;;;
|
||||
;;;; Copyright (C) 2010, 2011 Free Software Foundation, Inc.
|
||||
;;;;
|
||||
;;;; This library is free software; you can redistribute it and/or
|
||||
;;;; modify it under the terms of the GNU Lesser General Public
|
||||
;;;; License as published by the Free Software Foundation; either
|
||||
;;;; version 3 of the License, or (at your option) any later version.
|
||||
;;;;
|
||||
;;;; This library is distributed in the hope that it will be useful,
|
||||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
;;;; Lesser General Public License for more details.
|
||||
;;;;
|
||||
;;;; You should have received a copy of the GNU Lesser General Public
|
||||
;;;; License along with this library; if not, write to the Free Software
|
||||
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
;;;;
|
||||
|
||||
(define-module (ice-9 peg match-record)
|
||||
#:export (prec make-prec peg:start peg:end peg:string
|
||||
peg:tree peg:substring peg-record?))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;;; PMATCH STRUCTURE MUNGING
|
||||
;; Pretty self-explanatory.
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(define prec
|
||||
(make-record-type "peg" '(start end string tree)))
|
||||
(define make-prec
|
||||
(record-constructor prec '(start end string tree)))
|
||||
(define (peg:start pm)
|
||||
(if pm ((record-accessor prec 'start) pm) #f))
|
||||
(define (peg:end pm)
|
||||
(if pm ((record-accessor prec 'end) pm) #f))
|
||||
(define (peg:string pm)
|
||||
(if pm ((record-accessor prec 'string) pm) #f))
|
||||
(define (peg:tree pm)
|
||||
(if pm ((record-accessor prec 'tree) pm) #f))
|
||||
(define (peg:substring pm)
|
||||
(if pm (substring (peg:string pm) (peg:start pm) (peg:end pm)) #f))
|
||||
(define peg-record? (record-predicate prec))
|
Loading…
Add table
Add a link
Reference in a new issue