Commit fd14024d authored by POTTIER Francois's avatar POTTIER Francois

Cleanup in UnparameterizedPrinter. The only difference should be that

%on_error_reduce declarations are now preserved by the unit-actions
modes (as they should be, I suppose; this is undocumented anyway).
parent 023599b0
...@@ -101,14 +101,8 @@ let print_binding id = ...@@ -101,14 +101,8 @@ let print_binding id =
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
let if_normal_mode f x = (* Testing whether it is permitted to print OCaml code (semantic actions,
match mode with prelude, postlude). *)
| PrintNormal ->
f x
| PrintForOCamlyacc
| PrintUnitActions
| PrintUnitActionsUnitTokens ->
()
let if_ocaml_code_permitted f x = let if_ocaml_code_permitted f x =
match mode with match mode with
...@@ -121,6 +115,10 @@ let if_ocaml_code_permitted f x = ...@@ -121,6 +115,10 @@ let if_ocaml_code_permitted f x =
preludes, postludes, etc. *) preludes, postludes, etc. *)
() ()
(* -------------------------------------------------------------------------- *)
(* Printing a semantic action. *)
let print_semantic_action f g branch = let print_semantic_action f g branch =
let e = Action.to_il_expr branch.action in let e = Action.to_il_expr branch.action in
match mode with match mode with
...@@ -166,7 +164,7 @@ let print_semantic_action f g branch = ...@@ -166,7 +164,7 @@ let print_semantic_action f g branch =
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
(* Printing functions. *) (* Printing preludes and postludes. *)
let print_preludes f g = let print_preludes f g =
List.iter (fun prelude -> List.iter (fun prelude ->
...@@ -178,16 +176,37 @@ let print_postludes f g = ...@@ -178,16 +176,37 @@ let print_postludes f g =
fprintf f "%s\n" postlude.stretch_raw_content fprintf f "%s\n" postlude.stretch_raw_content
) g.postludes ) g.postludes
(* -------------------------------------------------------------------------- *)
(* Printing %start declarations. *)
let print_start_symbols f g = let print_start_symbols f g =
StringSet.iter (fun symbol -> StringSet.iter (fun symbol ->
fprintf f "%%start %s\n" (Misc.normalize symbol) fprintf f "%%start %s\n" (Misc.normalize symbol)
) g.start_symbols ) g.start_symbols
(* -------------------------------------------------------------------------- *)
(* Printing %parameter declarations. *)
let print_parameter f stretch = let print_parameter f stretch =
fprintf f "%%parameter<%s>\n" stretch.stretch_raw_content fprintf f "%%parameter<%s>\n" stretch.stretch_raw_content
let print_parameters f g = let print_parameters f g =
List.iter (print_parameter f) g.parameters match mode with
| PrintNormal ->
List.iter (print_parameter f) g.parameters
| PrintForOCamlyacc
| PrintUnitActions
| PrintUnitActionsUnitTokens ->
(* %parameter declarations are not supported by ocamlyacc,
and presumably become useless when the semantic actions
are removed. *)
()
(* -------------------------------------------------------------------------- *)
(* Printing token declarations and precedence declarations. *)
let print_assoc = function let print_assoc = function
| LeftAssoc -> | LeftAssoc ->
...@@ -240,6 +259,10 @@ let print_tokens f g = ...@@ -240,6 +259,10 @@ let print_tokens f g =
end end
) levels ) levels
(* -------------------------------------------------------------------------- *)
(* Printing %type declarations. *)
let print_types f g = let print_types f g =
StringMap.iter (fun symbol ty -> StringMap.iter (fun symbol ty ->
fprintf f "%%type%s %s\n" fprintf f "%%type%s %s\n"
...@@ -247,6 +270,10 @@ let print_types f g = ...@@ -247,6 +270,10 @@ let print_types f g =
(Misc.normalize symbol) (Misc.normalize symbol)
) g.types ) g.types
(* -------------------------------------------------------------------------- *)
(* Printing branches and rules. *)
let print_branch f g branch = let print_branch f g branch =
(* Print the producers. *) (* Print the producers. *)
let sep = Misc.once "" " " in let sep = Misc.once "" " " in
...@@ -306,6 +333,10 @@ let print_rules f g = ...@@ -306,6 +333,10 @@ let print_rules f g =
) r.branches ) r.branches
) rules ) rules
(* -------------------------------------------------------------------------- *)
(* Printing %on_error_reduce declarations. *)
let print_on_error_reduce_declarations f g = let print_on_error_reduce_declarations f g =
let cmp (_nt, oel) (_nt', oel') = let cmp (_nt, oel) (_nt', oel') =
compare_branch_production_levels oel oel' compare_branch_production_levels oel oel'
...@@ -323,13 +354,27 @@ let print_on_error_reduce_declarations f g = ...@@ -323,13 +354,27 @@ let print_on_error_reduce_declarations f g =
fprintf f "\n" fprintf f "\n"
) levels ) levels
let print_on_error_reduce_declarations f g =
match mode with
| PrintNormal
| PrintUnitActions
| PrintUnitActionsUnitTokens ->
print_on_error_reduce_declarations f g
| PrintForOCamlyacc ->
(* %on_error_reduce declarations are not supported by ocamlyacc *)
()
(* -------------------------------------------------------------------------- *)
(* The main entry point. *)
let print f g = let print f g =
if_normal_mode (print_parameters f) g; print_parameters f g;
if_ocaml_code_permitted (print_preludes f) g; if_ocaml_code_permitted (print_preludes f) g;
print_start_symbols f g; print_start_symbols f g;
print_tokens f g; print_tokens f g;
print_types f g; print_types f g;
if_normal_mode (print_on_error_reduce_declarations f) g; print_on_error_reduce_declarations f g;
fprintf f "%%%%\n"; fprintf f "%%%%\n";
print_rules f g; print_rules f g;
fprintf f "\n%%%%\n"; fprintf f "\n%%%%\n";
......
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