Commit 90d73cd5 authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2003-05-21 18:22:47 by cvscast] Start manual

Original author: cvscast
Date: 2003-05-21 18:22:50+00:00
parent 8408443f
......@@ -79,7 +79,7 @@ clean:
rm -f cduce cduce.opt webiface.opt ocamlprof.dump
rm -f dtd2cduce pool webiface
rm -Rf prepro package
rm -f web/*.php web/*.html web/*~
rm -f web/www/*.php web/www/*.html web/*~
.SUFFIXES: .ml .mli .cmo .cmi .cmx
......@@ -146,15 +146,15 @@ profile:
rsh cedre ". .env; cd IMPLEM/CDUCE; make webiface.opt; make web/files"
scp web/*.php web/cduce.css cduce@iris:public_html/
scp web/www/*.php web/cduce.css cduce@iris:public_html/
scp webiface.opt cduce@iris:cgi-bin/cduce
ssh cduce@iris "chmod +s cgi-bin/cduce"
ssh root@localhost "cp -f ~beppe/IMPLEM/CDUCE/webiface.opt /var/www/cgi-bin/cduce; cp -f ~beppe/IMPLEM/CDUCE/web/*.php /var/www/html/; chmod +s /var/www/cgi-bin/cduce;"
ssh root@localhost "cp -f ~beppe/IMPLEM/CDUCE/webiface.opt /var/www/cgi-bin/cduce; cp -f ~beppe/IMPLEM/CDUCE/web/www/*.php /var/www/html/; chmod +s /var/www/cgi-bin/cduce;"
website: web/files
scp web/*.php web/cduce.css cduce@iris:public_html/
scp web/www/*.php web/cduce.css cduce@iris:public_html/
local_website: cduce.opt webiface.opt
(cd web; ../cduce.opt -quiet -- site.xml)
......@@ -2,7 +2,6 @@
<page name="bench">
<p>This page briefly presents preliminary benchmarks on the CDuce
......@@ -2,7 +2,6 @@
<page name="examples">
<title>Code examples</title>
<banner>Code examples</banner>
<p>This page presents some simple CDuce programs.</p>
......@@ -21,6 +21,7 @@
<include file="examples.xml"/>
<include file="team.xml"/>
<include file="tutorial.xml"/>
<include file="manual.xml"/>
<include file="sitemap.xml"/>
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<page name="manual_types_patterns">
<title>CDuce: Types and patterns</title>
<box title="Types and patterns" link="gen">
In CDuce, a type denotes a set of values, and a pattern
extracts sub-values from a value. Syntactically, types and patterns
are very close. Indeed, any type can be seen as a pattern
(which accepts any value and extracts nothing), and a pattern
without any capture variable is nothing but a type.
Moreover, values
also share a common syntax with types and patterns. This is motivated
by the fact that basic and constructed values (that is, any values without
functional values inside) are themselves singleton types.
For instance <code>(1,2)</code> is both a value, a type and a pattern.
As a type, it can be interpreted as a singleton type,
or as a pair type made of two singleton types.
As a pattern, it can be interpreted as a type constraint,
or as a pair pattern of two type constraints.
In this page, we present all the types and patterns that CDuce recognize.
It is also the occasion to present the CDuce values themselves, the
corresponding expression constructions, and fundamental operations on them.
<box title="Boolean connectives" link="bool">
CDuce recognize the full set of boolean connectives.
<li><code>Empty</code> denotes the empty type (no value).</li>
<li><code>Any</code> and <code>_</code> denote the universal type (all the values); the preferred notation is <code>Any</code> for types
and <code>_</code> for patterns, but they are strictly equivalent.
<li><code>&amp;</code> is the conjunction boolean connective.
The type <code>%%t1%% &amp; %%t2%%</code> has all the values
that belongs to <code>%%t1%%</code> and to <code>%%t2%%</code>.
Similarly, the pattern <code>%%p1%% &amp; %%p2%%</code> accepts
all the values accepted by both sub-patterns; a capture variable
cannot appear on both side of this pattern.</li>
<li><code>|</code> is the disjunction boolean connective.
The type <code>%%t1%% | %%t2%%</code> has all the values
that belongs either to <code>%%t1%%</code> or to <code>%%t2%%</code>.
Similarly, the pattern <code>%%p1%% | %%p2%%</code> accepts
all the values accepted by any of the two sub-patterns;
if both match, the first match policy applies, and <code>%%p1%%</code>
dictates how to capture sub-values. The two sub-patterns
must have the same set of capture variables.</li>
<li><code>\</code> is the difference boolean connective.
The left hand-side can be a type or a pattern, but the right-hand side
is necessarily a type (no capture variable).</li>
<box title="Recursive types and patterns" link="recurs">
A set of mutually recursive types can be defined
by toplevel type declarations, as in:
type T1 = <a>[ T2* ];;
type T2 = <b>[ T1 T1 ];;
It is also possible to use the syntax
<code>%%T%% where %%T1%% = %%t1%% and ... and %%Tn%% = %%tn%%</code>
where <code>%%T%%</code> and the <code>%%Ti%%</code> are type identifiers
and the <code>%%ti%%</code> are type expressions. The same notation
works for recursive patterns (for which there is no toplevel declarations).
There is an important restriction concerning recursive types:
any cycle must cross
<box title="Scalar types" link="basic">
CDuce has three kind of atomic (scalar) values:
integers, characters, and atoms. To each kind corresponds a family of types.
<br/>CDuce integers are arbitrarily large. An integer
literal is a sequence of decimal digits, plus an optinal leading unary
minus (<code>-</code>) character.
<li><code>Int</code>: all the integers.</li>
<li><code>%%i%%--%%j%%</code> (where <code>%%i%%</code> and
<code>%%j%%</code> are integer literals, or <code>*</code>
for infinity): integer interval. E.g.: <code>100--*</code>. </li>
<li><code>%%i%%</code> (where <code>%%i%%</code> is an integer
literal): integer singleton type.</li>
<br/>CDuce manipulates Unicode characters. A character
literal is enclosed in single quotes, e.g. <code>'a', 'b', 'c'</code>.
The single quote and the backslash character must be escaped
by a backslash: <code>'\''</code>, <code>'\\'</code>. The double
quote can also be escaped, but this is not mandatory.
The usual <code>'\n', '\t', '\r'</code> are recognized.
Arbitrary Unicode codepoints can be written in decimal
<code>'\%%i%%;</code> (<code>%%i%%</code> is an decimal integer) or
in hexadecimal <code>'\x%%i%%;</code>. Any other occurence of
a backslash character is prohibited.
<li><code>Char</code>: all the Unicode character set.</li>
<li><code>%%c%%--%%d%%</code> (where <code>%%d%%</code> and
<code>%%d%%</code> are character literals):
interval of Unicode character set. E.g.: <code>'a'--'z'</code>. </li>
<li><code>%%c%%</code> (where <code>%%c%%</code> is an integer
literal): character singleton type.</li>
<br/>Atoms are symbolic elements. They are used in particular
to denote XML tag names, and also to simulate ML sum type
constructors and exceptions names.
An atomic is written <code>`%%xxx%%</code> where
<code>%%xxx%%</code> follows the rules for CDuce identifiers.
E.g.: <code>`yes, `No, `my-name</code>. The atom <code>`nil</code>
is used to denote empty sequences.
<li><code>Atom</code>: all the atoms.</li>
<li><code>%%a%%</code> (where <code>%%a%%</code> is an atom
literal): atom singleton type.</li>
<li><code>Bool</code>: the two atoms <code>`true</code> and
<box title="Pairs" link="pairs">
Pairs is a fundamental notion in CDuce, as they constitute a building
block for sequence. Even if syntactic sugar somewhat hides
pairs when you use sequences, it is good to know the existence of pairs.
A pair expression is written <code>(%%e1%%,%%e2%%)</code>
where <code>%%e1%%</code> and <code>%%e2%%</code> are expressions.
Similarly, pair types and patterns are written
<code>(%%t1%%,%%t2%%)</code> where <code>%%t1%%</code> and
<code>%%t2%%</code> are types or patterns. E.g.: <code>(Int,Char)</code>.
When a capture variable <code>%%x%%</code> appears on both
side of a pair pattern <code>%%p%% = (%%p1%%,%%p2%%)</code>, the semantics
is the following one: when a value match <code>%%p%%</code>,
if <code>%%x%%</code> is bound to <code>%%v1%%</code> by
<code>%%p1%%</code> and to <code>%%v2%%</code> by
then <code>%%x%%</code> is bound to the pair <code>%%(v1,v2)%%</code> by
Tuples are syntactic sugar for pairs. For instance,
<code>(1,2,3,4)</code> denotes <code>(1,(2,(3,4)))</code>.
<box title="Sequences" link="seq">
<section title="Expressions">
Sequences are fundamental in CDuce. They represents
the content of XML elements, and also character strings.
Actually, they are only syntactic sugar over pairs.
Sequences expressions are written inside square brackets; element
are simply separated by whitespaces:
<code>[ %%e1%% %%e2%% %%...%% %%en%% ]</code>.
Such an expression is syntactic sugar for:
<code>(%%e1%%,(%%e2%%, %%...%% (%%en%%,`nil) %%...%%))</code>.
E.g.: <code>[ 1 2 3 4 ]</code>.
The binary operator <code>@</code> denotes sequence concatenation.
It is possible to specify a terminator different from <code>`nil</code>;
for instance
<code>[ 1 2 3 4 ; %%q%% ]</code> denotes <code>(1,(2,(3,(4,%%q%%))))</code>,
and is equivalent to (but more efficient than):
<code>[ 1 2 3 4 ] @ %%q%%</code>.
Consequently, a pair <code>(%%e1%%,%%e2%%)</code> can also
be written <code>[ %%e1%%; %%e2%% ]</code>.
Inside the square brackets of a sequence expression, it is possible
to have elements of the form <code>! %%e%%</code> (which is not
an expression by itself), where <code>%%e%%</code> is an expression
which should evaluate to a sequence. The semantics is
to "open" <code>%%e%%</code>. For instance:
<code>[ 1 2 ![ 3 4 ] 5 ]</code>
evaluates to
<code>[ 1 2 3 4 5 ]</code>.
Consequently, the concatenation of two sequences <code>%%e1%% @ %%e2%%</code>
can also be written <code>[ !%%e1%% !%%e2%% ]</code>
or <code>[ !%%e1%% ; %%e2%% ]</code>.
<section title="Types and patterns">
In CDuce, a sequence can be heterogeneous: the element can all have
different types. Types and patterns for sequences are specified
by regular expressions over types or patterns. The syntax is
<code>[ %%R%% ]</code> where <code>%%R%%</code> is a regular expression, which
can be:
<li>A type or a pattern, which correspond to a single element in the
sequence (in particular, <code>[ _ ]</code> represents
sequences of length 1, <em>not</em> arbitrary sequences).</li>
<li>A juxtaposition of regular expression <code>%%R1%% %%R2%%</code>
which represents concatenation.
<li>A postfix repetition operator; the greedy operators are
<code>%%R%%*</code>, and the ungreedy operators are:
<code>%%R%%*?</code>. For types, there is no distinction in semantics between
greedy and ungreedy. </li>
<li>A sequence capture variable <code>%%x%%::%%R%%</code>.
The semantics is to capture in <code>%%x%%</code> the subsequence
matched by <code>%%R%%</code>. The same sequence capture variable
can appear several times inside a regular expression, including
under repetition operators; in that case, all the corresponding
subsequences are concatenated together.
Note the difference between <code>[ x::Int ]</code> and
<code>[ (x &amp; Int) ]</code>. Both accept sequences made of a single
integer, but the first one binds <code>x</code> to a sequence
(of a single integer), whereas the second one binds it to
the integer itself.</li>
Sequence types and patterns also accepts the <code>[ %%...%%; %%...%% ]</code>
notation. This is a convenient way to discard the tail of a sequence
in a pattern, e.g.: <code>[ x::Int* ; _ ]</code>.
<box title="XML elements" link="xml">
In CDuce, the general of an XML element is
<code>&lt;(%%tag%%) (%%attr%%)>%%content%%</code> where
<code>%%attr%%</code> and
<code>%%content%%</code> are three expressions.
Usually, <code>%%tag%%</code> is a tag literal <code>`%%xxx%%</code>, and
in this case, instead of writing <code>&lt;(`%%tag%%)></code>,
you can write: <code>&lt;%%tag%%></code>.
Similarly, when <code>%%attr%%</code> is a record literal, you can
omit the surrounding <code>({...})</code>.
E.g: <code>&lt;a href="http://...">[]</code>.
The syntax for XML elements types and patterns follows closely
the syntax for expressions:
<code>&lt;(%%tag%%) (%%attr%%)>%%content%%</code>
<code>%%attr%%</code> and
<code>%%content%%</code> are three types or patterns.
As for expressions, it is possible to simplify the notations
for tags and attributes. For instance,
<code>&lt;(`a) ({ href=String })>[]</code>
can be written:
<code>&lt;a href=String>[]</code>.
......@@ -2,7 +2,6 @@
<page name="memento">
<title>CDuce memento</title>
<banner> CDuce memento </banner>
<p>This page briefly presents the syntax of the CDuce language.</p>
......@@ -2,7 +2,6 @@
<page name="papers">
<title>Papers and talks</title>
<banner>Papers and talks about CDuce</banner>
<p>This page presents Papers and Talks about CDuce.</p>
......@@ -17,7 +17,7 @@ include "";; (* Categories (Inline, ...) from this DTD *)
(** Input types **)
type Page = <page name=String>[ <title>String <banner>[InlineText*] Item* ];;
type Page = <page name=String>[ <title>String <banner>[InlineText*]? Item* ];;
type External = <external {|href=String; title=String; name=String |}>[];;
type Item =
......@@ -77,7 +77,7 @@ let fun load_include (String -> [Any*])
let fun highlight (String -> [ (Char | Xvar | Xi)* ] )
| [ '{{' h ::(Char *?) '}}' ; rest ] ->
[ <var class="highlight">h; highlight rest ]
| [ '{/{' h ::(Char *?) '}}' ; rest ] ->
| [ '%%' h ::(Char *?) '%%' ; rest ] ->
[ <i>h; highlight rest ]
| [ c; rest ] -> [ c; highlight rest ]
| [] -> [];;
......@@ -170,7 +170,8 @@ let fun link_to (Page -> Xa)
let fun gen_page (prev : Page|[], page : Page, next : Page|[],
path : Path, sitemap : Tree) : [] =
match page with
<page name=name>[ <title>title <banner>banner ; items ] ->
<page name=name>[
<title>title <banner>banner | <title>(title & banner); items ] ->
let fun text (t : [InlineText*]) : Inlines =
map t with
......@@ -242,6 +243,9 @@ match page with
let navig : Flow = transform items with
| <left>c -> [<div class="box">(content c)]
let navig = match navig with
| [] -> [<div class="box">(content [<boxes-toc>[]])]
| n -> n in
let dpath : Inlines = transform path with
| { url = f; title = t } -> [ <a href=f>t ' :: ']
......@@ -272,7 +276,7 @@ match page with
[ '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
' "">'
!(patch_css (print_xml html)) ] in
dump_to_file (name @ (if php then ".html.php" else ".html")) txt;;
dump_to_file ("www/" @ name @ (if php then ".html.php" else ".html")) txt;;
let fun gen_page_seq
(prev : Page|[], pages : [Page*], next : Page|[],
......@@ -2,7 +2,6 @@
<page name="sitemap">
<p>This page lists all the pages from CDuce website.</p>
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<page name="team">
<title>CDuce team</title>
<banner> The CDuce team </banner>
<title>The CDuce team</title>
<p>This page briefly presents the syntax of the CDuce language.</p>
......@@ -2,7 +2,6 @@
<page name="tutorial">
<title>CDuce tutorial</title>
<banner> CDuce tutorial </banner>
<include file="tutorial/getting_started.xml"/>
......@@ -2,8 +2,6 @@
<page name="tutorial_getting_started">
<title>Getting started</title>
<banner>CDuce tutorial: getting started</banner>
<box title="Key concepts" link="concepts">
......@@ -65,13 +63,13 @@ of the local binding is:
let {/{p}} = {/{e}} in {/{e'}}
let %%p%% = %%e%% in %%e'%%
where <code>{/{p}}</code> is a pattern and <code>{/{e}}</code>,
<code>{/{e'}}</code> are expressions.
where <code>%%p%%</code> is a pattern and <code>%%e%%</code>,
<code>%%e'%%</code> are expressions.
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