Previous: , Up: expander clauses   [Index]


15.5.4 Clause specification objects

Clause specification objects are opaque objects, disjoint from all the other Scheme object types, representing the constraints enforceable on a syntax clause.

Object Type: <syntax-clause-spec>

Type of objects representing a syntax clause specification.

Function: make-syntax-clause-spec keyword min-occur max-occur min-args max-args mutually-inclusive mutually-exclusive
Function: make-syntax-clause-spec keyword min-occur max-occur min-args max-args mutually-inclusive mutually-exclusive custom-data

Build and return a new syntax clause specification object. The arguments are:

keyword

An identifier representing the keyword for this clause.

min-occur

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.

max-occur

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.

min-args

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.

max-args

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.

mutually-inclusive

A list identifiers representing clauses keywords that must appear along with this one.

mutually-exclusive

A list identifiers representing clauses keywords that must not appear along with this one.

custom-data

Optional free value available for the user. It is initialised to #f.

Function: syntax-clause-spec? obj

Return #t if obj is a syntax clause specification object, otherwise return #f.

Function: syntax-clause-spec-keyword spec
Function: syntax-clause-spec-min-number-of-occurrences spec
Function: syntax-clause-spec-max-number-of-occurrences spec
Function: syntax-clause-spec-min-number-of-arguments spec
Function: syntax-clause-spec-max-number-of-arguments spec
Function: syntax-clause-spec-mutually-inclusive spec
Function: syntax-clause-spec-mutually-exclusive spec
Function: syntax-clause-spec-custom-data spec

Accessors for the fields of syntax clause specification objects.

Function: syntax-clauses-single-spec spec unwrapped-clauses
Function: syntax-clauses-single-spec spec unwrapped-clauses synner

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))
Function: syntax-clauses-fold-specs combine knil specs unwrapped-clauses
Function: syntax-clauses-fold-specs combine knil specs unwrapped-clauses synner

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.

Function: syntax-clauses-validate-specs list-of-specs

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:


Previous: , Up: expander clauses   [Index]