ast ::= meta (metavariable) | ident (variable) | integer (positive integer) | string (quoted string) | path (section-path) | {
ident}
(identifier) | [
name]
ast(abstraction) | (
ident [ast ... ast])
(application node) | (
special-tok meta)
(special-operator) | '
ast(quoted ast) | quotation
meta::= $
identpath ::= #ident ... #ident .
kindkind ::= cci
|fw
|obj
name ::= <>
| ident | meta
special-tok::= $LIST
|$VAR
|$NUM
|$STR
|$PATH
|$ID
quotation::= <<
meta-command>>
| <:command:<
meta-command>>
| <:vernac:<
meta-vernac>>
| <:tactic:<
meta-tactic>>
Figure 9.1:Syntax of AST expressions
Ast
and
List
. The type of variables is checked statically: an
expression refering to undefined metavariables, or using metavariables
with an unappropriate type, will be rejected.(
special-tok meta)
, and cannot be confused with regular
nodes since special-tok begins with a $
. There is a
description of these nodes below.
[x]x
is equal to [y]y
). This makes the difference
between variables and identifiers clear: the former may be bound by
abstractions, whereas identifiers cannot be bound. To illustrate this,
[x]{x}
is equal to [y]{x}
, but not to [y]{y}
.(x:$A)$B
is mapped to the AST
(PROD $A [x]$B)
, whereas the non dependent product
$A->$B
is mapped to (PROD $A [<>]$B)
([<>]t
is an
anonymous abstraction).'
t construction means that the AST t should not be
interpreted at all. The main effect is that metavariables occurring in
it cannot be substituted or considered as binding in patterns.
<<(eq ? $f $g)>>
denotes the AST which is
the application (in the sense of CIC) of the constant eq to
three arguments. It is coded as an AST node labelled APPLIST
with four arguments.command command
grammar. This grammar
is invoked on this term to generate an AST by putting the term between
``<<
'' and ``>>
''.<< t >>
parses t with command command grammar
(terms of CIC).
<:command:< t >>
parses t with command command
grammar (same as << t >>
).
<:vernac:< t >>
parses t with vernac vernac
grammar (vernacular commands).
<:tactic:< t >>
parses t with tactic tactic
grammar (tactic expressions).
($LIST $x)
injects the AST list variable
$x in an AST position. For example, an application node is
composed of an identifier followed by a list of AST's that are glued
together. Each of these expressions must denote an AST. If we want to
insert an AST list, one has to use the $LIST
operator. Assume
the variable $idl
is bound to the list [x y z]
, the
expression (Intros ($LIST $idl) a b c)
will build the AST
(Intros x y z a b c)
. Note that $LIST
does not occur in
the result.$LIST
is not really
necessary. We enforce this annotation to stress on the fact that the
variable will be substituted by an arbitrary number of AST's.(PAIR $x $x)
matches any AST which is
a node labelled PAIR applied to two identical arguments, and
binds this argument to $x. If $x was already bound, the
arguments must also be equal to the current value of $x.$_
is not a regular metavariable: it
matches any term, but does not bind any variable. The pattern
(PAIR $_ $_)
matches any PAIR node applied to two
arguments.(Intros $id)
and (Intros ($LIST $idl))
. The
former matches nodes with exactly one argument, which is bound
in the AST variable $id. On the other hand, the latter pattern
matches any AST node labelled Intros, and it binds the
list of its arguments to the list variable $idl. The
$LIST pattern must be the last item of a list pattern, because
it would make the pattern matching operation more complicated. The
pattern (Intros ($LIST $idl) $lastid)
is not accepted.(DO ($NUM $n) $tc)
matches
(DO 5 (Intro))
, and creates the bindings ($n,5) and
($tc,(Intro)
). The pattern matching would fail on
(DO "5" (Intro))
.