Sublime-WolframLanguage icon indicating copy to clipboard operation
Sublime-WolframLanguage copied to clipboard

Word boundary (\b) is not a good separator for symbol names

Open batracos opened this issue 6 years ago • 9 comments

The current rules will match an expression like

Plus$Plus

as a system symbol (Plus) followed by a normal symbol ($Plus).

I have not looked into all the consequences but my current proposal is to replace the second \b in the regex expression by (?![$`[:alnum:]]). This would also fix expressions like

Plus`foo

batracos avatar Jun 13 '18 13:06 batracos

How about replacing \b with [\b$`]? In any case, isn't this best fixed by updating the variable "symbol", currently defined as

symbol: '[$[:alpha:]]+[$[:alnum:]]*'

ViktorQvarfordt avatar Jun 15 '18 11:06 ViktorQvarfordt

In which way would you update that? I can only think of a negative look-behind on defined symbols would be terribly expensive.

[\b$`] would just move the backtick or the dollar to the other match but in this case we want Plus$Plus to be a single scope.

@chere005, @Shigma, any idea?

batracos avatar Jun 18 '18 08:06 batracos

Was this fixed, or did you still want some input?

chere005 avatar Oct 23 '18 15:10 chere005

I did not touch this because good patterns (that I was able to find) bring bad performance and vice versa.

batracos avatar Oct 30 '18 10:10 batracos

I did not touch this because good patterns (that I was able to find) bring bad performance and vice versa.

I don't consider it a problem since the current syntax for wolfram is not complicated compared with other languages.

In my option, how about inserting a pattern (?![$`]) before the ending \b?

We should also be aware that some system contexts share the same name with built-in functions, although this seems beyond the scope of this issue.

shigma avatar Nov 04 '18 04:11 shigma

This is exactly what I am using locally. I never committed that because I am not super sure about it but given that we are already in two people coming up with the same solution I would go for it.

\b(?:AASTriangle|...)(?![$`])\b

Regarding the contexts: I don't think that Image should be highlighted in Image`foo.

batracos avatar Nov 04 '18 17:11 batracos

I just tested (?![$`]) and it looks good to me, @Shigma can you please add this to your current PR?

chere005 avatar Nov 08 '18 19:11 chere005

I just tested (?![$`]) and it looks good to me, @Shigma can you please add this to your current PR?

It has already been included in one of @batracos ' branches, see here.

shigma avatar Nov 09 '18 05:11 shigma

Yeah sorry. I have been meaning to create a PR for that for some time. I'll do it today.

batracos avatar Nov 09 '18 08:11 batracos