Skip to content

Commit 1d06017

Browse files
authored
Add syntax highlighting for Flix (#5356)
* Add mode for Flix language * Add Flix example to kitchen-sink * Add highlighting for Flix * Support highlighting of Flix holes * Remove `rel` and `lat` keywords from Flix * Add tests for Flix
1 parent 4fff99e commit 1d06017

File tree

6 files changed

+503
-0
lines changed

6 files changed

+503
-0
lines changed

ace-modes.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,12 @@ declare module "ace-code/src/mode/erlang" {
340340
declare module "ace-code/src/mode/erlang_highlight_rules" {
341341
export const ErlangHighlightRules: new () => import(".").Ace.HighlightRules;
342342
}
343+
declare module "ace-code/src/mode/flix" {
344+
export const Mode: new () => import(".").Ace.SyntaxMode;
345+
}
346+
declare module "ace-code/src/mode/flix_highlight_rules" {
347+
export const FlixHighlightRules: new () => import(".").Ace.HighlightRules;
348+
}
343349
declare module "ace-code/src/mode/forth" {
344350
export const Mode: new () => import(".").Ace.SyntaxMode;
345351
}

demo/kitchen-sink/docs/flix.flix

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/// Mooo's `n` times on channel `c`.
2+
def mooo(tx: Sender[String, r], n: Int32): Unit \ IO =
3+
match n {
4+
case 0 => ()
5+
case x => Channel.send("Mooo!", tx); mooo(tx, x - 1)
6+
}
7+
8+
/// Meow's `n` times on channel `c`.
9+
def meow(tx: Sender[String, r], n: Int32): Unit \ IO =
10+
match n {
11+
case 0 => ()
12+
case x => Channel.send("Meow!", tx); meow(tx, x - 1)
13+
}
14+
15+
/// Hiss'es `n` times on channel `c`.
16+
def hiss(tx: Sender[String, r], n: Int32): Unit \ IO =
17+
match n {
18+
case 0 => ()
19+
case x => Channel.send("Hiss!", tx); hiss(tx, x - 1)
20+
}
21+
22+
/// Start the animal farm...
23+
def main(): Unit \ IO = region rc {
24+
let (tx1, rx1) = Channel.buffered(rc, 10);
25+
let (tx2, rx2) = Channel.buffered(rc, 10);
26+
let (tx3, rx3) = Channel.buffered(rc, 10);
27+
spawn mooo(tx1, 0) @ rc;
28+
spawn meow(tx2, 3) @ rc;
29+
spawn hiss(tx3, 7) @ rc;
30+
select {
31+
case m <- recv(rx1) => m |> println
32+
case m <- recv(rx2) => m |> println
33+
case m <- recv(rx3) => m |> println
34+
}
35+
}

src/ext/modelist.js

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ var supportedModes = {
8888
Elixir: ["ex|exs"],
8989
Elm: ["elm"],
9090
Erlang: ["erl|hrl"],
91+
Flix: ["flix"],
9192
Forth: ["frt|fs|ldr|fth|4th"],
9293
Fortran: ["f|f90"],
9394
FSharp: ["fsi|fs|ml|mli|fsx|fsscript"],

src/mode/_test/tokens_flix.json

+293
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
[[
2+
"start",
3+
["text", " "]
4+
],[
5+
"start",
6+
["comment.block", "/* Hello comment */"],
7+
["text", "\n"],
8+
["comment.block", "/* Hello \n comment */"],
9+
["text", "\n"],
10+
["comment.line", "// Hello comment"]
11+
],[
12+
"start",
13+
["keyword", "use"],
14+
["text", " "],
15+
["identifier", "Add"],
16+
["text", "."],
17+
["identifier", "add"]
18+
],[
19+
"start",
20+
["storage.type", "mod"],
21+
["text", " "],
22+
["paren.lparen", "{"],
23+
["storage.type", "def"],
24+
["text", " "],
25+
["identifier", "main"],
26+
["paren.lparen", "("],
27+
["paren.rparen", ")"],
28+
["text", ": "],
29+
["support.type", "Int32"],
30+
["text", " = "],
31+
["constant.numeric", "42"],
32+
["paren.rparen", "}"]
33+
],[
34+
"start",
35+
["storage.type", "class"],
36+
["text", " "],
37+
["identifier", "Add"],
38+
["paren.lparen", "["],
39+
["identifier", "a"],
40+
["paren.rparen", "]"],
41+
["text", " "],
42+
["paren.lparen", "{"],
43+
["paren.rparen", "}"]
44+
],[
45+
"start",
46+
["storage.type", "enum"],
47+
["text", " "],
48+
["identifier", "Down"],
49+
["paren.lparen", "["],
50+
["identifier", "a"],
51+
["paren.rparen", "]"],
52+
["text", " "],
53+
["storage.modifier", "with"],
54+
["text", " "],
55+
["identifier", "Sendable"],
56+
["text", " "],
57+
["paren.lparen", "{"],
58+
["storage.type", "case"],
59+
["text", " "],
60+
["identifier", "Down"],
61+
["paren.lparen", "("],
62+
["identifier", "a"],
63+
["paren.rparen", ")}"]
64+
],[
65+
"start",
66+
["storage.type", "eff"],
67+
["text", " "],
68+
["identifier", "NonDet"]
69+
],[
70+
"start",
71+
["storage.type", "type"],
72+
["text", " "],
73+
["storage.type", "alias"],
74+
["text", " "],
75+
["identifier", "Static"],
76+
["text", " = "],
77+
["identifier", "Impure"]
78+
],[
79+
"start",
80+
["storage.type", "def"],
81+
["text", " "],
82+
["identifier", "main"],
83+
["paren.lparen", "("],
84+
["paren.rparen", ")"],
85+
["text", ": "],
86+
["support.type", "Int32"],
87+
["text", " = "],
88+
["paren.lparen", "{"],
89+
["constant.numeric", "42"],
90+
["paren.rparen", "}"]
91+
],[
92+
"start",
93+
["storage.type", "def"],
94+
["text", " "],
95+
["identifier", "main"],
96+
["paren.lparen", "("],
97+
["paren.rparen", ")"],
98+
["text", ": "],
99+
["support.type", "Float64"],
100+
["text", " = "],
101+
["keyword.control", "if"],
102+
["paren.lparen", "("],
103+
["constant.language.boolean", "true"],
104+
["paren.rparen", ")"],
105+
["paren.lparen", "{"],
106+
["constant.numeric", "42.0"],
107+
["paren.rparen", "}"],
108+
["keyword.control", "else"],
109+
["paren.lparen", "{"],
110+
["constant.numeric", "43.0"],
111+
["paren.rparen", "}"]
112+
],[
113+
"start",
114+
["storage.type", "def"],
115+
["text", " "],
116+
["identifier", "main"],
117+
["paren.lparen", "("],
118+
["paren.rparen", ")"],
119+
["text", ": "],
120+
["support.type", "String"],
121+
["text", " = "],
122+
["string", "\"Hello"],
123+
["constant.character.escape", "\\\""],
124+
["string", "World"],
125+
["constant.character.escape", "\\u0021"],
126+
["string", "\""]
127+
],[
128+
"start",
129+
["storage.type", "def"],
130+
["text", " "],
131+
["identifier", "main"],
132+
["paren.lparen", "("],
133+
["paren.rparen", ")"],
134+
["text", ": "],
135+
["support.type", "Char"],
136+
["text", " = "],
137+
["constant.character", "'a'"]
138+
],[
139+
"start",
140+
["storage.type", "def"],
141+
["text", " "],
142+
["identifier", "main"],
143+
["paren.lparen", "("],
144+
["paren.rparen", ")"],
145+
["text", ": "],
146+
["support.type", "Char"],
147+
["text", " = "],
148+
["constant.character", "'"],
149+
["constant.character.escape", "\\u0021"],
150+
["constant.character", "'"]
151+
],[
152+
"start",
153+
["storage.type", "def"],
154+
["text", " "],
155+
["identifier", "main"],
156+
["paren.lparen", "("],
157+
["paren.rparen", ")"],
158+
["text", ": "],
159+
["support.type", "Char"],
160+
["text", " = "],
161+
["constant.character", "'"],
162+
["constant.character.escape", "\\'"],
163+
["constant.character", "'"]
164+
],[
165+
"start",
166+
["storage.type", "def"],
167+
["text", " "],
168+
["identifier", "main"],
169+
["paren.lparen", "("],
170+
["paren.rparen", ")"],
171+
["text", ": "],
172+
["identifier", "Regex"],
173+
["text", " = "],
174+
["string.regexp", "regex\"Hello"],
175+
["constant.character.escape", "\\\""],
176+
["string.regexp", "World"],
177+
["constant.character.escape", "\\u0021"],
178+
["string.regexp", "\""]
179+
],[
180+
"start",
181+
["storage.type", "def"],
182+
["text", " "],
183+
["identifier", "main"],
184+
["paren.lparen", "("],
185+
["paren.rparen", ")"],
186+
["text", ": "],
187+
["support.type", "String"],
188+
["text", " = "],
189+
["keyword", "???"]
190+
],[
191+
"start",
192+
["storage.type", "def"],
193+
["text", " "],
194+
["identifier", "main"],
195+
["paren.lparen", "("],
196+
["paren.rparen", ")"],
197+
["text", ": "],
198+
["support.type", "String"],
199+
["text", " = "],
200+
["keyword", "?someHole"]
201+
],[
202+
"start",
203+
["storage.type", "def"],
204+
["text", " "],
205+
["identifier", "main"],
206+
["paren.lparen", "("],
207+
["paren.rparen", ")"],
208+
["text", ": "],
209+
["support.type", "Int32"],
210+
["text", " = "],
211+
["constant.numeric", "0x123i32"]
212+
],[
213+
"start",
214+
["storage.type", "def"],
215+
["text", " "],
216+
["identifier", "main"],
217+
["paren.lparen", "("],
218+
["paren.rparen", ")"],
219+
["text", ": "],
220+
["support.type", "Int32"],
221+
["text", " = "],
222+
["constant.numeric", "42i32"]
223+
],[
224+
"start",
225+
["storage.type", "def"],
226+
["text", " "],
227+
["identifier", "main"],
228+
["paren.lparen", "("],
229+
["paren.rparen", ")"],
230+
["text", ": "],
231+
["support.type", "Float64"],
232+
["text", " = "],
233+
["constant.numeric", "42.0f64"]
234+
],[
235+
"start",
236+
["storage.type", "def"],
237+
["text", " "],
238+
["identifier", "main"],
239+
["paren.lparen", "("],
240+
["paren.rparen", ")"],
241+
["text", ": "],
242+
["support.type", "Bool"],
243+
["text", " = "],
244+
["constant.language.boolean", "true"]
245+
],[
246+
"start",
247+
["storage.type", "def"],
248+
["text", " "],
249+
["identifier", "main"],
250+
["paren.lparen", "("],
251+
["paren.rparen", ")"],
252+
["text", ": "],
253+
["support.type", "Bool"],
254+
["text", " = "],
255+
["constant.language.boolean", "false"]
256+
],[
257+
"start",
258+
["storage.type", "def"],
259+
["text", " "],
260+
["identifier", "main"],
261+
["paren.lparen", "("],
262+
["paren.rparen", ")"],
263+
["text", ": "],
264+
["identifier", "Null"],
265+
["text", " = "],
266+
["constant.language", "null"]
267+
],[
268+
"start",
269+
["storage.modifier", "@Lazy"],
270+
["text", "\n"],
271+
["storage.type", "def"],
272+
["text", " "],
273+
["identifier", "main"],
274+
["paren.lparen", "("],
275+
["paren.rparen", ")"],
276+
["text", ": "],
277+
["support.type", "Int32"],
278+
["text", " = "],
279+
["constant.numeric", "42"]
280+
],[
281+
"start",
282+
["storage.modifier", "pub"],
283+
["text", " "],
284+
["storage.type", "def"],
285+
["text", " "],
286+
["identifier", "main"],
287+
["paren.lparen", "("],
288+
["paren.rparen", ")"],
289+
["text", ": "],
290+
["support.type", "Int32"],
291+
["text", " = "],
292+
["constant.numeric", "42"]
293+
]]

src/mode/flix.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use strict";
2+
3+
var oop = require("../lib/oop");
4+
var TextMode = require("./text").Mode;
5+
var FlixHighlightRules = require("./flix_highlight_rules").FlixHighlightRules;
6+
7+
var Mode = function() {
8+
this.HighlightRules = FlixHighlightRules;
9+
};
10+
oop.inherits(Mode, TextMode);
11+
12+
(function() {
13+
this.$id = "ace/mode/flix";
14+
}).call(Mode.prototype);
15+
16+
exports.Mode = Mode;

0 commit comments

Comments
 (0)