open Gramext
let tex_of_unicode s =
- let no_expansion = ["|";",";"(";")";"[";"]";":";"_";".";"=";";";"{";"}"] in
+ let no_expansion =
+ ["|";",";"(";")";"[";"]";":";"_";".";"=";";";"{";"}";">";"<"]
+ in
let contractions =
("\\Longrightarrow","=>") :: []
in
let s = Utf8Macro.tex_of_unicode s in
try List.assoc s contractions with Not_found -> s
-let visit_description desc fmt =
+let visit_description desc fmt self =
let skip s = List.mem s [ ] in
let inline s = List.mem s [ "int" ] in
let todo =
if is_tree_printable son then
begin
- let need_b = needs_brackets son in
+ let need_b = is_son && needs_brackets son in
if not is_son then
Format.fprintf fmt "@[<hov2>";
if need_b then
let todo = visit_symbol symbol todo is_son (nesting + 1) in
Format.fprintf fmt "]@] @ ";
todo
- | Sself -> Format.fprintf fmt "self "; todo
+ | Sself -> Format.fprintf fmt "%s " self; todo
| Snext -> Format.fprintf fmt "next "; todo
| Stoken pattern ->
let constructor, keyword = pattern in
if keyword = "" then
- Format.fprintf fmt "'%s' " constructor
+ Format.fprintf fmt "`%s' " constructor
else
Format.fprintf fmt "\"%s\" " (tex_of_unicode keyword);
todo
| x -> x
and clean_node = function
- | {node=node;son=son;brother=brother} when
- is_symbol_dummy node &&
- is_tree_dummy son &&
- is_tree_dummy brother -> DeadEnd
+ | {node=node;son=son;brother=brother} ->
+ let bn = is_symbol_dummy node in
+ let bs = is_tree_dummy son in
+ let bb = is_tree_dummy brother in
+ let son = if bs then DeadEnd else son in
+ let brother = if bb then DeadEnd else brother in
+ if bb && bs && bn then
+ DeadEnd
+ else
+ Node {node=node;son=son;brother=brother}
| x -> Node x
and is_level_dummy = function
let { ename = ename; edesc = desc } = hd in
Format.fprintf fmt "@[<hv2>%s ::=@ " ename;
let desc = clean_dummy_desc desc in
- let todo = visit_description desc fmt @ todo in
+ let todo = visit_description desc fmt ename @ todo in
Format.fprintf fmt "@]";
Format.pp_print_newline fmt ();
Format.pp_print_newline fmt ();
;;
let _ =
-(* let g_entry = Grammar.Entry.obj CicNotationParser.term in*)
let g_entry = Grammar.Entry.obj GrafiteParser.statement in
visit_entries [g_entry] []