Commit 7e482e83 authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2004-10-30 10:55:13 by beppe] Empty log message

Original author: beppe
Date: 2004-10-30 10:55:13+00:00
parent f439f418
......@@ -22,42 +22,41 @@ test it on the <a href="http://reglisse.ens.fr/cgi-bin/cduce">online interpreter
<box title="XML elements and attributes" link="xml">
<p>
Up to now we used for XML elements (and their types) an abbreviated notation
as for <code>&lt;table align="center" valign="top">[...]</code>. Actually precise syntax of XML elements is
as for <code>&lt;table align="center" valign="top">[...]</code>. Actually, the precise syntax of XML elements is
</p>
<sample><![CDATA[
<(%%expr1%%) (%%expr2%%)>%%expr3%%
]]></sample>
<p>
where <code>%%expr1%%</code>, <code>%%expr2%%</code>, and<code>%%expr3%%</code> are generic
expressions. The same holds true for record patterns and record types, but where
the expressions are respectively replaced by patterns and types. It is important
expressions. The same holds true for record patterns, but where
the generic expressions are replaced by generic patterns (that is, <code>&lt;(%%p1%%) (%%p2%%)>%%p3%%</code>). It is important
to notice that the parentheses (in red) <code>&lt;{{(}}%%expr1%%{{)}}
{{(}}%%expr2%%{{)}}>%%expr3%%</code> are part of the syntax.<br/>
Even if <code>%%expr1%%</code>, <code>%%expr2%%</code>, and
<code>%%expr3%%</code> may be any expression, in practice the always have a very
precise form. In particular <code>%%expr1%%</code> is an <a
<code>%%expr3%%</code> may be any expression, in practice they mostly occur in a very
precise form. In particular, <code>%%expr1%%</code> is an <a
href="manual_types_patterns.html#basictag">atom</a>, <code>%%expr2%%</code> is a
<a href="manual_types_patterns.html#record">record value</a>, while
<code>%%expr3%%</code> is a sequence. Since this correspond by far to the most
common use of XML elements we have introduce some handy abbreviation, in
particular allowing the programmer to omit the surrounding <code>{{(` )}}</code>
<code>%%expr3%%</code> is a sequence. Since this corresponds, by far, to the most
common use of XML elements we have introduced some handy abbreviations: in
particular we allow the programmer to omit the surrounding <code>{{(` )}}</code>
when <code>%%expr1%%</code> is an atom, and to omit the surrounding <code>{{{ }
}}</code> and the infix semicolon <code>;</code> semicolons when
<code>%%expr2%%</code> is a record value. This is why we can write rather
<code>&lt;table align="center" valign="top">[...]</code> than
<code>&lt;{{(`}}table{{)}} {{({}}align="center"{{;}} valign="top"{{})}}
}}</code> and the infix semicolons <code>{{;}}</code> when
<code>%%expr2%%</code> is a record value. This is why we can write
<code>&lt;table align="center" valign="top">[...]</code>, rather than
<code>&lt;$$(`$$table$$)$$ $$({$$align="center"$$;$$ valign="top"$$})$$
>[...]</code>
</p>
<p> While this abbreviation results quite handy it requires some care when using
record patterns. As we said the general form of a record pattern is:
<p> While these abbreviations are quite handy, they demand some care when used in record patterns. As we said, the general form of a record pattern is:
</p>
<sample><![CDATA[
<(%%p1%%) (%%p2%%)>%%p3%%
]]></sample>
<p>
and the same abbreviations as for expressions apply. In particular this means
and the same abbreviations as for expressions apply. In particular, this means
that, say, the pattern <code>&lt;t (a)>_</code> stands for <code>&lt;(`t)
(a)>_</code>. Therefore while <code>&lt;t (a)>_</code> matches all the elements
of tag <code>t</code> (and captures in the variable <code>a</code> the
......@@ -67,9 +66,12 @@ attributes), the pattern <code>&lt;(t) (a)>_</code> matches all XML elements
<code>&lt;t>_</code> stands for <code>&lt;t ({})>_</code> (more precisely, for
<code>&lt;(`t) ({})>_</code>). Since <code>{}</code> is the <i>open</i> empty
record type, then it matches all the records. Therefore <code>&lt;t>_</code>
matches all elements of tag <code>t</code> whatever they have whatever they have
attributes or not. In the following we enumerate some simple examples to show
what we explained. For that consider the following definitions for bibliographic data:
matches all elements of tag <code>t</code> independently from whether they have
attributes or not.
</p>
<p>
In the following we enumerate some simple examples to show
what we just explained. In these examples we use the following definitions for bibliographic data:
</p>
<sample><![CDATA[
type Biblio = [(Paper|Book)*]
......@@ -95,16 +97,16 @@ transform bib with
<(book) (a)> [ (x::(Any\Url)|_)* ] -> [ <(book) (a)> x ]
]]></sample>
<p>
returns the bibliography in which all entries (either books or paper) no longer
returns the bibliography in which all entries (either books or papers) no longer
have their Url elements (<code>book</code> is now a capture variable). Equivalently we could have
pushed the differences on tags:
pushed the difference on tags:
</p>
<sample><![CDATA[
transform bib with
<(book) (a)> [ (x::<(Any\`url)>_|_)* ] -> [ <(book) (a)> x ]
]]></sample>
<p>
We can furthermore perform many kinds of manipulations on the attributes by
We can perform many kinds of manipulations on the attributes by
using the <a href="manual_expressions.html#record">operators for records</a>,
namely <code>%%r%%\%%l%%</code> which deletes the field <code>%%l%%</code>
in the record <code>%%r%%</code> whenever it is present, and <code>%%r1%% +
......@@ -124,11 +126,10 @@ transform bib with
<_ (a)> [(x::(Author|Title|Url)|_)*] -> [ <book ({isbn="fake"}+a\year)> x ]
]]></sample>
<p>
returns the bibliography in which all the Paper elements are transformed into
books, by forgetting the Conference elements removing the year attribute and
possibly adding a fake isbn attribute. Note that since record concatenation the
right-hand side record has the priority then if the record captured by
<code>a</code> already contains an isbn attribute, then this is preserved.
returns the bibliography in which all Paper elements are transformed into
books; this is done by forgetting the Conference elements, by removing the year attributes and
possibly adding a fake isbn attribute. Note that since record concatenation gives priority to the record on the righ handside, then whenever the record captured by
<code>a</code> already contains an isbn attribute, this is preserved.
</p>
<p>
......@@ -137,8 +138,8 @@ As an example to summarize what we said above, consider the the elements
transitional XHTML these elements can have an attribute <code>bgcolor</code>
which is deprecated since in strict XHTML the background color must be specified
by the <code>style</code> attribute. So for instance <code>&lt;table
bgcolor="#ffff00" style="font-family:Arial">...</code> to conform strict XHTML
must be transformed into <code>&lt;table style="bgcolor:#ffff00;
bgcolor="#ffff00" style="font-family:Arial">...</code>
must be rewritten as <code>&lt;table style="bgcolor:#ffff00;
font-family:Arial">...</code> to be XHTML strict compliant. Here is a function
that does this transformation on a very simplified version of possibly nested
tables containing strings.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment