Commit 63581653 by POTTIER Francois

UnparameterizedPrinter: replace newlines with spaces when printing

%type declarations for ocamlyacc. (Reported by Kenji Maillard.)
parent 652e09f9
2016/11/15:
Fix in --only-preprocess-for-ocamlyacc mode: avoid printing newline characters
inside a %type declaration, as this is forbidden by ocamlyacc. (Reported by
Kenji Maillard.)
2016/09/01:
New command line switch --only-preprocess-for-ocamlyacc, supposed to print the
grammar in a form that ocamlyacc can accept. As of now, this feature is
......
......@@ -44,12 +44,24 @@ let print_ocamltype ty : string =
to carry a semantic value of type [unit].
*)
let print_ocamltype mode ty : string =
let s = print_ocamltype ty in
match mode with
| PrintForOCamlyacc ->
(* ocamlyacc does not allow a %type declaration to contain
a new line. *)
String.map (function '\r' | '\n' -> ' ' | c -> c) s
| PrintNormal
| PrintUnitActions
| PrintUnitActionsUnitTokens ->
s
let print_token_type mode (prop : token_properties) =
match mode with
| PrintNormal
| PrintForOCamlyacc
| PrintUnitActions ->
Misc.o2s prop.tk_ocamltype print_ocamltype
Misc.o2s prop.tk_ocamltype (print_ocamltype mode)
| PrintUnitActionsUnitTokens ->
"" (* omitted ocamltype after %token means <unit> *)
......@@ -57,7 +69,7 @@ let print_ocamltype_or_unit mode ty =
match mode with
| PrintNormal
| PrintForOCamlyacc ->
print_ocamltype ty
print_ocamltype mode ty
| PrintUnitActions
| PrintUnitActionsUnitTokens ->
" <unit>"
......
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