diff options
| author | Jim Fehrle | 2020-04-28 22:18:21 -0700 |
|---|---|---|
| committer | Jim Fehrle | 2020-06-08 16:50:53 -0700 |
| commit | 12540e172c890ebae65c6660e932af650ab0a800 (patch) | |
| tree | 82bba06d972b1362a34392a4a11abf006f4f7fd6 /doc | |
| parent | 485054ab819d9b1607baa671836d48f6ea84969f (diff) | |
Report an error for empty (sub)productions
(Sphinx notations don't support these.)
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/tools/docgram/doc_grammar.ml | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/doc/tools/docgram/doc_grammar.ml b/doc/tools/docgram/doc_grammar.ml index cb2b0234a9..f54a694e31 100644 --- a/doc/tools/docgram/doc_grammar.ml +++ b/doc/tools/docgram/doc_grammar.ml @@ -50,7 +50,7 @@ let default_args = { verify = false; } -let start_symbols = ["document"] +let start_symbols = ["document"; "REACHABLE"] let tokens = [ "bullet"; "string"; "unicode_id_part"; "unicode_letter" ] (* translated symbols *) @@ -1710,6 +1710,28 @@ type seen = { cmdvs: (string * int) NTMap.t; } +(* Sphinx notations can't handle empty productions *) +let has_empty_prod rhs = + let rec has_empty_prod_r rhs = + match rhs with + | [] -> false + | Sterm _ :: tl + | Snterm _ :: tl + | Sedit _ :: tl + | Sedit2 (_, _) :: tl -> has_empty_prod_r tl + + | Slist1 sym :: tl + | Slist0 sym :: tl + | Slist1sep (sym, _) :: tl + | Slist0sep (sym, _) :: tl + | Sopt sym :: tl -> has_empty_prod_r [ sym ] || has_empty_prod_r tl + + | Sparen prod :: tl -> List.length prod = 0 || has_empty_prod_r tl + | Sprod prods :: tl -> List.fold_left + (fun rv prod -> List.length prod = 0 || has_empty_prod_r tl || rv) false prods + in + List.length rhs = 0 || has_empty_prod_r rhs + let process_rst g file args seen tac_prods cmd_prods = let old_rst = open_in file in let new_rst = open_temp_bin file in @@ -1740,6 +1762,9 @@ let process_rst g file args seen tac_prods cmd_prods = List.iteri (fun i prod -> let rhs = String.trim (prod_to_prodn prod) in let sep = if i = 0 then " ::=" else "|" in + if has_empty_prod prod then + error "%s line %d: Empty (sub-)production for %s, edit to remove: '%s %s'\n" + file !linenum nt sep rhs; fprintf new_rst "%s %s%s %s\n" indent (if i = 0 then nt else "") sep rhs) prods; if nt <> end_ then copy_prods tl |
