syntax/parse: eliminate old minimatch struct syntaxes

This commit is contained in:
Ryan Culpepper 2012-03-21 07:27:10 -06:00
parent 6c369f2563
commit df265ddc67
3 changed files with 30 additions and 34 deletions

View File

@ -1,7 +1,7 @@
#lang racket/base #lang racket/base
(require unstable/struct (require unstable/struct
(for-syntax racket/base racket/struct-info unstable/struct)) (for-syntax racket/base racket/struct-info unstable/struct))
(provide match make ?) (provide match ?)
(define-syntax (match stx) (define-syntax (match stx)
(syntax-case stx () (syntax-case stx ()
@ -25,7 +25,7 @@
;; (match-p id Pattern SuccessExpr FailureExpr) ;; (match-p id Pattern SuccessExpr FailureExpr)
(define-syntax (match-p stx) (define-syntax (match-p stx)
(syntax-case stx (quote cons list vector make struct ?) (syntax-case stx (quote cons list vector STRUCT ?)
[(match-p x wildcard success failure) [(match-p x wildcard success failure)
(and (identifier? #'wildcard) (free-identifier=? #'wildcard #'_)) (and (identifier? #'wildcard) (free-identifier=? #'wildcard #'_))
#'success] #'success]
@ -51,9 +51,7 @@
[(match-p x var success failure) [(match-p x var success failure)
(identifier? #'var) (identifier? #'var)
#'(let ([var x]) success)] #'(let ([var x]) success)]
[(match-p x (make S p ...) success failure) [(match-p x (STRUCT S (p ...)) success failure)
#'(match-p x (struct S (p ...)) success failure)]
[(match-p x (struct S (p ...)) success failure)
(identifier? #'S) (identifier? #'S)
(let () (let ()
(define (not-a-struct) (define (not-a-struct)
@ -79,7 +77,7 @@
[(match-p x (S p ...) success failure) [(match-p x (S p ...) success failure)
(identifier? #'S) (identifier? #'S)
(if (struct-info? (syntax-local-value #'S (lambda () #f))) (if (struct-info? (syntax-local-value #'S (lambda () #f)))
#'(match-p x (struct S (p ...)) success failure) #'(match-p x (STRUCT S (p ...)) success failure)
(raise-syntax-error #f "bad minimatch form" stx #'S))] (raise-syntax-error #f "bad minimatch form" stx #'S))]
[(match-p x s success failure) [(match-p x s success failure)
(prefab-struct-key (syntax-e #'s)) (prefab-struct-key (syntax-e #'s))
@ -99,11 +97,8 @@
[(match-p* ((x1 p1) . rest) success failure) [(match-p* ((x1 p1) . rest) success failure)
(match-p x1 p1 (match-p* rest success failure) failure)])) (match-p x1 p1 (match-p* rest success failure) failure)]))
#;
(define-syntax struct
(lambda (stx)
(raise-syntax-error #f "illegal use of keyword" stx)))
(define-syntax ? (define-syntax ?
(lambda (stx) (lambda (stx)
(raise-syntax-error #f "illegal use of minimatch form '?'" stx))) (raise-syntax-error #f "illegal use of minimatch form '?'" stx)))
(define-syntax STRUCT #f) ;; internal keyword

View File

@ -5,6 +5,7 @@
syntax/private/id-table syntax/private/id-table
racket/syntax racket/syntax
syntax/parse/private/residual-ct ;; keep abs. path syntax/parse/private/residual-ct ;; keep abs. path
unstable/struct
"minimatch.rkt" "minimatch.rkt"
"kws.rkt" "kws.rkt"
"rep-attrs.rkt" "rep-attrs.rkt"
@ -126,23 +127,23 @@ expressions are duplicated, and may be evaluated in different scopes.
;; So blame-declare? only applies to stxclass declares ;; So blame-declare? only applies to stxclass declares
(let ([val (declenv-lookup env id #:use-conventions? #f)]) (let ([val (declenv-lookup env id #:use-conventions? #f)])
(match val (match val
[(struct den:lit (_i _e _ip _lp)) [(den:lit _i _e _ip _lp)
(wrong-syntax id "identifier previously declared as literal")] (wrong-syntax id "identifier previously declared as literal")]
[(struct den:magic-class (name _c _a _r)) [(den:magic-class name _c _a _r)
(if (and blame-declare? stxclass-name) (if (and blame-declare? stxclass-name)
(wrong-syntax name (wrong-syntax name
"identifier previously declared with syntax class ~a" "identifier previously declared with syntax class ~a"
stxclass-name) stxclass-name)
(wrong-syntax (if blame-declare? name id) (wrong-syntax (if blame-declare? name id)
"identifier previously declared"))] "identifier previously declared"))]
[(struct den:class (name _c _a)) [(den:class name _c _a)
(if (and blame-declare? stxclass-name) (if (and blame-declare? stxclass-name)
(wrong-syntax name (wrong-syntax name
"identifier previously declared with syntax class ~a" "identifier previously declared with syntax class ~a"
stxclass-name) stxclass-name)
(wrong-syntax (if blame-declare? name id) (wrong-syntax (if blame-declare? name id)
"identifier previously declared"))] "identifier previously declared"))]
[(struct den:parser (_p _a _sp _c _dc?)) [(den:parser _p _a _sp _c _dc?)
(wrong-syntax id "(internal error) late unbound check")] (wrong-syntax id "(internal error) late unbound check")]
['#f (void)]))) ['#f (void)])))

View File

@ -258,11 +258,11 @@
;; FIXME: replace with txlift mechanism ;; FIXME: replace with txlift mechanism
(define (create-aux-def entry) (define (create-aux-def entry)
(match entry (match entry
[(struct den:lit (_i _e _ip _lp)) [(den:lit _i _e _ip _lp)
(values entry null)] (values entry null)]
[(struct den:magic-class (name class argu role)) [(den:magic-class name class argu role)
(values entry null)] (values entry null)]
[(struct den:class (name class argu)) [(den:class name class argu)
;; FIXME: integrable syntax classes? ;; FIXME: integrable syntax classes?
(cond [(identifier? name) (cond [(identifier? name)
(let* ([pos-count (length (arguments-pargs argu))] (let* ([pos-count (length (arguments-pargs argu))]
@ -283,9 +283,9 @@
(values (make den:delayed #'parser class) (values (make den:delayed #'parser class)
(list #`(define-values (parser) (list #`(define-values (parser)
(curried-stxclass-parser #,class #,argu)))))])] (curried-stxclass-parser #,class #,argu)))))])]
[(struct den:parser (_p _a _sp _c _dc?)) [(den:parser _p _a _sp _c _dc?)
(values entry null)] (values entry null)]
[(struct den:delayed (_p _c)) [(den:delayed _p _c)
(values entry null)])) (values entry null)]))
(define (append-lits+litsets lits litsets) (define (append-lits+litsets lits litsets)
@ -361,18 +361,18 @@
(create-action:and (create-action:and
(for/list ([side (in-list sides)]) (for/list ([side (in-list sides)])
(match side (match side
[(make clause:fail condition message) [(clause:fail condition message)
(create-action:post (create-action:post
(create-action:fail condition message))] (create-action:fail condition message))]
[(make clause:with wpat expr defs) [(clause:with wpat expr defs)
(let ([ap (create-action:post (let ([ap (create-action:post
(create-action:parse wpat expr))]) (create-action:parse wpat expr))])
(if (pair? defs) (if (pair? defs)
(create-action:and (list (create-action:do defs) ap)) (create-action:and (list (create-action:do defs) ap))
ap))] ap))]
[(make clause:attr attr expr) [(clause:attr attr expr)
(create-action:bind (list side))] (create-action:bind (list side))]
[(make clause:do stmts) [(clause:do stmts)
(create-action:do stmts)])))) (create-action:do stmts)]))))
(define dummy-pattern (define dummy-pattern
(and (pair? sides) (and (pair? sides)
@ -607,18 +607,18 @@
(define (parse-pat:id id decls allow-head?) (define (parse-pat:id id decls allow-head?)
(define entry (declenv-lookup decls id)) (define entry (declenv-lookup decls id))
(match entry (match entry
[(struct den:lit (internal literal input-phase lit-phase)) [(den:lit internal literal input-phase lit-phase)
(create-pat:literal literal input-phase lit-phase)] (create-pat:literal literal input-phase lit-phase)]
[(struct den:magic-class (name class argu role)) [(den:magic-class name class argu role)
(let* ([pos-count (length (arguments-pargs argu))] (let* ([pos-count (length (arguments-pargs argu))]
[kws (arguments-kws argu)] [kws (arguments-kws argu)]
[sc (get-stxclass/check-arity class class pos-count kws)]) [sc (get-stxclass/check-arity class class pos-count kws)])
(parse-pat:var* id allow-head? id sc argu "." role #f))] (parse-pat:var* id allow-head? id sc argu "." role #f))]
[(struct den:class (_n _c _a)) [(den:class _n _c _a)
(error 'parse-pat:id (error 'parse-pat:id
"(internal error) decls had leftover stxclass entry: ~s" "(internal error) decls had leftover stxclass entry: ~s"
entry)] entry)]
[(struct den:parser (parser attrs splicing? commit? delimit-cut?)) [(den:parser parser attrs splicing? commit? delimit-cut?)
(check-no-delimit-cut-in-not id delimit-cut?) (check-no-delimit-cut-in-not id delimit-cut?)
(cond [splicing? (cond [splicing?
(unless allow-head? (unless allow-head?
@ -626,7 +626,7 @@
(parse-pat:id/h id parser no-arguments attrs commit? "." #f)] (parse-pat:id/h id parser no-arguments attrs commit? "." #f)]
[else [else
(parse-pat:id/s id parser no-arguments attrs commit? "." #f)])] (parse-pat:id/s id parser no-arguments attrs commit? "." #f)])]
[(struct den:delayed (parser class)) [(den:delayed parser class)
(let ([sc (get-stxclass class)]) (let ([sc (get-stxclass class)])
(parse-pat:var* id allow-head? id sc no-arguments "." #f parser))] (parse-pat:var* id allow-head? id sc no-arguments "." #f parser))]
['#f ['#f
@ -994,15 +994,15 @@
(define (check-list-pattern pattern stx) (define (check-list-pattern pattern stx)
(match pattern (match pattern
[(make pat:datum _base '()) [(pat:datum _base '())
#t] #t]
[(make pat:head _base _head tail) [(pat:head _base _head tail)
(check-list-pattern tail stx)] (check-list-pattern tail stx)]
[(make pat:action _base _action tail) [(pat:action _base _action tail)
(check-list-pattern tail stx)] (check-list-pattern tail stx)]
[(make pat:dots _base _head tail) [(pat:dots _base _head tail)
(check-list-pattern tail stx)] (check-list-pattern tail stx)]
[(make pat:pair _base _head tail) [(pat:pair _base _head tail)
(check-list-pattern tail stx)] (check-list-pattern tail stx)]
[_ [_
(wrong-syntax stx "expected proper list pattern")])) (wrong-syntax stx "expected proper list pattern")]))