Commits

Sébastien Ferré  committed 52dda69

Add of terms, and function 'list_of_stream' and 'stream_of_list'.

  • Participants
  • Parent commits b3f24e7

Comments (0)

Files changed (1)

 
 open Token
 
+let rec get_terms : t_list -> string list =
+  function
+      [] -> []
+    | Term name::l -> name::get_terms l
+    | _::l -> get_terms l
+
 let from_channel : in_channel -> t_stream =
   fun ch ->
     let lexbuf = Lexing.from_channel ch in
 	  EOL -> None
 	| tok -> Some tok)
 
+let rec list_of_stream : t_stream -> t_list = parser
+    [<'tok; toks = list_of_stream>] -> tok::toks
+  | [<>] -> []
+
+let stream_of_list : t_list -> t_stream = Stream.of_list
+
 (* get the string representation of the token *)
 type space_of_token = Sep | PonctL | PonctR | Op | Word
 
     | Int n -> string_of_int n, Word
     | Float f -> string_of_float f, Word
     | String s -> "\"" ^ String.escaped s ^ "\"", Word
-    | Term s -> "'" ^ String.escaped s ^ "'", Word
+    | Term s ->
+	let b = ref true in
+	(match s.[0] with 'A'..'Z' | '_' -> () | _ -> b:= false);
+	if !b then String.iter (function 'a'..'z' | 'A'..'Z' | '_' | '0'..'9' -> () | _ -> b:= false) s;
+	if !b
+	then s, Word
+	else "'" ^ String.escaped s ^ "'", Word
     | Char c -> "`" ^ Char.escaped c ^ "`", Word
 
 let rec stringizer : t_list -> string =