on master help sign in
Merge pull request #2127 from sharkdp/log_syntax_2123

Syntax: [Log] highlight escape characters in double quoted strings

commit1b030dc03b906aa345f44b8266bffeea77d763fe authorKeith Hall <keith-hall@users.noreply.github.com> dateWed 23 Mar 2022, 22:37 (5 years ago) parent9ab378bc0ec03e
5 files changed+36−9
CHANGELOG.md+1 assets/syntaxes/02_Extra/log.sublime-syntax+30−6 tests/syntax-tests/highlighted/Log/example.log+1 tests/syntax-tests/highlighted/Syslog/example.syslog+3−3 tests/syntax-tests/source/Log/example.log+1
CHANGELOG.md+1
@@ -13,6 +13,7 @@
1313## Syntaxes
1414
1515- Mapped clang-format config file (.clang-format) to YAML syntax (@TruncatedDinosour)
16+- log syntax: improved handling of escape characters in double quoted strings. See #2123 (@keith-hall)
1617
1718## Themes
1819
assets/syntaxes/02_Extra/log.sublime-syntax+30−6
@@ -6,6 +6,7 @@ file_extensions:
66scope: text.log
77variables:
88 ipv4_part: (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
9+ hours_minutes_seconds: (?:[01]\d|2[0-3]):(?:[0-5]\d):(?:[0-5]\d)
910contexts:
1011 main:
1112 - match: (\w+)(=)
@@ -17,11 +18,10 @@ contexts:
1718 captures:
1819 1: punctuation.definition.string.begin.log
1920 3: punctuation.definition.string.end.log
20− - match: (")([^"]*)(")
21− scope: string.quoted.double.log
21+ - match: \"
2222 captures:
2323 1: punctuation.definition.string.begin.log
24− 3: punctuation.definition.string.end.log
24+ push: double_quoted_string
2525 - include: dates
2626 - include: ip_addresses
2727 - include: numbers
@@ -29,19 +29,34 @@ contexts:
2929 scope: markup.error.log
3030 - match: \b(?i:warn(?:ing)?)\b
3131 scope: markup.warning.log
32+ - match: \b(?i:debug)\b
33+ scope: markup.info.log
3234 #- include: scope:text.html.markdown#autolink-inet
3335 - match: \b\w+:/{2,3}
3436 scope: markup.underline.link.scheme.log
3537 push: url-host
3638 dates:
37− - match: \b\d{4}-\d{2}-\d{2}\b
39+ - match: \b\d{4}-\d{2}-\d{2}(?=\b|T)
3840 scope: meta.date.log meta.number.integer.decimal.log constant.numeric.value.log
39− - match: \b\d{4}/\d{2}/\d{2}\b
41+ push: maybe_date_time_separator
42+ - match: \b\d{4}/\d{2}/\d{2}(?=\b|T)
4043 scope: meta.date.log meta.number.integer.decimal.log constant.numeric.value.log
41− - match: \b(?:[01]\d|2[0-3]):(?:[0-5]\d):(?:[0-5]\d)(?:(\.)\d{3})?\b
44+ push: maybe_date_time_separator
45+ - match: \b(?={{hours_minutes_seconds}})
46+ push: time
47+ time:
48+ - match: (?:{{hours_minutes_seconds}})(?:(\.)\d{3})?\b
4249 scope: meta.time.log meta.number.integer.decimal.log constant.numeric.value.log
4350 captures:
4451 1: punctuation.separator.decimal.log
52+ - match: ''
53+ pop: true
54+ maybe_date_time_separator:
55+ - match: T(?={{hours_minutes_seconds}})
56+ scope: meta.date.log meta.time.log keyword.other.log
57+ set: time
58+ - match: ''
59+ pop: true
4560 ip_addresses:
4661 - match: \b(?=(?:{{ipv4_part}}\.){3}{{ipv4_part}}\b)
4762 push:
@@ -114,3 +129,12 @@ contexts:
114129 scope: markup.underline.link.path.log
115130 - match: ''
116131 pop: true
132+ double_quoted_string:
133+ - meta_scope: string.quoted.double.log
134+ - match: \\"
135+ scope: constant.character.escape.log
136+ - match: \\n
137+ scope: constant.character.escape.log
138+ - match: \"
139+ scope: punctuation.definition.string.end.log
140+ pop: true
tests/syntax-tests/highlighted/Log/example.log+1
@@ -1,2 +1,3 @@
112021-03-06 23:22:21.392 https://[2001:db8:4006:812::200e]:8080/path/the%20page.html
222021-03-06 23:22:21 https://example.com:8080/path/the%20page(with_parens).html
3+2022-03-16T17:41:02.519 helix_term::application [WARN] unhandled window/showMessage: ShowMessageParams { typ: Error, message: "rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /home/zeta/dev/raytracer/Cargo.toml, cargo 1.61.0-nightly (65c8266 2022-03-09): Failed to run `\"cargo\" \"metadata\" \"--format-version\" \"1\" \"--manifest-path\" \"/home/zeta/dev/raytracer/Cargo.toml\" \"--filter-platform\" \"wasm32-unknown-unknown\"`: `cargo metadata` exited with an error: Updating crates.io index\nerror: failed to select a version for `parking_lot`.\n ... required by package `raytracer v0.1.0 (/home/zeta/dev/raytracer)`\nversions that meet the requirements `^0.12.0` are: 0.12.0\n\nthe package `raytracer` depends on `parking_lot`, with features: `wasm-bindgen` but `parking_lot` does not have these features.\n\n\nfailed to select a version for `parking_lot` which could resolve this conflict\n" }
tests/syntax-tests/highlighted/Syslog/example.syslog+3−3
@@ -1,7 +1,7 @@
11Apr 4 00:00:01 hostname-here systemd[1]: logrotate.service: Succeeded.
22Apr 4 00:00:01 hostname-here systemd[1]: Finished Rotate log files.
33Apr 4 00:00:01 hostname-here colord[920]: failed to get session [pid 137485]: No data available
4−Apr 4 00:00:21 hostname-here kernel: [55604.908232] audit: type=1400 audit(1617483621.094:28): apparmor="DENIED" operation="capable" profile="/usr/sbin/cups-browsed" pid=59311 comm="cups-browsed" capability=23 capname="sys_nice"
4+Apr 4 00:00:21 hostname-here kernel: [55604.908232] audit: type=1400 audit(1617483621.094:28): apparmor="DENIED" operation="capable" profile="/usr/sbin/cups-browsed" pid=59311 comm="cups-browsed" capability=23 capname="sys_nice"
55Apr 4 00:01:38 hostname-here systemd-resolved[721]: Server returned error NXDOMAIN, mitigating potential DNS violation DVE-2018-0001, retrying transaction with reduced feature level UDP.
66Apr 4 00:04:46 hostname-here ntpd[952]: Soliciting pool server 255.76.59.37
77Apr 4 00:05:21 hostname-here ntpd[952]: ::1 local addr 0:0:0:0:0:0:0:1 -> <null>
@@ -10,7 +10,7 @@
1010Apr 4 16:32:07 hostname-here NetworkManager[740]: <info> [1617629527.1101] manager: NetworkManager state is now CONNECTED_GLOBAL
1111Apr 4 22:00:45 hostname-here dbus-daemon[1094]: [session uid=1000 pid=1094] Successfully activated service 'io.github.celluloid_player.Celluloid'
1212Aug 11 13:29:06 hostname-here insomnia_insomnia.desktop[142666]: 13:29:06.316 › [updater] Updater not running platform=linux dev=false
13−Aug 11 13:36:34 192.168.220.5 nginx: 2021/08/11 13:36:34 [debug] 2031#2031: epoll add event: fd:6 op:1 ev:00002001
14−Aug 11 21:31:08 ::1 nginx: 2021/08/11 21:31:08 [debug] 760831#760831: epoll add event: fd:6 op:1 ev:10000001
13+Aug 11 13:36:34 192.168.220.5 nginx: 2021/08/11 13:36:34 [debug] 2031#2031: epoll add event: fd:6 op:1 ev:00002001
14+Aug 11 21:31:08 ::1 nginx: 2021/08/11 21:31:08 [debug] 760831#760831: epoll add event: fd:6 op:1 ev:10000001
1515Aug 11 21:40:31 hostname-here scop hello
1616Aug 16 21:38:21 hostname-here systemd[1]: Finished Cleanup of Temporary Directories.
tests/syntax-tests/source/Log/example.log+1
@@ -1,2 +1,3 @@
112021-03-06 23:22:21.392 https://[2001:db8:4006:812::200e]:8080/path/the%20page.html
222021-03-06 23:22:21 https://example.com:8080/path/the%20page(with_parens).html
3+2022-03-16T17:41:02.519 helix_term::application [WARN] unhandled window/showMessage: ShowMessageParams { typ: Error, message: "rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /home/zeta/dev/raytracer/Cargo.toml, cargo 1.61.0-nightly (65c8266 2022-03-09): Failed to run `\"cargo\" \"metadata\" \"--format-version\" \"1\" \"--manifest-path\" \"/home/zeta/dev/raytracer/Cargo.toml\" \"--filter-platform\" \"wasm32-unknown-unknown\"`: `cargo metadata` exited with an error: Updating crates.io index\nerror: failed to select a version for `parking_lot`.\n ... required by package `raytracer v0.1.0 (/home/zeta/dev/raytracer)`\nversions that meet the requirements `^0.12.0` are: 0.12.0\n\nthe package `raytracer` depends on `parking_lot`, with features: `wasm-bindgen` but `parking_lot` does not have these features.\n\n\nfailed to select a version for `parking_lot` which could resolve this conflict\n" }