From cb3e58cbed17f1edffa709487a990d0255005034 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sun, 29 Dec 2024 14:18:00 +0100 Subject: [PATCH 1/2] [LaTeX] Refactor LaTeX log file syntax This commit refactors logfile syntax based on real world latex log files. 1. It adds block and group contexts to enable syntax based folding. 2. Adjusts various other scopes Note: Logfiles are wrapped at 80chars, which can't be handled by ST's syntax engine, possibly causing smaller highlighting issues. Nevertheless it now looks way better than before. --- LaTeX/LaTeX Log Fold.tmPreferences | 31 ++++ LaTeX/LaTeX Log.sublime-syntax | 221 +++++++++++++++++++---------- LaTeX/tests/syntax_test_latex.log | 133 +++++++++++++++++ 3 files changed, 313 insertions(+), 72 deletions(-) create mode 100644 LaTeX/LaTeX Log Fold.tmPreferences create mode 100644 LaTeX/tests/syntax_test_latex.log diff --git a/LaTeX/LaTeX Log Fold.tmPreferences b/LaTeX/LaTeX Log Fold.tmPreferences new file mode 100644 index 0000000000..d06ff078b0 --- /dev/null +++ b/LaTeX/LaTeX Log Fold.tmPreferences @@ -0,0 +1,31 @@ + + + + scope + text.log.latex + settings + + indentationFoldingEnabled + + foldScopes + + + begin + punctuation.section.block.begin + end + punctuation.section.block.end + excludeTrailingNewlines + + + + begin + punctuation.section.group.begin + end + punctuation.section.group.end + excludeTrailingNewlines + + + + + + diff --git a/LaTeX/LaTeX Log.sublime-syntax b/LaTeX/LaTeX Log.sublime-syntax index 00837d28d6..685626e362 100644 --- a/LaTeX/LaTeX Log.sublime-syntax +++ b/LaTeX/LaTeX Log.sublime-syntax @@ -4,100 +4,177 @@ name: LaTeX Log scope: text.log.latex version: 2 -first_line_match: 'This is (pdf|pdfe)?TeXk?, Version ' +first_line_match: '^This is (?:LuaHB|pdfe?|Xe)?TeXk?, Version ' ################################################################################ contexts: main: - - include: log-entries - - include: file-paths - - include: under-over-full + - include: comments + - include: blocks - include: strings - under-over-full: - - match: (?:Overfull|Underfull) - scope: keyword.control.hyphenation.latex - push: under-over-full-body + comments: + # note: primarily used for syntax_test files + - match: \# + scope: punctuation.definition.comment.log + push: comment-body - under-over-full-body: - - meta_scope: meta.log.latex.hyphenation - - match: \[\]\n - scope: keyword.control.hyphenation.latex + comment-body: + - meta_scope: comment.line.log + - match: $\n? pop: 1 - - match: '[0-9]+\-\-[0-9]+' - scope: variable.parameter.hyphenation.latex - -###[ File paths ]############################################################### - - file-paths: - - include: function-file-paths - - include: tag-file-paths - - include: type-file-paths - function-file-paths: - - match: .*\.sty - scope: entity.name.function - - tag-file-paths: - - match: .*\.cfg - scope: entity.name.tag.configuration - - match: .*\.def - scope: entity.name.tag.definition - - type-file-paths: - - match: .*\.cls - scope: entity.name.type.class +###[ BLOCKS ]################################################################## + + blocks: + # block begin with full file name + - match: (\()((?:\\.|[^\s?!*)])+\.[A-Za-z]{2,}\b) + captures: + 1: punctuation.section.block.begin.log + 2: meta.toc-list.log entity.name.section.filename.log + push: + - block-body + - block-comment + # block begin with wrapped file name + - match: (\()((?:\\.|[^\s?!*)])+\n) + captures: + 1: punctuation.section.block.begin.log + 2: meta.toc-list.log entity.name.section.filename.log + push: + - block-body + - block-comment + - filename-continuation + + filename-continuation: + - match: ((?:\\.|[^\s?!*)])+\.[A-Za-z]{2,}\b) + scope: meta.toc-list.log entity.name.section.filename.log + pop: 1 + - match: (?=\S) + pop: 1 -###[ Log entries ]############################################################## + block-body: + - meta_scope: meta.block.log + - match: \) + scope: punctuation.section.block.end.log + pop: 1 + - include: comments + - include: blocks + - include: groups + - include: log-entries + - include: commands + - include: strings - log-entries: - - include: error-log-entries - - include: warning-log-entries - - include: info-log-entries - - include: fixme-log-entries + block-comment: + - match: '^Document Class:.{64}\n' + set: block-comment-body + - match: '^Document Class:.+' + scope: comment.line.log + pop: 1 + - match: '^File:.{74}\n' + set: block-comment-body + - match: '^File:.+' + scope: comment.line.log + pop: 1 + - match: '^Package:.{71}\n' + set: block-comment-body + - match: '^Package:.+' + scope: comment.line.log + pop: 1 + - match: ^|(?=\)) + pop: 1 - error-log-entries: - - match: '.*Error|^!.*' - scope: invalid.illegal + block-comment-body: + - meta_scope: comment.line.log + - match: ^.{80}\n # consume anything which has 80 chars + - match: \n + pop: 1 - warning-log-entries: - - match: '.*Warning:' - scope: invalid.deprecated - - match: '[^:]*:\d*:.*' - scope: invalid.deprecated + groups: + - match: \( + scope: punctuation.section.group.begin.log + push: group-body - info-log-entries: - - match: '.*Info.*' - scope: comment.block.documentation + group-body: + - meta_scope: meta.group.log + - match: \) + scope: punctuation.section.group.end.log + pop: 1 + - include: comments + - include: groups + - include: log-entries + - include: commands + - include: strings - fixme-log-entries: - - match: '.*FiXme:' - scope: meta.log.latex.fixme +###[ LOG ENTRIES ]############################################################## -###[ Strings ]################################################################## + log-entries: + # errors + - match: '^[^:]*Error:' + scope: markup.error.log + - match: '^!.*' + scope: markup.error.log + # warnings + - match: '^[^:]*(?:Overfull|Underfull)' + scope: markup.warning.log + push: box-warning-body + - match: '^[^:]*(FiXme|Warning):' + scope: markup.warning.log + - match: '^[^:]*:\d*:.*' + scope: markup.warning.log + # info + - match: '^[^:]*Info:' + scope: markup.info.log + + box-warning-body: + - meta_scope: meta.warning.box.log + - match: ^\s*\[\]\n + scope: punctuation.terminator.log + pop: 1 + - include: comments + - include: groups + - include: commands + + commands: + - match: (\\)[\w@]+ + scope: support.function.latex + captures: + 1: punctuation.definition.variable.latex + - match: :?= + scope: keyword.operator.assignment.latex + - match: ; + scope: punctuation.separator.latex + +###[ STRINGS ]################################################################## strings: - - include: angle-bracket-strings - - angle-bracket-strings: + - match: '<<' + scope: punctuation.definition.string.begin.log + push: double-angled-string-body - match: '<' - scope: punctuation.definition.string.begin.log.latex - push: angle-bracket-string-content + scope: punctuation.definition.string.begin.log + push: single-angled-string-body + - match: '`' + scope: punctuation.definition.string.begin.log + push: single-quoted-string-body + + double-angled-string-body: + - meta_scope: string.quoted.other.log + - match: '>>' + scope: punctuation.definition.string.end.log + pop: 1 - angle-bracket-string-content: - - meta_scope: string.unquoted.other.filename.log.latex + single-angled-string-body: + - meta_scope: string.quoted.other.log - match: '>' - scope: punctuation.definition.string.end.log.latex + scope: punctuation.definition.string.end.log pop: 1 - - match: .*/.*\.pdf - scope: - support.function.with-arg.latex - entity.name.function.filename.latex - - include: eol-pop -###[ Helpers ]################################################################## - - eol-pop: - - match: $\n? + single-quoted-string-body: + - meta_scope: string.quoted.single.log + - match: '''' + scope: punctuation.definition.string.end.log + pop: 1 + - match: \.$ + scope: punctuation.definition.string.end.log pop: 1 diff --git a/LaTeX/tests/syntax_test_latex.log b/LaTeX/tests/syntax_test_latex.log new file mode 100644 index 0000000000..d0b5de6cd4 --- /dev/null +++ b/LaTeX/tests/syntax_test_latex.log @@ -0,0 +1,133 @@ +# SYNTAX TEST "LaTeX Log.sublime-syntax" + +entering extended mode + restricted \write18 enabled. + %&-line parsing enabled. +**Analysis-I.tex +(./Analysis-I.tex) +# <- meta.block.log punctuation.section.block.begin.log +#^^^^^^^^^^^^^^^^^ meta.block.log +#^^^^^^^^^^^^^^^^ meta.toc-list.log entity.name.section.filename.log +# ^ punctuation.section.block.end.log +# ^ - meta.block + +(./Analysis-I.tex +LaTeX2e <2023-06-01> patch level 1 +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.log +# ^^^^^^^^^^^^ string.quoted.other.log +# ^ punctuation.definition.string.begin.log +# ^ punctuation.definition.string.end.log + +! fatal error +#^^^^^^^^^^^^ meta.block.log markup.error.log + +Package hyperref Error: Option `pdfauthor' not found, +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.log +#^^^^^^^^^^^^^^^^^^^^^^ markup.error.log +# ^^^^^^^^^^^ string.quoted.single.log +# ^ punctuation.definition.string.begin.log +# ^ punctuation.definition.string.end.log + +Package hyperref Warning: Option `pdfauthor' has already been used, +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.log +#^^^^^^^^^^^^^^^^^^^^^^^^ markup.warning.log +# ^^^^^^^^^^^ string.quoted.single.log +# ^ punctuation.definition.string.begin.log +# ^ punctuation.definition.string.end.log +(hyperref) setting the option has no effect on input line 13. +# <- meta.block.log meta.group.log punctuation.section.group.begin.log +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.log +#^^^^^^^^^ meta.group.log +# ^ punctuation.section.group.end.log + +Overfull \hbox (2.7858pt too wide) detected at line 369 +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.log meta.warning.box.log +#^^^^^^^ markup.warning.log +# ^^^^^ support.function.latex +# ^ punctuation.definition.variable.latex +# ^^^^^^^^^^^^^^^^^^^ meta.group.log +# ^ punctuation.section.group.begin.log +# ^ punctuation.section.group.end.log +\T1/cmr/m/n/10.95 23.20. +# <- meta.block.log meta.warning.box.log support.function.latex punctuation.definition.variable.latex +#^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.log meta.warning.box.log +#^^ support.function.latex + [] +# <- meta.block.log meta.warning.box.log punctuation.terminator.log +#^^ meta.block.log meta.warning.box.log punctuation.terminator.log + +Underfull \hbox (badness 10000) in paragraph at lines 3417--3445 +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.log meta.warning.box.log +#^^^^^^^^ markup.warning.log +# ^^^^^ support.function.latex +# ^ punctuation.definition.variable.latex +# ^^^^^^^^^^^^^^^ meta.group.log +# ^ punctuation.section.group.begin.log +# ^ punctuation.section.group.end.log + [] +# <- meta.block.log meta.warning.box.log punctuation.terminator.log +#^^ meta.block.log meta.warning.box.log punctuation.terminator.log + +(/opt/TeX/texmf-dist/tex/latex/base/fontenc.sty +Package: fontenc 2021/04/29 v2.0v Standard LaTeX package +<>) +# <- meta.block.log meta.block.log string.quoted.other.log punctuation.definition.string.begin.log +#^^^^^^^^^^^ meta.block.log meta.block.log +#^^^^^^^^^^ string.quoted.other.log +#^ punctuation.definition.string.begin.log +# ^^ punctuation.definition.string.end.log +# ^ punctuation.section.block.end.log + +(/opt/TeX/texmf-dist/tex/latex/koma-script/scrbook.cls +Document Class: scrbook 2023/07/07 v3.41 KOMA-Script document class (book) +# <- meta.block.log meta.block.log comment.line.log +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.log meta.block.log comment.line.log + +(/opt/TeX/texmf-dist/tex/latex/koma-script/tocbasic.sty +Document Class: scrbook 2023/07/07 v3.41 KOMA-Script document class with wrappe +d comment continued on next line (book) +# <- meta.block.log meta.block.log meta.block.log comment.line.log +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.log meta.block.log meta.block.log comment.line.log +\scr@dte@tocline@numberwidth=\skip48 +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.log meta.block.log meta.block.log +#^^^^^^^^^^^^^^^^^^^^^^^^^^^ support.function.latex +# ^ keyword.operator.assignment.latex +# ^^^^^^^ support.function.latex +# ^ punctuation.definition.variable.latex +) +# <- meta.block.log meta.block.log meta.block.log punctuation.section.block.end.log +#^ meta.block.log meta.block.log - meta.block meta.block meta.block + +Class scrbook Info: using compatibility default `runin=bysign' +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.log +#^^^^^^^^^^^^^^^^^^ markup.info.log +# ^^^^^^^^^^^^^^ string.quoted.single.log +# ^ punctuation.definition.string.begin.log +# ^ punctuation.definition.string.end.log + +(scrbook) for `\section on input line 6001. +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.log +#^^^^^^^^ meta.group.log +# ^ punctuation.section.group.end.log +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single.log +# ^ punctuation.definition.string.begin.log +# ^ punctuation.definition.string.end.log + +)) +# <- meta.block.log meta.block.log punctuation.section.block.end.log +#^ meta.block.log punctuation.section.block.end.log - meta.block meta.block +# ^ - meta.block + +# wrapped block file names +(/opt/TeX/texmf-dist/tex/latex/koma-scri +pt/scrbook.cls +# <- meta.block.log meta.toc-list.log entity.name.section.filename.log +#^^^^^^^^^^^^^ meta.block.log meta.toc-list.log entity.name.section.filename.log +) + +(/opt/TeX/texmf-dist/tex/latex/koma-scri +pt/scrbook.cls +File: tikzlibrarytopaths.code.tex 2023-01-15 v3.1.10 (3.1.10) +# <- meta.block.log comment.line.log +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.log comment.line.log +) From 625799b4a0f3419731b7b65bbe514aeeb7b51184 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 14 Jan 2025 13:02:47 +0100 Subject: [PATCH 2/2] [LaTeX] Indent folding rules using tabs --- LaTeX/LaTeX Log Fold.tmPreferences | 52 +++++++++++++++--------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/LaTeX/LaTeX Log Fold.tmPreferences b/LaTeX/LaTeX Log Fold.tmPreferences index d06ff078b0..3f366cff21 100644 --- a/LaTeX/LaTeX Log Fold.tmPreferences +++ b/LaTeX/LaTeX Log Fold.tmPreferences @@ -1,31 +1,31 @@ - scope - text.log.latex - settings - - indentationFoldingEnabled - - foldScopes - - - begin - punctuation.section.block.begin - end - punctuation.section.block.end - excludeTrailingNewlines - - - - begin - punctuation.section.group.begin - end - punctuation.section.group.end - excludeTrailingNewlines - - - - + scope + text.log.latex + settings + + indentationFoldingEnabled + + foldScopes + + + begin + punctuation.section.block.begin + end + punctuation.section.block.end + excludeTrailingNewlines + + + + begin + punctuation.section.group.begin + end + punctuation.section.group.end + excludeTrailingNewlines + + + +