From 38beaac7209db3ca80754ad73eed71cbc5d3ddd0 Mon Sep 17 00:00:00 2001 From: Chris Double Date: Fri, 30 Nov 2007 00:01:03 +1300 Subject: [PATCH] Infinite left recursion now causes a failed parser rather than a call stack error --- extra/peg/peg.factor | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extra/peg/peg.factor b/extra/peg/peg.factor index 39aacd974e..7fa1fb90e5 100644 --- a/extra/peg/peg.factor +++ b/extra/peg/peg.factor @@ -52,7 +52,11 @@ PRIVATE> packrat-cache get [ 2dup get-cached dup not-in-cache? [ ! "cache missed: " write over parser-id number>string write " - " write nl ! pick . - drop [ (parse) dup ] 2keep put-cached + drop + #! Protect against left recursion blowing the callstack + #! by storing a failed parse in the cache. + [ f ] dipd [ put-cached ] 2keep + [ (parse) dup ] 2keep put-cached ] [ ! "cache hit: " write over parser-id number>string write " - " write nl ! pick . 2nip