Commit ceb43247 authored by POTTIER Francois's avatar POTTIER Francois
Browse files

Detect unknown symbols in %attribute declarations.

parent b113b1b6
......@@ -641,8 +641,15 @@ let check_parameterized_grammar_is_well_defined grammar =
List.iter (check kind false) ps
in
List.iter (check "%type" true) (List.map fst grammar.p_types);
List.iter (check "%on_error_reduce" true) (List.map fst grammar.p_on_error_reduce);
let check_fst kind must_be_nonterminal (p, _) =
check kind must_be_nonterminal p
in
List.iter (check_fst "%type" true) grammar.p_types;
List.iter (check_fst "%on_error_reduce" true) grammar.p_on_error_reduce;
List.iter (fun (params, _) ->
List.iter (check "%attribute" false) params
) grammar.p_symbol_attributes;
(* Every reference to a symbol is well defined. *)
let used_tokens = ref StringSet.empty in
......
File "unknown_symbol_in_attribute.mly", line 2, characters 16-17:
Error: D is undefined.
%token A B C
%attribute list(D) [@foo "bar"] (* the symbol D is unknown, so this %attribute declaration cannot work *)
%start<unit> main
%%
main:
A B list(C) {}
File "unused-attribute.mly", line 3, characters 19-31:
File "unused-attribute.mly", line 2, characters 19-31:
Warning: this attribute could not be transferred to the symbol list(B)
File "unused-attribute.mly", line 2, characters 13-25:
Warning: this attribute could not be transferred to the symbol D
Grammar has 2 nonterminal symbols, among which 1 start symbols.
Grammar has 3 terminal symbols.
Grammar has 3 productions.
......
%token A B C
%attribute D [@foo "bar"] (* the symbol D is unknown, so this %attribute declaration cannot work *)
%attribute list(B) [@foo "bar"] (* the symbol list(B) is never created during expansion, so this declaration is not OK *)
%attribute list(C) [@foo "bar"] (* the symbol list(C) is created during expansion, so this declaration is OK *)
%start<unit> main
......
File "unused-attribute.mly", line 3, characters 19-31:
File "unused-attribute.mly", line 2, characters 19-31:
Warning: this attribute could not be transferred to the symbol list(B)
File "unused-attribute.mly", line 2, characters 13-25:
Warning: this attribute could not be transferred to the symbol D
%start main
%token A
%token B
......
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