Add unstable lenses package with sty lenses

This commit is contained in:
Jack Firth 2015-07-09 23:07:25 -07:00
parent 269cf13514
commit 499f8da222
9 changed files with 53 additions and 11 deletions

View File

@ -1,17 +1,20 @@
#lang racket
(provide lenses-examples
lenses-applicable-examples)
lenses-applicable-examples
lenses-unstable-examples)
(require scribble/eval)
(define-syntax-rule (define-examples-form id require-spec ...)
(begin
(define base-eval (make-base-eval))
(base-eval '(require require-spec)) ...
(define (eval-factory)
(define base-eval (make-base-eval))
(base-eval '(require require-spec)) ...
base-eval)
(define-syntax-rule (id datum (... ...))
(examples #:eval base-eval datum (... ...)))))
(examples #:eval (eval-factory) datum (... ...)))))
(define-examples-form lenses-examples
@ -19,3 +22,6 @@
(define-examples-form lenses-applicable-examples
lens/applicable racket/list)
(define-examples-form lenses-unstable-examples
lens unstable/lens racket/list)

4
unstable/info.rkt Normal file
View File

@ -0,0 +1,4 @@
#lang info
(define name "unstable")
(define scribblings '(("lens/main.scrbl" () (library) "unstable-lens")))

5
unstable/lens.rkt Normal file
View File

@ -0,0 +1,5 @@
#lang racket
(require "lens/main.rkt")
(provide (all-from-out "lens/main.rkt"))

5
unstable/lens/main.rkt Normal file
View File

@ -0,0 +1,5 @@
#lang racket
(require "syntax.rkt")
(provide (all-from-out "syntax.rkt"))

12
unstable/lens/main.scrbl Normal file
View File

@ -0,0 +1,12 @@
#lang scribble/manual
@title{Unstable Lenses}
@defmodule[unstable/lens]
This library provides additional features for the
@racketmodname[lens] library that are non-final and
may change in future releases. Do not depend on
this library being backwards-compatible.
@include-section["syntax.scrbl"]

7
unstable/lens/syntax.rkt Normal file
View File

@ -0,0 +1,7 @@
#lang racket
(require "syntax/syntax.rkt"
"syntax/syntax-keyword.rkt")
(provide (all-from-out "syntax/syntax.rkt"
"syntax/syntax-keyword.rkt"))

View File

@ -1,7 +1,7 @@
#lang scribble/manual
@(require scribble/eval
"lenses-examples.rkt"
lens/lenses-examples
(for-label lens
racket/base
racket/contract))
@ -9,11 +9,13 @@
@title{Syntax Lenses}
@defmodule[unstable/lens/syntax]
@defform[(syntax-lens target-id structure)]{
Constructs a lens that parses a syntax object and returns
a piece of that syntax object as determined by where
@racket[target-id] appears in @racket[structure].
@lenses-examples[
@lenses-unstable-examples[
(define first-of-second-stx-lens
(syntax-lens A
(_ (A _ ...) _ ...)))
@ -30,18 +32,19 @@
and views a syntax object containing all the terms in the
target syntax that appear after @racket[kw] but before any
other keyword.
@lenses-examples[
@lenses-unstable-examples[
(define foo-kw-seq-lens (syntax-keyword-seq-lens '#:foo))
(lens-view foo-kw-seq-lens #'(a #:foo c d #:bar f))
(lens-set foo-kw-seq-lens #'(a #:foo c d #:bar f) #'(1 2 3 4 5 6))
]
If the target syntax object has no occurence of @racket[kw],
or if the occurence of @racket[kw] is at the end of the syntax
object or immediately followed by another keyword, then viewing
produces the empty list syntax object @racket[#'()]. In the case
where @racket[kw] is not present, setting is a no-op.
@lenses-examples[
@lenses-unstable-examples[
(define foo-kw-seq-lens (syntax-keyword-seq-lens '#:foo))
(lens-view foo-kw-seq-lens #'(a b f g))
(lens-view foo-kw-seq-lens #'(a #:foo #:bar f))
(lens-set foo-kw-seq-lens #'(a #:foo #:bar f) #'(1 2 3 4 5 6))

View File

@ -1,6 +1,6 @@
#lang racket
(require "base/main.rkt"
(require lens
fancy-app
syntax/parse)

View File

@ -2,7 +2,7 @@
(require syntax/parse
rackunit
"base/main.rkt"
lens
(for-syntax racket/syntax
syntax/stx
syntax/parse))