Skip to content

Commit f71b8d2

Browse files
authored
Add OCamllex and OCamlyacc syntax highlighting support (#2616)
* feature: add syntax highlighting support for OCamllex and OCamlyacc * Fix: Simplify comment scopes in ocaml grammar - Reduced the scope names for `commentBlock` and `commentDoc` to just "comment". - Removed unnecessary `constant.regexp` and `meta.separator.markdown` scopes. - Added a missing newline at the end of the file.
1 parent b1bd30c commit f71b8d2

5 files changed

Lines changed: 665 additions & 4 deletions

File tree

THIRD-PARTY-LICENSES.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,23 @@ The project uses the following third-party libraries or assets
120120
- **License**: MIT License
121121
- **License Link**: https://github.com/shentao/vue-multiselect/blob/master/LICENSE
122122

123+
### OCamllex
124+
125+
- **Source**: https://github.com/textmate/ocaml.tmbundle/blob/master/Syntaxes/OCamllex.tmLanguage
126+
- **Commit**: 1eff26848b39368414cb4214183a2cba22f12d0e
127+
- **License**: Permission to copy, use, modify, sell and distribute this software is granted. This software is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.
128+
- **License Link**: https://github.com/textmate/ocaml.tmbundle/tree/master#license
129+
130+
### OCamlyacc
131+
132+
- **Source**: https://github.com/textmate/ocaml.tmbundle/blob/master/Syntaxes/OCamlyacc.tmLanguage
133+
- **Commit**: 08a892aef6a4b285b1902d9ed1427653fce53e31
134+
- **License**: Permission to copy, use, modify, sell and distribute this software is granted. This software is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.
135+
- **License Link**: https://github.com/textmate/ocaml.tmbundle/tree/master#license
136+
123137
### Erlang
124138

125139
- **Source**: https://github.com/shentao/vue-multiselect/blob/master/docs/shiki/languages/erlang.tmLanguage.json
126140
- **Commit**: 8092917041f0ae02cbe4c6982deddc931c6adecd
127141
- **License**: MIT License
128-
- **License Link**: https://github.com/shentao/vue-multiselect/blob/master/LICENSE
142+
- **License Link**: https://github.com/shentao/vue-multiselect/blob/master/LICENSE

src/Models/TextMateHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public static class GrammarUtility
2929
new ExtraGrammar("source.vue", [".vue"], "vue.json"),
3030
new ExtraGrammar("source.erlang", [".erl", ".escript", ".hrl"], "erlang.json"),
3131
new ExtraGrammar("source.ocaml", [".ml", ".mli"], "ocaml.json"),
32+
new ExtraGrammar("source.ocamllex", [".mll"], "ocamllex.json"),
33+
new ExtraGrammar("source.ocamlyacc", [".mly"], "ocamlyacc.json"),
3234
];
3335

3436
private static readonly Dictionary<string, IRawGrammar> s_cachedRawGrammars = new();

src/Resources/Grammars/ocaml.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@
729729
"commentBlock": {
730730
"begin": "\\(\\*(?!\\*[^\\)])",
731731
"end": "\\*\\)",
732-
"name": "comment constant.regexp meta.separator.markdown",
732+
"name": "comment",
733733
"contentName": "emphasis",
734734
"patterns": [
735735
{
@@ -743,7 +743,7 @@
743743
"commentDoc": {
744744
"begin": "\\(\\*\\*",
745745
"end": "\\*\\)",
746-
"name": "comment constant.regexp meta.separator.markdown",
746+
"name": "comment",
747747
"patterns": [
748748
{
749749
"match": "\\*"
@@ -2958,4 +2958,4 @@
29582958
}
29592959
}
29602960
}
2961-
}
2961+
}
Lines changed: 302 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,302 @@
1+
{
2+
"name": "ocamllex",
3+
"scopeName": "source.ocamllex",
4+
"fileTypes": [ "mll" ],
5+
"foldingStartMarker": "{",
6+
"foldingStopMarker": "}",
7+
"keyEquivalent": "^~O",
8+
"patterns": [
9+
{
10+
"begin": "^\\s*({)",
11+
"beginCaptures": {
12+
"1": {
13+
"name": "punctuation.section.embedded.ocaml.begin.ocamllex"
14+
}
15+
},
16+
"end": "^\\s*(})",
17+
"endCaptures": {
18+
"1": {
19+
"name": "punctuation.section.embedded.ocaml.end.ocamllex"
20+
}
21+
},
22+
"name": "meta.embedded.ocaml",
23+
"patterns": [
24+
{
25+
"include": "source.ocaml"
26+
}
27+
]
28+
},
29+
{
30+
"begin": "\\b(let)\\s+([a-z][a-zA-Z0-9'_]*)\\s+=",
31+
"beginCaptures": {
32+
"1": {
33+
"name": "keyword.other.pattern-definition.ocamllex"
34+
},
35+
"2": {
36+
"name": "entity.name.type.pattern.stupid-goddamn-hack.ocamllex"
37+
}
38+
},
39+
"end": "^(?:\\s*let)|(?:\\s*(rule|$))",
40+
"name": "meta.pattern-definition.ocaml",
41+
"patterns": [
42+
{
43+
"include": "#match-patterns"
44+
}
45+
]
46+
},
47+
{
48+
"begin": "(rule|and)\\s+([a-z][a-zA-Z0-9_]*)\\s+(=)\\s+(parse)(?=\\s*$)|((?<!\\|)(\\|)(?!\\|))",
49+
"beginCaptures": {
50+
"1": {
51+
"name": "keyword.other.ocamllex"
52+
},
53+
"2": {
54+
"name": "entity.name.function.entrypoint.ocamllex"
55+
},
56+
"3": {
57+
"name": "keyword.operator.ocamllex"
58+
},
59+
"4": {
60+
"name": "keyword.other.ocamllex"
61+
},
62+
"5": {
63+
"name": "punctuation.separator.match-pattern.ocamllex"
64+
}
65+
},
66+
"end": "(?:^\\s*((and)\\b|(?=\\|)|$))",
67+
"endCaptures": {
68+
"3": {
69+
"name": "keyword.other.entry-definition.ocamllex"
70+
}
71+
},
72+
"name": "meta.pattern-match.ocaml",
73+
"patterns": [
74+
{
75+
"include": "#match-patterns"
76+
},
77+
{
78+
"include": "#actions"
79+
}
80+
]
81+
},
82+
{
83+
"include": "#strings"
84+
},
85+
{
86+
"include": "#comments"
87+
},
88+
{
89+
"match": "=",
90+
"name": "keyword.operator.symbol.ocamllex"
91+
},
92+
{
93+
"begin": "\\(",
94+
"end": "\\)",
95+
"name": "meta.paren-group.ocamllex",
96+
"patterns": [
97+
{
98+
"include": "$self"
99+
}
100+
]
101+
},
102+
{
103+
"match": "(’|‘|“|”)",
104+
"name": "invalid.illegal.unrecognized-character.ocamllex"
105+
}
106+
],
107+
"repository": {
108+
"actions": {
109+
"patterns": [
110+
{
111+
"begin": "[^\\']({)",
112+
"beginCaptures": {
113+
"1": {
114+
"name": "punctuation.definition.action.begin.ocamllex"
115+
}
116+
},
117+
"end": "(})",
118+
"endCaptures": {
119+
"1": {
120+
"name": "punctuation.definition.action.end.ocamllex"
121+
}
122+
},
123+
"name": "meta.action.ocamllex",
124+
"patterns": [
125+
{
126+
"include": "source.ocaml"
127+
}
128+
]
129+
}
130+
]
131+
},
132+
"chars": {
133+
"patterns": [
134+
{
135+
"captures": {
136+
"1": {
137+
"name": "punctuation.definition.char.begin.ocamllex"
138+
},
139+
"4": {
140+
"name": "punctuation.definition.char.end.ocamllex"
141+
}
142+
},
143+
"match": "(')([^\\\\]|\\\\(x[a-fA-F0-9][a-fA-F0-9]|[0-2]\\d\\d|[bnrt'\"\\\\]))(')",
144+
"name": "constant.character.ocamllex"
145+
}
146+
]
147+
},
148+
"comments": {
149+
"patterns": [
150+
{
151+
"begin": "\\(\\*",
152+
"beginCaptures": {
153+
"0": {
154+
"name": "punctuation.definition.comment.begin.ocaml"
155+
}
156+
},
157+
"end": "\\*\\)",
158+
"endCaptures": {
159+
"0": {
160+
"name": "punctuation.definition.comment.end.ocaml"
161+
}
162+
},
163+
"name": "comment.block.ocaml",
164+
"patterns": [
165+
{
166+
"include": "#comments"
167+
}
168+
]
169+
},
170+
{
171+
"begin": "(?=[^\\\\])(\")",
172+
"end": "\"",
173+
"name": "comment.block.string.quoted.double.ocaml",
174+
"patterns": [
175+
{
176+
"match": "\\\\(x[a-fA-F0-9][a-fA-F0-9]|[0-2]\\d\\d|[bnrt'\"\\\\])",
177+
"name": "comment.block.string.constant.character.escape.ocaml"
178+
}
179+
]
180+
}
181+
]
182+
},
183+
"match-patterns": {
184+
"patterns": [
185+
{
186+
"begin": "(\\()",
187+
"beginCaptures": {
188+
"1": {
189+
"name": "punctuation.definition.sub-pattern.begin.ocamllex"
190+
}
191+
},
192+
"end": "(\\))",
193+
"endCaptures": {
194+
"1": {
195+
"name": "punctuation.definition.sub-pattern.end.ocamllex"
196+
}
197+
},
198+
"name": "meta.pattern.sub-pattern.ocamllex",
199+
"patterns": [
200+
{
201+
"include": "#match-patterns"
202+
}
203+
]
204+
},
205+
{
206+
"match": "[a-z][a-zA-Z0-9'_]",
207+
"name": "entity.name.type.pattern.reference.stupid-goddamn-hack.ocamllex"
208+
},
209+
{
210+
"match": "\\bas\\b",
211+
"name": "keyword.other.pattern.ocamllex"
212+
},
213+
{
214+
"match": "eof",
215+
"name": "constant.language.eof.ocamllex"
216+
},
217+
{
218+
"match": "_",
219+
"name": "constant.language.universal-match.ocamllex"
220+
},
221+
{
222+
"begin": "(\\[)(\\^?)",
223+
"beginCaptures": {
224+
"1": {
225+
"name": "punctuation.definition.character-class.begin.ocamllex"
226+
},
227+
"2": {
228+
"name": "punctuation.definition.character-class.negation.ocamllex"
229+
}
230+
},
231+
"end": "(])(?!\\')",
232+
"endCaptures": {
233+
"1": {
234+
"name": "punctuation.definition.character-class.end.ocamllex"
235+
}
236+
},
237+
"name": "meta.pattern.character-class.ocamllex",
238+
"patterns": [
239+
{
240+
"match": "-",
241+
"name": "punctuation.separator.character-class.range.ocamllex"
242+
},
243+
{
244+
"include": "#chars"
245+
}
246+
]
247+
},
248+
{
249+
"match": "\\*|\\+|\\?",
250+
"name": "keyword.operator.pattern.modifier.ocamllex"
251+
},
252+
{
253+
"match": "\\|",
254+
"name": "keyword.operator.pattern.alternation.ocamllex"
255+
},
256+
{
257+
"include": "#chars"
258+
},
259+
{
260+
"include": "#strings"
261+
}
262+
]
263+
},
264+
"strings": {
265+
"patterns": [
266+
{
267+
"begin": "(?=[^\\\\])(\")",
268+
"beginCaptures": {
269+
"1": {
270+
"name": "punctuation.definition.string.begin.ocaml"
271+
}
272+
},
273+
"end": "(\")",
274+
"endCaptures": {
275+
"1": {
276+
"name": "punctuation.definition.string.end.ocaml"
277+
}
278+
},
279+
"name": "string.quoted.double.ocamllex",
280+
"patterns": [
281+
{
282+
"match": "\\\\$[ \\t]*",
283+
"name": "punctuation.separator.string.ignore-eol.ocaml"
284+
},
285+
{
286+
"match": "\\\\(x[a-fA-F0-9][a-fA-F0-9]|[0-2]\\d\\d|[bnrt'\"\\\\])",
287+
"name": "constant.character.string.escape.ocaml"
288+
},
289+
{
290+
"match": "\\\\[\\|\\(\\)1-9$^.*+?\\[\\]]",
291+
"name": "constant.character.regexp.escape.ocaml"
292+
},
293+
{
294+
"match": "\\\\(?!(x[a-fA-F0-9][a-fA-F0-9]|[0-2]\\d\\d|[bnrt'\"\\\\]|[\\|\\(\\)1-9$^.*+?\\[\\]]|$[ \\t]*))(?:.)",
295+
"name": "invalid.illegal.character.string.escape"
296+
}
297+
]
298+
}
299+
]
300+
}
301+
}
302+
}

0 commit comments

Comments
 (0)