Expose function-header's name, document attributes, fix links

This commit is contained in:
Sorawee Porncharoenwase 2019-06-04 18:35:57 -07:00 committed by Sam Tobin-Hochstadt
parent 1b4126d1e5
commit 3043dbd35c
4 changed files with 60 additions and 23 deletions

View File

@ -1,28 +1,39 @@
#lang scribble/doc #lang scribble/doc
@(require (for-syntax racket/base) @(require (for-syntax racket/base)
syntax/parse/define
scribble/manual scribble/manual
scribble/struct scribble/struct
scribble/decode scribble/decode
scribble/eval scribble/eval
"../common.rkt" "../common.rkt"
"parse-common.rkt" "parse-common.rkt"
(for-label racket/base racket/contract racket/syntax syntax/kerncase)) (for-label racket/base racket/contract racket/syntax
syntax/kerncase syntax/parse/lib/function-header))
@(define the-eval (make-sp-eval)) @(define the-eval (make-sp-eval))
@(the-eval `(require syntax/parse/lib/function-header)) @(the-eval '(require syntax/parse/lib/function-header))
@title{Library Syntax Classes and Literal Sets} @title{Library Syntax Classes and Literal Sets}
@section{Syntax Classes} @section{Syntax Classes}
@(begin @(begin
(define-syntax (defstxclass stx) (begin-for-syntax
(syntax-case stx () (define-splicing-syntax-class stxclass-option
[(defstxclass name . pre-flows) #:attributes (type)
(identifier? #'name) (pattern {~seq #:splicing}
#'(defidform #:kind "syntax class" name . pre-flows)] #:with type #'"splicing syntax class")
[(defstxclass datum . pre-flows) (pattern {~seq}
#'(defproc #:kind "syntax class" datum @#,tech{syntax class} . pre-flows)]))) #:with type #'"syntax class")))
(define-syntax-parser defstxclass
[(_ name:id :stxclass-option . pre-flows)
#'(defidform #:kind type name . pre-flows)]
[(_ datum . pre-flows)
#'(defproc #:kind "syntax class" datum @#,tech{syntax class} . pre-flows)])
(define-syntax-parser defattribute
[(_ name:id . pre-flows)
#'(subdefthing #:kind "attribute" #:link-target? #f name
. pre-flows)]))
@defstxclass[expr]{ @defstxclass[expr]{
@ -221,18 +232,37 @@ Note that the literal-set uses the names @racket[#%plain-lambda] and
@defmodule[syntax/parse/lib/function-header] @defmodule[syntax/parse/lib/function-header]
@defstxclass[function-header]{ @defstxclass[function-header]{
Matches the formals found in function headers. Including Matches a name and formals found in function header.
keyword and rest arguments.} It also supports the curried function shorthand.
@defstxclass[formal]{ @defattribute[name syntax?]{
Matches a single formal that can be used in a function The name part in the function header.
header.} }
@defattribute[params syntax?]{
The list of parameters in the function header.
}
}
@defstxclass[formal #:splicing]{
Matches a single formal that can be used in a function header.
@defattribute[name syntax?]{
The name part in the formal.
}
@defattribute[kw (or/c syntax? #f)]{
The keyword part in the formal, if it exists.
}
@defattribute[default (or/c syntax? #f)]{
The default expression part in the formal, if it exists.
}
}
@defstxclass[formals]{ @defstxclass[formals]{
Matches a list of formals that would be used in a function Matches a list of formals that would be used in a function header.
header.} @defattribute[params syntax?]{
The list of parameters in the formals.
}
}
@interaction[#:eval the-eval @interaction[#:eval the-eval
(syntax-parse #'(define ((foo x) y) 1) (syntax-parse #'(define ((foo x) y) 1)
[(_ header:function-header body ...+) #'(header header.params)]) [(_ header:function-header body ...+) #'(header header.name header.params)])
(syntax-parse #'(lambda xs xs) (syntax-parse #'(lambda xs xs)
[(_ fmls:formals body ...+) #'(fmls fmls.params)]) [(_ fmls:formals body ...+) #'(fmls fmls.params)])
(syntax-parse #'(lambda (x y #:kw [kw 42] . xs) xs) (syntax-parse #'(lambda (x y #:kw [kw 42] . xs) xs)

View File

@ -104,9 +104,13 @@
(racket id) (racket id)
#|(superscript (symbol->string 'suffix)) ...|# )])) #|(superscript (symbol->string 'suffix)) ...|# )]))
(define-syntax-rule (subdefthing . xs)
(nested #:style "leftindent" (defthing . xs)))
(provide defhere (provide defhere
ref ref
def) def
subdefthing)
;; ---- ;; ----

View File

@ -81,10 +81,12 @@
(syntax-parse #'(f a b c) (syntax-parse #'(f a b c)
[a:function-header [a:function-header
(s= a '(f a b c )) (s= a '(f a b c ))
(s= a.params '(a b c))])) (s= a.params '(a b c))
(s= a.name 'f)]))
(test-case "function header: curried" (test-case "function header: curried"
(syntax-parse #'((f doing) currying) (syntax-parse #'((f doing) currying)
[a:function-header [a:function-header
(s= a '((f doing) currying)) (s= a '((f doing) currying))
(s= a.params '(doing currying))])) (s= a.params '(doing currying))
(s= a.name 'f)]))

View File

@ -6,9 +6,10 @@
(provide function-header formal formals) (provide function-header formal formals)
(define-syntax-class function-header (define-syntax-class function-header
(pattern ((~or header:function-header name:id) . args:formals) #:attributes (name params)
#:attr params (pattern ((~or header:function-header name*:id) . args:formals)
#'((~@ . (~? header.params ())) . args.params))) #:attr params #'((~@ . (~? header.params ())) . args.params)
#:attr name #'(~? header.name name*)))
(define-syntax-class formals (define-syntax-class formals
#:attributes (params) #:attributes (params)