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

Add support for boxes and templates #22

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
79 changes: 64 additions & 15 deletions WolframLanguage.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ variables:

nb_code_styles: (Input)


contexts:

main:
Expand All @@ -75,9 +74,9 @@ contexts:
- match: '(\(\*\s*)(::)([[:alnum:]]+)(::)(\s*\*\))'
captures:
1: comment.line.wolfram
2: constant.numeric.line-number.find-in-files
3: constant.language.wolfram
4: constant.numeric.line-number.find-in-files
2: constant.numeric.line-number.find-in-files punctuation.style.begin.wolfram
3: constant.language.style.wolfram
4: constant.numeric.line-number.find-in-files punctuation.style.end.wolfram
5: comment.line.wolfram
- match: \(\*
push: comment-block
Expand All @@ -99,20 +98,50 @@ contexts:
- match: ((?:System`)?{{built_in_options}})
scope: variable.function.wolfram
- match: \"
scope: punctuation.definition.string.begin
scope: string.quoted.wolfram punctuation.definition.string.begin
push:
- meta_scope: string.quoted.wolfram
- match: \"
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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]\)"

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

scope: punctuation.definition.string.end
scope: string.quoted.wolfram punctuation.definition.string.end
pop: true
- match: \\\[\w+\]
scope: constant.character.escape.wolfram
- match: \\[()!*]
scope: keyword.operator.wolfram
- match: \\[^()!*]

# box representation
- match: \\!\\\(
scope: keyword.operator.string-box.wolfram
push:
# workaround plain scope in string meta scope
- meta_scope: meta.string-box.wolfram
- match: \\\)
scope: keyword.operator.string-box.wolfram
pop: true
- match: (?=\")
pop: true
- include: boxed

# escape characters
- match: \\(["nrtbf\\]|\r?\n)
scope: constant.character.escape.wolfram
- match: (?<=[\s\"\`])\`\w*\`
scope: constant.other.placeholder.wolfram
- match: \\\.[0-9A-Fa-f]{2}|\\:[0-9A-Fa-f]{4}
scope: constant.character.encoding.wolfram
- match: \\\[\w+\]
scope: constant.character.built-in.wolfram

# string template
- match: \`\w*\`
scope: variable.parameter.wolfram
- match: <\*
scope: keyword.operator.template-expression.wolfram
push:
# workaround plain scope in string meta scope
- meta_scope: meta.template-expression.wolfram
- match: \*>
scope: keyword.operator.template-expression.wolfram
pop: true
shigma marked this conversation as resolved.
Show resolved Hide resolved
- match: (?=\")
pop: true
- include: expressions

- match: '[\s\S]'
scope: string.quoted.wolfram

shorthand:
- match: (::)\s*([[:alnum:]]+)
Expand Down Expand Up @@ -249,7 +278,6 @@ contexts:
pop: true
- include: expressions


declarations:
- match: |-
(?x)
Expand Down Expand Up @@ -330,3 +358,24 @@ contexts:
scope: punctuation.section.association.end.wolfram
pop: true
- include: expressions
- match: (\\!)?\\\(
scope: punctuation.section.box.begin.wolfram
push:
- meta_scope: meta.box.wolfram
- match: \\\)
scope: punctuation.section.box.end.wolfram
pop: true
- include: boxed

boxed:
- include: expressions
- match: \\[%&+_^]
scope: keyword.operator.x-scriptBox.wolfram
- match: \\/
scope: keyword.operator.FractionBox.wolfram
- match: \\@
scope: keyword.operator.SqrtBox.wolfram
- match: \\`
scope: keyword.operator.FormBox.wolfram
- match: \\\*
scope: keyword.operator.box-constructor.wolfram
Loading