*** empty log message ***

original commit: 90f5b4a6b959e3279d12afa521b01b5b7075ee71
tokens
Scott Owens 23 years ago
parent 04a0fb7a4f
commit d7837cf5b7

@ -1,6 +1,6 @@
;; This implements the equivalent of mzscheme's read-syntax for R5RS scheme. ;; This implements the equivalent of mzscheme's read-syntax for R5RS scheme.
;; It has not been thoroughly tested. Also it will read an entire file into a ;; It has not been thoroughly tested. Also it will read an entire file into a
;; list of syntax objects ;; list of syntax objects, instead of returning one syntax object at a time
;; Everything in this module will be read with case sensitivity. ;; Everything in this module will be read with case sensitivity.
#cs #cs

@ -8,19 +8,23 @@
(provide parse-input get-term-list) (provide parse-input get-term-list)
;; get-args: num * syntax-object -> syntax-object list (define stx-for-original-property (read-syntax #f (open-input-string "original")))
(define (get-args x act src-pos)
(let loop ((i 1)) ;; get-args: int * syntax-object list * syntax-object -> syntax-object list
(cond (define (get-args i rhs act src-pos)
((> i x) null) (cond
(src-pos ((null? rhs) null)
`(,(datum->syntax-object act (string->symbol (format "$~a" i))) (else
,(datum->syntax-object act (string->symbol (format "$~a-start-pos" i))) (let ((b (syntax-local-introduce (car rhs))))
,(datum->syntax-object act (string->symbol (format "$~a-end-pos" i))) (cond
,@(loop (add1 i)))) (src-pos
(else `(,(datum->syntax-object act (string->symbol (format "$~a" i)) b stx-for-original-property)
`(,(datum->syntax-object act (string->symbol (format "$~a" i))) ,(datum->syntax-object act (string->symbol (format "$~a-start-pos" i)) b stx-for-original-property)
,@(loop (add1 i))))))) ,(datum->syntax-object act (string->symbol (format "$~a-end-pos" i)) b stx-for-original-property)
,@(get-args (add1 i) (cdr rhs) act src-pos)))
(else
`(,(datum->syntax-object act (string->symbol (format "$~a" i)) b stx-for-original-property)
,@(get-args (add1 i) (cdr rhs) act src-pos))))))))
;; nullable: production list * int -> non-term set ;; nullable: production list * int -> non-term set
;; determines which non-terminals can derive epsilon ;; determines which non-terminals can derive epsilon
@ -297,12 +301,12 @@
"production right-hand-side must have form (symbol ...)" "production right-hand-side must have form (symbol ...)"
prod-so))))) prod-so)))))
;; parse-action: gram-sym vector * syntax-object -> syntax-object ;; parse-action: syntax-object * syntax-object -> syntax-object
(parse-action (parse-action
(lambda (prod act) (lambda (rhs act)
(datum->syntax-object (datum->syntax-object
runtime runtime
`(lambda ,(get-args (vector-length prod) act src-pos) `(lambda ,(get-args 1 (syntax->list rhs) act src-pos)
,act) ,act)
act))) act)))
@ -326,7 +330,7 @@
(term-prec gs) (term-prec gs)
(loop (sub1 i)))) (loop (sub1 i))))
#f)) #f))
(parse-action p (syntax action))))) (parse-action (syntax prod-rhs) (syntax action)))))
((prod-rhs (prec term) action) ((prod-rhs (prec term) action)
(identifier? (syntax term)) (identifier? (syntax term))
(let ((p (parse-prod (syntax prod-rhs)))) (let ((p (parse-prod (syntax prod-rhs))))
@ -346,7 +350,7 @@
"unrecognized terminal ~a in precedence declaration" "unrecognized terminal ~a in precedence declaration"
(syntax-object->datum (syntax term))) (syntax-object->datum (syntax term)))
(syntax term))))) (syntax term)))))
(parse-action p (syntax action))))) (parse-action (syntax prod-rhs) (syntax action)))))
(_ (_
(raise-syntax-error (raise-syntax-error
'parser-production-rhs 'parser-production-rhs

@ -16,7 +16,7 @@
so so
so))) so)))
(define (fix-check-syntax start terms prods) (define (fix-check-syntax start terms prods precs ends)
(syntax-case prods () (syntax-case prods ()
((_ (bind ((bound ...) x ...) ...) ...) ((_ (bind ((bound ...) x ...) ...) ...)
(let ((binds (syntax->list (syntax (bind ...)))) (let ((binds (syntax->list (syntax (bind ...))))
@ -28,11 +28,14 @@
append append
(map syntax->list (map syntax->list
(syntax->list (syntax (((bound ...) ...) ...))))))))) (syntax->list (syntax (((bound ...) ...) ...)))))))))
(terms (get-term-list terms))) (terms (get-term-list terms))
(precs (syntax-case precs ()
((_ (__ term ...) ...)
(apply append (map syntax->list (syntax->list (syntax ((term ...) ...)))))))))
`(if #f (let ,(map (lambda (bind) `(if #f (let ,(map (lambda (bind)
`(,(strip bind) void)) `(,(strip bind) void))
(append terms binds)) (append terms binds))
(void ,@(map strip bounds)))))))) (void ,@(append ends precs (map strip bounds)))))))))
(define (build-parser filename src-pos suppress error-expr input-terms start end assocs prods runtime src) (define (build-parser filename src-pos suppress error-expr input-terms start end assocs prods runtime src)
(let* ((grammar (parse-input start end input-terms assocs prods runtime src-pos)) (let* ((grammar (parse-input start end input-terms assocs prods runtime src-pos))
@ -235,5 +238,5 @@
#f #f #f #f #f))))))))))) #f #f #f #f #f)))))))))))
(datum->syntax-object (datum->syntax-object
runtime runtime
`(begin ,(fix-check-syntax start input-terms prods) ,parser-code) `(begin ,(fix-check-syntax start input-terms prods assocs end) ,parser-code)
src)))) src))))

Loading…
Cancel
Save