► |  | Syntax: Meta-Programming Helpers

1 | Parsing and Specifying Syntax
2 | Syntax Object Helpers
3 | Datum Pattern Matching
4 | Module-Processing Helpers
5 | Macro Transformer Helpers
6 | Reader Helpers
7 | Parsing for Bodies
8 | Unsafe for Clause Transforms
9 | Source Locations
10 | Preserving Source Locations
11 | Non-Module Compilation And Expansion
12 | Trusting Standard Recertifying Transformers
13 | Attaching Documentation to Exports
14 | Contracts for Macro Subexpressions
15 | Macro Testing
16 | Internal-Definition Context Helpers
| Index

▼ | 1 | Parsing and Specifying Syntax

1.1 | Introduction
1.2 | Examples
1.3 | Parsing Syntax
1.4 | Specifying Syntax with Syntax Classes
1.5 | Syntax Patterns
1.6 | Defining Simple Macros
1.7 | Literal Sets and Conventions
1.8 | Library Syntax Classes and Literal Sets
1.9 | Unwindable State
1.10 | Debugging and Inspection Tools
1.11 | Experimental

On this page:

syntax-parse-state-ref
syntax-parse-state-set!
syntax-parse-state-update!
syntax-parse-state-cons!
syntax-parse-track-literals

top ← prev up next →

#### 1.9`` Unwindable State

> > procedure

> > (syntax-parse-state-ref key [default]) → any/c

> key : any/c
> default : default/c = (lambda () (error ....))

> > procedure

> > (syntax-parse-state-set! key value) → void?

> key : any/c
> value : any/c

> > procedure

> > (syntax-parse-state-update! |  | key |  |  |  |
> > |  | update |  |  |  |
> > | [ | default]) |  | → |  | void?

> key : any/c
> update : (-> any/c any/c)
> default : default/c = (lambda () (error ....))

> > procedure

> > (syntax-parse-state-cons! key value [default]) → void?

> key : any/c
> value : any/c
> default : default/c = null

Get or update the current syntax-parse state. Updates to the state are unwound when syntax-parse backtracks. Keys are compared using eq?.

The state can be updated only within ~do patterns (or #:do blocks). In addition, syntax-parse automatically adds identifiers that match literals (from ~literal patterns and literals declared with #:literals, but not from ~datum or #:datum-literals) under the key 'literals.

Examples:

> > (define-syntax-class cond-clause
> #:literals (=> else)
> (pattern [test:expr => ~! answer:expr ...])
> (pattern [else answer:expr ...])
> (pattern [test:expr answer:expr ...]))

> > (syntax-parse #'(cond [A => B] [else C])
> [(_ c:cond-clause ...) (syntax-parse-state-ref 'literals null)])

> '(#<syntax:eval:2:0 else> #<syntax:eval:2:0 =>>)

Added in version 6.11.0.4 of package base.

> > procedure

> > (syntax-parse-track-literals |  | stx |  |  |  |
> > | [ | #:introduce? introduce?]) |  | → |  | syntax?

> stx : syntax?
> introduce? : any/c = #t

Add a 'disappeared-use syntax property to stx containing the information stored in the current syntax-parse state under the key 'literals. If stx already has a 'disappeared-use property, the added information is consed onto the property’s current value.

Due to the way syntax-parse automatically adds identifiers that match literals to the state under the key 'literals, as described in the documentation for syntax-parse-state-ref, syntax-parse-track-literals can be used to automatically add any identifiers used as literals to the 'disappeared-use property.

If syntax-parse-track-literals is called within the dynamic extent of a syntax transformer (see syntax-transforming?), introduce? is not #f, and the value in the current syntax-parse state under the key 'literals is a list, then syntax-local-introduce is applied to any identifiers in the list before they are added to stx’s 'disappeared-use property.

Most of the time, it is unnecessary to call this function directly. Instead, the #:track-literals option should be provided to syntax-parse, which will automatically call syntax-parse-track-literals on syntax-valued results.

Examples:

> > (define-syntax-class cond-clause
> #:literals (=> else)
> (pattern [test:expr => ~! answer:expr ...])
> (pattern [else answer:expr ...])
> (pattern [test:expr answer:expr ...]))

> > (syntax-property
> (syntax-parse #'(cond [A => B] [else C])
> [(_ c:cond-clause ...) (syntax-parse-track-literals #'#f)])
> 'disappeared-use)

> '(#<syntax:eval:4:0 else> #<syntax:eval:4:0 =>>)

Added in version 6.90.0.29 of package base.

top ← prev up next →