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

[r2003-05-13 20:04:12 by cvscast] added a couple of pages of tutorials Beppe

Original author: cvscast
Date: 2003-05-13 20:04:13+00:00
parent 777b37ec
......@@ -7,5 +7,7 @@
<include file="papers.xml"/>
<include file="examples.xml"/>
<include file="tutorial.xml"/>
<include file="tutorial1.xml"/>
<include file="tutorial2.xml"/>
<include file="team.xml"/>
</site>
......@@ -6,7 +6,16 @@
<!-- ********* Left panel ********* -->
<navig>
<toc/>
<box title="Tutorial Index">
<ul><li><a href="tutorial.php" color="red">Main tutorial page</a></li>
<li><a href="tutorial1.php">Type declarations</a></li>
<li><a href="tutorial2.php">Load files</a></li>
</ul>
</box>
<box>
<p>
This page is a step-by-step introduction to CDuce.
......@@ -18,6 +27,10 @@ This page is a step-by-step introduction to CDuce.
<li><a href="memento.php">Memento</a></li>
</ul>
</box>
</navig>
<!-- ********* Main panel ********* -->
......@@ -53,3 +66,5 @@ let y = <a>[] in ...
</main>
</page>
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<page output="tutorial1.php">
<title>CDuce tutorial</title>
<banner> CDuce tutorial </banner>
<!-- ********* Left panel ********* -->
<navig>
<toc/>
<box>
<ul><li><a href="tutorial.php" color="red">Main tutorial page</a></li>
<li><a href="tutorial1.php">Type declarations</a></li>
<li><a href="tutorial2.php">Load files</a></li>
</ul>
</box>
<box>
<p>
This page is a step-by-step introduction to CDuce.
</p>
<ul>
<li><a href="/cgi-bin/cduce">Online demo</a></li>
<li><a href="/">Home page</a></li>
<li><a href="memento.php">Memento</a></li>
</ul>
</box>
</navig>
<!-- ********* Main panel ********* -->
<main>
<box title="Type declarations" link="t1">
<p>
First, we declare some types:
</p>
<sample><![CDATA[
type ParentBook = <parentbook>[Person*];;
type Person = FPerson | MPerson;;
type FPerson = <person gender="F">[ Name Children (Tel | Email)*];;
type MPerson = <person gender="M">[ Name Children (Tel | Email)*];;
type Name = <name>[ PCDATA ];;
type Children = <children>[Person*];;
type Tel = <tel kind=?"home"|"work">['0'--'9'+ '-'? '0'--'9'+];;
type Echar = 'a'--'z' | 'A'--'Z' | '_' | '0'--'9';;
type Email= <email>[ Echar+ ('.' Echar+)* '@' Echar+ ('.' Echar+)+ ];;
]]></sample>
<p>
The type ParentBook describes XML documents that store information
of persons. A tag &lt;tag attr1=...; attr2=...; ...&gt; 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 (note that a regular
expression over types <i>is not</i> a type, it just describes the content
of a sequence type, therefore if it is not enclosed in square brackets
it is meaningless). The definitions above state that a ParentBook
element is formed by a possibly empty sequence of persons. A person is
either of type FPerson or MPerson according to the value of the
gender attribute. An equivalent definition for Person would
thus be:
</p>
<sample><![CDATA[
<person gender="F"|"M">[ Name Children (Tel | Email)*];;
]]></sample>
<p>
A person element is composed by a sequence formed of a name element, a
children element, and zero or more telephone and e-mail elements, in this order.
</p>
Name elements contain strings. These are encoded as sequences of
characters. The PCDATA keyword is equivalent to the regexp
Char*, then String, [Char*], [PCDATA], [PCDATA* PCDATA],
..., are all
equivalent notations. Children are composed of zero or more Person
elements. Telephone elements have an optional (as indicated by =?)
string attribute whose value is either ``home'' or ``work'' and they are
formed by a single string of two non-empty sequences of numeric characters
separated by an optional dash character. Had we wanted to state that a
phone number is an integer with at least, say, 5 digits (of course this is
meaningful only if no phone number starts by 0) we would have used
an interval type such as &lt;tel kind=?"home"|"work"&gt;[10000- -*], where
* here denotes plus infinity.
Echar is the type of characters in e-mails
addresses. It is used in the regular expression defining Email to
precisely constrain the form of the addresses. An XML document satisfying
these constraints is shown
</box>
</main>
</page>
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<page output="tutorial2.php">
<title>CDuce tutorial</title>
<banner> CDuce tutorial </banner>
<!-- ********* Left panel ********* -->
<navig>
<toc/>
<box>
<ul><li><a href="tutorial.php" color="red">Main tutorial page</a></li>
<li><a href="tutorial1.php">Type declarations</a></li>
<li><a href="tutorial2.php">Load files</a></li>
</ul>
</box>
<box>
<p>
This page is a step-by-step introduction to CDuce.
</p>
<ul>
<li><a href="/cgi-bin/cduce">Online demo</a></li>
<li><a href="/">Home page</a></li>
<li><a href="memento.php">Memento</a></li>
</ul>
</box>
</navig>
<!-- ********* Main panel ********* -->
<main>
<box title="First functions" link="t2">
<p>
A first example of transformation is \msf{names}, which extracts the
sequences of all names of parents in a \msf {ParentBook} element:
</p>
<sample><![CDATA[
let fun names (ParentBook -> [Name*])
<parentbook>x -> (map x with <person>[ n _*] -> n)
]]></sample>
The name of the transformation is followed by an {\it interface\/} that
states that \msf{names} is a function from
\msf{ParentBook} elements to (possibly empty) sequences of
\msf{Name} elements. This is obtained by matching the argument of the
function against the pattern <sample><![CDATA[<parentbook>x ]]></sample>
which binds \msf{x} to
the sequence of person elements forming the parentbook. The operator
\msf{map} applies to each element of a sequence (in this case \msf{x}) the
transformation defined by the subsequent pattern matching. Here \msf{map}
returns the sequence obtained by replacing each person in \msf{x} by its
\msf{Name} element. Note that we use the pattern
<sample><![CDATA[<person>[ n \_*],
]]></sample>
to
match the person elements: \msf{n} matches (and captures) the \msf{Name}
element-that is, the first element of the sequence-, \msf{\_*} matches (and discards) the sequence of elements that
follow, and person matches the tag of the person (although the
latter contains an attribute). The interface and the type definitions
ensure that the tags will be the expected ones, so we could optimize the
code by defining a body that skips the check of the tags:
<sample><![CDATA[
<_> x -> (map x with <_>[ n _*] -> n)
]]></sample>
</box>
</main>
</page>
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