Commit 6a23aac9 authored by fpottier's avatar fpottier

Added a new option --fixed-exception for better ocamlyacc compatibility.


git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/menhir@330 0f8b5475-4b4e-0410-85a8-ee3154a6bfe7
parent ac7e538a
...@@ -105,6 +105,7 @@ ...@@ -105,6 +105,7 @@
\newcommand{\oerrorrecovery}{\texttt{--error-recovery}\xspace} \newcommand{\oerrorrecovery}{\texttt{--error-recovery}\xspace}
\newcommand{\oexplain}{\texttt{--explain}\xspace} \newcommand{\oexplain}{\texttt{--explain}\xspace}
\newcommand{\oexternaltokens}{\texttt{--external-tokens}\xspace} \newcommand{\oexternaltokens}{\texttt{--external-tokens}\xspace}
\newcommand{\ofixedexc}{\texttt{--fixed-exception}\xspace}
\newcommand{\ograph}{\texttt{--graph}\xspace} \newcommand{\ograph}{\texttt{--graph}\xspace}
\newcommand{\oinfer}{\texttt{--infer}\xspace} \newcommand{\oinfer}{\texttt{--infer}\xspace}
\newcommand{\ointerpret}{\texttt{--interpret}\xspace} \newcommand{\ointerpret}{\texttt{--interpret}\xspace}
......
...@@ -129,6 +129,10 @@ the user to define module $T$ and to make sure that it exports a suitable ...@@ -129,6 +129,10 @@ the user to define module $T$ and to make sure that it exports a suitable
\token type. Module $T$ can be hand-written. It can also be automatically generated \token type. Module $T$ can be hand-written. It can also be automatically generated
out of a grammar specification using the \oonlytokens switch. out of a grammar specification using the \oonlytokens switch.
\docswitch{\ofixedexc} This switch causes the exception \texttt{Error} to be
declared equal to \texttt{Parsing.Parse\_error}. This helps increase Menhir's
compatibility with \ocamlyacc. There is otherwise no reason to use it.
\docswitch{\ograph} This switch causes a description of the grammar's \docswitch{\ograph} This switch causes a description of the grammar's
dependency graph to be written to the file \nt{basename}\dott. The graph's dependency graph to be written to the file \nt{basename}\dott. The graph's
vertices are the grammar's nonterminal symbols. There is a directed edge from vertices are the grammar's nonterminal symbols. There is a directed edge from
......
...@@ -10,7 +10,7 @@ let excname = ...@@ -10,7 +10,7 @@ let excname =
let excdef = { let excdef = {
excname = excname; excname = excname;
exceq = None; exceq = (if Settings.fixedexc then Some "Parsing.Parse_error" else None);
} }
let excredef = { let excredef = {
......
...@@ -583,15 +583,16 @@ let directive f = function ...@@ -583,15 +583,16 @@ let directive f = function
let directives = let directives =
pdefs directive nothing nothing pdefs directive nothing nothing
let excdef f def = let excdef in_intf f def =
match def.exceq with match in_intf, def.exceq with
| None -> | _, None
| true, Some _ ->
fprintf f "%s%t%t" def.excname nl nl fprintf f "%s%t%t" def.excname nl nl
| Some s -> | false, Some s ->
fprintf f "%s = %s%t%t" def.excname s nl nl fprintf f "%s = %s%t%t" def.excname s nl nl
let excdefs = let excdefs in_intf =
pdefs excdef exc exc pdefs (excdef in_intf) exc exc
let functorparams intf body b f params = let functorparams intf body b f params =
match params with match params with
...@@ -609,7 +610,7 @@ let structure f p = ...@@ -609,7 +610,7 @@ let structure f p =
indent 2 (fun f p -> indent 2 (fun f p ->
fprintf f "%t%a%a%a" fprintf f "%t%a%a%a"
nl nl
excdefs p.struct_excdefs (excdefs false) p.struct_excdefs
typedefs p.struct_typedefs typedefs p.struct_typedefs
nonrecvaldefs p.struct_nonrecvaldefs nonrecvaldefs p.struct_nonrecvaldefs
) )
...@@ -629,7 +630,7 @@ let moduledef f d = ...@@ -629,7 +630,7 @@ let moduledef f d =
let program f p = let program f p =
fprintf f "%a%a" fprintf f "%a%a"
excdefs p.excdefs (excdefs false) p.excdefs
typedefs p.typedefs; typedefs p.typedefs;
List.iter (stretch false f) p.prologue; List.iter (stretch false f) p.prologue;
fprintf f "%a%a%a" fprintf f "%a%a%a"
...@@ -642,7 +643,7 @@ let valdecl f (x, ts) = ...@@ -642,7 +643,7 @@ let valdecl f (x, ts) =
fprintf f "val %s: %a" x typ ts.body fprintf f "val %s: %a" x typ ts.body
let interface f i = let interface f i =
fprintf f "%a%a%a%!" excdefs i.excdecls typedefs i.typedecls (list valdecl nl) i.valdecls fprintf f "%a%a%a%!" (excdefs true) i.excdecls typedefs i.typedecls (list valdecl nl) i.valdecls
let program p = let program p =
functorparams false program p X.f p.paramdefs functorparams false program p X.f p.paramdefs
......
...@@ -143,6 +143,9 @@ let coq_no_actions = ...@@ -143,6 +143,9 @@ let coq_no_actions =
let strict = let strict =
ref false ref false
let fixedexc =
ref false
type suggestion = type suggestion =
| SuggestNothing | SuggestNothing
| SuggestCompFlags | SuggestCompFlags
...@@ -163,6 +166,7 @@ let options = Arg.align [ ...@@ -163,6 +166,7 @@ let options = Arg.align [
"--error-recovery", Arg.Set recovery, " Attempt recovery by discarding tokens after errors"; "--error-recovery", Arg.Set recovery, " Attempt recovery by discarding tokens after errors";
"--explain", Arg.Set explain, " Explain conflicts in <basename>.conflicts"; "--explain", Arg.Set explain, " Explain conflicts in <basename>.conflicts";
"--external-tokens", Arg.String codeonly, "<module> Import token type definition from <module>"; "--external-tokens", Arg.String codeonly, "<module> Import token type definition from <module>";
"--fixed-exception", Arg.Set fixedexc, " Declares Error = Parsing.Parse_error";
"--follow-construction", Arg.Set follow, " (undocumented)"; "--follow-construction", Arg.Set follow, " (undocumented)";
"--graph", Arg.Set graph, " Write grammar's dependency graph to <basename>.dot"; "--graph", Arg.Set graph, " Write grammar's dependency graph to <basename>.dot";
"--infer", Arg.Set infer, " Invoke ocamlc for ahead of time type inference"; "--infer", Arg.Set infer, " Invoke ocamlc for ahead of time type inference";
...@@ -363,3 +367,6 @@ let coq_no_actions = ...@@ -363,3 +367,6 @@ let coq_no_actions =
let strict = let strict =
!strict !strict
let fixedexc =
!fixedexc
...@@ -154,3 +154,11 @@ val coq_no_actions : bool ...@@ -154,3 +154,11 @@ val coq_no_actions : bool
val strict: bool val strict: bool
(* This flag causes the exception [Error] should be declared equal to
[Parsing.Parse_error]. This is useful when full compatibility with
ocamlyacc is desired. In particular, this is used when building
Menhir itself, since Menhir is compiled first using ocamlyacc, then
using Menhir. *)
val fixedexc: bool
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