Skip to content

Proper Lambda Support #358

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

Merged
merged 5 commits into from
Apr 4, 2016
Merged

Proper Lambda Support #358

merged 5 commits into from
Apr 4, 2016

Conversation

amadeus
Copy link
Collaborator

@amadeus amadeus commented Apr 4, 2016

This PR is a first pass at properly supporting ES6 lambdas. Currently we only support the => (arrow) itself, and don't actually recognize the rest as a function declaration.

This first pass should handle the majority of use cases, although there may be some scenarios I missed.

For reference, this is what syntax highlighting looked like prior to this PR:

before

And this is how it looks with this PR applied:

after

I also fixed a bug when defining a generator that would break jsFuncArgs highlighting

" Matches a single keyword argument with no parens
syntax match jsArrowFuncArgs /\(\k\)\+\s\+\(=>\)\@=/ skipwhite contains=jsFuncArgs extend
" Matches a series of arguments surrounded in parens
syntax match jsArrowFuncArgs /(\(\k\|,\|\s\|\n\|\.\)*)\s\+\(=>\)\@=/ skipwhite contains=jsFuncArgs extend
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain these two patterns?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used to match the arguments definition for an => function.

Currently for normal functions we actually highlight the parenthesis and actual arguments definitions, see this example:

func arg example

My color theme makes them orange.

To match this for lambdas, it's a bit trickier. We have to use a lookahead to match against the =>.

I separated it into 2 lines to make the overall regexes easier to understand.

Lambda functions can be both defined like this:

// The first of the syntax match lines matches this case
arg => obj.getter();

And like this:

// The second syntax match line matches for this
(arg) => obj.getter()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! What is \k?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\k is for a keyword character, :help \\k for more deets

@davidchambers
Copy link
Collaborator

LGTM

amadeus added 5 commits April 4, 2016 00:00
Tacking this on since it relates to ES6 functions.  The generator
astericks were breaking the highlighting of function arguments.  This
should fix generators
@amadeus amadeus merged commit d87bcd1 into pangloss:develop Apr 4, 2016
@amadeus amadeus deleted the arrow-functions branch April 4, 2016 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants