Commit d052311b authored by Pietro Abate's avatar 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 3449b942
(* 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
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