-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add #lang envy, which uses sweet-exp syntax
- Loading branch information
1 parent
7c71f90
commit 06b4fee
Showing
10 changed files
with
292 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#lang info | ||
|
||
(define scribblings '(("scribblings/envy.scrbl"))) | ||
(define scribblings '(("scribblings/envy.scrbl" (multi-page)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#lang s-exp syntax/module-reader envy/s-exp/lang/language | ||
|
||
#:read sw:read | ||
#:read-syntax sw:read-syntax | ||
|
||
(require (submod sweet-exp link-reader) | ||
(prefix-in tr: typed-racket/typed-reader)) | ||
|
||
(define-values (sw:read sw:read-syntax) | ||
(sweet-link tr:read tr:read-syntax)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#lang typed-racket/minimal | ||
|
||
(require (rename-in typed/racket/base | ||
[#%module-begin tr:module-begin]) | ||
envy | ||
(for-syntax racket/base)) | ||
|
||
(provide (except-out (all-from-out typed/racket/base) | ||
tr:module-begin) | ||
(rename-out [module-begin #%module-begin])) | ||
|
||
(define-syntax (module-begin stx) | ||
(syntax-case stx () | ||
[(_ clause ...) | ||
(with-syntax ([injected-require (datum->syntax stx '(require envy))]) | ||
#'(tr:module-begin injected-require | ||
(define/provide-environment clause ...)))])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#lang s-exp syntax/module-reader envy/s-exp/lang/language | ||
|
||
#:read r:read | ||
#:read-syntax r:read-syntax | ||
|
||
(require (prefix-in r: typed-racket/typed-reader)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#lang scribble/manual | ||
|
||
@(require (for-label envy | ||
typed/racket/base)) | ||
|
||
@title[#:tag "api-reference"]{API Reference} | ||
|
||
@defform[#:literals (:) | ||
(define-environment clause ...) | ||
#:grammar | ||
([clause name-id | ||
[name-id maybe-type option ...]] | ||
[maybe-type (code:line) | ||
(code:line : type-id)] | ||
[option (code:line #:name env-var-name-expr) | ||
(code:line #:default default-expr)])]{ | ||
Defines a set of variables to be initialized with values from the environment. | ||
|
||
Each @racket[name-id] is assigned the value of the environment variable with the name | ||
@racket[env-var-name-expr]. If no @racket[env-var-name-expr] is provided, the environment variable | ||
name is inferred based on @racket[name-id]: the identifier is converted to all caps, all dashes are | ||
converted to underscores, and all question marks are stripped. | ||
|
||
Before being assigned to @racket[name-id], the value of the environment variable is parsed based on | ||
@racket[type-id]. If no @racket[type-id] is provided, the type is inferred to be @racket[String]. | ||
The following types are supported: | ||
|
||
@itemlist[ | ||
@item{@racket[String]} | ||
@item{@racket[Symbol]} | ||
@item{@racket[Boolean] (must be either @racket["true"] or @racket["false"])} | ||
@item{@racket[Number]} | ||
@item{@racket[Integer]} | ||
@item{@racket[Positive-Integer]} | ||
@item{@racket[Negative-Integer]} | ||
@item{@racket[Nonnegative-Integer]}] | ||
|
||
If the specified variable does not exist in the environment, @racket[name-id] is set to the value of | ||
@racket[default-expr]. If no @racket[default-expr] is provided, an error is raised.} | ||
|
||
@defform[(define/provide-environment clause ...)]{ | ||
Exactly the same as @racket[define-environment] but also @racket[provide]s each @racket[_name-id].} | ||
|
||
@defform[(define-environment-variable name-id maybe-type option ...)]{ | ||
Exactly the same as @racket[define-environment] but only defines a single variable. The syntax is | ||
the same as @racket[define-environment]'s @racket[_clause].} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#lang scribble/manual | ||
|
||
@(require (for-label envy | ||
typed/racket/base)) | ||
|
||
@title[#:tag "syntax"]{Using Envy with S-expression syntax} | ||
|
||
Envy's syntax does not look like traditional S-expressions, but in fact it is just using ordinary | ||
Racket syntax with a special reader, called | ||
@seclink["top" #:doc '(lib "sweet-exp/sweet.scrbl")]{“sweet expressions”}. The ordinary, S-expression | ||
based syntax is exposed through the @racketmodname[envy/s-exp] language, as well as the | ||
@racketmodname[envy] module, which can be used in any Typed Racket module via @racket[require]. | ||
|
||
@section{@tt{#lang envy/s-exp}} | ||
|
||
@defmodule[envy/s-exp #:lang] | ||
|
||
The @racketmodname[envy/s-exp] language works exactly like the @racketmodname[envy] language, but it | ||
does not enable the sweet expression reader. Each declaration must be properly grouped. | ||
|
||
@codeblock{ | ||
#lang envy/s-exp | ||
[some-var : Positive-Integer #:default #f] | ||
[another-var : Boolean #:name "CUSTOM NAME"] | ||
} | ||
|
||
This language works just like using the @racketmodname[envy] module directly, but its body is wrapped | ||
in @racket[define/provide-environment]. | ||
|
||
@section{The @racketmodname[envy] module} | ||
|
||
Using @racketmodname[envy] as a module imports the Envy API, which allows embedding Envy's | ||
functionality in larger modules. | ||
|
||
@(racketblock | ||
(require @#,racketmodname[envy]) | ||
(define/provide-environment | ||
[some-var : Positive-Integer #:default #f] | ||
[another-var : Boolean #:name "CUSTOM NAME"])) | ||
|
||
For full information on all the forms provided by Envy, see the @secref["api-reference"]. |
Oops, something went wrong.