Previous: expander clauses constr, Up: expander clauses [Index]
Clause specification objects are opaque objects, disjoint from all the other Scheme object types, representing the constraints enforceable on a syntax clause.
Type of objects representing a syntax clause specification.
Build and return a new syntax clause specification object. The arguments are:
An identifier representing the keyword for this clause.
A non–negative real number representing the allowed minimum number of occurrences for this clause. ‘0’ means the clause is optional; ‘1’ means the clause is mandatory.
A non–negative real number representing the allowed maximum number of occurrences for this clause. ‘0’ means the clause is forbidden; ‘1’ means the clause must appear at most once; ‘+inf.0’ means the clause can appear any number of times.
A non–negative real number representing the allowed minimum number of arguments for this clause. ‘0’ means the clause can have no arguments; ‘1’ means the clause must have at least one argument.
A non–negative real number representing the allowed maximum number of arguments for this clause. ‘0’ means the clause has no arguments; ‘1’ means the clause must have at most one arguments; ‘+inf.0’ means the clause can have any number of arguments.
A list identifiers representing clauses keywords that must appear along with this one.
A list identifiers representing clauses keywords that must not appear along with this one.
Optional free value available for the user. It is initialised to
#f
.
Return #t
if obj is a syntax clause specification object,
otherwise return #f
.
Accessors for the fields of syntax clause specification objects.
Given a fully unwrapped syntax object holding a list of clauses (for
example the return value of syntax-clauses-unwrap
) verify if
there are clauses conforming to the given specification spec.
If successful return a (possibly empty) vector of vectors of syntax
objects; else call synner or raise a &syntax
exception.
The length of the returned vector is the number of clauses from
unwrapped-clauses conforming to spec. Each nested vector
represents the cdr of a clause matching spec:
Examples:
(import (vicare)) (syntax-clauses-single-spec (make-syntax-clause-spec #'b 1 1 1 1 '() '()) (syntax-clauses-unwrap #'((a 123) (b 456) (d 789)))) ⇒ #(#(456)) (syntax-clauses-single-spec (make-syntax-clause-spec #'b 1 1 0 +inf.0 '() '()) (syntax-clauses-unwrap #'((a 123) (b) (d 789)))) ⇒ #(#()) (syntax-clauses-single-spec (make-syntax-clause-spec #'b 1 1 0 +inf.0 '() '()) (syntax-clauses-unwrap #'((a 123) (b 4 5 6) (d 789)))) ⇒ #(#(4 5 6)) (syntax-clauses-single-spec (make-syntax-clause-spec #'b 1 1 0 +inf.0 '() '()) (syntax-clauses-unwrap #'((a 123) (b 4) (b 5) (b 6) (d 789)))) ⇒ #(#(4) #(5) #(6)) (syntax-clauses-single-spec (make-syntax-clause-spec #'b 1 1 0 +inf.0 '() '()) (syntax-clauses-unwrap #'((a 123) (b 4 4.1) (b 5 5.1) (d 789)))) ⇒ #(#(4 4.1) #(5 5.1)) (syntax-clauses-single-spec (make-syntax-clause-spec #'b 1 1 0 +inf.0 '() '()) (syntax-clauses-unwrap #'((a 123) (b 4 ciao 6) (d 789)))) ⇒ #(#(4 #<syntax-object expr=ciao> 6))
Given a fully unwrapped syntax object holding a list of clauses (for
example the return value of syntax-clauses-unwrap
) verify that
the clauses conform to the given specs, which must be a list of
syntax clause specification objects.
Combine the clause arguments with the given knil in a
fold-left
fashion, if successful return the resulting knil;
if an invalid clause is found call synner or raise a
&syntax
object.
The operation is conceptually as follows:
(fold-left (lambda (knil spec) (let ((args (syntax-clauses-single-spec spec unwrapped-clauses synner))) (if (fxzero? (vector-length args)) knil (combine knil spec args)))) knil specs)
notice that combine is called only if a clause from specs is present in unwrapped-clauses; combine must return the new value for knil.
Given a list of syntax-clause-spec
objects: perform some
validations among them. If successful return list-of-specs
itself, otherwise raise an assertion violation.
The following checks are performed:
mutually-inclusive
field of
every syntax-clause-spec
: check that such identifier is equal,
according to free-identifier=?
, to an identifier in the
keyword
field of another syntax-clause-spec
object.
mutually-exclusive
field of
every syntax-clause-spec
: check that such identifier is equal,
according to free-identifier=?
, to an identifier in the
keyword
field of another syntax-clause-spec
object.
Previous: expander clauses constr, Up: expander clauses [Index]