Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cduce
cduce
Commits
737c8d2b
Commit
737c8d2b
authored
Oct 05, 2007
by
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
4c80830e
Changes
12
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
737c8d2b
...
...
@@ -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:
cedre_build
:
rsh cedre
". .env; cd IMPLEM/CDUCE; make webiface.opt; make web/files"
install_web
:
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"
install_web_local
:
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.cd
--
site.xml
)
...
...
web/bench.xml
View file @
737c8d2b
...
...
@@ -2,7 +2,6 @@
<page
name=
"bench"
>
<title>
Benchmarks
</title>
<banner>
Benchmarks
</banner>
<left>
<p>
This page briefly presents preliminary benchmarks on the CDuce
...
...
web/examples.xml
View file @
737c8d2b
...
...
@@ -2,7 +2,6 @@
<page
name=
"examples"
>
<title>
Code examples
</title>
<banner>
Code examples
</banner>
<left>
<p>
This page presents some simple CDuce programs.
</p>
...
...
web/index.xml
View file @
737c8d2b
...
...
@@ -21,6 +21,7 @@
<include
file=
"examples.xml"
/>
<include
file=
"team.xml"
/>
<include
file=
"tutorial.xml"
/>
<include
file=
"manual.xml"
/>
<include
file=
"sitemap.xml"
/>
<left>
...
...
web/manual/types_patterns.xml
0 → 100644
View file @
737c8d2b
<?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"
>
<p>
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.
</p>
<p>
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.
</p>
<p>
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.
</p>
</box>
<box
title=
"Boolean connectives"
link=
"bool"
>
<p>
CDuce recognize the full set of boolean connectives.
</p>
<ul>
<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>
<li><code>
&
</code>
is the conjunction boolean connective.
The type
<code>
%%t1%%
&
%%t2%%
</code>
has all the values
that belongs to
<code>
%%t1%%
</code>
and to
<code>
%%t2%%
</code>
.
Similarly, the pattern
<code>
%%p1%%
&
%%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>
</ul>
</box>
<box
title=
"Recursive types and patterns"
link=
"recurs"
>
<p>
A set of mutually recursive types can be defined
by toplevel type declarations, as in:
</p>
<sample>
<![CDATA[
type T1 = <a>
[ T2* ];;
type T2 =
<b>
[ T1 T1 ];;
]]>
</sample>
<p>
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).
</p>
<p>
There is an important restriction concerning recursive types:
any cycle must cross
</p>
</box>
<box
title=
"Scalar types"
link=
"basic"
>
<p>
CDuce has three kind of atomic (scalar) values:
integers, characters, and atoms. To each kind corresponds a family of types.
</p>
<ul>
<li><b>
Integers
</b>
.
<br/>
CDuce integers are arbitrarily large. An integer
literal is a sequence of decimal digits, plus an optinal leading unary
minus (
<code>
-
</code>
) character.
<ul>
<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>
</ul>
</li>
<li><b>
Characters
</b>
.
<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.
<ul>
<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>
</ul>
</li>
<li><b>
Atoms
</b>
.
<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.
<ul>
<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
<code>
`false
</code>
.
</li>
</ul>
</li>
</ul>
</box>
<box
title=
"Pairs"
link=
"pairs"
>
<p>
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.
</p>
<p>
A pair expression is written
<code>
(%%e1%%,%%e2%%)
</code>
where
<code>
%%e1%%
</code>
and
<code>
%%e2%%
</code>
are expressions.
</p>
<p>
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>
.
</p>
<p>
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
<code>
%%p2%%
</code>
,
then
<code>
%%x%%
</code>
is bound to the pair
<code>
%%(v1,v2)%%
</code>
by
<code>
%%p%%
</code>
.
</p>
<p>
Tuples are syntactic sugar for pairs. For instance,
<code>
(1,2,3,4)
</code>
denotes
<code>
(1,(2,(3,4)))
</code>
.
</p>
</box>
<box
title=
"Sequences"
link=
"seq"
>
<section
title=
"Expressions"
>
<p>
Sequences are fundamental in CDuce. They represents
the content of XML elements, and also character strings.
Actually, they are only syntactic sugar over pairs.
</p>
<p>
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>
.
</p>
<p>
The binary operator
<code>
@
</code>
denotes sequence concatenation.
</p>
<p>
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>
.
</p>
<p>
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>
.
</p>
</section>
<section
title=
"Types and patterns"
>
<p>
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:
</p>
<ul>
<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>
<li>
A postfix repetition operator; the greedy operators are
<code>
%%R%%?
</code>
,
<code>
%%R%%+
</code>
,
<code>
%%R%%*
</code>
, and the ungreedy operators are:
<code>
%%R%%??
</code>
,
<code>
%%R%%+?
</code>
,
<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.
<br/>
Note the difference between
<code>
[ x::Int ]
</code>
and
<code>
[ (x
&
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>
</ul>
<p>
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>
.
</p>
</section>
</box>
<box
title=
"XML elements"
link=
"xml"
>
<p>
In CDuce, the general of an XML element is
<code>
<
(%%tag%%) (%%attr%%)>%%content%%
</code>
where
<code>
%%tag%%
</code>
,
<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>
<
(`%%tag%%)>
</code>
,
you can write:
<code>
<
%%tag%%>
</code>
.
Similarly, when
<code>
%%attr%%
</code>
is a record literal, you can
omit the surrounding
<code>
({...})
</code>
.
E.g:
<code>
<
a href="http://...">[]
</code>
.
</p>
<p>
The syntax for XML elements types and patterns follows closely
the syntax for expressions:
<code>
<
(%%tag%%) (%%attr%%)>%%content%%
</code>
where
<code>
%%tag%%
</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>
<
(`a) ({ href=String })>[]
</code>
can be written:
<code>
<
a href=String>[]
</code>
.
</p>
</box>
</page>
web/memento.xml
View file @
737c8d2b
...
...
@@ -2,7 +2,6 @@
<page
name=
"memento"
>
<title>
CDuce memento
</title>
<banner>
CDuce memento
</banner>
<left>
<p>
This page briefly presents the syntax of the CDuce language.
</p>
...
...
web/papers.xml
View file @
737c8d2b
...
...
@@ -2,7 +2,6 @@
<page
name=
"papers"
>
<title>
Papers and talks
</title>
<banner>
Papers and talks about CDuce
</banner>
<left>
<p>
This page presents Papers and Talks about CDuce.
</p>
...
...
web/site.cd
View file @
737c8d2b
...
...
@@ -17,7 +17,7 @@ include "xhtml-categ.cd";; (* 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)]
in
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 ' :: ']
in
...
...
@@ -272,7 +276,7 @@ match page with
[ '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
'
!(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|[],
...
...
web/sitemap.xml
View file @
737c8d2b
...
...
@@ -2,7 +2,6 @@
<page
name=
"sitemap"
>
<title>
Sitemap
</title>
<banner>
Sitemap
</banner>
<left>
<p>
This page lists all the pages from CDuce website.
</p>
...
...
web/team.xml
View file @
737c8d2b
<?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>
<left>
<p>
This page briefly presents the syntax of the CDuce language.
</p>
...
...
web/tutorial.xml
View file @
737c8d2b
...
...
@@ -2,7 +2,6 @@
<page
name=
"tutorial"
>
<title>
CDuce tutorial
</title>
<banner>
CDuce tutorial
</banner>
<include
file=
"tutorial/getting_started.xml"
/>
...
...
web/tutorial/getting_started.xml
View file @
737c8d2b
...
...
@@ -2,8 +2,6 @@
<page
name=
"tutorial_getting_started"
>
<title>
Getting started
</title>
<banner>
CDuce tutorial: getting started
</banner>
<left><boxes-toc/></left>
<box
title=
"Key concepts"
link=
"concepts"
>
...
...
@@ -65,13 +63,13 @@ of the local binding is:
</p>
<sample>
<![CDATA[
let
{/{p}} = {/{e}} in {/{e'}}
let
%%p%% = %%e%% in %%e'%%
]]>
</sample>
</section>
<p>
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.
</p>
</box>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment