From 4f2b78fbffc611cab16da8268494b5697b234dcc Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 19 Nov 2022 11:20:29 +0100 Subject: [PATCH] [LaTeX] Refactor braces contexts Illustrate how `braces` are implemented in both TeX & LaTeX with same content but different sub-scopes. Re-implementing a context without meta_prepend/meta_append overrides it completely. --- LaTeX/LaTeX.sublime-syntax | 17 +++++++++++------ LaTeX/TeX.sublime-syntax | 21 +++++++++++---------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/LaTeX/LaTeX.sublime-syntax b/LaTeX/LaTeX.sublime-syntax index 9a8a943ed8..bfc552aae6 100644 --- a/LaTeX/LaTeX.sublime-syntax +++ b/LaTeX/LaTeX.sublime-syntax @@ -39,12 +39,17 @@ contexts: braces: - match: \{ scope: punctuation.definition.group.brace.begin.latex - push: - - meta_scope: meta.group.brace.latex - - match: \} - scope: punctuation.definition.group.brace.end.latex - pop: true - - include: main + push: brace-group-body + + brace-group-body: + - meta_scope: meta.group.brace.latex + - include: brace-group-end + - include: main + + brace-group-end: + - match: \} + scope: punctuation.definition.group.brace.end.latex + pop: true # these are used to identify arguments in commands general-optional-arguments: diff --git a/LaTeX/TeX.sublime-syntax b/LaTeX/TeX.sublime-syntax index 255b19cf03..a773088707 100644 --- a/LaTeX/TeX.sublime-syntax +++ b/LaTeX/TeX.sublime-syntax @@ -154,10 +154,17 @@ contexts: braces: - match: \{ scope: punctuation.definition.group.brace.begin.tex - push: - - meta_scope: meta.group.brace.tex - - include: brace-group-end - - include: main + push: brace-group-body + + brace-group-body: + - meta_scope: meta.group.brace.tex + - include: brace-group-end + - include: main + + brace-group-end: + - match: \} + scope: punctuation.definition.group.brace.end.tex + pop: true # within macros, it is possible that only part of some nested struture # is present. To prevent this from causing problems, here we only match @@ -383,12 +390,6 @@ contexts: - match: (?=\S) pop: true - # matches a closing brace and pops the context - brace-group-end: - - match: \} - scope: punctuation.definition.group.brace.end.tex - pop: true - immediately-pop: - match: '' pop: true