Commit 0cc4c6b9 authored by Pietro Abate's avatar Pietro Abate

[r2003-05-21 21:24:56 by cvscast] Manual

Original author: cvscast
Date: 2003-05-21 21:24:56+00:00
parent 212a5b59
......@@ -79,9 +79,9 @@ runtime/load_xml.cmo: types/atoms.cmi misc/encodings.cmi types/ident.cmo \
runtime/load_xml.cmx: types/atoms.cmx misc/encodings.cmx types/ident.cmx \
parser/location.cmx runtime/value.cmx runtime/load_xml.cmi
runtime/print_xml.cmo: types/atoms.cmi misc/encodings.cmi types/ident.cmo \
types/sequence.cmi runtime/value.cmi
parser/location.cmi types/sequence.cmi runtime/value.cmi
runtime/print_xml.cmx: types/atoms.cmx misc/encodings.cmx types/ident.cmx \
types/sequence.cmx runtime/value.cmx
parser/location.cmx types/sequence.cmx runtime/value.cmx
runtime/run_dispatch.cmo: types/atoms.cmi types/chars.cmi misc/encodings.cmi \
types/ident.cmo types/patterns.cmi types/types.cmi runtime/value.cmi \
runtime/run_dispatch.cmi
......@@ -102,10 +102,10 @@ driver/cduce.cmx: parser/ast.cmx types/builtin.cmx runtime/eval.cmx \
types/ident.cmx parser/location.cmx parser/parser.cmx types/patterns.cmx \
misc/state.cmx typing/typed.cmx typing/typer.cmx types/types.cmx \
runtime/value.cmx parser/wlexer.cmx driver/cduce.cmi
driver/run.cmo: driver/cduce.cmi parser/location.cmi types/sequence.cmi \
misc/state.cmi runtime/value.cmi parser/wlexer.cmo
driver/run.cmx: driver/cduce.cmx parser/location.cmx types/sequence.cmx \
misc/state.cmx runtime/value.cmx parser/wlexer.cmx
driver/run.cmo: driver/cduce.cmi types/ident.cmo parser/location.cmi \
types/sequence.cmi misc/state.cmi runtime/value.cmi parser/wlexer.cmo
driver/run.cmx: driver/cduce.cmx types/ident.cmx parser/location.cmx \
types/sequence.cmx misc/state.cmx runtime/value.cmx parser/wlexer.cmx
driver/webiface.cmo: driver/cduce.cmi driver/examples.cmo parser/location.cmi \
misc/state.cmi
driver/webiface.cmx: driver/cduce.cmx driver/examples.cmx parser/location.cmx \
......@@ -125,4 +125,4 @@ runtime/load_xml.cmi: runtime/value.cmi
runtime/run_dispatch.cmi: types/patterns.cmi runtime/value.cmi
runtime/value.cmi: types/atoms.cmi types/chars.cmi misc/encodings.cmi \
types/ident.cmo types/intervals.cmi types/types.cmi
driver/cduce.cmi: types/types.cmi runtime/value.cmi
driver/cduce.cmi: types/ident.cmo types/types.cmi runtime/value.cmi
......@@ -2,8 +2,10 @@ type source = [ `None | `File of string | `Stream | `String of string ]
type loc = source * int * int
type viewport = [ `Html | `Text ]
let merge_loc ((s1,i1,j1) as loc1) (s2,i2,j2) =
if s1 = s2 then (s1, min i1 i2, max j1 j2)
let merge_loc ((s1,i1,j1) as loc1) ((s2,i2,j2) as loc2) =
if s1 = s2 then
if i1 = -1 then loc2 else if i2 = -1 then loc1 else
(s1, min i1 i2, max j1 j2)
else loc1
let source = ref `None
......
......@@ -909,29 +909,20 @@ and type_rec_funs env l =
and type_op loc op args =
match (op,args) with
| "+", [loc1,t1; loc2,t2] ->
check loc1 t1 int_cup_record
"The first argument of + must be an integer or a record";
let int = Types.Int.get t1 in
let int = if Intervals.is_empty int then None else Some int in
let r = if Types.Record.has_record t1 then Some t1 else None in
(match (int,r) with
| Some t1, None ->
check loc2 t2 Types.Int.any
"The second argument of + must be an integer";
Types.interval
(Intervals.add t1 (Types.Int.get t2));
| None, Some r1 ->
check loc2 t2 Types.Record.any
"The second argument of + must be a record";
Types.Record.merge r1 t2
| None, None ->
Types.empty
| Some t1, Some r1 ->
check loc2 t2 int_cup_record
"The second argument of + must be an integer or a record";
Types.cup
(Types.interval (Intervals.add t1 (Types.Int.get t2)))
(Types.Record.merge r1 t2)
if (Types.is_empty t1) || (Types.is_empty t2) then Types.empty
else if Types.subtype t1 Types.Int.any
then (
check loc2 t2 Types.Int.any
"The second argument of + must be an integer as the first one";
Types.interval
(Intervals.add (Types.Int.get t1) (Types.Int.get t2))
)
else (
check loc1 t1 Types.Record.any
"The first argument of + must be a record or an integer";
check loc2 t2 Types.Record.any
"The second argument of + must be a record as the first one";
Types.Record.merge t1 t2
)
| "-", [loc1,t1; loc2,t2] ->
type_int_binop Intervals.sub loc1 t1 loc2 t2
......
......@@ -5,6 +5,7 @@
<include file="manual/types_patterns.xml"/>
<include file="manual/expressions.xml"/>
<box title="Table of Contents" link="toc">
<p><b>This manual is under construction !</b></p>
......
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<page name="manual_types_patterns">
<title>CDuce: Types and patterns</title>
<title>Types and patterns</title>
<box title="Types and patterns" link="gen">
......@@ -33,6 +33,34 @@ corresponding expression constructions, and fundamental operations on them.
</box>
<box title="Capture variable" link="capture">
<p>
A value identifier inside a pattern behaves as a capture variable:
it accepts and bind any value.
</p>
<p>
Another form of capture variable is the default value pattern
<code>( %%x%% := %%c%% )</code> where <code>%%x%%</code>
is a capture variable (that is, an identifier),
and <code>%%c%%</code> is a scalar constant.
The semantics of this pattern is to bind the capture variable
to the constant, disregarding the matched value (and accepting
any value).
</p>
<p>
Such a pattern is useful in conjunction with the first match policy
(see below) to define "default cases". For instance, the pattern
<code>((x &amp; Int) | (x := 0), (y &amp; Int) | (y := 0))</code>
accepts any pair and bind <code>x</code> to the left component
if it is an integer (and <code>0</code> otherwise), and similarly
for <code>y</code> with the right component of the pair.
</p>
</box>
<box title="Boolean connectives" link="bool">
<p>
CDuce recognize the full set of boolean connectives, whose
......@@ -48,7 +76,8 @@ 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>
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>.
......@@ -312,6 +341,16 @@ to use <code>PCDATA</code> instead of <code>Char*</code>
inside square brackets, contrary to <code>String</code>).
</p>
<p>
Several consecutive characters literal in a sequence can be
merged together between two single quotes:
<code>[ 'abc' ]</code> instead of <code>[ 'a' 'b' 'c' ]</code>.
Also it is possible to avoid square brackets by using
double quotes: <code>"abc"</code>. The same escaping rules applies
inside double quotes, except that single quotes may be escaped (but
must not), and double quotes must be.
</p>
</box>
<box title="Records" link="record">
......@@ -454,8 +493,10 @@ such that <code>%%t1%% -> %%s1%% &amp; %%...%% &amp; %%tn%% ->
%%sn%%</code> is a subtype of <code>%%t%% -> %%s%%</code>.
</p>
</box>
<p>
Functional types have no counterpart in patterns.
</p>
</box>
</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