Skip to content

Commit

Permalink
[LaTeX] Refactor LaTeX log file syntax
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
deathaxe committed Jan 12, 2025
1 parent 83da0ee commit cb3e58c
Show file tree
Hide file tree
Showing 3 changed files with 313 additions and 72 deletions.
31 changes: 31 additions & 0 deletions LaTeX/LaTeX Log Fold.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>scope</key>
<string>text.log.latex</string>
<key>settings</key>
<dict>
<key>indentationFoldingEnabled</key>
<false/>
<key>foldScopes</key>
<array>
<dict>
<key>begin</key>
<string>punctuation.section.block.begin</string>
<key>end</key>
<string>punctuation.section.block.end</string>
<key>excludeTrailingNewlines</key>
<false/>
</dict>
<dict>
<key>begin</key>
<string>punctuation.section.group.begin</string>
<key>end</key>
<string>punctuation.section.group.end</string>
<key>excludeTrailingNewlines</key>
<false/>
</dict>
</array>
</dict>
</dict>
</plist>
221 changes: 149 additions & 72 deletions LaTeX/LaTeX Log.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit cb3e58c

Please sign in to comment.