Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[fix] TRX: Admitting some grammars that could be looping.

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...
commit 5878f87ff60b201415cf7cb6dd8e951b1f406217 1 parent d53e17e
@akoprow akoprow authored
Showing with 14 additions and 1 deletion.
  1. +14 −1 libtrx/pgrammar.ml
View
15 libtrx/pgrammar.ml
@@ -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)) ||
Please sign in to comment.
Something went wrong with that request. Please try again.