Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion components.json
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,11 @@
"alias": "rpy",
"owner": "HyuchiaDiego"
},
"rescript": {
"title": "ReScript",
"alias": "res",
"owner": "vmarcosp"
},
"rest": {
"title": "reST (reStructuredText)",
"owner": "Golmote"
Expand Down Expand Up @@ -1724,4 +1729,4 @@
"owner": "Golmote"
}
}
}
}
44 changes: 44 additions & 0 deletions components/prism-rescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var operator = /\.{3}|:[:=]|\|>|->|=(?:==?|>)?|<=?|>=?|[|^?'#!~`]|[+\-*\/]\.?|\b(?:asr|land|lor|lsl|lsr|lxor|mod)\b/;
var className = /(\b[A-Z]\w*)|(@[a-z.]*)|#[A-Za-z]\w*|#\d/;
var number = /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i;
var 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|val|virtual|when|while|with)\b/;

Prism.languages.rescript = {
'comment': {
pattern: /\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,
greedy: true
},
'class-name': className,
'function': {
pattern: /[a-zA-Z]\w*(?=\()|(\.)[a-z]\w*/,
lookbehind: true,
},
'number': /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
'string': {
pattern: /("(?:\\(?:\r\n|[\s\S])|[^\\\r\n"])*")|(`(?:\\(?:\r\n|[\s\S])|[^\\\r\n"])*`)/,
greedy: true,
inside: {
'tag': {
pattern: /\$\{.*\}/,
inside: {
'class-name': /[A-Z]\w*/g,
'function': /[a-z]\w*/g,
'punctuation': /\./g,
'operator': operator,
'number': number,
'keyword': keyword
}
},
}
},
'attr-value': /[A-Za-z]\w*(?==)/,
'constant': new RegExp('(?<=type\\s)[a-z]\\w*'),
'tag': {
pattern: new RegExp('((?<=<)[a-z]\\w*)|((?:<\\/)[a-z]\\w*)'),
inside: {
'operator': /<|>|\//,
},
},
'keyword': keyword,
'operator': operator
};
1 change: 1 addition & 0 deletions components/prism-rescript.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions examples/prism-rescript.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<h2>Comments</h2>
<pre><code>/* This is a comment */
// Another comment
</code></pre>

<h2>Strings and characters</h2>
<pre><code>let name = "Alonzo Church"
let message = `Hello ${name}`
let message2 = `Hello ${person.name}`
let result = `Testing => ${Module.Another.value}`
</code></pre>

<h2>Type declarations & Functions</h2>
<pre><code>type role = | Admin | Editor | Viewer
type numeric = #1 | #2 | #3
type normal = #Poly | #Variant
type myPolyVar = [ #"poly-variant" | #"test-chars" ]

type person = {
name: string,
age: int,
role: role
}

let sum = (a, b) => a + b
let sum = (a:int, b: int) => a + b
</code></pre>

<h2>JSX & Components</h2>
<pre>
<code>
module Button = {
@react.component
let make = (~count: int) => {
let times = switch count {
| 1 => "once"
| 2 => "twice"
| n => Belt.Int.toString(n) ++ " times"
}
let msg = "Click me " ++ times

&lt;button onClick={Js.log}>{msg->React.string}&lt;/button>;
}
}

@react.component
let make = () => &lt;MyModule.Button count=1 />
</code>
</pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
"rkt": "racket",
"razor": "cshtml",
"rpy": "renpy",
"res": "rescript",
"robot": "robotframework",
"rb": "ruby",
"sh-session": "shell-session",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
"tsx": "React TSX",
"renpy": "Ren'py",
"rpy": "Ren'py",
"res": "ReScript",
"rest": "reST (reStructuredText)",
"robotframework": "Robot Framework",
"robot": "Robot Framework",
Expand Down
Loading