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
Closure syntax requires arbitrary lookahead #664
Comments
@xiaq commented about this a few days ago in the Telegram group. Search for "unapologetically haskellesque" in the group to find the discussion :) |
Personally I like the current syntax. It reminds me of Clojure's argument lists - I agree from a purely formal point of view what you say is an issue, but in practice it seems to work well - hence the working syntax-highlighting support already existing for multiple editors. |
Do they work if a new line is in the middle of the argument list? You can do some hacks where match the whole decl as a regex, and pull it apart, but at least in editors that use tmLanguage (sublime text also has sublime-syntax, but that has this restriction as well), those regexps cannot go over multiple lines (there are other issues with doing this as well, but this is the biggest one). Maybe that's enough of an edge case where it doesn't matter though, although not being able to offer good help for someone who accidentally separates the |
I agree about the thing with The Elvish mode in Emacs uses regex-based syntax highlighting, so many cases are not properly handled - e.g. the new-line-in-the-middle (note the color change): |
Some thoughts:
|
Yeah, that makes sense. I feel like it could be made work in either case, but would likely introduce other confusing aspects to the grammar.
Well, really the point of my proposal wasn't to propose new syntax so much as to indicate that the current syntax was not good for these reasons. But yeah, I gave examples so as not to simply be complaining without offering solutions. That said, either of these could eliminate the requirement for no spaces between |
While trying to implement #1279 I realized that the syntax of using This has led me to revisit the issue. Unfortunately I'm still going to reject the The syntax I'm considering now is This is how it can look like, from tight to spacey: fn f {|a b c|echo $a $b $c}
fn f { |a b c| echo $a $b $c }
fn f { |a b c|
echo $a $b $c
}
fn f {
| a b c |
echo $a $b $c
}
put a b c | each {|x|echo $x}
put a b c | each { |x| echo $x }
put a b c | each { |x|
echo $x
}
put a b c | each {
| x |
echo $x
} After this change, the condition for parsing a lambda becomes:
There is no longer any overlap between parsing of lambdas and lists. FWIW it appears that this looks the same as Ruby's block syntax. I was thinking of Smalltalk's block syntax consciously but I may have seen Ruby's syntax somewhere before. |
The new syntax is now supported. Next steps are
|
Nothing more to do for 0.17. |
I was surprised to see so many legacy lambda syntax examples in the documentation. This replaces all of them with the new syntax -- excluding the handful of cases meant to explicitly verify the legacy form is still valid. This also adds a link to the issue in the release notes which documents the change in syntax. Related elves#664
I was surprised to see so many legacy lambda syntax examples in the documentation. This replaces all of them with the new syntax -- excluding the handful of cases meant to explicitly verify the legacy form is still valid. This also adds a link to the issue in the release notes which documents the change in syntax. Related #664
You need unbounded lookahead to distinguish between function parameters and a list. This makes syntax highlighting and other parsing or analysis much more difficult.
Specifically, when you encounter
[
you don't know if the items inside are function parameters or members of a list until you hit the]{
. This is generally something you want to avoid, especially in cases where you're defining symbols into a scope, or doing other things that tooling might want to understand.As a result, syntax highlighting this correctly for elvish isn't really possible using common methods (tmLanguage, sublime-syntax, etc) without fragile hacks. It also means that it's harder to report errors if a user puts a space between
]
and{
(you have no way of knowing if it was intentional or not).Many parser generators also have trouble with cases like these, as well (although I'm not sure when someone would be implementing a parser generator for the language they use with their shell).
The easiest fix would probably be adding a token that comes before the parameter list.
fn[a b c]{ ... }
would be somewhat consistent with function declaration. A sigil already used by the language like$
,@
,&
in the place offn
would also work as well.There are a lot of other choices as well, and I have no preference for which you end up going with (so long as it doesn't also have the same issue).
That said, this would require breaking a large amount of existing elvish code, so I'd understand being reluctant about changing it. A tool to fix code like that automatically would not be hard to implement though.
The text was updated successfully, but these errors were encountered: