-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add support for boxes and templates #22
base: master
Are you sure you want to change the base?
Conversation
WolframLanguage.sublime-syntax
Outdated
@@ -105,14 +104,38 @@ contexts: | |||
- match: \" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this line at the and to avoid popping when an escaped "
occurs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If escape characters include "
, there is no need to change here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are still some issues though. Compare
"\!\(\*FractionBox[1, 2]\)"
"\!\(\*FractionBox[\"1\", 2]\)"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds a difficult problem for me. I haven't worked out a solution.
Perhaps with_prototype
will work but every time I used this key my sublime crashed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's very corner case. I suggest to make an issue for tracking purpose and not lose too much time now.
Co-Authored-By: Shigma <[email protected]>
Co-Authored-By: Shigma <[email protected]>
I'm not sure I see a difference in:
Should I? |
This breaks strings like |
Emmm, it does. How do you plan to solve it? |
What do you mean by "difference"? |
When I pasted these code snippets and applied your changes, the highlighting didn't change at all. |
I'm not sure, this is a much bigger issue than not supporting StringTemplate. I discussed this with @batracos at one point back in May actually and we couldn't find a good solution.. The closest thing I came up with was something along these lines for L140:
It seems to work but @batracos didn't like it. @shigma and @batracos can we improve this, use it, or come up with something better? If not, we should hold off on StringExpression backtick support |
It's wield. Syntax rules before this PR should not have been able to handle these syntaxes. Can you tell me which commit? |
I'm not sure I get your point by In[11]:= StringTemplate["FOO`BAR`BAZ`"][<|"BAR" -> "-"|>]
Out[11]= "FOO-BAZ`" The syntax for python didn't work out a solution for string templates, either: str = 'I just want a {plain} brace'
# ^^^^^^^ constant.other.placeholder.python We don't show an attempt to If you really want to distinguish those behaviour, maybe we can just match the function outside the string, for example, treat strings inside a I'm interested in it but suggest not to do such things in this PR but open a new one instead because this PR has already does too many things. |
Mathematica is not that strict: In[21]:= "\a" // InputForm
(* Syntax::stresc: Unknown string escape \a. *)
Out[21]//InputForm= "\\a"
In[31]:= "\a"
Out[31]= "\\a" Should out program be that strict? I just don't know. If yes, maybe we can preserve the current rule and append the following rule: match: \\[\s\S]
scope: invalid.character.escape.wolfram |
I think you missed my point. Mathematica IS that strict. If the message isn't appearing, it is a bug that it isn't appearing. That syntax is never actually valid, and we must indicate that |
Contexts show up in many other strings. We absolutely cannot break this for StringTemplated strings. All strings can contain normal backticks. Only in the case for StringTemplate are the backticks special. What this means is assume and default to the backtick being a normal backtick in a string, unless we can properly distinguish. I was suggesting a hacky solution so that sometimes StringTemplate would be right but that contexts would always be right, but I'm less convinced by this. I 100% think we should not support StringTemplate backtick syntax, please remove it from this PR unless there is a much, much better solution. |
1. Now string templates will only be colored in assignment of usages and inside StringTemplate and TemplateApply. 2. Support 3-octal encoding. 3. Better detection for invalid strings.
I don't entirely agree with you but given that the colorization for string template is a break change I decide to remove all the related rules from general string recognition but preserve them for some functions (specifically StringTemplate and TemplateApply) and assignment for usages (which will automatically use string template when displayed in a message). Is this OK? |
I see. Hope the following rules are satisfactory: Sublime-WolframLanguage/WolframLanguage.sublime-syntax Lines 137 to 161 in 4fa3e82
I found only In[69]:= "\8" // Characters
Out[69]= {"\\", "8"} |
This is a great idea, I'll test it soon. |
I want to bring the idea of if there are spaces around the backticks back on the table. While it won't fix every other StringTemplate, it would fix most of the ones that I use. There would just be some instances (when the backticks where next to other characters but it was actually a StringTemplate and not inside the functions we whitelisted.. so very rare). I also suggest we add Success and Failure to the list of functions which commonly use StringTemplate and always turn on the syntax highlighting for this. |
At first glance this seems to work, but it does look like it can be cleaned up. Perhaps another thing to put an issue for, but I'll take another look next week |
It looks a bit to me like some of the escape character rules are leaking here. I wasn't really sure why this was the list of escape characters, in particular ()%+_@/ could you give some insight on everything past f in the list perhaps?
This is the best resource I've found: https://reference.wolfram.com/language/tutorial/InputSyntax.html apparently \000 is a thing too.. |
I tried to respond to most questions tonight, I won't be back on over the weekend. I plan to leave your most recent commits in my local sublime for a few days at work next week before approving so I have time to see if I notice anything with my normal workflows. |
See this: In[153]:= Characters /@ {"\+", "\-", "\>"}
Out[153]= {{"\+"}, {"\\", "-"}, {}} |
@chere005 The following code may better depict the escaping behavior: Quiet @ Last @ Reap[
Scan[
Sow[#, Check[Length @ Characters @ ToExpression["\"\\" <> # <> "\""], -1]] &,
CharacterRange[33, 126]
],
_,
#1 -> StringJoin[#2] &
] With the following result:
|
Any questions @batracos ? |
(* ^^^^^^^^^^^^^^ variable.function*) | ||
(* ^^ keyword.operator*) | ||
(*^ entity.name.function *) | ||
(* ^ variable.parameter *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variable.parameter
is not aligned with x_
.
Same issue at line 173 and 177
Sorry for the long time off the project. I simply did not have the bandwidth to spare. |
Hold off on this until I can take another look..
…Sent from my iPhone
On Mar 23, 2019, at 12:04 PM, batracos ***@***.***> wrote:
Sorry for the long time off the project. I simply did not have the bandwidth to spare.
Except for those three tests not passing this seems good to go.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@batracos and I discussed this, in a string the only characters that should show up as valid escape characters is |
@shigma any plans to update this with the changes we mentioned? |
Support built-in characters and character encoding in strings.
Not treat
\
as escape anymore, but special characters like\n
will be recognized as escapes as usual.Support string templates.
Support string representation of boxes.