Commit 64b3f1f2 authored by Pietro Abate's avatar Pietro Abate

[r2003-06-07 17:10:30 by cvscast] Empty log message

Original author: cvscast
Date: 2003-06-07 17:10:30+00:00
parent 19d44f5f
......@@ -9,7 +9,7 @@ let gen = "split.ml"
let xml = "split"
let cduce = [ "split0.cd"; "split1.cd"; "split2.cd" ]
let xslt = [ "split1.xsl"; "split2.xsl" ]
let xduce = [ "split1.q"; "split2.q" ]
let xduce = [ "split1.q"; "split2.q"; "split3.q" ]
let sp = sprintf
let langs =
......@@ -49,7 +49,7 @@ let time s =
let sys = input_line ic in
match (Unix.close_process_in ic) with
| Unix.WEXITED 0 ->
pr "%s,%s " (extract "real" real) (extract "user" user);
pr "%s,%s " (extract "real " real) (extract "user " user);
flush stdout;
| _ ->
pr "err"
......
import "xml.q"
type Person = FPerson | MPerson
type MPerson = person[ @gender["M"], Name, Children ]
type FPerson = person[ @gender["F"], Name, Children ]
type Children = children[Person*]
type Name = name[ String ]
type Man = man[ @name[String], Sons,Daughters ]
type Woman = woman[ @name[String], Sons,Daughters ]
type Sons = sons[ Man* ]
type Daughters = daughters[ Woman* ]
fun split_mpersons (val c as Person* ) : Man* = match c with
val m as ~[ @gender["M"], ~[Any]* ], val rest ->
split_m(m), split_mpersons(rest)
| ~[Any], val rest ->
split_mpersons(rest)
| () ->
()
fun split_fpersons (val c as Person* ) : Woman* = match c with
val f as ~[ @gender["F"], ~[Any]* ], val rest ->
split_f(f), split_fpersons(rest)
| ~[Any], val rest ->
split_fpersons(rest)
| () ->
()
fun split_children (val c as Person* ) : (Sons,Daughters) =
let val s = split_mpersons(c) in
let val d = split_fpersons(c) in
sons[s], daughters[d]
fun split_m (val p as MPerson) : Man =
match p with
~[ @gender[String], ~[val n], ~[val c] ] ->
man[ @name[n], split_children(c) ]
fun split_f (val p as FPerson) : Woman =
match p with
~[ @gender[String], ~[val n], ~[val c] ] ->
woman[ @name[n], split_children(c) ]
fun split_seq (val p as Person* ) : (Man|Woman)* =
filter p {
( val f as ~[ @gender["F"], ~[Any], ~[Any] ] { split_f(f) }
| val m as ~[ @gender["M"], ~[Any], ~[Any] ] { split_m(m) })*
}
let val _ =
match argv() with
val fn as String ->
( match load_xml(fn) with
doc[val p as Person*] -> doc[ split_seq(p) ]
| Any -> raise("Invalid document") )
| Any -> raise("Invalid command line")
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