Commit 82c839d4 authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2005-08-29 11:48:44 by afrisch] Add an example

Original author: afrisch
Date: 2005-08-29 11:48:44+00:00
parent 624dec74
......@@ -1226,6 +1226,32 @@ Some features of XML Schema are not parsed, such as
</section>
<section title="String regular expressions">
<p>
OCamlDuce supports regular expression types and patterns, not only
for sequences of XML elements, but also for strings. The following
example shows how to use regular expressions to split a string
of the form <code>name1=val1,...,namen=valn</code> with
<code>n>0</code> into
a list of pairs <code>[ (name1,val1); ...; (namen,valn) ]</code>.
The <code>*?</code> operator in regular expressions means ``ungreedy
match'' (match the shortest possible subsequence). The last
pattern describes precisely strings which are not matched by
the other cases. It would be possible to replace it with
the wildcard <code>_</code>.
</p>
<sample><![CDATA[{{ON}}
let rec split (s : {{ String }}) =
match s with
| {{ [ n::_*? '=' v::_*? ',' rest::_* ] }} -> (n,v)::(split rest)
| {{ [ n::_*? '=' v::_*? ] }} -> [ (n,v) ]
| {{ Any - [ _* '=' _* ] }} -> failwith "split"
]]></sample>
</section>
</box>
</page>
\ No newline at end of file
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