
Changed backtracking algorithm, runtime representations - syntax classes, ~describe no longer implicitly commit - ~describe no longer delimits effect of cut Added keyword & optional args for stxclasses Added ~do and #:do, ~post, ~commit and #:commit, ~delimit-cut and #:no-delimit-cut Added syntax/parse/debug, syntax/parse/experimental/* - expr/c for contracting macro sub-expressions moved from syntax/parse to syntax/parse/experimental/contract - syntax class reflection (~reflect, ~splicing-reflect) - eh-alternative-sets (~eh-var) - provide-syntax-class/contract (only for params, not attrs so far) Changed ~fail to not include POST progress (#:fail still does) old (~fail _) is now (~post (~fail _)) Made msg argument of ~fail optional Removed generic "repetition constraint violated" msg Removed atom-in-list stxclass Removed unnecessary datum->syntax on cdr of pair pattern massive improvements to long-list microbenchmarks Optimization: integrable syntax classes (id, expr, keyword) need better measurements Optimization: ad hoc elimination of head/tail choice point for (EH ... . ()) patterns Added unstable/wrapc (proc version of expr/c)
87 lines
2.5 KiB
Racket
87 lines
2.5 KiB
Racket
#lang racket/base
|
|
(require "sc.rkt"
|
|
"keywords.rkt"
|
|
syntax/stx
|
|
unstable/syntax
|
|
(for-syntax racket/base
|
|
"rep.rkt"))
|
|
|
|
(provide identifier
|
|
boolean
|
|
str
|
|
character
|
|
keyword
|
|
number
|
|
integer
|
|
exact-integer
|
|
exact-nonnegative-integer
|
|
exact-positive-integer
|
|
|
|
id
|
|
nat
|
|
char
|
|
|
|
expr
|
|
static)
|
|
|
|
;; == Integrable syntax classes ==
|
|
|
|
(define-syntax-class identifier
|
|
#:description (quote "identifier")
|
|
(pattern (~fail #:unless (identifier? this-syntax))))
|
|
|
|
(define-syntax-class keyword
|
|
#:description (quote "keyword")
|
|
(pattern (~fail #:unless (and (syntax? this-syntax) (keyword? (syntax-e this-syntax))))))
|
|
|
|
(define-syntax-class expr
|
|
#:description (quote "expression")
|
|
(pattern (~fail #:when (and (syntax? this-syntax) (keyword? (syntax-e this-syntax))))))
|
|
|
|
;; == Normal syntax classes ==
|
|
|
|
(define-syntax-rule (define-pred-stxclass name pred)
|
|
(define-syntax-class name #:attributes () #:opaque #:commit
|
|
(pattern (~and x (~fail #:unless (pred (syntax-e #'x)))))))
|
|
|
|
;;(define-pred-stxclass identifier symbol?)
|
|
;;(define-pred-stxclass keyword keyword?)
|
|
(define-pred-stxclass boolean boolean?)
|
|
(define-pred-stxclass character char?)
|
|
|
|
(define-syntax-class str #:attributes () #:opaque #:commit
|
|
#:description "string"
|
|
(pattern (~and x (~fail #:unless (string? (syntax-e #'x))))))
|
|
|
|
(define-pred-stxclass number number?)
|
|
(define-pred-stxclass integer integer?)
|
|
(define-pred-stxclass exact-integer exact-integer?)
|
|
(define-pred-stxclass exact-nonnegative-integer exact-nonnegative-integer?)
|
|
(define-pred-stxclass exact-positive-integer exact-positive-integer?)
|
|
|
|
;; Aliases
|
|
(define-syntax id (make-rename-transformer #'identifier))
|
|
(define-syntax nat (make-rename-transformer #'exact-nonnegative-integer))
|
|
(define-syntax char (make-rename-transformer #'character))
|
|
|
|
(define notfound (box 'notfound))
|
|
|
|
(define-syntax-class (static pred name)
|
|
#:attributes (value)
|
|
#:description name
|
|
#:commit
|
|
(pattern (~and x:id
|
|
(~fail #:unless (syntax-transforming?)
|
|
"not within the extent of a macro transformer")
|
|
(~bind [value (syntax-local-value #'x (lambda () notfound))])
|
|
(~fail #:when (eq? (attribute value) notfound))
|
|
(~fail #:unless (pred (attribute value))))))
|
|
|
|
#|
|
|
(define-syntax-class expr
|
|
#:attributes ()
|
|
#:description "expression"
|
|
#:commit
|
|
(pattern (~and x (~fail #:when (keyword? (syntax-e #'x))))))
|
|
|#
|