Skip to content

Commit cbef9af

Browse files
authored
Added support for ReScript (#3435)
1 parent c2d2c4b commit cbef9af

21 files changed

+508
-3
lines changed

components.js

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

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"

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;

components/prism-rescript.min.js

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

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>

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",

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.

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",

0 commit comments

Comments
 (0)