Commit 663a0bc1 authored by POTTIER Francois's avatar POTTIER Francois

Allow a %public symbol to be split, even within a single unit.

parent b0498800
File "arity-split.mly", line 7, characters 8-11:
File "arity-split.mly", line 6, characters 8-11:
Error: the symbol foo is defined with arities 1 and 0.
%token A B
%start<unit> main
%%
main: foo {}
%public foo : A {}
%public foo(X): X {}
File "multiple-symbol-definition.mly", line 9, characters 0-1:
File "multiple-symbol-definition.mly", line 10, characters 0-1:
Error: the nonterminal symbol a is multiply defined.
File "multiple-symbol-definition.mly", line 11, characters 0-1:
File "multiple-symbol-definition.mly", line 12, characters 0-1:
Error: the nonterminal symbol b is multiply defined.
Only %public symbols can have split definitions.
/* This grammar is accepted by ocamlyacc, but rejected by Menhir,
as there are two definitions of the symbol [a], and we view
this as a potential mistake. We allow splitting the definition
of %public symbols only. */
of %public symbols only. (The start symbol is implicitly viewed
as %public.) */
%token A B C
%start a
%type<unit> a
%%
a: A B C {}
a: B {}
a: b C {}
b: A B C {}
b: B {}
File "non-terminal-multiple-branch-groups.mly", line 4, characters 0-1:
File "non-terminal-multiple-branch-groups.mly", line 5, characters 0-1:
Error: the nonterminal symbol b is multiply defined.
Only %public symbols can have split definitions.
File "non-terminal-multiple-definitions.mly", line 4, characters 8-9:
File "non-terminal-multiple-definitions.mly", line 6, characters 0-1:
Error: the nonterminal symbol b is multiply defined.
Only %public symbols can have split definitions.
File "obc.mly", line 107, characters 0-7:
File "obc.mly", line 110, characters 0-7:
Error: the nonterminal symbol imports is multiply defined.
Only %public symbols can have split definitions.
......@@ -321,24 +321,31 @@ let store_symbol (symbols : symbol_table) symbol kind =
| exception Not_found ->
add_in_symbol_table symbols symbol kind
(* There are two definitions of this symbol in one unit.
(* There are two definitions of this symbol in one grammatical unit
(that is, one .mly file), and at least one of them is private.
This is forbidden. *)
| (PublicNonTerminal p | PrivateNonTerminal p),
(PublicNonTerminal p' | PrivateNonTerminal p') ->
| PrivateNonTerminal p, PrivateNonTerminal p'
| PublicNonTerminal p, PrivateNonTerminal p'
| PrivateNonTerminal p, PublicNonTerminal p' ->
Error.error [ p; p']
"the nonterminal symbol %s is multiply defined."
"the nonterminal symbol %s is multiply defined.\n\
Only %%public symbols can have split definitions."
symbol
(* The symbol is known to be a token but declared as a nonterminal.*)
| (Token tkp, (PrivateNonTerminal p | PublicNonTerminal p))
| ((PrivateNonTerminal p | PublicNonTerminal p), Token tkp) ->
| Token tkp, (PrivateNonTerminal p | PublicNonTerminal p)
| (PrivateNonTerminal p | PublicNonTerminal p), Token tkp ->
Error.error [ p; tkp.tk_position ]
"the identifier %s is a reference to a token."
symbol
(* We do not gain any piece of information. *)
(* In the following cases, we do not gain any piece of information.
As of 2017/03/29, splitting the definition of a %public nonterminal
symbol is permitted. (It used to be permitted over multiple units,
but forbidden within a single unit.) *)
| _, DontKnow _
| Token _, Token _ ->
| Token _, Token _
| PublicNonTerminal _, PublicNonTerminal _ ->
symbols
(* We learn that the symbol is a nonterminal or a token. *)
......
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