So this is a post that is in regards to what I think may be an overall 
limitation in the syntax region API, or perhaps there is some sort of 
workaround that I am not thinking of, but I figured I would post here to get 
thoughts. I have a theory that it's not possible, but I would love to hear your 
thoughts.

The quick summary here is, I would like to be able to use the syntax region API 
to differentiate between statements in parenthesis and the arguments 
declaration of a lambda (arrow) method. I would like to use regions because 
they are very good about handling sub regions and the opening and closing of 
said regions.

A quick code example of the 2 different uses of parenthesis in JS, and how they 
are different

// A simple expression using parenthesis
var x = (2 + 2);

// parenthesis are actually defining the arguments of this method
var func = (x, y) => {};

The basic equivalent of this in normal JS syntax would be:

var func = function(x, y){};

Another iteration of a lambda definition that is valid Javascript:

var func = (
    x,
    y
) => {}

You can also introduce things like argument destructuring:

var func = (
    x = (2 + 10),
    y = 10
) => {}

Or we can get even more gnarly:

var func = (
    x = () => {}.
    y = 10,
) => {}

Or how about something like this:

someMethod(() => {})

Which would be roughly the equivalent of:

someMethod(function(){})

The problem I am facing right now, is that there is no way to use a region to 
match the arguments definition of a lambda method. The reason for this is 
because per the docs for syntax region - only a start match needs to be made, 
in order to start the region. The problem with lambda methods, is they require 
a check on the closing parenthesis to validate. Thus, either general 
parentheses or lambda arguments match would win a match, depending on which 
item was defined last, as per the rules of the syntax engine (later defined 
regions/matches/keywords/etc are higher priority than previously defined ones).

Perhaps there's some way to do a crazy extreme look ahead in the start regex to 
find the closing parenthesis that is matched with a =>? But if you start having 
deeper levels of parenthesis inside this block, I don't think it's a reasonable 
proposition.

If the lambda arguments definition is only allowed to exist on 1 line, I can 
actually sort of work around all this using a syntax match instead of a region, 
but then I also have problems dealing with how to match and interpret embedded 
parentheses or lambda definitions within that.

Ultimately what makes it so tricky, is that regions ALWAYS start if the start 
matches, but not necessarily if the end matches; lamdba arguments are defined 
by that ending arrow (=>) operator.

It almost kinda makes me wish there was a way to run the JS file through a JS 
parser and then get the matching/highlight groups from that...

Anyways, the only reason I am posting this is because JS is a very widely used 
language, and lamdba methods are becoming quite a common usage pattern. To be 
fair, no other editor (except maybe Emacs) seems to be able to handle all the 
crazy combinations of the aforementioned syntax patterns, but at the very least 
I think it would be super helpful to get a dialogue started since I see this as 
something that could start generating a lot of issues on our JS syntax plugin 
for Vim - https://github.com/pangloss/vim-javascript

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui