Commit 83c3eb1b authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2003-05-11 09:30:40 by cvscast] atom_of

Original author: cvscast
Date: 2003-05-11 09:30:41+00:00
parent d583e1a7
......@@ -194,6 +194,7 @@ EXTEND
| LIDENT "raise"
| LIDENT "int_of"
| LIDENT "string_of"
| LIDENT "atom_of"
];
e = expr -> exp loc (Op (op,[e]))
| op = [ LIDENT "dump_to_file" ];
......
......@@ -72,6 +72,7 @@ let rec eval env e0 =
| Typed.Op ("print_xml", [e]) -> eval_print_xml (eval env e)
| Typed.Op ("print", [e]) -> eval_print (eval env e)
| Typed.Op ("int_of", [e]) -> eval_int_of (eval env e)
| Typed.Op ("atom_of", [e]) -> eval_atom_of (eval env e)
| Typed.Op ("string_of", [e]) -> eval_string_of (eval env e)
| Typed.Op ("dump_to_file", [e1; e2]) ->
eval_dump_to_file (eval env e1) (eval env e2)
......@@ -200,6 +201,11 @@ and eval_int_of e =
let s = get_string_latin1 e in
try Integer (Intervals.mk s)
with Failure _ -> raise exn_int_of
and eval_atom_of e =
let s = get_string_latin1 e in (* TODO: UTF-8 *)
(* TODO: check that s is a correct Name wrt XML *)
Atom (Atoms.mk s)
and eval_print_xml v =
string_latin1 (Print_xml.string_of_xml v)
......
......@@ -790,6 +790,9 @@ and type_check' loc env e constr precise = match e with
let res = Sequence.flatten t in
check loc res constr "";
if precise then res else constr
| Op ("atom_of", [e]) ->
let t = type_check env e Sequence.string false in
Types.atom Atoms.any
| _ ->
let t : Types.descr = compute_type' loc env e in
check loc t constr "";
......
......@@ -54,6 +54,7 @@ _" character, starting by a capitalized letter or underscore.</li>
<ul>
<li>Values: <duce>`A, `B, `a, `b, `true, `false, ...</duce> </li>
<li>Types: singletons <duce>`A, `B, ...</duce> </li>
<li>Operators: <duce>atom_of</duce> : String -> Atom</li>
</ul>
</li>
</ul>
......
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