Fix exponentionality in Clean.Types.Parse
Previously, the time and heap needed for these start rules would grow exponentionally:
Start = parseType ['[(Int,{#Char},T)] -> [(Int,String,T)]']
Start = parseType ['[(Int,{#Char},T)] -> [(Int,String,T,T)]']
Start = parseType ['[(Int,{#Char},T)] -> [(Int,String,T,T,T)]']
This was due to pure [] <|> optContext
in addContextAsConstFunction
. This function adds context to a type which is not a function type (e.g., a | toString a
), but should only be used when it cannot be added to a parent function type (e.g., a -> b | toString a
must be parsed as ~Func [a] b [toString a]
rather than ~Func [a] (Func [] b [toString a]) []
; hence the pure [] <|> ...
.
The solution taken here is to add a pPeek
which returns the current token stream, and have addContextAsConstFunction
return immediately if the next token is not |
.