Skip to content
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 highlight has a bug when parameters default value are "(" or ")" #428

Closed
belchior opened this issue Oct 7, 2017 · 2 comments
Closed

Comments

@belchior
Copy link

belchior commented Oct 7, 2017

const functionHighlight = (param = 'A') => {};

const variableHighlight = (param = '(') => {};

const variableHighlight = (param = ')') => {};

package version: language-babel 2.75.1

@gandm
Copy link
Owner

gandm commented Oct 7, 2017

Yes I'm aware of this issue but it is difficult to fix without making a regex impossibly difficult. Currently the regex that parses lines of this type is

\s*+(\basync\b)?\s*+(?=(<(?:(?>[^<>]+)|\g<-1>)*>)?\s*+(\((?:(?>[^()]+)|\g<-1>)*\))\s*+(((?::(?:(\s*+(&|\|)?(\s*+((?:[$_\p{L}\p{Nl}]|\\u\h{4}|\\u{\h+})(?:[$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Nl}\p{Pc}]|\\u\h{4}|\\u{\h+})*+)(<(?:(?>[^<>]+)|\g<-1>)*>)?|\s*+({(?:(?>[^{}]+)|\g<-1>)*\})|\s*+(\[(?:(?>[^\[\]]+)|\g<-1>)*\])|\s*+(\s*(["']).*?\k<-1>(?<!\\.))|\s*[x0-9A-Fa-f]+))|(?:\s*+/\*.*?\*/))*+)*)|(?:/\*.*?\*/))\s*=>)

in particular a bit of the above is (\((?:(?>[^()]+)|\g<-1>)*\) which parses any balanced brackets that might appear prior to an arrow. I realised that any unbalanced parens inside a string might upset this but as the only purpose of the above if to change the scopename of the variable to indicate it holds a function it doesn't seem too worthwhile changing it. The whole regex is quite complex because of the various syntax items that flow might introduce.

@gandm
Copy link
Owner

gandm commented Nov 6, 2017

Note to self (\((?>[^()"']|("(\\.|[^"])*+")++|('(\\.|[^'])*+')++|\g<-5>)*+\))

gandm pushed a commit that referenced this issue Nov 8, 2017
Solves (arg="(") => {} type syntax.
Issue #428
@gandm gandm closed this as completed in f2840f5 Nov 15, 2017
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

No branches or pull requests

2 participants