Skip to content

Commit

Permalink
Incremental syntax updates (#18)
Browse files Browse the repository at this point in the history
* Removing the double list of contexts as it seems that pattern can be the first one without issues (so far)

* The Optional operator rule should exclude SetDelayed

* Slightly better regex for numbers that also matches with Accuracy (``) instead of just Precision (`)

* Improved (and somewhat sorted) the list of operators that pop the pattern scope

* Added match for global variable declaration ($name) so they can be picked up by the index

* Added a sublime-setting local to the package

* Added matching rules for Span operator

* Include all expressions in the scoping functions variable list

* Adding a valid optional Condition after the function definition but before the SetDelayed

* Updated tests
  • Loading branch information
batracos authored and ViktorQvarfordt committed Oct 20, 2018
1 parent 0fd4b36 commit 20f3e51
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
12 changes: 12 additions & 0 deletions WolframLanguage.sublime-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extensions":
[
"m",
"wl",
"wls",
"nb",
"mt",
"wlt"
],
"word_separators": "./\\()\"'-:,.;<>~!@#%^&*|+=[]{}`~?_"
}
29 changes: 13 additions & 16 deletions WolframLanguage.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,8 @@ contexts:
- include: expressions

expressions:
- include: comments
- include: literals
- include: shorthand
- include: operators
- include: pattern
- include: pattern-short
- include: scoping
- include: function
- include: variable
- include: nested
- include: expressions-nopattern

expressions-nopattern:
- include: comments
Expand Down Expand Up @@ -98,7 +90,7 @@ contexts:
pop: true

literals:
- match: (\d+(\.\d*)?`?|\d*\.\d+`?)
- match: (?:\d+\.?|\.\d)\d*\`{0,2}
scope: constant.numeric.wolfram
- match: ((?:System`)?{{built_in_numeric_constants}})
scope: constant.numeric.wolfram
Expand Down Expand Up @@ -154,6 +146,8 @@ contexts:
scope: keyword.operator.string.wolfram
- match: \.\.\.?
scope: keyword.operator.repeat.wolfram
- match: ';;'
scope: keyword.operator.span.wolfram
- match: ';'
scope: keyword.operator.compound.wolfram
- match: \\\[[[:alnum:]]+\]
Expand All @@ -172,27 +166,27 @@ contexts:
captures:
1: keyword.operator.PatternTest.wolfram
pop: true
- match: (?:\s*)(:)(?=[^:>])
- match: (?:\s*)(:)(?=[^:>=])
captures:
1: keyword.operator.Optional.wolfram
pop: true
- match: (?=.)
pop: true

pattern:
- match: '({{identifier}})\s*(:(?=[^:>]))'
- match: '({{identifier}})\s*(:(?=[^:>=]))'
captures:
1: variable.parameter.wolfram
3: keyword.operator.Pattern.wolfram
push:
- meta_content_scope: meta.pattern.wolfram
- match: \?
scope: keyword.operator.PatternTest.wolfram
- match: ':(?=[^:>])'
- match: ':(?=[^:>=])'
scope: keyword.operator.Optional.wolfram
pop: true
# we should check the precedence here
- match: (?=,|;|/;|[:-]>|(:)?=|\]|\))
- match: (?=[:-]>|:?=|\/[;.\/]|[\]\)\},;&]|>>|<<)
pop: true
- include: expressions-nopattern

Expand Down Expand Up @@ -253,6 +247,7 @@ contexts:
pop: true
- match: (?=[\,|\}])
pop: true
- include: expressions


declarations:
Expand All @@ -262,14 +257,14 @@ contexts:
(?=
\s*
(
\[
\[(?!\[)
(?>
[^\[\]]+|
\g<-1>
)*
\]
)
\s*:=
\s*(?:\/;.*)?\s*:=
)
scope: entity.name.function
push:
Expand All @@ -283,6 +278,8 @@ contexts:
- include: sequence
- match: (?=[^\[])
pop: true
- match: ((?:{{symbol}}`)*(\${{symbol}}))(?=\s*:?=)
scope: entity.name.constant.wolfram

sequence:
- meta_scope: meta.sequence.wolfram
Expand Down
27 changes: 23 additions & 4 deletions syntax_test_wolfram_language.wl
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,15 @@
(*^ entity.name.function*)
(* ^ variable.parameter*)

(* <<< the scoping from above is breaking this one *)
f[x_] := 2x
(*^ entity.name.function*)
(* ^ variable.parameter*)

f[x_] /; x > 0 := x
(*^ entity.name.function *)

f[[]]


(* STRINGS *)

Expand Down Expand Up @@ -230,10 +234,10 @@
(* ^ meta.parens.wolfram *)
(* ^ meta.parens.wolfram punctuation.section.parens.end.wolfram *)

[ [ ] ]
[ [ ]]
(*^^^ meta.parts.wolfram punctuation.section.parts.begin.wolfram *)
(* ^ meta.parts.wolfram *)
(* ^^^ meta.parts.wolfram punctuation.section.parts.end.wolfram *)
(* ^^ meta.parts.wolfram punctuation.section.parts.end.wolfram *)


(* SCOPING *)
Expand All @@ -249,11 +253,26 @@ Module[
(* ^^^ meta.block.wolfram variable.other *)
]

Block[
{
var1, (*comment*) var2 , var3 = var4
(* ^^^^ meta.block.local.wolfram variable.parameter.wolfram *)
(* ^^^^^^^^^^^ meta.block.local.wolfram comment.block.wolfram *)
(* ^^^^ meta.block.local.wolfram variable.parameter.wolfram *)
(* ^^^^ meta.block.local.wolfram variable.parameter.wolfram *)
(* ^^^^ meta.block.local.wolfram variable.other*)
},

code
(*^^^^ meta.block.wolfram variable.other *)

]


(* ASSERTION FREE *)

System`foo[[1]]

a//a
StringMatchQ[IgnoreCase -> Automatic, foo -> bar]

foo["bar", baz_Lisght] :=
Expand Down

0 comments on commit 20f3e51

Please sign in to comment.