Make left recursion in pegs a failed parse
Eventually left recursion will work fine, but this is prevents an infinite loop for now.db4
parent
4c50daed22
commit
4e29081e93
|
@ -175,6 +175,8 @@ IN: peg.tests
|
|||
[ "1" token , "+" token , "1" token , ] seq* ,
|
||||
] choice*
|
||||
"1-1" over parse parse-result-ast swap
|
||||
"1+1" swap parse parse-result-ast
|
||||
] with-packrat
|
||||
[
|
||||
"1+1" swap parse parse-result-ast
|
||||
] with-packrat
|
||||
] unit-test
|
|
@ -34,12 +34,12 @@ GENERIC: (compile) ( parser -- quot )
|
|||
#! that maps the input string position to the parser result.
|
||||
[ drop H{ } clone ] cache ;
|
||||
|
||||
: cached-result ( n input-cache input quot -- result )
|
||||
:: cached-result ( n input-cache input quot -- result )
|
||||
#! Get the cached result for input position n
|
||||
#! from the input cache. If the item is not in the cache,
|
||||
#! call 'quot' with 'input' on the stack to get the result
|
||||
#! and store that in the cache and return it.
|
||||
[ nip ] swap compose curry cache ; inline
|
||||
n input-cache [ drop input quot call ] cache ; inline
|
||||
|
||||
:: run-packrat-parser ( input quot c -- result )
|
||||
input input-from
|
||||
|
|
Loading…
Reference in New Issue