Skip to content

Commit

Permalink
[fix] TRX: Admitting some grammars that could be looping.
Browse files Browse the repository at this point in the history
Well, the problem is that we cannot analyze productions where
{| ... |} is used. It would be good to be conservative here, but
we have a grammar that fails because of that so until we come
with a better solution I relax a bit the looping check to
admit such grammars.
  • Loading branch information
akoprow committed Nov 4, 2011
1 parent d53e17e commit 5878f87
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion libtrx/pgrammar.ml
Expand Up @@ -219,12 +219,25 @@ let grammar_analysis pg =
| `Success -> assert false

and analyze_seq s prop ((seq, q1, q2) as seqf) =
let backtraceable =
match q2 with
| None -> false
| Some code ->
let (_, _, _, b) = code in
b
in
match seq, prop with
| _, `Success -> analyze_seq s `Empty seqf || analyze_seq s `NonEmpty seqf
| [], `Empty -> true
| [], `Fail
| [], `NonEmpty -> false
| x::xs, `Empty -> analyze_item s `Empty x && analyze_seq s `Empty (xs, q1, q2)
| x::xs, `Empty ->
if backtraceable then
(* WARNING, we assume that a backtraceable expression will not admit an empty expression;
this may not be true and hence it can lead to a non-terminating parser... *)
false
else
analyze_item s `Empty x && analyze_seq s `Empty (xs, q1, q2)
| x::xs, `Fail -> analyze_item s `Fail x || (analyze_item s `Success x && analyze_seq s `Fail (xs, q1, q2))
| x::xs, `NonEmpty ->
(analyze_item s `NonEmpty x && analyze_seq s `Success (xs, q1, q2)) ||
Expand Down

0 comments on commit 5878f87

Please sign in to comment.