The following Raku program defines a grammar Parser
then attempts to use it to parse the string baa
. However, program execution takes too long. Is there a way to limit the amount of execution time devoted to parsing so that parsing can be deemed to have exceeded the desired limit and timed out ?
grammar Parser
{
token TOP { <S> }
token S { '' | <S> <S> | 'a' <S> 'b' | <S> 'a' | 'b' <S> 'b' }
}
sub MAIN()
{
say Parser.parse( 'baa' ).Bool ; # Would like True, False, or Timeout
} # end sub MAIN
Also, might there be plans to have Raku implement the Adaptive LL(*) parsing of ANTLR? Version 4.11.1 of ANTLR has code generation targets including Java, Python, and others, but not Raku.
There is currently no way to stop parsing other, other than by exiting the process. If that is ok with your situation, then you could do something like:
start {
sleep 10; # however much time you want it to give
note "Sorry, it took to long";
exit 1;
}
If that is not an option, there are several variations on the above theme, with e.g. putting the grammar parsing into a start
block and wait for the promise to be kept, or broken.