add udelimify
This commit is contained in:
parent
17fe28f3dd
commit
dcaad607ab
|
@ -3,36 +3,16 @@
|
||||||
udelim
|
udelim
|
||||||
)
|
)
|
||||||
|
|
||||||
(provide (rename-out [at-read read]
|
(provide (rename-out [u-read read]
|
||||||
[at-read-syntax read-syntax]
|
[u-read-syntax read-syntax]
|
||||||
[at-get-info get-info]))
|
[u-get-info get-info]))
|
||||||
|
|
||||||
(define udelim-table
|
|
||||||
(make-list-delim-readtable/wrap
|
|
||||||
#\🌜 #\🌛 '#%moon-faces
|
|
||||||
#:base-readtable
|
|
||||||
(make-list-delim-readtable/wrap
|
|
||||||
#\⦕ #\⦖ '#%double-inequality-brackets
|
|
||||||
#:base-readtable
|
|
||||||
(make-list-delim-readtable/wrap
|
|
||||||
#\⦓ #\⦔ '#%inequality-brackets
|
|
||||||
#:base-readtable
|
|
||||||
(make-list-delim-readtable/wrap
|
|
||||||
#\﴾ #\﴿ '#%ornate-parens
|
|
||||||
#:base-readtable
|
|
||||||
(make-list-delim-readtable/wrap
|
|
||||||
#\⟅ #\⟆ '#%s-shaped-bag-delim
|
|
||||||
#:base-readtable
|
|
||||||
(make-string-delim-readtable/wrap
|
|
||||||
#\「 #\」 '#%cjk-corner-quotes
|
|
||||||
#:base-readtable
|
|
||||||
(make-string-delim-readtable #\« #\»))))))))
|
|
||||||
(define (wrap-reader p)
|
(define (wrap-reader p)
|
||||||
(lambda args
|
(lambda args
|
||||||
(parameterize ([current-readtable udelim-table])
|
(parameterize ([current-readtable (udelimify (current-readtable))])
|
||||||
(apply p args))))
|
(apply p args))))
|
||||||
|
|
||||||
(define-values (at-read at-read-syntax at-get-info)
|
(define-values (u-read u-read-syntax u-get-info)
|
||||||
(make-meta-reader
|
(make-meta-reader
|
||||||
'udelim
|
'udelim
|
||||||
"language path"
|
"language path"
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
(->* (char? char?) (#:base-readtable readtable?) readtable?)]
|
(->* (char? char?) (#:base-readtable readtable?) readtable?)]
|
||||||
[make-list-delim-readtable/wrap
|
[make-list-delim-readtable/wrap
|
||||||
(->* (char? char? symbol?) (#:base-readtable readtable?) readtable?)]
|
(->* (char? char? symbol?) (#:base-readtable readtable?) readtable?)]
|
||||||
|
[udelimify (->* ((or/c readtable? false/c)) readtable?)]
|
||||||
[stx-string->port (->* (syntax?) input-port?)]
|
[stx-string->port (->* (syntax?) input-port?)]
|
||||||
[scribble-strings->string (->* (syntax?) syntax?)]
|
[scribble-strings->string (->* (syntax?) syntax?)]
|
||||||
))
|
))
|
||||||
|
@ -115,6 +116,29 @@
|
||||||
(define make-list-delim-readtable/wrap
|
(define make-list-delim-readtable/wrap
|
||||||
(make-make-delim-readtable/wrap make-list-reader/wrap))
|
(make-make-delim-readtable/wrap make-list-reader/wrap))
|
||||||
|
|
||||||
|
(define (udelimify table)
|
||||||
|
(make-list-delim-readtable/wrap
|
||||||
|
#\🌜 #\🌛 '#%moon-faces
|
||||||
|
#:base-readtable
|
||||||
|
(make-list-delim-readtable/wrap
|
||||||
|
#\⦕ #\⦖ '#%double-inequality-brackets
|
||||||
|
#:base-readtable
|
||||||
|
(make-list-delim-readtable/wrap
|
||||||
|
#\⦓ #\⦔ '#%inequality-brackets
|
||||||
|
#:base-readtable
|
||||||
|
(make-list-delim-readtable/wrap
|
||||||
|
#\﴾ #\﴿ '#%ornate-parens
|
||||||
|
#:base-readtable
|
||||||
|
(make-list-delim-readtable/wrap
|
||||||
|
#\⟅ #\⟆ '#%s-shaped-bag-delim
|
||||||
|
#:base-readtable
|
||||||
|
(make-string-delim-readtable/wrap
|
||||||
|
#\「 #\」 '#%cjk-corner-quotes
|
||||||
|
#:base-readtable
|
||||||
|
(make-string-delim-readtable
|
||||||
|
#\« #\»
|
||||||
|
#:base-readtable table))))))))
|
||||||
|
|
||||||
(define (stx-string->port stx)
|
(define (stx-string->port stx)
|
||||||
(let ([str (syntax->datum stx)]
|
(let ([str (syntax->datum stx)]
|
||||||
[line (syntax-line stx)]
|
[line (syntax-line stx)]
|
||||||
|
|
|
@ -16,7 +16,7 @@ Don't consider this library to be stable right now. Particularly the udelim met
|
||||||
@section{Guide}
|
@section{Guide}
|
||||||
This is a library I wrote primarily to help make nestable embedding of different syntax in #lang rash, but is generally useful for adding extra types of parenthesis or string delimiters to a language. After watching Jay McCarthy's talk at Sixth Racketcon, I also decided to steal his idea of making different types of parenthesis wrap their contents with an additional #%symbol.
|
This is a library I wrote primarily to help make nestable embedding of different syntax in #lang rash, but is generally useful for adding extra types of parenthesis or string delimiters to a language. After watching Jay McCarthy's talk at Sixth Racketcon, I also decided to steal his idea of making different types of parenthesis wrap their contents with an additional #%symbol.
|
||||||
|
|
||||||
You can use the udelim meta-language (eg #lang udelim racket/base) to add a few extra parenthesis types and string types to any language. Specifically, «» are nestable non-escaping string delimiters (IE «foo «bar»» reads as "foo «bar»"), 「」 are like «» but wrapped so 「foo bar」 produces (#%cjk-corner-quotes "foo bar"), ﴾foo bar﴿ reads as (#%ornate-parens foo bar), ⦓foo bar⦔ reads as (#%inequality-brackets foo bar), ⦕foo bar⦖ reads as (#%double-inequality-brackets foo bar), 🌜foo bar🌛 reads as (#%moon-faces foo bar), and ⟅foo bar⟆ reads as (#%s-shaped-bag-delim foo bar). To get default meanings for the #% identifiers (currently just pass-through macros), use (require udelim/defaults).
|
You can use the udelim meta-language (eg. #lang udelim racket/base) to essentially wrap your language's readtable with @racket[udelimify].
|
||||||
|
|
||||||
@section{Reference}
|
@section{Reference}
|
||||||
|
|
||||||
|
@ -96,6 +96,15 @@ EOS
|
||||||
)))]
|
)))]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@defproc[(udelimify [table (or/c readtable? false/c)]) readtable?]{
|
||||||
|
Returns the readtable given, but extended with several more delimiters (the same ones as #lang udelim).
|
||||||
|
|
||||||
|
Specifically: «» are nestable non-escaping string delimiters (IE «foo «bar»» reads as "foo «bar»"), 「」 are like «» but wrapped so 「foo bar」 produces (#%cjk-corner-quotes "foo bar"), ﴾foo bar﴿ reads as (#%ornate-parens foo bar), ⦓foo bar⦔ reads as (#%inequality-brackets foo bar), ⦕foo bar⦖ reads as (#%double-inequality-brackets foo bar), 🌜foo bar🌛 reads as (#%moon-faces foo bar), and ⟅foo bar⟆ reads as (#%s-shaped-bag-delim foo bar).
|
||||||
|
|
||||||
|
To get default meanings for the #% identifiers (currently just pass-through macros), use @code{(require udelim/defaults)}.
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@defproc[(stx-string->port [stx syntax?]) input-port?]{
|
@defproc[(stx-string->port [stx syntax?]) input-port?]{
|
||||||
@racket[stx] should only contain a string. The location data on @racket[stx] is used to give the resulting port accurate location information when it is read. This is useful for creating macros that allow embedding of alternate syntax, such as #lang rash does.
|
@racket[stx] should only contain a string. The location data on @racket[stx] is used to give the resulting port accurate location information when it is read. This is useful for creating macros that allow embedding of alternate syntax, such as #lang rash does.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user