Skip to content

Commit cbef9af

Browse files
authoredApr 15, 2022
Added support for ReScript (#3435)
1 parent c2d2c4b commit cbef9af

21 files changed

+508
-3
lines changed
 

Diff for: ‎components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎components.json

+5
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,11 @@
12121212
"alias": "rpy",
12131213
"owner": "HyuchiaDiego"
12141214
},
1215+
"rescript": {
1216+
"title": "ReScript",
1217+
"alias": "res",
1218+
"owner": "vmarcosp"
1219+
},
12151220
"rest": {
12161221
"title": "reST (reStructuredText)",
12171222
"owner": "Golmote"

Diff for: ‎components/prism-rescript.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Prism.languages.rescript = {
2+
'comment': {
3+
pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
4+
greedy: true
5+
},
6+
'char': { pattern: /'(?:[^\r\n\\]|\\(?:.|\w+))'/, greedy: true },
7+
'string': {
8+
pattern: /"(?:\\(?:\r\n|[\s\S])|[^\\\r\n"])*"/,
9+
greedy: true
10+
},
11+
'class-name': /\b[A-Z]\w*|@[a-z.]*|#[A-Za-z]\w*|#\d/,
12+
'function': {
13+
pattern: /[a-zA-Z]\w*(?=\()|(\.)[a-z]\w*/,
14+
lookbehind: true,
15+
},
16+
'number': /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
17+
'boolean': /\b(?:false|true)\b/,
18+
'attr-value': /[A-Za-z]\w*(?==)/,
19+
'constant': {
20+
pattern: /(\btype\s+)[a-z]\w*/,
21+
lookbehind: true
22+
},
23+
'tag': {
24+
pattern: /(<)[a-z]\w*|(?:<\/)[a-z]\w*/,
25+
lookbehind: true,
26+
inside: {
27+
'operator': /<|>|\//,
28+
},
29+
},
30+
'keyword': /\b(?:and|as|assert|begin|bool|class|constraint|do|done|downto|else|end|exception|external|float|for|fun|function|if|in|include|inherit|initializer|int|lazy|let|method|module|mutable|new|nonrec|object|of|open|or|private|rec|string|switch|then|to|try|type|when|while|with)\b/,
31+
'operator': /\.{3}|:[:=]?|\|>|->|=(?:==?|>)?|<=?|>=?|[|^?'#!~`]|[+\-*\/]\.?|\b(?:asr|land|lor|lsl|lsr|lxor|mod)\b/,
32+
'punctuation': /[(){}[\],;.]/
33+
};
34+
35+
Prism.languages.insertBefore('rescript', 'string', {
36+
'template-string': {
37+
pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
38+
greedy: true,
39+
inside: {
40+
'template-punctuation': {
41+
pattern: /^`|`$/,
42+
alias: 'string'
43+
},
44+
'interpolation': {
45+
pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
46+
lookbehind: true,
47+
inside: {
48+
'interpolation-punctuation': {
49+
pattern: /^\$\{|\}$/,
50+
alias: 'tag'
51+
},
52+
rest: Prism.languages.rescript
53+
}
54+
},
55+
'string': /[\s\S]+/
56+
}
57+
},
58+
});
59+
60+
Prism.languages.res = Prism.languages.rescript;

Diff for: ‎components/prism-rescript.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎examples/prism-rescript.html

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<h2>Comments</h2>
2+
<pre><code>/* This is a comment */
3+
// Another comment
4+
</code></pre>
5+
6+
<h2>Let bindings</h2>
7+
<pre><code>let name = "Alonzo Church"
8+
let message = `Hello ${name}`
9+
let message2 = `Hello ${person.name}`
10+
let result = `Testing => ${Module.Another.value}`
11+
let value = 1
12+
let result = 1 + 1
13+
let langs = ["ReScript", "JavaScript"]
14+
let person = ("Alonzo", 32)</code></pre>
15+
16+
<h2>Type declarations & Functions</h2>
17+
<pre><code>type role = | Admin | Editor | Viewer
18+
type numeric = #1 | #2 | #3
19+
type normal = #Poly | #Variant
20+
type myPolyVar = [ #"poly-variant" | #"test-chars" ]
21+
22+
type person = {
23+
name: string,
24+
age: int,
25+
role: role
26+
}
27+
28+
type record = {
29+
"field": string
30+
}
31+
32+
let sum = (a, b) => a + b
33+
let sum2 = (a:int, b: int) => a + b</code></pre>
34+
35+
<h2>Modules, JSX & Components</h2>
36+
<pre><code>%%raw(``)
37+
module Button = {
38+
@react.component
39+
let make = (~count: int) =>{
40+
let times = switch count {
41+
| 1 => "once"
42+
| 2 => "twice"
43+
| n => Belt.Int.toString(n) ++ " times"
44+
}
45+
let msg = "Click me " ++ times
46+
47+
&lt;button onClick={Js.log}>{msg->React.string}&lt;/button>;
48+
}
49+
}
50+
51+
@react.component
52+
let make = () => &lt;MyModule.Button count=1 /></code></pre>

Diff for: ‎plugins/autoloader/prism-autoloader.js

+1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@
244244
"rkt": "racket",
245245
"razor": "cshtml",
246246
"rpy": "renpy",
247+
"res": "rescript",
247248
"robot": "robotframework",
248249
"rb": "ruby",
249250
"sh-session": "shell-session",

Diff for: ‎plugins/autoloader/prism-autoloader.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎plugins/show-language/prism-show-language.js

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
"tsx": "React TSX",
214214
"renpy": "Ren'py",
215215
"rpy": "Ren'py",
216+
"res": "ReScript",
216217
"rest": "reST (reStructuredText)",
217218
"robotframework": "Robot Framework",
218219
"robot": "Robot Framework",

Diff for: ‎plugins/show-language/prism-show-language.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎tests/languages/rescript/attr-value_feature.test

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<button onClick={Js.log}>
2+
3+
----------------------------------------------------
4+
5+
[
6+
["operator", "<"],
7+
["tag", ["button"]],
8+
["attr-value", "onClick"],
9+
["operator", "="],
10+
["punctuation", "{"],
11+
["class-name", "Js"],
12+
["punctuation", "."],
13+
["function", "log"],
14+
["punctuation", "}"],
15+
["operator", ">"]
16+
]
17+
18+
----------------------------------------------------
19+
20+
Checks for attr-value.

Diff for: ‎tests/languages/rescript/boolean_feature.test

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
false
2+
true
3+
4+
----------------------------------------------------
5+
6+
[
7+
["boolean", "false"],
8+
["boolean", "true"]
9+
]
10+
11+
----------------------------------------------------
12+
13+
Checks for boolean.

Diff for: ‎tests/languages/rescript/char_feature.test

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'b'
2+
'\''
3+
'\\'
4+
'\xff'
5+
'\o214'
6+
7+
----------------------------------------------------
8+
9+
[
10+
["char", "'b'"],
11+
["char", "'\\''"],
12+
["char", "'\\\\'"],
13+
["char", "'\\xff'"],
14+
["char", "'\\o214'"]
15+
]
16+
17+
----------------------------------------------------
18+
19+
Checks for characters.

Diff for: ‎tests/languages/rescript/class-name_feature.test

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Belt.Int.toString(n)
2+
<Button />
3+
@react.component
4+
type poly = [ | #Poly | #Variant ]
5+
6+
----------------------------------------------------
7+
8+
[
9+
["class-name", "Belt"],
10+
["punctuation", "."],
11+
["class-name", "Int"],
12+
["punctuation", "."],
13+
["function", "toString"],
14+
["punctuation", "("],
15+
"n",
16+
["punctuation", ")"],
17+
18+
["operator", "<"],
19+
["class-name", "Button"],
20+
["operator", "/"],
21+
["operator", ">"],
22+
23+
["class-name", "@react.component"],
24+
25+
["keyword", "type"],
26+
["constant", "poly"],
27+
["operator", "="],
28+
["punctuation", "["],
29+
["operator", "|"],
30+
["class-name", "#Poly"],
31+
["operator", "|"],
32+
["class-name", "#Variant"],
33+
["punctuation", "]"]
34+
]
35+
36+
----------------------------------------------------
37+
38+
Checks for class names.

Diff for: ‎tests/languages/rescript/comment_feature.test

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// foobar
2+
/**/
3+
/* one line */
4+
/* multiline
5+
comment */
6+
/**
7+
another comment
8+
*/
9+
10+
----------------------------------------------------
11+
12+
[
13+
["comment", "// foobar"],
14+
["comment", "/**/"],
15+
["comment", "/* one line */"],
16+
["comment", "/* multiline\r\ncomment */"],
17+
["comment", "/**\r\nanother comment\r\n*/"]
18+
]
19+
20+
----------------------------------------------------
21+
22+
Checks for comments.

Diff for: ‎tests/languages/rescript/function_feature.test

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
sum(a, b)
2+
Belt.Int.toString(n)
3+
4+
----------------------------------------------------
5+
6+
[
7+
["function", "sum"],
8+
["punctuation", "("],
9+
"a",
10+
["punctuation", ","],
11+
" b",
12+
["punctuation", ")"],
13+
14+
["class-name", "Belt"],
15+
["punctuation", "."],
16+
["class-name", "Int"],
17+
["punctuation", "."],
18+
["function", "toString"],
19+
["punctuation", "("],
20+
"n",
21+
["punctuation", ")"]
22+
]
23+
24+
----------------------------------------------------
25+
26+
Checks for functions.

Diff for: ‎tests/languages/rescript/keyword_feature.test

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
and
2+
as
3+
assert
4+
begin
5+
bool
6+
class
7+
constraint
8+
do
9+
done
10+
downto
11+
else
12+
end
13+
exception
14+
external
15+
float
16+
for
17+
fun
18+
function
19+
if
20+
in
21+
include
22+
inherit
23+
initializer
24+
int
25+
lazy
26+
let
27+
method
28+
module
29+
mutable
30+
new
31+
nonrec
32+
object
33+
of
34+
open
35+
or
36+
private
37+
rec
38+
string
39+
switch
40+
then
41+
to
42+
try
43+
when
44+
while
45+
with
46+
type
47+
48+
----------------------------------------------------
49+
50+
[
51+
["keyword", "and"],
52+
["keyword", "as"],
53+
["keyword", "assert"],
54+
["keyword", "begin"],
55+
["keyword", "bool"],
56+
["keyword", "class"],
57+
["keyword", "constraint"],
58+
["keyword", "do"],
59+
["keyword", "done"],
60+
["keyword", "downto"],
61+
["keyword", "else"],
62+
["keyword", "end"],
63+
["keyword", "exception"],
64+
["keyword", "external"],
65+
["keyword", "float"],
66+
["keyword", "for"],
67+
["keyword", "fun"],
68+
["keyword", "function"],
69+
["keyword", "if"],
70+
["keyword", "in"],
71+
["keyword", "include"],
72+
["keyword", "inherit"],
73+
["keyword", "initializer"],
74+
["keyword", "int"],
75+
["keyword", "lazy"],
76+
["keyword", "let"],
77+
["keyword", "method"],
78+
["keyword", "module"],
79+
["keyword", "mutable"],
80+
["keyword", "new"],
81+
["keyword", "nonrec"],
82+
["keyword", "object"],
83+
["keyword", "of"],
84+
["keyword", "open"],
85+
["keyword", "or"],
86+
["keyword", "private"],
87+
["keyword", "rec"],
88+
["keyword", "string"],
89+
["keyword", "switch"],
90+
["keyword", "then"],
91+
["keyword", "to"],
92+
["keyword", "try"],
93+
["keyword", "when"],
94+
["keyword", "while"],
95+
["keyword", "with"],
96+
["keyword", "type"]
97+
]
98+
99+
----------------------------------------------------
100+
101+
Checks for keyword.

Diff for: ‎tests/languages/rescript/number_feature.test

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
let value = 1
2+
1 + 2
3+
4+
----------------------------------------------------
5+
6+
[
7+
["keyword", "let"], " value ", ["operator", "="], ["number", "1"],
8+
["number", "1"], ["operator", "+"], ["number", "2"]
9+
]
10+
11+
----------------------------------------------------
12+
13+
Checks for number.

Diff for: ‎tests/languages/rescript/operator_feature.test

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
...
2+
:: :=
3+
= == ===
4+
< <= > >=
5+
| ^ ? ' :
6+
# ! ~ `
7+
+ - * /
8+
+. -. *. /.
9+
mod land lor lxor
10+
lsl lsr asr
11+
|> ->
12+
13+
----------------------------------------------------
14+
15+
[
16+
["operator", "..."],
17+
18+
["operator", "::"],
19+
["operator", ":="],
20+
21+
["operator", "="],
22+
["operator", "=="],
23+
["operator", "==="],
24+
25+
["operator", "<"],
26+
["operator", "<="],
27+
["operator", ">"],
28+
["operator", ">="],
29+
30+
["operator", "|"],
31+
["operator", "^"],
32+
["operator", "?"],
33+
["operator", "'"],
34+
["operator", ":"],
35+
36+
["operator", "#"],
37+
["operator", "!"],
38+
["operator", "~"],
39+
["operator", "`"],
40+
41+
["operator", "+"],
42+
["operator", "-"],
43+
["operator", "*"],
44+
["operator", "/"],
45+
46+
["operator", "+."],
47+
["operator", "-."],
48+
["operator", "*."],
49+
["operator", "/."],
50+
51+
["operator", "mod"],
52+
["operator", "land"],
53+
["operator", "lor"],
54+
["operator", "lxor"],
55+
56+
["operator", "lsl"],
57+
["operator", "lsr"],
58+
["operator", "asr"],
59+
60+
["operator", "|>"],
61+
["operator", "->"]
62+
]
63+
64+
----------------------------------------------------
65+
66+
Checks for operators.

Diff for: ‎tests/languages/rescript/punctuation_feature.test

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
type poly = [ | #Poly | #Variant ]
2+
type person = { name: string }
3+
4+
----------------------------------------------------
5+
6+
[
7+
["keyword", "type"],
8+
["constant", "poly"],
9+
["operator", "="],
10+
["punctuation", "["],
11+
["operator", "|"],
12+
["class-name", "#Poly"],
13+
["operator", "|"],
14+
["class-name", "#Variant"],
15+
["punctuation", "]"],
16+
17+
["keyword", "type"],
18+
["constant", "person"],
19+
["operator", "="],
20+
["punctuation", "{"],
21+
" name",
22+
["operator", ":"],
23+
["keyword", "string"],
24+
["punctuation", "}"]
25+
]
26+
27+
----------------------------------------------------
28+
29+
Checks for punctuation.

Diff for: ‎tests/languages/rescript/string_feature.test

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
""
2+
"foo\"bar"
3+
`foo bar`
4+
5+
----------------------------------------------------
6+
7+
[
8+
["string", "\"\""],
9+
["string", "\"foo\\\"bar\""],
10+
["template-string", [
11+
["template-punctuation", "`"],
12+
["string", "foo bar"],
13+
["template-punctuation", "`"]
14+
]]
15+
]
16+
17+
----------------------------------------------------
18+
19+
Checks for strings.

Diff for: ‎tests/languages/rescript/tag_feature.test

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<button></button>
2+
3+
----------------------------------------------------
4+
5+
[
6+
["operator", "<"],
7+
["tag", ["button"]],
8+
["operator", ">"],
9+
["tag", [
10+
["operator", "<"],
11+
["operator", "/"],
12+
"button"
13+
]],
14+
["operator", ">"]
15+
]
16+
17+
----------------------------------------------------
18+
19+
Checks for tag.

0 commit comments

Comments
 (0)
Please sign in to comment.