Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for ReScript #3435

Merged
merged 20 commits into from Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

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

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
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
57 changes: 57 additions & 0 deletions components/prism-rescript.js
@@ -0,0 +1,57 @@
(function (Prism) {
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 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/;
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved

Prism.languages.rescript = {
'comment': {
pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
greedy: true
},
'string': /"(?:\\(?:\r\n|[\s\S])|[^\\\r\n"])*"/,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
'class-name': className,
'function': /[a-zA-Z]\w*(?=\()|(\.)[a-z]\w*/,
'number': /(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,
'attr-value': /[A-Za-z]\w*(?==)/,
'constant': {
pattern: /(\btype\s+)[a-z]\w*/,
lookbehind: true
},
'tag': {
pattern: /(<)[a-z]\w*|(?:<\/)[a-z]\w*/,
lookbehind: true,
inside: {
'operator': /<|>|\//,
},
},
'keyword': keyword,
'operator': operator
};

Prism.languages.insertBefore('rescript', 'string', {
'template-string': {
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
greedy: true,
inside: {
'template-punctuation': {
pattern: /^`|`$/,
alias: 'string'
},
'interpolation': {
pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,
lookbehind: true,
inside: {
'interpolation-punctuation': {
pattern: /^\$\{|\}$/,
alias: 'punctuation'
},
rest: Prism.languages.rescript
}
},
'string': /[\s\S]+/
}
},
});

Prism.languages.res = Prism.languages.rescript;
}(Prism));
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.

51 changes: 51 additions & 0 deletions examples/prism-rescript.html
@@ -0,0 +1,51 @@
<h2>Comments</h2>
<pre><code>/* This is a comment */
// Another comment
</code></pre>

<h2>Let bindings</h2>
<pre><code>let name = "Alonzo Church"
let message = `Hello ${name}`
let message2 = `Hello ${person.name}`
let result = `Testing => ${Module.Another.value}`
let value = 1
let result = 1 + 1
let langs = ["ReScript", "JavaScript"]
let person = ("Alonzo", 32)</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
}

type record = {
"field": string
}

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

<h2>Modules, 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
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
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