diff --git a/LaTeX/LaTeX.sublime-syntax b/LaTeX/LaTeX.sublime-syntax index 685497733a..b8a6145c4e 100644 --- a/LaTeX/LaTeX.sublime-syntax +++ b/LaTeX/LaTeX.sublime-syntax @@ -41,6 +41,12 @@ contexts: scope: punctuation.definition.group.brace.begin.latex push: brace-group-body + brace-group-begin: + - meta_include_prototype: false + - match: \{ + scope: punctuation.definition.group.brace.begin.latex + pop: true + brace-group-body: - meta_scope: meta.group.brace.latex - include: brace-group-end @@ -83,26 +89,34 @@ contexts: - include: general-optional-arguments - include: else-pop +###[ MACROS ]################################################################## + macros: - meta_append: true + - include: latex-newcommand-macros + - include: xparse-newcommand-macros + +###[ LATEX NEWCOMMAND MACROS ]################################################# + + latex-newcommand-macros: - match: (\\)(?:new|renew|provide)command(?:\*|(?![A-Za-z@])) scope: keyword.declaration.function.latex storage.modifier.newcommand.latex captures: 1: punctuation.definition.backslash.latex push: - - newcommand-definition - - newcommand-optarg - - newcommand-argspec - - newcommand-commandname + - latex-newcommand-definition + - latex-newcommand-optarg + - latex-newcommand-argspec + - latex-newcommand-commandname - match: (\\)DeclareMathOperator(?:\*|(?![A-Za-z@])) scope: support.function.declare-math-operator.latex storage.modifier.newcommand.latex captures: 1: punctuation.definition.backslash.latex push: - - newcommand-definition - - newcommand-commandname + - latex-newcommand-definition + - latex-newcommand-commandname - newcommand-argspec: + latex-newcommand-argspec: - match: \[ scope: punctuation.definition.group.bracket.begin.latex push: @@ -119,14 +133,14 @@ contexts: - include: paragraph-pop - include: else-pop - newcommand-optarg: + latex-newcommand-optarg: - match: \[ scope: punctuation.definition.group.bracket.begin.latex - push: newcommand-optarg-body + push: latex-newcommand-optarg-body - include: paragraph-pop - include: else-pop - newcommand-optarg-body: + latex-newcommand-optarg-body: - clear_scopes: 1 - meta_scope: meta.function.parameters.default-value.latex - match: \] @@ -136,7 +150,7 @@ contexts: - include: general-commands - include: macro-braces - newcommand-commandname: + latex-newcommand-commandname: # version one: brace-wrapped command name - match: \{ scope: punctuation.definition.group.brace.begin.latex @@ -167,19 +181,18 @@ contexts: # we need a separate context for command definitions, because they can contain # un-balanced elements. - newcommand-definition: + latex-newcommand-definition: - meta_scope: meta.function.latex - match: (?=\{) set: - def-function-body-meta - macro-braces-begin - match: (?=\\) - set: newcommand-expression + set: latex-newcommand-expression - include: paragraph-pop - include: else-pop - - newcommand-expression: + latex-newcommand-expression: - meta_scope: meta.function.body.latex # but in principle, a single token is also valid, # thus either a command sequence ... @@ -198,6 +211,145 @@ contexts: - include: paragraph-pop - include: else-pop +###[ XPARSE NEWCOMMAND MACROS ]################################################ + + xparse-newcommand-macros: + # https://www.ctan.org/pkg/xparse + - match: (\\)(?:(?:New|Renew|Provide|Declare)(:?Expandable)?DocumentCommand){{endcs}} + scope: keyword.declaration.function.latex storage.modifier.newcommand.latex + captures: + 1: punctuation.definition.backslash.latex + push: + - latex-newcommand-definition + - xparse-newcommand-argspec + - latex-newcommand-commandname + + xparse-newcommand-argspec: + - match: (?=\{) + set: + - xparse-newcommand-argspec-body + - brace-group-begin + - include: paragraph-pop + - include: else-pop + + xparse-newcommand-argspec-body: + - clear_scopes: 1 + - meta_scope: meta.function.parameters.latex + - include: brace-group-end + - include: macro-braces + - include: xparse-newcommand-single-argspec + # not actually allowed, but included here to future-proof highlighting + - include: general-constants + - include: general-commands + - include: paragraph-pop + + xparse-newcommand-single-argspec: + # modifiers and simple specs + - match: '[+!]' + scope: storage.modifier.latex + - match: '[movsb]' + scope: storage.type.latex + - match: t + scope: storage.type.latex + push: xparse-newcommand-args-token + # delimited arguments without default + - match: '[rd]' + scope: storage.type.latex + push: + - xparse-newcommand-args-token + - xparse-newcommand-args-token + # delimited arguments with default + - match: '[RD]' + scope: storage.type.latex + push: + - xparse-newcommand-optarg-value + - xparse-newcommand-args-token + - xparse-newcommand-args-token + # optional argument with default + - match: O + scope: storage.type.latex + push: xparse-newcommand-optarg-value + # embellishment argument + - match: e + scope: storage.type.latex + push: xparse-newcommand-args-token + # embellishment argument with default + - match: E + scope: storage.type.latex + push: + - xparse-newcommand-optarg-value + - xparse-newcommand-args-token + # argument processors + - match: '>' + scope: storage.modifier.latex + + xparse-newcommand-args-token: + - meta_include_prototype: false + - include: unmatched-brace-pop + - match: (?={) + set: + - xparse-newcommand-args-wrapped-token + - brace-group-begin + - match: (?=\S) + set: xparse-newcommand-args-bare-token + - include: paragraph-pop + + xparse-newcommand-args-bare-token: + # either a command + - match: (\\){{cmdname}}{{endcs}} + scope: constant.other.token.latex + captures: + 1: punctuation.definition.backslash.latex + pop: 1 + # or a single character + - match: \S + scope: constant.character.latex constant.other.token.latex + pop: 1 + - include: paragraph-pop + + xparse-newcommand-args-wrapped-token: + - meta_scope: meta.group.brace.latex + - include: brace-group-end + # either a command + - match: (\\){{cmdname}}{{endcs}} + scope: constant.other.token.latex + captures: + 1: punctuation.definition.backslash.latex + # or a single character + - match: \S + scope: constant.character.latex constant.other.token.latex + + xparse-newcommand-optarg-value: + - meta_include_prototype: false + - include: unmatched-brace-pop + - match: (?={) + set: + - xparse-newcommand-optarg-wrapped-value + - brace-group-begin + - match: (?=\S) + set: xparse-newcommand-optarg-bare-value + - include: paragraph-pop + + xparse-newcommand-optarg-bare-value: + - clear_scopes: 1 + - meta_scope: meta.function.parameters.default-value.latex + - match: (\\){{cmdname}}{{endcs}} + scope: support.function.latex + captures: + 1: punctuation.definition.backslash.latex + pop: 1 + - match: \S + pop: 1 + - include: paragraph-pop + + xparse-newcommand-optarg-wrapped-value: + - clear_scopes: 1 + - meta_scope: meta.function.parameters.default-value.latex meta.group.brace.latex + - include: brace-group-end + - include: macro-braces-content + +###[ CONSTANTS ]############################################################### + general-constants: - meta_prepend: true - match: (\\\\)(?:(\[)\s*-?((?:[[:digit:]]|\.)*)\s*(\w*)\s*(\]))? @@ -566,7 +718,6 @@ contexts: scope: punctuation.definition.verb.latex pop: true - text-decorators: - match: ((\\)emph)(\{) captures: diff --git a/LaTeX/TeX.sublime-syntax b/LaTeX/TeX.sublime-syntax index 38813ed57a..c1fdad0114 100644 --- a/LaTeX/TeX.sublime-syntax +++ b/LaTeX/TeX.sublime-syntax @@ -327,6 +327,12 @@ contexts: scope: punctuation.definition.group.brace.begin.tex push: brace-group-body + brace-group-begin: + - meta_include_prototype: false + - match: \{ + scope: punctuation.definition.group.brace.begin.tex + pop: true + brace-group-body: - meta_scope: meta.group.brace.tex - include: brace-group-end @@ -645,3 +651,7 @@ contexts: paragraph-pop: - match: ^(?=\s*$) pop: true + + unmatched-brace-pop: + - match: (?=}) + pop: true diff --git a/LaTeX/syntax_test_latex.xparse.tex b/LaTeX/syntax_test_latex.xparse.tex new file mode 100644 index 0000000000..28e982fea0 --- /dev/null +++ b/LaTeX/syntax_test_latex.xparse.tex @@ -0,0 +1,428 @@ +% SYNTAX TEST "Packages/LaTeX/LaTeX.sublime-syntax" + +% <- text.tex.latex + +\NewDocumentCommand{\noparams}{}{content} +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function meta.function +%^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^^^ meta.function.identifier.latex +% ^^ meta.function.parameters.latex +% ^^^^^^^^^ meta.function.body.tex meta.group.brace.tex +% ^ - meta.function +%^^^^^^^^^^^^^^^^^^ keyword.declaration.function.latex storage.modifier.newcommand.latex +% ^ punctuation.definition.group.brace.begin.latex +% ^^^^^^^^^ entity.name.newcommand.latex +% ^ punctuation.definition.backslash.latex +% ^ punctuation.definition.group.brace.end.latex +% ^ punctuation.definition.group.brace.begin.latex +% ^ punctuation.definition.group.brace.end.latex +% ^ punctuation.definition.group.brace.begin.tex +% ^ punctuation.definition.group.brace.end.tex + +\NewDocumentCommand{\mandatory}{m}{content #1} +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function meta.function +%^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^^^^ meta.function.identifier.latex +% ^^^ meta.function.parameters.latex +% ^^^^^^^^^^^^ meta.function.body meta.group.brace +% ^ - meta.function +%^^^^^^^^^^^^^^^^^^ keyword.declaration.function.latex storage.modifier.newcommand.latex +% ^ punctuation.definition.group.brace.begin.latex +% ^^^^^^^^^^ entity.name.newcommand.latex +% ^ punctuation.definition.backslash.latex +% ^ punctuation.definition.group.brace.end.latex +% ^ punctuation.definition.group.brace.begin.latex +% ^ storage.type.latex +% ^ punctuation.definition.group.brace.end.latex +% ^ punctuation.definition.group.brace.begin.tex +% ^^ variable.parameter.tex +% ^ punctuation.definition.group.brace.end.tex + +\NewDocumentCommand\nobrace{o}{content} +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function meta.function +%^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^ meta.function.identifier.latex +% ^^^ meta.function.parameters.latex +% ^^^^^^^^^ meta.function.body +% ^ - meta.function +%^^^^^^^^^^^^^^^^^^ keyword.declaration.function.latex storage.modifier.newcommand.latex +% ^^^^^^^ entity.name.newcommand.latex +% ^ storage.type.latex + +\NewDocumentCommand{\many@args}{o +m s !v}{content} +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function meta.function +%^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^^^^ meta.function.identifier.latex +% ^^^^^^^^^^ meta.function.parameters.latex +% ^^^^^^^^^ meta.function.body +% ^ - meta.function +%^^^^^^^^^^^^^^^^^^ keyword.declaration.function.latex storage.modifier.newcommand.latex +% ^^^^^^^^^^ entity.name.newcommand.latex +% ^ storage.type.latex +% ^ storage.modifier.latex +% ^ storage.type.latex +% ^ storage.type.latex +% ^ storage.modifier.latex +% ^ storage.type.latex + +\NewDocumentCommand{\delimone}{d{a}{b}}{arg #1} +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function meta.function +%^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^^^ meta.function.identifier.latex +% ^^^^^^^^^ meta.function.parameters.latex - meta.function.latex +% ^^^^^^^^ meta.function.body - meta.function.parameters.latex +% ^ - meta.function +%^^^^^^^^^^^^^^^^^^ keyword.declaration.function.latex storage.modifier.newcommand.latex +% ^^^^^^^^^ entity.name.newcommand.latex +% ^ storage.type.latex +% ^ constant.character.latex constant.other.token.latex +% ^ constant.character.latex constant.other.token.latex + +\ProvideDocumentCommand{\delimtwo}{d\start \end} {arg #1} +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function meta.function +%^^^^^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^^^ meta.function.identifier.latex +% ^^^^^^^^^^^^^^ meta.function.parameters.latex - meta.function.latex +% ^ meta.function.latex +% ^^^^^^^^ meta.function.body - meta.function.parameters.latex +% ^ - meta.function +%^^^^^^^^^^^^^^^^^^^^^^ keyword.declaration.function.latex storage.modifier.newcommand.latex +% ^^^^^^^^^ entity.name.newcommand.latex +% ^ storage.type.latex +% ^^^^^^ constant.other.token.latex +% ^^^ constant.other.token.latex + +\DeclareDocumentCommand{\delimthree}% +%^^^^^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^^^^^ meta.function.identifier.latex +% ^^^^^^^^^^^ entity.name.newcommand.latex +{d()}{arg #1} +%^^^^ meta.function.parameters.latex - meta.function.latex +%^ storage.type.latex +% ^^ constant.character.latex constant.other.token.latex +% ^^^^^^^^ meta.function.body - meta.function.parameters.latex + + +% TODO should the backslashes be part of constant.other.token.latex here? +\RenewDocumentCommand{\delimfour}% + {r\{\}}{body} +%^^^^^^^ meta.function.parameters.latex - meta.function.latex +% ^ storage.type.latex +% ^^^^ constant.other.token.latex +% ^ punctuation.definition.backslash.latex +% ^ punctuation.definition.backslash.latex + + +% This is wrong, because the default value is missing. +% We are making sure that the scoping is somewhat reasonable nonetheless. +\NewDocumentCommand{\delimfive}{D{a}{b}}{arg #1} +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function meta.function +%^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^^^^ meta.function.identifier.latex +% ^^^^^^^^^ meta.function.parameters.latex - meta.function.latex +% ^^^^^^^^ meta.function.body -meta.function.latex +% ^ - meta.function +%^^^^^^^^^^^^^^^^^^ keyword.declaration.function.latex storage.modifier.newcommand.latex +% ^^^^^^^^^^ entity.name.newcommand.latex +% ^ storage.type.latex +% ^ constant.character.latex constant.other.token.latex +% ^ constant.character.latex constant.other.token.latex + +\NewDocumentCommand{\delimsix}{R(){a complicated{default} \test{value}}}{arg #1} +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function meta.function +%^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^^^ meta.function.identifier.latex +% ^^^^ meta.function.parameters.latex - meta.function.latex +% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.default-value.latex - meta.function.parameters.latex +% ^ meta.function.parameters.latex +% ^^^^^^^^ meta.function.body meta.group.brace +%^^^^^^^^^^^^^^^^^^ keyword.declaration.function.latex storage.modifier.newcommand.latex +% ^^^^^^^^^ entity.name.newcommand.latex +% ^ storage.type.latex +% ^^ constant.character.latex constant.other.token.latex +% ^ punctuation.definition.group.brace.end.latex + + +\NewDocumentCommand{\optional}{O{default}}{function body} +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function meta.function +%^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^^^ meta.function.identifier.latex +% ^^ meta.function.parameters.latex +% ^^^^^^^^^ meta.function.parameters.default-value.latex meta.group.brace.latex +% ^ meta.function.parameters.latex punctuation.definition.group.brace.end.latex +% ^^^^^^^^^^^^^^^ meta.function.body +% ^ - meta.function +%^^^^^^^^^^^^^^^^^^ keyword.declaration.function.latex storage.modifier.newcommand.latex +% ^^^^^^^^^ entity.name.newcommand.latex +% ^ storage.type.latex + +% Check that default values can include paragraph breaks +\NewDocumentCommand{\optionaltwo}{O{default +% ^^ meta.function.parameters.latex +% ^^^^^^^^ meta.function.parameters.default-value.latex + +with paragraph}}{function body} +% ^ meta.function.parameters.latex +%^^^^^^^^^^^^^^ meta.function.parameters.default-value.latex +% ^^^^^^^^^^^^^^^ meta.function.body + +\NewDocumentCommand{\optional}{Ov}{function body} +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function meta.function +%^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^^^ meta.function.identifier.latex +% ^^ meta.function.parameters.latex +% ^ meta.function.parameters.default-value.latex +% ^ meta.function.parameters.latex +% ^^^^^^^^^^^^^^^ meta.function.body +% ^ - meta.function +%^^^^^^^^^^^^^^^^^^ keyword.declaration.function.latex storage.modifier.newcommand.latex +% ^^^^^^^^^ entity.name.newcommand.latex +% ^ storage.type.latex + +\NewDocumentCommand{\optional}{O\{}{function body} +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function meta.function +%^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^^^ meta.function.identifier.latex +% ^ meta.function.parameters.latex +% ^^ meta.function.parameters.default-value.latex +% ^ meta.function.parameters.latex +% ^^^^^^^^^^^^^^^ meta.function.body +% ^ - meta.function +%^^^^^^^^^^^^^^^^^^ storage.modifier.newcommand.latex +% ^ punctuation.definition.group.brace.begin.latex +% ^^^^^^^^^ entity.name.newcommand.latex +% ^ punctuation.definition.group.brace.end.latex +% ^ punctuation.definition.group.brace.begin.latex +% ^ storage.type.latex +% ^ - punctuation.definition.group +% ^ punctuation.definition.group.brace.end.latex +% ^ punctuation.definition.group.brace.begin.tex +% ^ punctuation.definition.group.brace.end.tex + +\NewDocumentCommand{\optional}{O\value m}{function body} +% ^^ meta.function.parameters.latex +% ^ punctuation.definition.group.brace.begin.latex +% ^ storage.type.latex +% ^^^^^^ meta.function.parameters.default-value.latex support.function.latex +% ^ punctuation.definition.backslash.latex +% ^^^ meta.function.parameters.latex +% ^ storage.type.latex +% ^ punctuation.definition.group.brace.end.latex + +\NewDocumentCommand{\optional}{O{#1: \year \parskip1em }}{function body} +% ^ storage.type.latex +% ^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.default-value.latex meta.group.brace.latex +% ^ punctuation.definition.group.brace.begin.latex +% ^^ variable.parameter.tex +% ^ punctuation.definition.placeholder.tex +% ^ meta.number.integer.decimal.tex constant.numeric.value.tex +% ^^^^^ constant.language.tex +% ^^^^^^^^ constant.language.tex +% ^ punctuation.definition.backslash.tex +% ^ punctuation.definition.backslash.tex +% ^^^ meta.number.integer.decimal.tex +% ^ constant.numeric.value.tex +% ^^ constant.numeric.suffix.tex + + +% A "token" argument +\NewExpandableDocumentCommand{\withtoken}{t\test}{function body} +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function meta.function +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^^^^ meta.function.identifier.latex +% ^^^^^^^^ meta.function.parameters.latex +% ^^^^^^^^^^^^^^^ meta.function.body +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^ storage.modifier.newcommand.latex +% ^^^^^^^^^^ entity.name.newcommand.latex +% ^ storage.type.latex +% ^^^^^ constant.other.token.latex + + +% embellishments +\NewDocumentCommand{\embellish}{e\test}{body} +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function meta.function +%^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^^^^ meta.function.identifier.latex +% ^^^^^^^^ meta.function.parameters.latex +% ^^^^^^ meta.function.body +%^^^^^^^^^^^^^^^^^^ keyword.declaration.function.latex storage.modifier.newcommand.latex +% ^^^^^^^^^^ entity.name.newcommand.latex +% ^ storage.type.latex +% ^^^^^ constant.other.token.latex + +\NewDocumentCommand{\embellish}{e{\test}}{body} +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function meta.function +%^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^^^^ meta.function.identifier.latex +% ^^^^^^^^^^ meta.function.parameters.latex +% ^^^^^^ meta.function.body +%^^^^^^^^^^^^^^^^^^ keyword.declaration.function.latex storage.modifier.newcommand.latex +% ^^^^^^^^^^ entity.name.newcommand.latex +% ^ storage.type.latex +% ^^^^^ constant.other.token.latex + + +\NewDocumentCommand{\embellish}{e{_^}}{body} +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function meta.function +%^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^^^^ meta.function.identifier.latex +% ^^^^^^^ meta.function.parameters.latex +% ^^^^^^ meta.function.body +%^^^^^^^^^^^^^^^^^^ keyword.declaration.function.latex storage.modifier.newcommand.latex +% ^^^^^^^^^^ entity.name.newcommand.latex +% ^ storage.type.latex +% ^^ constant.character.latex constant.other.token.latex + +\NewDocumentCommand{\embellish}{E{_^}{default}}{body} +%^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^^^^ meta.function.identifier.latex +% ^^^^^^ meta.function.parameters.latex +% ^^^^^^^^^ meta.function.parameters.default-value.latex +% ^ meta.function.parameters.latex +% ^^^^^^ meta.function.body +% ^ - meta.function +% ^^^^^^^^^^ entity.name.newcommand.latex +% ^^ constant.character.latex constant.other.token.latex + +\NewDocumentCommand{\MyMacro}{e{\up \down}}{up: #1 down: #2} +% ^ storage.type.latex +% ^ punctuation.definition.group.brace.begin.latex +% ^^^ constant.other.token.latex +% ^^^^^ constant.other.token.latex +% ^ punctuation.definition.backslash.latex +% ^ punctuation.definition.backslash.latex +% ^^ punctuation.definition.group.brace.end.latex +% ^^^^^^^^^^^^^^^^^ meta.function.body.tex meta.group.brace.tex + + +% Argument processors: example from +% https://www.nic.funet.fi/pub/TeX/CTAN/macros/latex/contrib/l3packages/xparse.pdf +\NewDocumentCommand \foo { O{,} >{\SplitList{#1}} m } { \foobar{#2} } +% ^^^ meta.function.parameters.latex +% ^^^ meta.function.parameters.default-value.latex meta.group.brace.latex +% ^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.latex +% ^ meta.function.latex +% ^^^^^^^^^^^^^^^ meta.function.body.tex meta.group.brace.tex +% ^ punctuation.definition.group.brace.begin.latex +% ^ storage.type.latex +% ^ punctuation.definition.group.brace.begin.latex +% ^ punctuation.definition.group.brace.end.latex +% ^ storage.modifier.latex +% ^^^^^^^^^^^^^^^^ meta.group.brace.tex +% ^ punctuation.definition.group.brace.begin.tex +% ^^^^^^^^^^ support.function.general.latex +% ^ punctuation.definition.backslash.latex +% ^^^^ meta.group.brace.tex +% ^ punctuation.definition.group.brace.begin.tex +% ^^ variable.parameter.tex +% ^ punctuation.definition.placeholder.tex +% ^ meta.number.integer.decimal.tex constant.numeric.value.tex +% ^ punctuation.definition.group.brace.end.tex +% ^ punctuation.definition.group.brace.end.tex +% ^ storage.type.latex +% ^ punctuation.definition.group.brace.end.latex + + + +% Now for some broken and incomplete examples +\NewDocumentCommand{\incomplete} + +other stuff +% ^^^^^^^^^^ - meta.fuction + +\NewDocumentCommand{\incompletearg}{m + +other stuff +% ^^^^^^^^^^ - meta.fuction + +\NewDocumentCommand{\incompleteoptional}{O + +other stuff +%<- - meta.fuction + +\NewDocumentCommand{\optional}{O}{sdfsdf} +% ^^^^^^^^ - meta.function.parameters + +% missing token +\NewDocumentCommand {\conjugate} { t } {(#1,#2,#3)} +% ^^^^^ meta.function.parameters +% ^^^^^^^^^^^^^ - meta.function.parameters + + +% This is not a valid command, but we still want to make sure we get reasonable +% highlighting, e.g. scoping of all braces, grouping etc. +\NewDocumentCommand{\broken}{m{default}}{body} +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function meta.function +%^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^ meta.function.identifier.latex +% ^^^^^^^^^^^^ meta.function.parameters.latex +% ^^^^^^^^^ meta.group.brace.tex +% ^^^^^^ meta.function.body.tex meta.group.brace.tex +% ^ punctuation.definition.group.brace.begin.latex +% ^^^^^^^ entity.name.newcommand.latex +% ^ punctuation.definition.backslash.latex +% ^ punctuation.definition.group.brace.end.latex +% ^ punctuation.definition.group.brace.begin.latex +% ^ storage.type.latex +% ^ punctuation.definition.group.brace.begin.tex +% ^ punctuation.definition.group.brace.end.tex +% ^ punctuation.definition.group.brace.end.latex +% ^ punctuation.definition.group.brace.begin.tex +% ^ punctuation.definition.group.brace.end.tex + +% \other is not allowed here, but we try to get decent highlighting. We should +% not mark this as an error, in case the xparse syntax gets extended at some +% point +\NewDocumentCommand{\embellish}{e\test\other @}{content (#1)} +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.function meta.function +%^^^^^^^^^^^^^^^^^^ meta.function.latex +% ^^^^^^^^^^^^ meta.function.identifier.latex +% ^^^^^^^^^^^^^^^^ meta.function.parameters.latex +% ^^^^^^^^^^^^^^ meta.function.body.tex meta.group.brace.tex +% ^ - meta.function +% ^ punctuation.definition.group.brace.begin.latex +% ^^^^^^^^^^ entity.name.newcommand.latex +% ^ punctuation.definition.backslash.latex +% ^ punctuation.definition.group.brace.end.latex +% ^ punctuation.definition.group.brace.begin.latex +% ^ storage.type.latex +% ^^^^^ constant.other.token.latex +% ^ punctuation.definition.backslash.latex +% ^^^^^^ support.function.general.latex +% ^ punctuation.definition.backslash.latex +% ^ punctuation.definition.group.brace.end.latex +% ^ punctuation.definition.group.brace.begin.tex +% ^^ variable.parameter.tex +% ^ punctuation.definition.placeholder.tex +% ^ meta.number.integer.decimal.tex constant.numeric.value.tex +% ^ punctuation.definition.group.brace.end.tex + + +% Currently unsupported syntax versions: +% These are very rare, so at this point we have opted for reduced complexity +% of the syntax highlighting, with the cost that some syntactially valid patterns +% get suboptimal highlighting. + +\NewDocumentCommand{\braces}{{m}}{content} +% ^^^^^ meta.function.parameters.latex +% ^ punctuation.definition.group.brace.begin.latex +% ^^^ meta.group.brace.tex +% ^ punctuation.definition.group.brace.begin.tex +% ^ punctuation.definition.group.brace.end.tex +% ^ punctuation.definition.group.brace.end.latex +% ^^^^^^^^^ meta.function.body.tex meta.group.brace.tex + +\NewDocumentCommand{\braces}{m {O}{value} m}{content} +% ^^^^^^^^^^^^^^^^ meta.function.parameters.latex +% ^ punctuation.definition.group.brace.begin.latex +% ^ storage.type.latex +% ^^^^^^^^^^ meta.group.brace.tex +% ^ punctuation.definition.group.brace.begin.tex +% ^ punctuation.definition.group.brace.end.tex +% ^ punctuation.definition.group.brace.begin.tex +% ^ punctuation.definition.group.brace.end.tex +% ^ storage.type.latex +% ^ punctuation.definition.group.brace.end.latex +% ^^^^^^^^^ meta.function.body.tex meta.group.brace.tex +% ^ punctuation.definition.group.brace.begin.tex +% ^ punctuation.definition.group.brace.end.tex