From 354a639ec013be29081b442bd88324a160926dd9 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Thu, 2 Nov 2023 20:20:58 +0100 Subject: [PATCH] [LaTeX] sublime syntax version 2 --- LaTeX/Bibtex.sublime-syntax | 27 +++---- LaTeX/DocStrip.sublime-syntax | 3 +- LaTeX/LaTeX Log.sublime-syntax | 1 + LaTeX/LaTeX.sublime-syntax | 123 ++++++++++++++---------------- LaTeX/TeX.sublime-syntax | 17 +++-- LaTeX/tests/syntax_test_latex.tex | 37 ++++++--- 6 files changed, 111 insertions(+), 97 deletions(-) diff --git a/LaTeX/Bibtex.sublime-syntax b/LaTeX/Bibtex.sublime-syntax index 06238862ba8..6cfac69a2f7 100644 --- a/LaTeX/Bibtex.sublime-syntax +++ b/LaTeX/Bibtex.sublime-syntax @@ -6,6 +6,7 @@ # TODO: Does not support @preamble name: BibTeX scope: text.bibtex +version: 2 file_extensions: - bib @@ -25,7 +26,7 @@ contexts: push: - meta_scope: comment.line.at-sign.bibtex - match: $\n? - pop: true + pop: 1 - match: '((@)[Ss]tring)\s*(\{)\s*({{var}})' captures: 1: keyword.other.string-constant.bibtex @@ -36,7 +37,7 @@ contexts: - meta_scope: meta.string-constant.braces.bibtex - match: '\}' scope: punctuation.section.string-constant.end.bibtex - pop: true + pop: 1 - include: string_content - include: variables - include: operators @@ -50,7 +51,7 @@ contexts: - meta_scope: meta.string-constant.parenthesis.bibtex - match: \) scope: punctuation.section.string-constant.end.bibtex - pop: true + pop: 1 - include: string_content - include: variables - include: operators @@ -65,7 +66,7 @@ contexts: - meta_content_scope: meta.mapping.bibtex - match: '\}' scope: punctuation.section.entry.end.bibtex - pop: true + pop: 1 - match: '([a-zA-Z]+)(\s*(=)\s*)' captures: 1: meta.mapping.key.bibtex string.unquoted.key.bibtex @@ -74,8 +75,8 @@ contexts: push: - clear_scopes: 1 - meta_content_scope: meta.mapping.value.bibtex - - match: "(?=[,}])" - pop: true + - match: (?=[,}]) + pop: 1 - include: string_content - include: integer - include: variables @@ -93,7 +94,7 @@ contexts: - meta_content_scope: meta.mapping.bibtex - match: \) scope: punctuation.section.entry.end.bibtex - pop: true + pop: 1 - match: '([a-zA-Z]+)(\s*(=)\s*)' captures: 1: meta.mapping.key.bibtex string.unquoted.key.bibtex @@ -102,8 +103,8 @@ contexts: push: - clear_scopes: 1 - meta_content_scope: meta.mapping.value.bibtex - - match: "(?=[,)])" - pop: true + - match: (?=[,)]) + pop: 1 - include: string_content - include: integer - include: variables @@ -114,7 +115,7 @@ contexts: push: - meta_scope: comment.block.bibtex - match: (?=@) - pop: true + pop: 1 integer: - match: \d+ scope: meta.number.integer.decimal.bibtex constant.numeric.value.bibtex @@ -130,7 +131,7 @@ contexts: push: - match: '\}' scope: punctuation.definition.group.end.bibtex - pop: true + pop: 1 - include: nested_braces string_content: - match: '"' @@ -139,7 +140,7 @@ contexts: - meta_scope: string.quoted.double.bibtex - match: '"' scope: punctuation.definition.string.end.bibtex - pop: true + pop: 1 - include: nested_braces - match: '\{' scope: punctuation.definition.string.begin.bibtex @@ -147,7 +148,7 @@ contexts: - meta_scope: string.quoted.other.braces.bibtex - match: '\}' scope: punctuation.definition.string.end.bibtex - pop: true + pop: 1 - match: "@" scope: invalid.illegal.at-sign.bibtex - include: nested_braces diff --git a/LaTeX/DocStrip.sublime-syntax b/LaTeX/DocStrip.sublime-syntax index f4777a8eb4f..73995e2f6f2 100644 --- a/LaTeX/DocStrip.sublime-syntax +++ b/LaTeX/DocStrip.sublime-syntax @@ -4,7 +4,8 @@ # https://www.texlive.info/CTAN/macros/latex/base/docstrip.pdf name: TeX (DocStrip) scope: source.tex.docstrip -version: 1 +version: 2 + extends: Packages/LaTeX/TeX.sublime-syntax file_extensions: diff --git a/LaTeX/LaTeX Log.sublime-syntax b/LaTeX/LaTeX Log.sublime-syntax index 2d2890e2faa..00837d28d64 100644 --- a/LaTeX/LaTeX Log.sublime-syntax +++ b/LaTeX/LaTeX Log.sublime-syntax @@ -2,6 +2,7 @@ --- name: LaTeX Log scope: text.log.latex +version: 2 first_line_match: 'This is (pdf|pdfe)?TeXk?, Version ' diff --git a/LaTeX/LaTeX.sublime-syntax b/LaTeX/LaTeX.sublime-syntax index 0504e4963b2..3558c88d443 100644 --- a/LaTeX/LaTeX.sublime-syntax +++ b/LaTeX/LaTeX.sublime-syntax @@ -3,6 +3,7 @@ # http://www.sublimetext.com/docs/syntax.html name: LaTeX scope: text.tex.latex +version: 2 extends: TeX.sublime-syntax @@ -47,7 +48,7 @@ contexts: - meta_scope: meta.group.bracket.latex - match: \] scope: punctuation.definition.group.bracket.end.latex - pop: true + pop: 1 - include: general-constants - include: general-commands - include: braces @@ -58,7 +59,7 @@ contexts: - meta_scope: meta.group.brace.tex - match: \} scope: punctuation.definition.group.brace.end.tex - pop: true + pop: 1 - include: main argument: @@ -364,14 +365,14 @@ contexts: - meta_scope: meta.function.box.latex - match: \} scope: punctuation.definition.group.brace.end.tex - pop: true + pop: 1 - include: main - match: ((\\)(?:framebox|makebox))\b captures: 1: support.function.box.latex 2: punctuation.definition.backslash.latex push: - - [{meta_scope: meta.function.box.latex}, {match: '', pop: true}] + - [{meta_scope: meta.function.box.latex}, {match: '', pop: 1}] - argument - optional-arguments - match: ((\\)parbox)\b @@ -379,7 +380,7 @@ contexts: 1: support.function.box.latex 2: punctuation.definition.backslash.latex push: - - [{meta_scope: meta.function.box.latex}, {match: '', pop: true}] + - [{meta_scope: meta.function.box.latex}, {match: '', pop: 1}] - argument - argument - optional-arguments @@ -388,48 +389,42 @@ contexts: 1: support.function.box.latex 2: punctuation.definition.backslash.latex push: - - [{meta_scope: meta.function.box.latex}, {match: '', pop: true}] + - [{meta_scope: meta.function.box.latex}, {match: '', pop: 1}] - argument - optional-arguments preamble: - match: (\\)documentclass\b + scope: meta.preamble.documentclass.latex keyword.control.preamble.latex captures: - 0: keyword.control.preamble.latex 1: punctuation.definition.backslash.latex push: - - meta_scope: meta.preamble.documentclass.latex + - meta_content_scope: meta.preamble.documentclass.latex - include: general-optional-arguments - match: \{ scope: punctuation.definition.group.brace.begin.tex set: - meta_scope: meta.preamble.documentclass.latex meta.group.brace.tex + - include: brace-group-end - match: '[A-Za-z[:digit:]-]' scope: support.class.latex - - match: \} - scope: punctuation.definition.group.brace.end.tex - pop: true - - match: '' - pop: true + - include: immediately-pop - match: (\\)usepackage\b + scope: meta.preamble.usepackage.latex keyword.control.preamble.latex captures: - 0: keyword.control.preamble.latex 1: punctuation.definition.backslash.latex push: - - meta_scope: meta.preamble.usepackage.latex + - meta_content_scope: meta.preamble.usepackage.latex - include: general-optional-arguments - match: \{ scope: punctuation.definition.group.brace.begin.tex set: - meta_scope: meta.preamble.usepackage.latex meta.group.brace.tex - - match: \} - scope: punctuation.definition.group.brace.end.tex - pop: true + - include: brace-group-end - match: '[A-Za-z[:digit:]-]*' scope: support.class.latex - - match: '' - pop: true + - include: immediately-pop includes: - match: ((\\)(?:include|includeonly))(\{) @@ -497,7 +492,7 @@ contexts: 3: punctuation.definition.group.brace.begin.tex 4: variable.parameter.function.latex 5: punctuation.definition.group.brace.end.tex - pop: true + pop: 1 lists: - match: ((\\)begin)(\{)\s*(itemize\*?)\s*(\}) @@ -516,7 +511,7 @@ contexts: 3: punctuation.definition.group.brace.begin.tex 4: variable.parameter.function.latex 5: punctuation.definition.group.brace.end.tex - pop: true + pop: 1 - include: main - match: ((\\)begin)(\{)\s*(enumerate\*?)\s*(\}) captures: @@ -534,7 +529,7 @@ contexts: 3: punctuation.definition.group.brace.begin.tex 4: variable.parameter.function.latex 5: punctuation.definition.group.brace.end.tex - pop: true + pop: 1 - include: main - match: ((\\)begin)(\{)\s*(list\*?)\s*(\}) captures: @@ -552,7 +547,7 @@ contexts: 3: punctuation.definition.group.brace.begin.tex 4: variable.parameter.function.latex 5: punctuation.definition.group.brace.end.tex - pop: true + pop: 1 - include: main - match: ((\\)begin)(\{)\s*(description\*?)\s*(\}) captures: @@ -570,7 +565,7 @@ contexts: 3: punctuation.definition.group.brace.begin.tex 4: variable.parameter.function.latex 5: punctuation.definition.group.brace.end.tex - pop: true + pop: 1 - include: main ###[ MATH ]#################################################################### @@ -582,20 +577,20 @@ contexts: inline-math-ensuremath: - match: (\\)ensuremath{{endcs}} - scope: support.function.ensuremath.latex + scope: meta.function.ensuremath.latex support.function.ensuremath.latex captures: 1: punctuation.definition.backslash.latex push: inline-math-ensuremath-begin inline-math-ensuremath-begin: - - meta_scope: meta.function.ensuremath.latex + - meta_content_scope: meta.function.ensuremath.latex - match: \{ scope: punctuation.definition.group.brace.begin.tex set: inline-math-ensuremath-body - include: paragraph-pop inline-math-ensuremath-body: - - meta_scope: meta.function.ensuremath.latex + - meta_scope: meta.function.ensuremath.latex meta.group.brace.tex - meta_content_scope: meta.environment.math.inline.ensuremath.latex markup.math.inline - include: brace-group-end - include: math-content @@ -614,7 +609,7 @@ contexts: inline-math-parens-end: - match: \\\) scope: string.other.math.latex punctuation.definition.string.end.latex - pop: true + pop: 1 block-math: - meta_append: true @@ -650,7 +645,7 @@ contexts: 3: punctuation.definition.group.brace.begin.tex 4: variable.parameter.function.latex 5: punctuation.definition.group.brace.end.tex - pop: true + pop: 1 block-math-brackets: - match: \\\[ @@ -666,12 +661,12 @@ contexts: block-math-brackets-end: - match: \\\] scope: string.other.math.latex punctuation.definition.string.end.latex - pop: true + pop: 1 math-content: - meta_prepend: true - match: (?=\}) - pop: true + pop: 1 - include: verb - include: text-decorators - include: references @@ -685,7 +680,7 @@ contexts: 1: support.function.includegraphics.latex 2: punctuation.definition.backslash.latex push: - - [{meta_scope: meta.function.includegraphics.latex}, {match: '', pop: true}] + - [{meta_scope: meta.function.includegraphics.latex}, {match: '', pop: 1}] - argument - optional-arguments @@ -711,7 +706,7 @@ contexts: - meta_content_scope: markup.raw.verb.latex - match: \3 scope: punctuation.definition.verb.latex - pop: true + pop: 1 ###[ FONTS ]#################################################################### @@ -1031,7 +1026,7 @@ contexts: expect-text-markup-open-brace: - match: \{ scope: punctuation.definition.group.brace.begin.tex - pop: true + pop: 1 - match: (?=\S) pop: 3 @@ -1111,7 +1106,7 @@ contexts: - include: brace-group-end - include: main - match: (?=\S) - pop: true + pop: 1 - match: |- (?x) ((\\)footnotemark)\b @@ -1162,7 +1157,7 @@ contexts: scope: constant.other.citation.latex - include: brace-group-end - match: '' - pop: true + pop: 1 - match: |- (?x) ( @@ -1184,7 +1179,7 @@ contexts: scope: constant.other.reference.latex - include: brace-group-end - match: '' - pop: true + pop: 1 - match: ((\\)label)(\{) captures: 1: support.function.label.latex storage.type.label.latex @@ -1207,7 +1202,7 @@ contexts: push: - include: general-optional-arguments - match: '' - pop: true + pop: 1 - match: ((\\)end)(\{)\s*(\w*)\*?\s*(\}) captures: 1: support.function.end.latex keyword.control.flow.end.latex @@ -1227,30 +1222,29 @@ contexts: # listings package pkglistings: - match: (\\)lstinline\b + scope: meta.environment.verbatim.lstinline.latex support.function.lstinline.latex captures: - 0: support.function.lstinline.latex 1: punctuation.definition.backslash.latex push: - meta_include_prototype: false - - meta_scope: meta.environment.verbatim.lstinline.latex + - meta_content_scope: meta.environment.verbatim.lstinline.latex - include: general-optional-arguments - match: \{ scope: punctuation.definition.group.brace.begin.tex set: - meta_include_prototype: false - - meta_scope: meta.group.brace.tex - - meta_content_scope: meta.environment.verbatim.lstinline.latex markup.raw.verb.latex - - match: '\}' - scope: meta.environment.verbatim.lstinline.latex punctuation.definition.group.brace.end.tex - pop: true + - meta_scope: meta.environment.verbatim.lstinline.latex meta.group.brace.tex + - meta_content_scope: markup.raw.verb.latex + - include: brace-group-end - match: (\W) scope: punctuation.definition.verb.latex set: - meta_include_prototype: false - - meta_content_scope: meta.environment.verbatim.lstinline.latex markup.raw.verb.latex + - meta_scope: meta.environment.verbatim.lstinline.latex + - meta_content_scope: markup.raw.verb.latex - match: \1 - scope: meta.environment.verbatim.lstinline.latex punctuation.definition.verb.latex - pop: true + scope: punctuation.definition.verb.latex + pop: 1 - match: ((\\)begin)(\{)(lstlisting)(\}) captures: @@ -1269,7 +1263,7 @@ contexts: 3: punctuation.definition.group.brace.begin.tex 4: variable.parameter.function.latex 5: punctuation.definition.group.brace.end.tex - pop: true + pop: 1 - include: general-optional-arguments - match: .*(%\s*(?i:c))$ captures: @@ -1377,7 +1371,7 @@ contexts: push: - meta_scope: meta.environment.embedded.generic.latex markup.raw.verb.latex - match: (?=\\end\{lstlisting\}) - pop: true + pop: 1 minted: - include: minted-env @@ -1401,7 +1395,7 @@ contexts: 3: punctuation.definition.group.brace.begin.tex 4: variable.parameter.function.latex 5: punctuation.definition.group.brace.end.tex - pop: true + pop: 1 - include: general-optional-arguments - match: (\{)(c)(\}) captures: @@ -1591,7 +1585,7 @@ contexts: push: - meta_scope: meta.environment.embedded.generic.latex markup.raw.verb.latex - match: (?=\\end\{minted\}) - pop: true + pop: 1 mint: - match: ((\\)mint)\b|((\\)mintinline)\b @@ -1926,7 +1920,7 @@ contexts: 1: punctuation.definition.group.brace.begin.tex 2: punctuation.definition.verb.latex - match: '' - pop: true + pop: 1 # comment package pkgcomment: @@ -1940,7 +1934,7 @@ contexts: captures: 0: punctuation.definition.comment.end.latex 1: punctuation.definition.backslash.latex - pop: true + pop: 1 - match: ((\\)begin)(\{)\s*(comment)\s*(\}) captures: 1: support.function.begin.latex keyword.control.flow.begin.latex @@ -1958,7 +1952,7 @@ contexts: 3: punctuation.definition.group.brace.begin.tex 4: variable.parameter.function.latex 5: punctuation.definition.group.brace.end.tex - pop: true + pop: 1 # beamer support beamer: @@ -1978,7 +1972,7 @@ contexts: 3: punctuation.definition.group.brace.begin.tex 4: variable.parameter.function.latex 5: punctuation.definition.group.brace.end.tex - pop: true + pop: 1 - include: frametitles - include: main @@ -2046,18 +2040,17 @@ contexts: - meta_content_scope: meta.environment.tabular.latex meta.function.column-spec.latex - include: array-preamble - match: \} - scope: punctuation.definition.group.brace.end.tex + scope: meta.function.column-spec.latex punctuation.definition.group.brace.end.tex set: - - meta_content_scope: meta.environment.tabular.latex + - meta_scope: meta.environment.tabular.latex - match: ((\\)end)(\{)(tabular)(\}) - scope: meta.environment.tabular.latex captures: 1: support.function.end.latex keyword.control.flow.end.latex 2: punctuation.definition.backslash.latex 3: punctuation.definition.group.brace.begin.tex 4: variable.parameter.function.latex 5: punctuation.definition.group.brace.end.tex - pop: true + pop: 1 - include: main @@ -2076,7 +2069,7 @@ contexts: - match: (?:p|m|b)(?=\s*\{) scope: support.function.parbox-column.latex push: - - [{meta_scope: meta.function.parbox-column.latex}, {match: '', pop: true}] + - [{meta_scope: meta.function.parbox-column.latex}, {match: '', pop: 1}] - argument - match: (>)\s*(\{) @@ -2136,7 +2129,7 @@ contexts: scope: constant.numeric.array-count.latex - include: general-commands - match: \} - scope: punctuation.definition.group.brace.end.tex + scope: meta.function.insert-repeated-count.latex punctuation.definition.group.brace.end.tex set: - match: \{ scope: meta.function.insert-repeated-content.latex punctuation.definition.group.brace.begin.tex @@ -2145,6 +2138,6 @@ contexts: - include: array-preamble - match: \} scope: meta.function.insert-repeated-content.latex punctuation.definition.group.brace.end.tex - pop: true + pop: 1 - match: '' - pop: true + pop: 1 diff --git a/LaTeX/TeX.sublime-syntax b/LaTeX/TeX.sublime-syntax index 1f76a6fc1c5..87ee91868e9 100644 --- a/LaTeX/TeX.sublime-syntax +++ b/LaTeX/TeX.sublime-syntax @@ -3,6 +3,7 @@ # http://www.sublimetext.com/docs/syntax.html name: TeX scope: text.tex +version: 2 file_extensions: - sty @@ -156,7 +157,7 @@ contexts: - meta_include_prototype: false - match: \{ scope: punctuation.definition.group.brace.begin.tex - pop: true + pop: 1 brace-group-body: - meta_scope: meta.group.brace.tex @@ -166,7 +167,7 @@ contexts: brace-group-end: - match: \} scope: punctuation.definition.group.brace.end.tex - pop: true + pop: 1 boxes: - match: ((\\)[hv]box)\s*(\{) @@ -550,7 +551,7 @@ contexts: inline-math-dollar-end: - match: \$ scope: string.other.math.tex punctuation.definition.string.end.tex - pop: true + pop: 1 block-math: - match: \$\$ @@ -566,7 +567,7 @@ contexts: block-math-dollar-end: - match: \$\$ scope: string.other.math.tex punctuation.definition.string.end.tex - pop: true + pop: 1 math-content: - include: math-builtin @@ -707,17 +708,17 @@ contexts: # matches any nospace and pops the context else-pop: - match: (?=\S) - pop: true + pop: 1 immediately-pop: - match: '' - pop: true + pop: 1 # pops out of the current context if there is a new paragraph paragraph-pop: - match: ^(?=\s*$) - pop: true + pop: 1 unmatched-brace-pop: - match: (?=}) - pop: true + pop: 1 diff --git a/LaTeX/tests/syntax_test_latex.tex b/LaTeX/tests/syntax_test_latex.tex index 0d943f0eb85..271c755bc3d 100644 --- a/LaTeX/tests/syntax_test_latex.tex +++ b/LaTeX/tests/syntax_test_latex.tex @@ -3,14 +3,30 @@ % <- text.tex.latex \documentclass[12pt]{article} -% ^ keyword.control.preamble.latex -% ^ support.class.latex +% <- meta.preamble.documentclass.latex keyword.control.preamble.latex punctuation.definition.backslash.latex +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.preamble.documentclass.latex - meta.preamble.documentclass meta.preamble.documentclass +% ^^^^^^ meta.group.bracket.latex +% ^^^^^^^^^ meta.group.brace.tex +%^^^^^^^^^^^^^ keyword.control.preamble.latex +% ^ punctuation.definition.group.bracket.begin.latex +% ^ punctuation.definition.group.bracket.end.latex +% ^ punctuation.definition.group.brace.begin.tex +% ^^^^^^^ support.class.latex +% ^ punctuation.definition.group.brace.end.tex \usepackage[args]{mypackage, anotherpackage} -% ^ keyword.control.preamble.latex -% ^ support.class.latex -% ^ -support.class.latex -% ^ support.class.latex +% <- meta.preamble.usepackage.latex keyword.control.preamble.latex punctuation.definition.backslash.latex +%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.preamble.usepackage.latex - meta.preamble.usepackage meta.preamble.usepackage +% ^^^^^^ meta.group.bracket.latex +% ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.brace.tex +%^^^^^^^^^^ keyword.control.preamble.latex +% ^ punctuation.definition.group.bracket.begin.latex +% ^^^^ +% ^ punctuation.definition.group.bracket.end.latex +% ^ punctuation.definition.group.brace.begin.tex +% ^^^^^^^^^ support.class.latex +% ^^^^^^^^^^^^^^ support.class.latex +% ^ punctuation.definition.group.brace.end.tex \usepackage[pdftex, %plainpages={false}, @@ -792,7 +808,8 @@ \subsubsection{name} \ensuremath{f(x) = x^2} % <- meta.function.ensuremath.latex support.function.ensuremath.latex punctuation.definition.backslash.latex -%^^^^^^^^^^^^^^^^^^^^^^ meta.function.ensuremath.latex +%^^^^^^^^^^ meta.function.ensuremath.latex - meta.function meta.function - meta.group +% ^^^^^^^^^^^^ meta.function.ensuremath.latex meta.group.brace.tex - meta.function meta.function % ^ - meta.environment.math - markup.math % ^^^^^^^^^^ meta.environment.math.inline.ensuremath.latex markup.math.inline % ^ - meta.environment.math - markup.math @@ -801,7 +818,7 @@ \subsubsection{name} % ^ punctuation.definition.group.brace.end.tex \ensuremath % -%^^^^^^^^^^^^^ meta.function.ensuremath.latex +%^^^^^^^^^^^^^ meta.function.ensuremath.latex - meta.function meta.function %^^^^^^^^^^ support.function.ensuremath.latex % ^^ comment.line.percentage.tex {x^2}{normal text} @@ -914,7 +931,7 @@ \subsubsection{name} \end{lstlisting} \lstinline{var x = 15;} -% ^^^^^^^^^^^^^^^^^^^^^ meta.environment.verbatim.lstinline.latex +% ^^^^^^^^^^^^^^^^^^^^^ meta.environment.verbatim.lstinline.latex - meta.environment meta.environment % ^^^^^^^^^^^^^ meta.group.brace.tex % ^ punctuation.definition.group.brace.begin % ^^^^^^^^^^^ markup.raw.verb.latex @@ -922,7 +939,7 @@ \subsubsection{name} % ^ - meta.environment.verbatim.lstinline.latex \lstinline|var x = 15;| -% ^^^^^^^^^^^^^^^^^^^^^ meta.environment.verbatim.lstinline.latex +% ^^^^^^^^^^^^^^^^^^^^^ meta.environment.verbatim.lstinline.latex - meta.environment meta.environment % ^^^^^^^^^^^ markup.raw.verb.latex % ^ - meta.environment.verbatim.lstinline.latex