-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function declarations without parentheses #159
Conversation
Remove need for `()` in defining argumentless functions with `function`
source/parser.hera
Outdated
@@ -1037,15 +1038,17 @@ FunctionDeclaration | |||
|
|||
FunctionSignature | |||
# NOTE: Merged in async and generator with optionals | |||
( Async __ )? Function Star? BindingIdentifier?:id __ NonEmptyParameters:parameters ReturnTypeSuffix?:suffix -> | |||
( Async __ )?:async Function:func ( __ Star )?:star ( __ BindingIdentifier )?:wid _?:w Parameters:parameters ReturnTypeSuffix?:suffix -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BindingIdentifier
already includes __
inside its productions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, indeed. But we actually need a _?
version, to support anonymous functions.
It'd be nice to have consistent names for rules that have or don't have whitespace at the start... The current grammar is a bit of a mix. Maybe a leading W
or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely worth exploring some conventions now that the parser is getting large.
With this change both of these are equivalent:
I think that's fine and some people may prefer one to the other. Will someone prefer this style to the other? Probably. Will someone go nuts and annoy their teammates? Also probably, but that is true for many Civet features :) |
Yeah, I had similar thoughts. I was going for the indented block case, where the parens really seemed unnecessary. The one-line tests were just seeing what it could do, and maybe shouldn't be encouraged e.g. via docs. It's particularly weird that I wonder of we should introduce |
I think
|
Remove need for
()
in defining argumentless functions withfunction
:One catch is that I removed the ability to have newlines between the function name and the opening parenthesis of the arguments. Otherwise we have issues with tracking indentation but also the following ambiguity:
function f (x)
I'd say this is an argumentless function
f()
that returnsx
. But currently it parses as the TS function declarationfunction f(x)
.Note that JS does allow
so this is technically an incompatibility with JS... Perhaps there should be a toggle?