Skip to content

Commit 80eff93

Browse files
committed
feat: add RON grammar
1 parent 8375e1d commit 80eff93

4 files changed

Lines changed: 366 additions & 4 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ your markup stays clean and editable.
1313

1414
- About 2 KiB compressed
1515
- No runtime dependencies
16-
- 35 languages, loaded on demand
16+
- 38 languages, loaded on demand
1717
- 10 bundled themes
1818
- Clean DOM with no token markup
1919
- Programmatic, automatic, and web component APIs
@@ -175,8 +175,8 @@ MicroLighter includes these grammars:
175175
`assembly`, `bash`, `c`, `cpp`, `csharp`, `css`, `dart`, `dockerfile`, `elixir`,
176176
`git-diff`, `go`, `graphql`, `heex`, `html`, `java`, `javascript`, `json`,
177177
`kotlin`, `lua`, `markdown`, `objective-c`, `perl`, `php`, `powershell`,
178-
`python`, `r`, `ruby`, `rust`, `scss`, `sql`, `svelte`, `swift`, `toml`, `tsx`,
179-
`typescript`, `vue`, and `yaml`.
178+
`python`, `r`, `ron`, `ruby`, `rust`, `scss`, `sql`, `svelte`, `swift`, `toml`,
179+
`tsx`, `typescript`, `vue`, and `yaml`.
180180

181181
Grammars are ES modules and load on demand.
182182

docs/index.html

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ <h2>No more spans!</h2>
121121
<article class="feature">
122122
<span class="feature-index" aria-hidden="true">02</span>
123123
<div class="feature-specimen size-specimen" aria-hidden="true">
124-
<span class="size-value">2.09</span><span class="size-unit">kb<br>gzip</span>
124+
<span class="size-value">2.10</span><span class="size-unit">kb<br>gzip</span>
125125
</div>
126126
<h2>Blazingly fast!!</h2>
127127
</article>
@@ -398,6 +398,7 @@ <h3>Data, config &amp; docs</h3>
398398
<li data-lang="json">JSON</li>
399399
<li data-lang="yaml">YAML</li>
400400
<li data-lang="toml">TOML</li>
401+
<li data-lang="ron">RON</li>
401402
<li data-lang="sql">SQL</li>
402403
<li data-lang="markdown">Markdown</li>
403404
<li data-lang="graphql">GraphQL</li>
@@ -595,6 +596,22 @@ <h2 id="playground-label">Playground</h2>
595596
def tokenize(source)
596597
source.split(" ")
597598
end</code></pre>
599+
</template>
600+
<template data-lang="ron" data-label="RON">
601+
<pre><code class="language-ron">// Syntax highlighter settings
602+
Config(
603+
title: "MicroLighter\n",
604+
initial: Some('M'),
605+
raw: r#"not \escaped"#,
606+
enabled: true,
607+
retries: 3,
608+
ratio: -1.25e+2,
609+
labels: {
610+
"syntax": r#"highlighting"#,
611+
fallback: None,
612+
},
613+
/* Keep unknown fields for future versions. */
614+
)</code></pre>
598615
</template>
599616
<template data-lang="rust" data-label="Rust">
600617
<pre><code class="language-rust">/// A scoped span of source text.

src/grammars/ron.js

Lines changed: 331 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,331 @@
1+
// Reference: a5huynh/vscode-ron (MIT) - https://github.com/a5huynh/vscode-ron/blob/master/syntaxes/ron.tmGrammar.json
2+
export default {
3+
"scopeName": "source.ron",
4+
"patterns": [
5+
{
6+
"include": "#expression"
7+
}
8+
],
9+
"repository": {
10+
"expression": {
11+
"patterns": [
12+
{
13+
"include": "#array"
14+
},
15+
{
16+
"include": "#block_comment"
17+
},
18+
{
19+
"include": "#constant"
20+
},
21+
{
22+
"include": "#dictionary"
23+
},
24+
{
25+
"include": "#line_comment"
26+
},
27+
{
28+
"include": "#number"
29+
},
30+
{
31+
"include": "#raw_string"
32+
},
33+
{
34+
"include": "#struct-field"
35+
},
36+
{
37+
"include": "#struct-name"
38+
},
39+
{
40+
"include": "#object"
41+
},
42+
{
43+
"include": "#string"
44+
},
45+
{
46+
"include": "#character"
47+
},
48+
{
49+
"include": "#enum-variant"
50+
}
51+
]
52+
},
53+
"array": {
54+
"begin": "\\[",
55+
"end": "\\]",
56+
"beginCaptures": {
57+
"0": {
58+
"name": "punctuation.section.array.begin.ron"
59+
}
60+
},
61+
"endCaptures": {
62+
"0": {
63+
"name": "punctuation.section.array.end.ron"
64+
}
65+
},
66+
"patterns": [
67+
{
68+
"include": "#value"
69+
},
70+
{
71+
"include": "#struct-name"
72+
},
73+
{
74+
"meta_scope": "meta.structure.array.ron"
75+
}
76+
]
77+
},
78+
"block_comment": {
79+
"name": "comment.block.ron",
80+
"begin": "/\\*",
81+
"end": "\\*/",
82+
"patterns": [
83+
{
84+
"include": "#block_comment"
85+
}
86+
]
87+
},
88+
"constant": {
89+
"match": "\\b(true|false)\\b",
90+
"name": "constant.language.ron"
91+
},
92+
"dictionary": {
93+
"begin": "\\{",
94+
"end": "\\}",
95+
"beginCaptures": {
96+
"0": {
97+
"name": "punctuation.section.dictionary.begin.ron"
98+
}
99+
},
100+
"endCaptures": {
101+
"0": {
102+
"name": "punctuation.section.dictionary.end.ron"
103+
}
104+
},
105+
"patterns": [
106+
{
107+
"include": "#value"
108+
},
109+
{
110+
"include": "#struct-name"
111+
},
112+
{
113+
"include": "#object"
114+
},
115+
{
116+
"include": "#enum-variant"
117+
},
118+
{
119+
"match": ",",
120+
"name": "punctuation.separator.dictionary.ron"
121+
},
122+
{
123+
"match": ":",
124+
"name": "punctuation.separator.dictionary.key-value.ron"
125+
}
126+
]
127+
},
128+
"line_comment": {
129+
"name": "comment.line.double-slash.ron",
130+
"begin": "//",
131+
"end": "$"
132+
},
133+
"struct-field": {
134+
"comment": "Struct field key: identifier followed by :",
135+
"match": "([a-z_][A-Za-z_0-9]*)\\s*(:)",
136+
"captures": {
137+
"1": {
138+
"name": "variable.other.member.ron"
139+
},
140+
"2": {
141+
"name": "punctuation.separator.key-value.ron"
142+
}
143+
}
144+
},
145+
"struct-name": {
146+
"comment": "Struct/type name: capitalized identifier typically followed by ( or {",
147+
"match": "[A-Z][A-Za-z_0-9]*",
148+
"name": "entity.name.type.ron"
149+
},
150+
"enum-variant": {
151+
"comment": "Enum variant or field name (lowercase identifier not followed by :)",
152+
"match": "[a-z_][A-Za-z_0-9]*",
153+
"name": "entity.name.tag.ron"
154+
},
155+
"object": {
156+
"begin": "\\(",
157+
"end": "\\)",
158+
"beginCaptures": {
159+
"0": {
160+
"name": "punctuation.section.parens.begin.ron"
161+
}
162+
},
163+
"endCaptures": {
164+
"0": {
165+
"name": "punctuation.section.parens.end.ron"
166+
}
167+
},
168+
"patterns": [
169+
{
170+
"include": "#value"
171+
},
172+
{
173+
"include": "#dictionary"
174+
},
175+
{
176+
"include": "#struct-field"
177+
},
178+
{
179+
"include": "#struct-name"
180+
},
181+
{
182+
"include": "#enum-variant"
183+
},
184+
{
185+
"include": "#object"
186+
}
187+
]
188+
},
189+
"number": {
190+
"patterns": [
191+
{
192+
"comment": "Hexadecimal integer",
193+
"match": "-?\\b0x[0-9a-fA-F_]+\\b",
194+
"name": "constant.numeric.hex.ron"
195+
},
196+
{
197+
"comment": "Binary integer",
198+
"match": "-?\\b0b[01_]+\\b",
199+
"name": "constant.numeric.binary.ron"
200+
},
201+
{
202+
"comment": "Octal integer",
203+
"match": "-?\\b0o[0-7_]+\\b",
204+
"name": "constant.numeric.octal.ron"
205+
},
206+
{
207+
"comment": "Float or decimal integer",
208+
"match": "-?\\b[0-9][0-9_]*(?:\\.[0-9][0-9_]*)?(?:[eE][+-]?[0-9_]+)?\\b",
209+
"name": "constant.numeric.ron"
210+
}
211+
]
212+
},
213+
"raw_string": {
214+
"patterns": [
215+
{
216+
"comment": "Raw string r#####\"...\"#####",
217+
"begin": "r#{5}\"",
218+
"end": "\"#{5}",
219+
"name": "string.quoted.other.raw.ron"
220+
},
221+
{
222+
"comment": "Raw string r####\"...\"####",
223+
"begin": "r#{4}\"",
224+
"end": "\"#{4}",
225+
"name": "string.quoted.other.raw.ron"
226+
},
227+
{
228+
"comment": "Raw string r###\"...\"###",
229+
"begin": "r#{3}\"",
230+
"end": "\"#{3}",
231+
"name": "string.quoted.other.raw.ron"
232+
},
233+
{
234+
"comment": "Raw string r##\"...\"##",
235+
"begin": "r#{2}\"",
236+
"end": "\"#{2}",
237+
"name": "string.quoted.other.raw.ron"
238+
},
239+
{
240+
"comment": "Raw string r#\"...\"#",
241+
"begin": "r#\"",
242+
"end": "\"#",
243+
"name": "string.quoted.other.raw.ron"
244+
},
245+
{
246+
"comment": "Raw string r\"...\"",
247+
"begin": "r\"",
248+
"end": "\"",
249+
"name": "string.quoted.other.raw.ron"
250+
}
251+
]
252+
},
253+
"string": {
254+
"begin": "(b?)(\")",
255+
"end": "\"",
256+
"name": "string.quoted.double",
257+
"patterns": [
258+
{
259+
"include": "#escapes"
260+
}
261+
]
262+
},
263+
"character": {
264+
"begin": "'",
265+
"end": "'",
266+
"contentName": "constant.character.ron",
267+
"name": "string.quoted.single",
268+
"patterns": [
269+
{
270+
"include": "#escapes"
271+
}
272+
]
273+
},
274+
"value": {
275+
"patterns": [
276+
{
277+
"include": "#array"
278+
},
279+
{
280+
"include": "#block_comment"
281+
},
282+
{
283+
"include": "#constant"
284+
},
285+
{
286+
"include": "#dictionary"
287+
},
288+
{
289+
"include": "#line_comment"
290+
},
291+
{
292+
"include": "#number"
293+
},
294+
{
295+
"include": "#object"
296+
},
297+
{
298+
"include": "#raw_string"
299+
},
300+
{
301+
"include": "#string"
302+
},
303+
{
304+
"include": "#character"
305+
}
306+
]
307+
},
308+
"escapes": {
309+
"comment": "escapes: ASCII, byte, Unicode, quote, regex",
310+
"name": "constant.character.escape.ron",
311+
"match": "(\\\\)(?:(?:(x[0-7][0-7a-fA-F])|(u(\\{)[\\da-fA-F]{4,6}(\\}))|.))",
312+
"captures": {
313+
"1": {
314+
"name": "constant.character.escape.backslash.ron"
315+
},
316+
"2": {
317+
"name": "constant.character.escape.bit.ron"
318+
},
319+
"3": {
320+
"name": "constant.character.escape.unicode.ron"
321+
},
322+
"4": {
323+
"name": "constant.character.escape.unicode.punctuation.ron"
324+
},
325+
"5": {
326+
"name": "constant.character.escape.unicode.punctuation.ron"
327+
}
328+
}
329+
}
330+
}
331+
};

0 commit comments

Comments
 (0)