Closed freddie-freeloader closed 4 years ago
I think this is a duplicate of #44.
Sorry, for not making a clearer suggestion.
The only difference between the two versions is the white space after fun
.
I'd suggest that zero or more white spaces would be allowed at this location.
EDIT: Or this breaking the disambiguation between named and anonymous functions regarding lookahead?
Thank you for the clarification.
According to the specification this behaviour is not a bug. The specification says the following about production rule matching:
[..] the order of the productions is not important and at each point the longest matching lexeme is preferred [..] a prefix or postfix pattern is included when considering a longest match.
The rule for anonymous functions reads (here I have quoted lexemes for clarity):
funanon ::= ('fun' | 'function')< '<' | '(' > (anonymous functions must be followed by a '(' or '<'))
Thus no space is allowed between fun
/function
and <
/(
as that would break the longest matching lexeme rule.
As I mentioned in #44, an argument can be made for relaxing such syntactic constraints, however, as per the current language specification the program
val x = (fun (x) { x })
is not a valid Koka program.
Currently, the parser works the following way:
This seems to me overly restrictive and the error message doesn't help here either.