Skip to content

Commit ab54b55

Browse files
authored
Merge pull request #40 from vkarpov15/vkarpov15/polar-grammar
Add polar to list of supported languages
2 parents 96be244 + 332a0e8 commit ab54b55

File tree

5 files changed

+351
-0
lines changed

5 files changed

+351
-0
lines changed

.changeset/tough-fishes-compare.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@code-hike/lighter": patch
3+
---
4+
5+
Add polar grammar

lib/grammars/polar.tmLanguage.json

+331
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,331 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3+
"name": "polar",
4+
"patterns": [
5+
{
6+
"include": "#comment"
7+
},
8+
{
9+
"include": "#rule"
10+
},
11+
{
12+
"include": "#rule-type"
13+
},
14+
{
15+
"include": "#inline-query"
16+
},
17+
{
18+
"include": "#resource-block"
19+
},
20+
{
21+
"include": "#test-block"
22+
}
23+
],
24+
"repository": {
25+
"comment": {
26+
"name": "comment.line.number-sign",
27+
"match": "#.*"
28+
},
29+
"rule": {
30+
"name": "meta.rule",
31+
"patterns": [
32+
{
33+
"include": "#rule-functor"
34+
},
35+
{
36+
"begin": "\\bif\\b",
37+
"beginCaptures": {
38+
"0": {
39+
"name": "keyword.control.if"
40+
}
41+
},
42+
"end": ";",
43+
"patterns": [
44+
{
45+
"include": "#term"
46+
}
47+
]
48+
},
49+
{
50+
"match": ";"
51+
}
52+
]
53+
},
54+
"rule-type": {
55+
"name": "meta.rule-type",
56+
"begin": "\\btype\\b",
57+
"beginCaptures": {
58+
"0": {
59+
"name": "keyword.other.type-decl"
60+
}
61+
},
62+
"end": ";",
63+
"patterns": [
64+
{
65+
"include": "#rule-functor"
66+
}
67+
]
68+
},
69+
"inline-query": {
70+
"name": "meta.inline-query",
71+
"begin": "\\?=",
72+
"end": ";",
73+
"beginCaptures": {
74+
"0": {
75+
"name": "keyword.control"
76+
}
77+
},
78+
"patterns": [
79+
{
80+
"include": "#term"
81+
}
82+
]
83+
},
84+
"resource-block": {
85+
"name": "meta.resource-block",
86+
"begin": "((resource|actor)\\s+([a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*)|(global))\\s*\\{",
87+
"beginCaptures": {
88+
"2": {
89+
"name": "keyword.control"
90+
},
91+
"3": {
92+
"name": "entity.name.type"
93+
},
94+
"4": {
95+
"name": "keyword.control"
96+
}
97+
},
98+
"end": "\\}",
99+
"patterns": [
100+
{
101+
"name": "punctuation.separator.sequence.declarations",
102+
"match": ";"
103+
},
104+
{
105+
"name": "meta.relation-declaration",
106+
"begin": "\\{",
107+
"end": "\\}",
108+
"patterns": [
109+
{
110+
"include": "#specializer"
111+
},
112+
{
113+
"include": "#comment"
114+
},
115+
{
116+
"name": "punctuation.separator.sequence.dict",
117+
"match": ","
118+
}
119+
]
120+
},
121+
{
122+
"include": "#term"
123+
}
124+
]
125+
},
126+
"test-block": {
127+
"name": "meta.test-block",
128+
"begin": "(test)\\s+(\"[^\"]*\")\\s*\\{",
129+
"beginCaptures": {
130+
"1": {
131+
"name": "keyword.control"
132+
},
133+
"2": {
134+
"name": "string.quoted.double"
135+
}
136+
},
137+
"end": "\\}",
138+
"patterns": [
139+
{
140+
"name": "meta.test-setup",
141+
"begin": "(setup)\\s*\\{",
142+
"beginCaptures": {
143+
"1": {
144+
"name": "keyword.control"
145+
}
146+
},
147+
"end": "\\}",
148+
"patterns": [
149+
{
150+
"include": "#rule"
151+
},
152+
{
153+
"include": "#comment"
154+
}
155+
]
156+
},
157+
{
158+
"include": "#rule"
159+
},
160+
{
161+
"name": "keyword.other",
162+
"match": "\\b(assert|assert_not)\\b"
163+
},
164+
{
165+
"include": "#comment"
166+
}
167+
]
168+
},
169+
"term": {
170+
"patterns": [
171+
{
172+
"include": "#comment"
173+
},
174+
{
175+
"include": "#string"
176+
},
177+
{
178+
"include": "#number"
179+
},
180+
{
181+
"include": "#keyword"
182+
},
183+
{
184+
"include": "#operator"
185+
},
186+
{
187+
"include": "#boolean"
188+
},
189+
{
190+
"include": "#object-literal"
191+
},
192+
{
193+
"name": "meta.bracket.list",
194+
"begin": "\\[",
195+
"end": "\\]",
196+
"patterns": [
197+
{
198+
"include": "#term"
199+
},
200+
{
201+
"name": "punctuation.separator.sequence.list",
202+
"match": ","
203+
}
204+
]
205+
},
206+
{
207+
"name": "meta.bracket.dict",
208+
"begin": "\\{",
209+
"end": "\\}",
210+
"patterns": [
211+
{
212+
"include": "#term"
213+
},
214+
{
215+
"name": "punctuation.separator.sequence.dict",
216+
"match": ","
217+
}
218+
]
219+
},
220+
{
221+
"name": "meta.parens",
222+
"begin": "\\(",
223+
"end": "\\)",
224+
"patterns": [
225+
{
226+
"include": "#term"
227+
}
228+
]
229+
}
230+
]
231+
},
232+
"string": {
233+
"name": "string.quoted.double",
234+
"begin": "\"",
235+
"end": "\"",
236+
"patterns": [
237+
{
238+
"name": "constant.character.escape",
239+
"match": "\\\\."
240+
}
241+
]
242+
},
243+
"number": {
244+
"patterns": [
245+
{
246+
"name": "constant.numeric.float",
247+
"match": "\\b[+-]?\\d+(?:(\\.)\\d+(?:e[+-]?\\d+)?|(?:e[+-]?\\d+))\\b"
248+
},
249+
{
250+
"name": "constant.numeric.integer",
251+
"match": "\\b(\\+|\\-)[\\d]+\\b"
252+
},
253+
{
254+
"name": "constant.numeric.natural",
255+
"match": "\\b[\\d]+\\b"
256+
}
257+
]
258+
},
259+
"boolean": {
260+
"name": "constant.language.boolean",
261+
"match": "\\b(true|false)\\b"
262+
},
263+
"keyword": {
264+
"patterns": [
265+
{
266+
"match": "\\b(cut|or|debug|print|in|forall|if|and|of|not|matches|type|on|global)\\b",
267+
"name": "constant.character"
268+
}
269+
]
270+
},
271+
"operator": {
272+
"match": "(\\+|-|\\*|\\/|<|>|=|!)",
273+
"captures": {
274+
"1": {
275+
"name": "keyword.control"
276+
}
277+
}
278+
},
279+
"rule-functor": {
280+
"begin": "([a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*)\\s*\\(",
281+
"beginCaptures": {
282+
"1": {
283+
"name": "support.function.rule"
284+
}
285+
},
286+
"end": "\\)",
287+
"patterns": [
288+
{
289+
"include": "#specializer"
290+
},
291+
{
292+
"name": "punctuation.separator.sequence.list",
293+
"match": ","
294+
},
295+
{
296+
"include": "#term"
297+
}
298+
]
299+
},
300+
"specializer": {
301+
"match": "[a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*\\s*:\\s*([a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*)",
302+
"captures": {
303+
"1": {
304+
"name": "entity.name.type.resource"
305+
}
306+
}
307+
},
308+
"object-literal": {
309+
"name": "constant.other.object-literal",
310+
"begin": "([a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*)\\s*\\{",
311+
"beginCaptures": {
312+
"1": {
313+
"name": "entity.name.type.resource"
314+
}
315+
},
316+
"end": "\\}",
317+
"patterns": [
318+
{
319+
"include": "#string"
320+
},
321+
{
322+
"include": "#number"
323+
},
324+
{
325+
"include": "#boolean"
326+
}
327+
]
328+
}
329+
},
330+
"scopeName": "source.polar"
331+
}

lib/src/language-data.ts

+9
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export const LANG_NAMES = [
130130
"perl6",
131131
"php",
132132
"plsql",
133+
"polar",
133134
"postcss",
134135
"powerquery",
135136
"powershell",
@@ -321,6 +322,7 @@ export type LanguageName =
321322
| "perl"
322323
| "php"
323324
| "plsql"
325+
| "polar"
324326
| "postcss"
325327
| "powerquery"
326328
| "powershell"
@@ -490,6 +492,7 @@ export type ScopeName =
490492
| "source.perl"
491493
| "source.php"
492494
| "source.plsql.oracle"
495+
| "source.polar"
493496
| "source.css.postcss"
494497
| "source.powerquery"
495498
| "source.powershell"
@@ -686,6 +689,7 @@ export const aliasOrIdToScope: Record<LanguageAlias, ScopeName> = {
686689
"perl": "source.perl",
687690
"php": "source.php",
688691
"plsql": "source.plsql.oracle",
692+
"polar": "source.polar",
689693
"postcss": "source.css.postcss",
690694
"powerquery": "source.powerquery",
691695
"powershell": "source.powershell",
@@ -1840,6 +1844,11 @@ export const scopeToLanguageData: Record<ScopeName, LanguageData> = {
18401844
"path": "plsql.tmLanguage.json",
18411845
"embeddedScopes": []
18421846
},
1847+
"source.polar": {
1848+
"id": "polar",
1849+
"path": "polar.tmLanguage.json",
1850+
"embeddedScopes": []
1851+
},
18431852
"source.css.postcss": {
18441853
"id": "postcss",
18451854
"path": "postcss.tmLanguage.json",

lib/utils/languages.mjs

+5
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,11 @@ export const languages = [
877877
"scopeName": "source.plsql.oracle",
878878
"path": "plsql.tmLanguage.json"
879879
},
880+
{
881+
"id": "polar",
882+
"scopeName": "source.polar",
883+
"path": "polar.tmLanguage.json"
884+
},
880885
{
881886
"id": "postcss",
882887
"scopeName": "source.css.postcss",

web/public/grammars/polar.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"$schema":"https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json","name":"polar","patterns":[{"include":"#comment"},{"include":"#rule"},{"include":"#rule-type"},{"include":"#inline-query"},{"include":"#resource-block"},{"include":"#test-block"}],"repository":{"comment":{"name":"comment.line.number-sign","match":"#.*"},"rule":{"name":"meta.rule","patterns":[{"include":"#rule-functor"},{"begin":"\\bif\\b","beginCaptures":{"0":{"name":"keyword.control.if"}},"end":";","patterns":[{"include":"#term"}]},{"match":";"}]},"rule-type":{"name":"meta.rule-type","begin":"\\btype\\b","beginCaptures":{"0":{"name":"keyword.other.type-decl"}},"end":";","patterns":[{"include":"#rule-functor"}]},"inline-query":{"name":"meta.inline-query","begin":"\\?=","end":";","beginCaptures":{"0":{"name":"keyword.control"}},"patterns":[{"include":"#term"}]},"resource-block":{"name":"meta.resource-block","begin":"((resource|actor)\\s+([a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*)|(global))\\s*\\{","beginCaptures":{"2":{"name":"keyword.control"},"3":{"name":"entity.name.type"},"4":{"name":"keyword.control"}},"end":"\\}","patterns":[{"name":"punctuation.separator.sequence.declarations","match":";"},{"name":"meta.relation-declaration","begin":"\\{","end":"\\}","patterns":[{"include":"#specializer"},{"include":"#comment"},{"name":"punctuation.separator.sequence.dict","match":","}]},{"include":"#term"}]},"test-block":{"name":"meta.test-block","begin":"(test)\\s+(\"[^\"]*\")\\s*\\{","beginCaptures":{"1":{"name":"keyword.control"},"2":{"name":"string.quoted.double"}},"end":"\\}","patterns":[{"name":"meta.test-setup","begin":"(setup)\\s*\\{","beginCaptures":{"1":{"name":"keyword.control"}},"end":"\\}","patterns":[{"include":"#rule"},{"include":"#comment"}]},{"include":"#rule"},{"name":"keyword.other","match":"\\b(assert|assert_not)\\b"},{"include":"#comment"}]},"term":{"patterns":[{"include":"#comment"},{"include":"#string"},{"include":"#number"},{"include":"#keyword"},{"include":"#operator"},{"include":"#boolean"},{"include":"#object-literal"},{"name":"meta.bracket.list","begin":"\\[","end":"\\]","patterns":[{"include":"#term"},{"name":"punctuation.separator.sequence.list","match":","}]},{"name":"meta.bracket.dict","begin":"\\{","end":"\\}","patterns":[{"include":"#term"},{"name":"punctuation.separator.sequence.dict","match":","}]},{"name":"meta.parens","begin":"\\(","end":"\\)","patterns":[{"include":"#term"}]}]},"string":{"name":"string.quoted.double","begin":"\"","end":"\"","patterns":[{"name":"constant.character.escape","match":"\\\\."}]},"number":{"patterns":[{"name":"constant.numeric.float","match":"\\b[+-]?\\d+(?:(\\.)\\d+(?:e[+-]?\\d+)?|(?:e[+-]?\\d+))\\b"},{"name":"constant.numeric.integer","match":"\\b(\\+|\\-)[\\d]+\\b"},{"name":"constant.numeric.natural","match":"\\b[\\d]+\\b"}]},"boolean":{"name":"constant.language.boolean","match":"\\b(true|false)\\b"},"keyword":{"patterns":[{"match":"\\b(cut|or|debug|print|in|forall|if|and|of|not|matches|type|on|global)\\b","name":"constant.character"}]},"operator":{"match":"(\\+|-|\\*|\\/|<|>|=|!)","captures":{"1":{"name":"keyword.control"}}},"rule-functor":{"begin":"([a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*)\\s*\\(","beginCaptures":{"1":{"name":"support.function.rule"}},"end":"\\)","patterns":[{"include":"#specializer"},{"name":"punctuation.separator.sequence.list","match":","},{"include":"#term"}]},"specializer":{"match":"[a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*\\s*:\\s*([a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*)","captures":{"1":{"name":"entity.name.type.resource"}}},"object-literal":{"name":"constant.other.object-literal","begin":"([a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*)\\s*\\{","beginCaptures":{"1":{"name":"entity.name.type.resource"}},"end":"\\}","patterns":[{"include":"#string"},{"include":"#number"},{"include":"#boolean"}]}},"scopeName":"source.polar"}]

0 commit comments

Comments
 (0)