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
7a36ebe0
Commit
7a36ebe0
authored
Oct 05, 2007
by
Pietro Abate
Browse files
[r2003-06-30 13:56:40 by cvscast] Empty log message
Original author: cvscast Date: 2003-06-30 13:56:40+00:00
parent
880d5f1c
Changes
1
Hide whitespace changes
Inline
Side-by-side
web/examples/xtransform.cd
View file @
7a36ebe0
(* For the purpose of the example we can consider this hugely
simplified definition of Xhtml
*)
type Flow = Char | Block | Inline ;;
type Block = P | Heading | Lists | Blocktext | Char
type Lists = Ul
type Blocktext = Pre | Address | Center;;
type Inline = Char | A | Fontstyle
type Fontstyle = Tt | I | B | Big | Small;;
type Xhtml =
<html>
[ Head Body ];;
type Head =
<head>
[ Title
<link>
[ ]];;
type Title =
<title>
[ PCDATA ];;
type Body =
<body
bgcolor=
?String
>
[ Block* ];;
type P =
<p>
[ Inline* ];;
type Heading =
<
(`
h1
|
`
h2
|
`
h3
|
`
h4
)
>
[ Inline* ];;
type Ul =
<ul>
[Li+];;
type Li =
<li>
[ Flow* ];;
type Address =
<address>
[ Inline* ];;
type Pre =
<pre>
[ (PCDATA | A | Fontstyle)* ];;
type Center =
<center>
[ Block* ];;
type A =
<a
({
name =
String
}
|
{
href =
String
})
>
[ (Inline \ A)* ];;
type Tt =
<tt>
[ Inline* ];;
type I =
<i>
[ Inline* ];;
type B =
<b>
[ Inline* ];;
type Big =
<big>
[ Inline* ];;
type Small =
<small>
[ Inline* ];;
(* xtransform matches the patterns against the root element of each
XML tree and, if it fails, it recursively applies itself to the
sequence of sons of the root.
...
...
@@ -7,4 +43,37 @@
*)
let bold(x:[Xhtml]):[Xhtml]=xtransform x with <a (y)>t -> [ <a(y)>[<b>t] ]
\ No newline at end of file
let bold(x:[Xhtml]):[Xhtml]=xtransform x with
<a
(
y
)
>
t -> [
<a
(
y
)
>
[
<b>
t] ]
(* let us apply the function to a document where links appear
at different depths
*)
let doc : Xhtml =
<html>
[
<head>
[
<title>
"Example"
<link>
[]]
<body>
[
<h2>
['You can have links '
<a
href=
"here"
>
"here"]
<p>
['Or they can be down']
<ul>
[
<li>
['In '
<a
name=
"list"
>
"lists" ' for instance']
<li>
['or you oddly decided to '
<center>
[
<p>
[
<a
href=
"what?"
>
"center"]]
' them '
]
]
<address>
[
'and even if they are in fancy '
<a
name=
"address"
>
"address boxes"
]
<p>
['nevertheless '
<a
href=
"http://www.cduce.org"
>
"Cduce" ' and '
<a
href=
"xtransform"
>
[
<tt>
"xtransform"] ' will put all links in bold ']
]
];;
bold [doc];;
match
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