Commit 8aee11ed authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2004-10-30 00:43:38 by beppe] Empty log message

Original author: beppe
Date: 2004-10-30 00:43:53+00:00
parent 18fad93b
......@@ -16,7 +16,7 @@
This page presents some advanced programming examples in CDuce. <b
style="color:#FF0080">If you never saw CDuce programs before, this is the wrong
page</b> to start with. Rather follow our <local href="tutorial"/>, or test the
simple examples in our <a href="/cgi-bin/cduce">on line demo</a>.
simple examples in our <a href="http://reglisse.ens.fr/cgi-bin/cduce">on line demo</a>.
</box>
......
......@@ -8,7 +8,7 @@
<boxes-toc/>
<p>
You can cut and paste the code on this page and
test it on the <a href="cgi-bin/cduce">online interpreter</a>.
test it on the <a href="http://reglisse.ens.fr/cgi-bin/cduce">online interpreter</a>.
</p>
</left>
......@@ -142,7 +142,7 @@ correctly do not yield any warning: in this case it is possible to build a value
We paid special care in localizing errors and suggesting solutions.
You can try it by
yourself by picking the examples available on the <a
href="../cgi-bin/cduce">on line demo</a> and putting in
href="../http://reglisse.ens.fr/cgi-bin/cduce">on line demo</a> and putting in
them random errors.
</p>
</box>
......@@ -186,4 +186,4 @@ Ok.
]]></sessionsample>
</box>
</page>
\ No newline at end of file
</page>
......@@ -6,7 +6,7 @@
<boxes-toc/>
<p>
You can cut and paste the code on this page and
test it on the <a href="cgi-bin/cduce">online interpreter</a>.
test it on the <a href="http://reglisse.ens.fr/cgi-bin/cduce">online interpreter</a>.
</p>
</left>
......
......@@ -8,7 +8,7 @@
<boxes-toc/>
<p>
You can cut and paste the code on this page and
test it on the <a href="cgi-bin/cduce">online interpreter</a>.
test it on the <a href="http://reglisse.ens.fr/cgi-bin/cduce">online interpreter</a>.
</p>
</left>
......
......@@ -7,7 +7,7 @@
<boxes-toc/>
<p>
You can cut and paste the code on this page and
test it on the <a href="cgi-bin/cduce">online interpreter</a>.
test it on the <a href="http://reglisse.ens.fr/cgi-bin/cduce">online interpreter</a>.
</p>
</left>
......@@ -317,7 +317,7 @@ type Email= <email>[ Echar+ ('.' Echar+)* '@' Echar+ ('.' Echar+)+ ]
]]></sample>
<p> The type ParentBook describes XML documents that store information
of persons. A tag <code>&lt;tag attr1=...; attr2=...; ...&gt;</code>
of persons. A tag <code>&lt;tag attr1=... attr2=... ...&gt;</code>
followed by a sequence type denotes an XML document type. Sequence
types classify ordered lists of heterogeneous elements and they are
denoted by square brackets that enclose regular expressions over types
......
......@@ -6,7 +6,7 @@
<boxes-toc/>
<p>
You can cut and paste the code on this page and
test it on the <a href="cgi-bin/cduce">online interpreter</a>.
test it on the <a href="http://reglisse.ens.fr/cgi-bin/cduce">online interpreter</a>.
</p>
</left>
......
......@@ -6,7 +6,7 @@
<boxes-toc/>
<p>
You can cut and paste the code on this page and
test it on the <a href="cgi-bin/cduce">online interpreter</a>.
test it on the <a href="http://reglisse.ens.fr/cgi-bin/cduce">online interpreter</a>.
</p>
</left>
......
......@@ -8,7 +8,7 @@
<boxes-toc/>
<p>
You can cut and paste the code on this page and
test it on the <a href="cgi-bin/cduce">online interpreter</a>.
test it on the <a href="http://reglisse.ens.fr/cgi-bin/cduce">online interpreter</a>.
</p>
</left>
......@@ -17,6 +17,93 @@ test it on the <a href="cgi-bin/cduce">online interpreter</a>.
<b style="color:#FF0080">TO BE DONE</b>
</box>
<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
</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
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
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>
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>
</p>
<p> While this abbreviation results quite handy it requires some care when using
record patterns. As we sais 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
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 varible <code>a</code> the attributes),
the pattern <code>&lt;(t) (a)>_</code> matches all XML elements (whatever their
tag is) and captures their tag in the variable <code>t</code> (and their
attributes in <code>a</code>). Another point to notice is that <code>&lt;t>_</code>
stands for <code>&lt;t ({})>_</code> (more precisely, for <code>&lt;(`t) ({})>_</code>). Since
<code>{}</code> is the open 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:
</p>
<b style="color:#FF0080">TO BE DONE</b>
<p>
As an example to summarize what we said above, consider the the elements
<code>table</code>, <code>td</code> and <code>tr</code> in XHTML. In
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;
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.
</p>
<sample><![CDATA[
type Table = <table {| bgcolor=?String; style=?String |}>[ Tr+]
type Tr = <tr {| bgcolor=?String; style=?String |}>[ Td+]
type Td = <td {| bgcolor=?String; style=?String |}>[ Table* | PCDATA ]
let strict ([Table*]->[Table*]; [Tr+]->[Tr+]; [Td+]->[Td+]; [PCDATA]->[PCDATA])
x -> map x with
<(t) (a& {| bgcolor=c; style=s |})> l
-> <(t) (a \ bgcolor+{style=(s@"; bgcolor:"@c)})>(strict l)
| <(t) (a& {| bgcolor=c |})> l
-> <(t) (a \ bgcolor+{style=("bgcolor:"@c)})>(strict l)
| <(t)> l -> <(t)>(strict l)
| c -> c
]]></sample>
<p>
As an exercise the reader can try to rewrite the function strict so that the first three branches of the map are condensated into a unique branch.
</p>
</box>
<box title="Handling optional attributes" link="optatrr">
<p>
The blend of type type constructors and boolean combinator can be used to
......
......@@ -45,8 +45,7 @@ transform %%e1%% with %%p1%% ->
<box title="XPath-like expressions" link="xpath">
<p> XPath-like expressions are of two kind :
<code> %%e%%/%%t%% </code> and <code> %%e%%/@%%a%% </code> where <code>%%e%%</code> is an expression, <code> %%t%% </code> a type, and <code> %%a%% </code> an attribute.
<code> %%e%%/%%t%% </code>, <code> %%e%%/@%%a%% </code>, and <code> %%e%%//%%t%% </code> where <code>%%e%%</code> is an expression, <code> %%t%% </code> a type, and <code> %%a%% </code> an attribute.
</p>
<p>
......
......@@ -6,7 +6,7 @@
<boxes-toc/>
<p>
You can cut and paste the code on this page and
test it on the <a href="cgi-bin/cduce">online interpreter</a>.
test it on the <a href="http://reglisse.ens.fr/cgi-bin/cduce">online interpreter</a>.
</p>
</left>
<box title="Introduction" link="xpath">
......
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