Commit d85c61c0 authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2002-11-11 20:01:29 by cvscast] Empty log message

Original author: cvscast
Date: 2002-11-11 20:01:29+00:00
parent 7eefc5b0
type Person = FPerson | MPerson;;
type FPerson = <person gender = ['F'] >[ Name Children ];;
type MPerson = <person gender="M">[ Name Children];;
type FPerson = <person gender = "F" >[ Name Children (Tel | Email)?];;
type MPerson = <person gender="M">[ Name Children (Tel | Email)?];;
type Children = <children>[Person*];;
type Name = <name>[ PCDATA ];;
type Tel = <tel kind=?"home"|"work">['0'--'9'+ '-' '0'--'9'+];;
type Email = <email>[PCDATA '@' PCDATA];;
type Man = <man name=String>[ Sons Daughters ];;
type Woman = <woman name=String>[ Sons Daughters ];;
......@@ -10,27 +12,44 @@ type Sons = <sons>[ Man* ];;
type Daughters = <daughters>[ Woman* ];;
let fun sort (MPerson -> Man ; FPerson -> Woman)
<person gender=g>[ <name>n <children>[(mc::MPerson | fc::FPerson)*] ] ->
<person gender=g>[ <name>n <children>[(mc::MPerson | fc::FPerson)*]; _] ->
let tag = match g with "F" -> `woman | "M" -> `man in
let s = map mc with x -> sort x in
let d = map fc with x -> sort x in
<(tag) name=n>[ <sons>s <daughters>d ]
;;
let base : Person =
<person gender="F">[
<name>"Veronique"
<person gender="M">[
<name>"Claude"
<children>[
<person gender="F">[
<name>"Vronique"
<children>[
<person gender="F">[
<name>"Ilaria"
<children>[]
]
]
<tel> "314-1592654"
]
]
<tel kind="home"> "271-828182"
]
;;
sort base;;
let fun contact(Person->String)
| <person>[ _ _ ((<tel kind="work"> x) | (<email> x) | (<tel kind="home"> x))] -> x
| _ ->"no contact";;
(* compilation efficace avec _ a la place de person *)
let fun name (Person | Man | Woman -> String)
<person>[ <name>n ; _ ]
| <_ name=n>_ -> n;;
......
......@@ -37,9 +37,6 @@ let refill_buf buffer len =
done;
!i
with
| End_of_file ->
print_newline();
if !i > 0 then (got_eof := true; !i) else 0
| Exit -> !i
end
......@@ -77,9 +74,13 @@ let loop =
first_line := true;
let semicolon = ref 0 in
while !semicolon < 2 do
try
let c = Stream.next input in
if c = ';' then incr semicolon
else semicolon := 0
with
| End_of_file ->
if !first_line then exit 0
done
with
| End_of_file -> exit 0
......
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