From 20f3e51c4a228b688e0d92a84414fc03a844eb11 Mon Sep 17 00:00:00 2001 From: batracos Date: Sat, 20 Oct 2018 05:44:03 -0500 Subject: [PATCH] Incremental syntax updates (#18) * 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 --- WolframLanguage.sublime-settings | 12 ++++++++++++ WolframLanguage.sublime-syntax | 29 +++++++++++++---------------- syntax_test_wolfram_language.wl | 27 +++++++++++++++++++++++---- 3 files changed, 48 insertions(+), 20 deletions(-) create mode 100644 WolframLanguage.sublime-settings diff --git a/WolframLanguage.sublime-settings b/WolframLanguage.sublime-settings new file mode 100644 index 0000000..46dba90 --- /dev/null +++ b/WolframLanguage.sublime-settings @@ -0,0 +1,12 @@ +{ + "extensions": + [ + "m", + "wl", + "wls", + "nb", + "mt", + "wlt" + ], + "word_separators": "./\\()\"'-:,.;<>~!@#%^&*|+=[]{}`~?_" +} diff --git a/WolframLanguage.sublime-syntax b/WolframLanguage.sublime-syntax index a7a07a6..6557c64 100644 --- a/WolframLanguage.sublime-syntax +++ b/WolframLanguage.sublime-syntax @@ -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 @@ -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 @@ -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:]]+\] @@ -172,7 +166,7 @@ contexts: captures: 1: keyword.operator.PatternTest.wolfram pop: true - - match: (?:\s*)(:)(?=[^:>]) + - match: (?:\s*)(:)(?=[^:>=]) captures: 1: keyword.operator.Optional.wolfram pop: true @@ -180,7 +174,7 @@ contexts: pop: true pattern: - - match: '({{identifier}})\s*(:(?=[^:>]))' + - match: '({{identifier}})\s*(:(?=[^:>=]))' captures: 1: variable.parameter.wolfram 3: keyword.operator.Pattern.wolfram @@ -188,11 +182,11 @@ contexts: - 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 @@ -253,6 +247,7 @@ contexts: pop: true - match: (?=[\,|\}]) pop: true + - include: expressions declarations: @@ -262,14 +257,14 @@ contexts: (?= \s* ( - \[ + \[(?!\[) (?> [^\[\]]+| \g<-1> )* \] ) - \s*:= + \s*(?:\/;.*)?\s*:= ) scope: entity.name.function push: @@ -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 diff --git a/syntax_test_wolfram_language.wl b/syntax_test_wolfram_language.wl index c789bbb..35a354b 100644 --- a/syntax_test_wolfram_language.wl +++ b/syntax_test_wolfram_language.wl @@ -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 *) @@ -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 *) @@ -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] :=