Skip to content

Commit 5001ce6

Browse files
committed
Add syntax highlighting with syntect
1 parent f99f60e commit 5001ce6

File tree

11 files changed

+493
-37
lines changed

11 files changed

+493
-37
lines changed

Cargo.lock

Lines changed: 129 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ itertools = "0.13.0"
3838
jaq-core = "2.1.1"
3939
jaq-std = "2.1.0"
4040
bigdecimal = "0.4.8"
41+
syntect = "5.2.0"
42+
syntect-assets = "0.23.6"
4143

4244
[target.'cfg(not(target_os = "windows"))'.dependencies]
4345
pager = "0.16.1"

src/bin/ion/assets/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The packdump files are generated via the `synpack` command from the `gendata` example in `syntect`.
2+
3+
Check out `syntect` and then run:
4+
```shell
5+
cargo run --features=metadata --example gendata -- \
6+
synpack ion.sublime-syntax ion.newlines.packdump ion.nonewlines.packdump
7+
```
8+
9+
`ion.sublime-syntax` is sourced from `partiql/partiql-rust-cli`.
1.53 KB
Binary file not shown.
1.53 KB
Binary file not shown.

src/bin/ion/assets/ion.sublime-syntax

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
%YAML 1.2
2+
# See https://www.sublimetext.com/docs/syntax.htm
3+
---
4+
name: ion
5+
version: "2"
6+
file_extensions:
7+
- ion
8+
scope: source.ion
9+
contexts:
10+
keywords:
11+
- match: "\\b(?i:true|false)\\b"
12+
scope: constant.language.bool.ion
13+
- match: "\\b(?i:null.null|null.bool|null.int|null.float|null.decimal|null.timestamp|null.string|null.symbol|null.blob|null.clob|null.struct|null.list|null.sexp|null)\\b"
14+
scope: constant.language.null.ion
15+
main:
16+
- include: value
17+
value:
18+
- include: whitespace
19+
- include: comment
20+
- include: annotation
21+
- include: string
22+
- include: number
23+
- include: keywords
24+
- include: symbol
25+
- include: clob
26+
- include: blob
27+
- include: struct
28+
- include: list
29+
- include: sexp
30+
sexp:
31+
- match: "\\("
32+
scope: punctuation.definition.sexp.begin.ion
33+
push: sexp__0
34+
sexp__0:
35+
- match: "\\)"
36+
scope: punctuation.definition.sexp.end.ion
37+
pop: true
38+
- include: comment
39+
- include: value
40+
- match: "[\\!\\#\\%\\&\\*\\+\\-\\.\\/\\;\\<\\=\\>\\?\\@\\^\\`\\|\\~]+"
41+
scope: storage.type.symbol.operator.ion
42+
comment:
43+
- match: "\\/\\/[^\\n]*"
44+
scope: comment.line.ion
45+
- match: "\\/\\*"
46+
scope: comment.block.ion
47+
push: comment__1
48+
comment__1:
49+
- match: "[*]\\/"
50+
scope: comment.block.ion
51+
pop: true
52+
- match: "[^*\\/]+"
53+
scope: comment.block.ion
54+
- match: "[*\\/]+"
55+
scope: comment.block.ion
56+
list:
57+
- match: "\\["
58+
scope: punctuation.definition.list.begin.ion
59+
push: list__0
60+
list__0:
61+
- match: "\\]"
62+
scope: punctuation.definition.list.end.ion
63+
pop: true
64+
- include: comment
65+
- include: value
66+
- match: ","
67+
scope: punctuation.definition.list.separator.ion
68+
struct:
69+
- match: "\\{"
70+
scope: punctuation.definition.struct.begin.ion
71+
push: struct__0
72+
struct__0:
73+
- match: "\\}"
74+
scope: punctuation.definition.struct.end.ion
75+
pop: true
76+
- include: comment
77+
- include: value
78+
- match: ",|:"
79+
scope: punctuation.definition.struct.separator.ion
80+
blob:
81+
- match: "(\\{\\{)([^\"]*)(\\}\\})"
82+
captures:
83+
1: punctuation.definition.blob.begin.ion
84+
2: string.other.blob.ion
85+
3: punctuation.definition.blob.end.ion
86+
clob:
87+
- match: "(\\{\\{)(\"[^\"]*\")(\\}\\})"
88+
captures:
89+
1: punctuation.definition.clob.begin.ion
90+
2: string.other.clob.ion
91+
3: punctuation.definition.clob.end.ion
92+
symbol:
93+
- match: "(['])((?:(?:\\\\')|(?:[^']))*?)(['])"
94+
scope: storage.type.symbol.quoted.ion
95+
- match: "[\\$_a-zA-Z][\\$_a-zA-Z0-9]*"
96+
scope: storage.type.symbol.identifier.ion
97+
number:
98+
- match: "\\d{4}(?:-\\d{2})?(?:-\\d{2})?T(?:\\d{2}:\\d{2})(?::\\d{2})?(?:\\.\\d+)?(?:Z|[-+]\\d{2}:\\d{2})?"
99+
scope: constant.numeric.timestamp.ion
100+
- match: "\\d{4}-\\d{2}-\\d{2}T?"
101+
scope: constant.numeric.timestamp.ion
102+
- match: "-?0[bB][01](?:_?[01])*"
103+
scope: constant.numeric.integer.binary.ion
104+
- match: "-?0[xX][0-9a-fA-F](?:_?[0-9a-fA-F])*"
105+
scope: constant.numeric.integer.hex.ion
106+
- match: "-?(?:0|[1-9](?:_?\\d)*)(?:\\.(?:\\d(?:_?\\d)*)?)?(?:[eE][+-]?\\d+)"
107+
scope: constant.numeric.float.ion
108+
- match: "(?:[-+]inf)|(?:nan)"
109+
scope: constant.numeric.float.ion
110+
- match: "-?(?:0|[1-9](?:_?\\d)*)(?:(?:(?:\\.(?:\\d(?:_?\\d)*)?)(?:[dD][+-]?\\d+)|\\.(?:\\d(?:_?\\d)*)?)|(?:[dD][+-]?\\d+))"
111+
scope: constant.numeric.decimal.ion
112+
- match: "-?(?:0|[1-9](?:_?\\d)*)"
113+
scope: constant.numeric.integer.ion
114+
string:
115+
- match: "([\"])((?:(?:\\\\\")|(?:[^\"]))*?)([\"])"
116+
captures:
117+
1: punctuation.definition.string.begin.ion
118+
2: string.quoted.double.ion
119+
3: punctuation.definition.string.end.ion
120+
- match: "'{3}"
121+
scope: punctuation.definition.string.begin.ion
122+
push: string__1
123+
string__1:
124+
- match: "'{3}"
125+
scope: punctuation.definition.string.end.ion
126+
pop: true
127+
- match: "(?:\\\\'|[^'])+"
128+
scope: string.quoted.triple.ion
129+
- match: "'"
130+
scope: string.quoted.triple.ion
131+
annotation:
132+
- match: "('(?:[^']|\\\\\\\\|\\\\')*')\\s*(::)"
133+
captures:
134+
1: variable.language.annotation.ion
135+
2: punctuation.definition.annotation.ion
136+
- match: "([\\$_a-zA-Z][\\$_a-zA-Z0-9]*)\\s*(::)"
137+
captures:
138+
1: variable.language.annotation.ion
139+
2: punctuation.definition.annotation.ion
140+
whitespace:
141+
- match: "\\s+"
142+
scope: text.ion

src/bin/ion/commands/cat.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ impl IonCliCommand for CatCommand {
3030
.with_input()
3131
.with_output()
3232
.with_format()
33+
.with_color()
3334
.with_ion_version()
3435
}
3536

0 commit comments

Comments
 (0)