ViktorQvarfordt / Sublime-WolframLanguage

Sublime Text 3 support for the Wolfram Language, the language used in Mathematica.
MIT License
31 stars 10 forks source link

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

Open batracos opened 6 years ago

batracos commented 6 years ago

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
ViktorQvarfordt commented 6 years ago

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:]]*'
batracos commented 6 years ago

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?

chere005 commented 6 years ago

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

batracos commented 6 years ago

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

shigma commented 6 years ago

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.

batracos commented 6 years ago

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.

chere005 commented 6 years ago

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

shigma commented 6 years ago

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.

batracos commented 6 years ago

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