| 7 |
<p>This page briefly presents the syntax of the CDuce language.</p> |
<p>This page briefly presents the syntax of the CDuce language.</p> |
| 8 |
<boxes-toc/> |
<boxes-toc/> |
| 9 |
<p>See also:</p> |
<p>See also:</p> |
| 10 |
<local-links href="index,proto,manual,tutorial,papers"/> |
<local-links href="index,manual,tutorial"/> |
| 11 |
</left> |
</left> |
| 12 |
|
|
| 13 |
<box title="Identifiers" link="id"> |
<box title="Identifiers" link="id"> |
| 30 |
<li>Operators: <code>+,-,/,*,div,mod, int_of</code> </li> |
<li>Operators: <code>+,-,/,*,div,mod, int_of</code> </li> |
| 31 |
</ul> |
</ul> |
| 32 |
</li> |
</li> |
| 33 |
|
<li>Floats: |
| 34 |
|
<ul> |
| 35 |
|
<li>Values: <i>none built-in</i>. </li> |
| 36 |
|
<li>Types: only <code>Float</code>. </li> |
| 37 |
|
<li>Operators: <code>float_of</code> : String -> Float</li> |
| 38 |
|
</ul> |
| 39 |
|
</li> |
| 40 |
<li>Unicode characters: |
<li>Unicode characters: |
| 41 |
<ul> |
<ul> |
| 42 |
<li>Values: <code>'a','b','c'...</code> </li> |
<li>Values: <code>'a','b','c'...</code> </li> |
| 55 |
</ul> |
</ul> |
| 56 |
</box> |
</box> |
| 57 |
|
|
| 58 |
<box title="Operators" link="op"> |
<box title="Operators, built-in functions" link="op"> |
| 59 |
<ul> |
<ul> |
| 60 |
<li>Infix: |
<li>Infix: |
| 61 |
<br/> <code>@</code> : concatenation of sequences |
<br/> <code>@</code> : concatenation of sequences |
| 66 |
<br/> <code>not</code>: Bool -> Bool |
<br/> <code>not</code>: Bool -> Bool |
| 67 |
</li> |
</li> |
| 68 |
<li>Prefix: |
<li>Prefix: |
| 69 |
<br/><code>load_xml,load_html</code> : String -> Any, |
<br/><code>load_xml</code> : Latin1 -> AnyXml, |
| 70 |
<br/><code>dump_to_file</code> : String -> String -> Any, |
<br/><code>load_html</code> : Latin1 -> [ Any* ], |
| 71 |
<br/><code>print_xml</code> : Any -> String |
<br/><code>load_file</code> : Latin1 -> Latin1, |
| 72 |
<br/><code>print</code> : String -> [] |
<br/><code>load_file_utf8</code> : Latin1 -> String, |
| 73 |
<br/><code>int_of</code> : ['-'? ('0'--'9')+] -> Integer |
<br/><code>dump_to_file</code> : Latin1 -> String -> [], |
| 74 |
<br/><code>string_of</code> : Any -> Latin1 |
<br/><code>dump_to_file_utf8</code> : Latin1 -> String -> [], |
| 75 |
|
<br/><code>print_xml</code> : Any -> Latin1, |
| 76 |
|
<br/><code>print_xml_utf8</code> : Any -> String, |
| 77 |
|
<br/><code>print</code> : Latin1 -> [], |
| 78 |
|
<br/><code>print_utf8</code> : String -> [], |
| 79 |
|
<br/><code>int_of</code> : String -> Int, |
| 80 |
|
<br/><code>float_of</code> : String -> Float, |
| 81 |
|
<br/><code>string_of</code> : Any -> Latin1, |
| 82 |
|
<br/><code>atom_of</code> : String -> Atom, |
| 83 |
|
<br/><code>system</code> : Latin1 -> { stdout = Latin1; stderr = Latin1; |
| 84 |
|
status = (`exited,Int) | (`stopped,Int) | (`signaled,Int) |
| 85 |
|
}, |
| 86 |
|
<br/><code>exit</code> : 0--255 -> Empty, |
| 87 |
|
<br/><code>getenv</code> : Latin1 -> Latin1, |
| 88 |
|
<br/><code>argv</code> : [] -> [ String* ], |
| 89 |
|
<br/><code>raise</code> : Any -> Empty |
| 90 |
</li> |
</li> |
| 91 |
</ul> |
</ul> |
| 92 |
</box> |
</box> |
| 129 |
<li>Transform: <code>transform e with p1 -> e1 | ... | pn -> en</code>. |
<li>Transform: <code>transform e with p1 -> e1 | ... | pn -> en</code>. |
| 130 |
Unmatched elements are discarded; each branch returns a sequence |
Unmatched elements are discarded; each branch returns a sequence |
| 131 |
and all the resulting sequences are concatenated together. </li> |
and all the resulting sequences are concatenated together. </li> |
| 132 |
|
<li>Selection: : <code>select %%e%% from %%p1%% in %%e1%% ... %%pn%% |
| 133 |
|
in %%en%% where %%e'%%</code>. SQL-like selection with the possibility |
| 134 |
|
of using CDuce patterns instead of variables. <code>%%e1%% ... |
| 135 |
|
%%en%%</code> must be sequences and <code>%%e'%%</code> a boolean |
| 136 |
|
expression.</li> |
| 137 |
<li>Operators: concatenation <code>e1 @ e2 = [ !e1 !e2 ]</code>, |
<li>Operators: concatenation <code>e1 @ e2 = [ !e1 !e2 ]</code>, |
| 138 |
flattening <code>flatten e = transform e with x -> x</code>. |
flattening <code>flatten e = transform e with x -> x</code>. |
| 139 |
</li> |
</li> |
| 142 |
|
|
| 143 |
<box title="Record" link="record"> |
<box title="Record" link="record"> |
| 144 |
<ul> |
<ul> |
| 145 |
<li>Records litteral <code>{ l1 = e1; ...; ln = en }</code></li> |
<li>Records literal <code>{ l1 = e1; ...; ln = en }</code></li> |
| 146 |
<li>Types: <code>{| l1 = t1; ...; ln = tn |}</code> (closed, no more |
<li>Types: <code>{ l1 = t1; ...; ln = tn }</code> (closed, no more |
| 147 |
fields allowed), <code>>{ l1 = t1; ...; ln = tn }</code> (open, |
fields allowed), <code>{ l1 = t1; ...; ln = tn; .. }</code> (open, |
| 148 |
any other field allowed). Optional fields: <code>li =? ti</code> |
any other field allowed). Optional fields: <code>li =? ti</code> |
| 149 |
instead of <code>li = ti</code>.</li> |
instead of <code>li = ti</code>. Semi-colons are optional.</li> |
| 150 |
<li>Record concatenation: <code>e1 + e2</code> |
<li>Record concatenation: <code>e1 + e2</code> |
| 151 |
(priority to the fields from the right argument) </li> |
(priority to the fields from the right argument) </li> |
| 152 |
<li>Field removal: <code>e1 \ l</code> (does nothing if the |
<li>Field removal: <code>e1 \ l</code> (does nothing if the |
| 153 |
field <code>l</code> is not present)</li> |
field <code>l</code> is not present)</li> |
| 154 |
<li>Field access: <code>e1 . l</code></li> |
<li>Field access: <code>e1 . l</code></li> |
|
<li>Record: <code>{ l1 = p1; ...; ln = pn }</code></li> |
|
| 155 |
<li>Labels are in fact Qualified Names (see <local href="namespaces"/>)</li> |
<li>Labels are in fact Qualified Names (see <local href="namespaces"/>)</li> |
| 156 |
</ul> |
</ul> |
| 157 |
</box> |
</box> |
| 175 |
(semicolon can also be omitted in this case). |
(semicolon can also be omitted in this case). |
| 176 |
E.g: <code><a href="abc">[ 'abc' ]</code>.</li> |
E.g: <code><a href="abc">[ 'abc' ]</code>.</li> |
| 177 |
<li>Types and patterns: same notations.</li> |
<li>Types and patterns: same notations.</li> |
| 178 |
|
<li>XPath like projection: <code>%%e%%/%%t%%</code>. For every |
| 179 |
|
XML tree in <code>%%e%%</code> it returns the sequence of children |
| 180 |
|
of type <code>%%t%%</code></li> |
| 181 |
<li>Tree transformation: <code>xtransform e with p1 -> e1 | ... | pn -> en</code>. |
<li>Tree transformation: <code>xtransform e with p1 -> e1 | ... | pn -> en</code>. |
| 182 |
Applies to sequences of XML trees. Unmatched elements are left unchanged and the |
Applies to sequences of XML trees. Unmatched elements are left unchanged and the |
| 183 |
transformation is recursively applied to the sequence of children of the unmatched |
transformation is recursively applied to the sequence of children of the unmatched |
| 184 |
element; as for transform, each branch returns a sequence |
element; as for transform, each branch returns a sequence |
| 185 |
and all the resulting sequences are concatenated together. </li> |
and all the resulting sequences are concatenated together. </li> |
| 186 |
<li>Operators: <code>load_xml : String -> Any; print_xml : Any -> String</code> |
<li>Operators: <code>load_xml : Latin1 -> AnyXml; print_xml : Any -> Latin1</code> |
| 187 |
</li> |
</li> |
| 188 |
</ul> |
</ul> |
| 189 |
</box> |
</box> |
| 198 |
equivalent to <code>fun f (t -> s) p -> e</code> </li> |
equivalent to <code>fun f (t -> s) p -> e</code> </li> |
| 199 |
<li>Multiple arguments: <code>fun f (p1 : t1, p2 : t2,...) : s = |
<li>Multiple arguments: <code>fun f (p1 : t1, p2 : t2,...) : s = |
| 200 |
e</code>, equivalent to <code>fun f ((p1,p2,...):(t1,t2,...)) : s |
e</code>, equivalent to <code>fun f ((p1,p2,...):(t1,t2,...)) : s |
| 201 |
= e</code> (note the blank spaces around colons to avoid ambiguity with namespaces) </li> |
= e</code> (note the blank spaces around colons to avoid ambiguity |
| 202 |
|
with namespaces) </li> |
| 203 |
|
<li>Currified function: <code>fun f (p1 : t1) (p2 : t2) ... : s = |
| 204 |
|
e</code> (can be combined with the multiple arguments syntax).</li> |
| 205 |
</ul> |
</ul> |
| 206 |
</li> |
</li> |
| 207 |
<li>Types: <code>t -> s</code> </li> |
<li>Types: <code>t -> s</code> </li> |