Skip to content

Closure syntax requires arbitrary lookahead #664

@thomcc

Description

@thomcc

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 of fn 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions