Adapt examples.

git-svn-id: http://caml.inria.fr/svn/ocaml/branches/extension_points@13379 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Alain Frisch 2013-03-08 09:34:02 +00:00
parent a483bbaaf4
commit 7c4129960b
1 changed files with 17 additions and 26 deletions

View File

@ -364,7 +364,7 @@ with Killed -> bar
-- Bolt -- Bolt
let funct n = let funct n =
[%log "funct(%d)" n LEVEL DEBUG]; (%log "funct(%d)" n LEVEL DEBUG);
for i = 1 to n do for i = 1 to n do
print_endline "..." print_endline "..."
done done
@ -372,26 +372,20 @@ let funct n =
-- pre-polyrecord -- pre-polyrecord
let r = ({ x = 1; y = ref None } [@polyrec]) let r = {%polyrec x = 1; y = ref None }
let () = (r.y <- Some 2) [@polyrec] let () = (%polyrec r.y <- Some 2)
or maybe:
let r = {[@polyrec] x = 1; y = ref None }
let () = r.y <-[@polyrec] Some 2
-- orakuda -- orakuda
[%regexp function function%regexp
| "$/^[0-9]+$/" as v -> `Int (int_of_string v#_0) | "$/^[0-9]+$/" as v -> `Int (int_of_string v#_0)
| "$/^[a-z][A-Za-z0-9_]*$" as v -> `Variable v#_0 | "$/^[a-z][A-Za-z0-9_]*$" as v -> `Variable v#_0
| _ -> failwith "parse error" | _ -> failwith "parse error"
]
-- bitstring -- bitstring
let bits = Bitstring.bitstring_of_file "/bin/ls" in let bits = Bitstring.bitstring_of_file "/bin/ls" in
[%bit match bits with match%bitstring bits with
| [ 0x7f, 8; "ELF", 24, string; (* ELF magic number *) | [ 0x7f, 8; "ELF", 24, string; (* ELF magic number *)
e_ident, Mul(12,8), bitstring; (* ELF identifier *) e_ident, Mul(12,8), bitstring; (* ELF identifier *)
e_type, 16, littleendian; (* object file type *) e_type, 16, littleendian; (* object file type *)
@ -399,14 +393,12 @@ let bits = Bitstring.bitstring_of_file "/bin/ls" in
] -> ] ->
printf "This is an ELF binary, type %d, arch %d\n" printf "This is an ELF binary, type %d, arch %d\n"
e_type e_machine e_type e_machine
]
-- sedlex -- sedlex
let rec token buf = let rec token buf =
[%sedlex let%regexp ('a'..'z'|'A'..'Z') = letter in
let Regexp ('a'..'z'|'A'..'Z') = letter in match%sedlex buf with
match buf with
| number -> Printf.printf "Number %s\n" (Sedlexing.Latin1.lexeme buf); token buf | number -> Printf.printf "Number %s\n" (Sedlexing.Latin1.lexeme buf); token buf
| letter, Star ('A'..'Z' | 'a'..'z' | digit) -> Printf.printf "Ident %s\n" (Sedlexing.Latin1.lexeme buf); token buf | letter, Star ('A'..'Z' | 'a'..'z' | digit) -> Printf.printf "Ident %s\n" (Sedlexing.Latin1.lexeme buf); token buf
| Plus xml_blank -> token buf | Plus xml_blank -> token buf
@ -414,7 +406,6 @@ let rec token buf =
| Range(128,255) -> print_endline "Non ASCII" | Range(128,255) -> print_endline "Non ASCII"
| eof -> print_endline "EOF" | eof -> print_endline "EOF"
| _ -> failwith "Unexpected character" | _ -> failwith "Unexpected character"
]
-- cppo -- cppo
@ -431,9 +422,9 @@ debug("test")
-- PG'OCaml -- PG'OCaml
let fetch_users dbh = let fetch_users dbh =
[%pgsql dbh "select id, name from users"] (%pgsql dbh "select id, name from users")
-- Macaque -- Macaque
let names view = [%view {name = t.name}, t <- !view] let names view = (%view {name = t.name}, t <- !view)