Skip to content

Commit 2e688f5

Browse files
committed
Refine CM / hljs highlighting
1 parent c812385 commit 2e688f5

File tree

5 files changed

+24
-28
lines changed

5 files changed

+24
-28
lines changed

plugins/cm-rescript-mode.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import "codemirror/addon/mode/simple";
88
import CodeMirror from "codemirror/lib/codemirror";
99

10+
1011
CodeMirror.defineSimpleMode("rescript", {
1112
start: [
1213
// string and byte string
@@ -35,22 +36,18 @@ CodeMirror.defineSimpleMode("rescript", {
3536
token: ["keyword", "keyword2", null, "def"]
3637
},
3738
{
38-
regex: /(?:switch|module|as|else|external|for|if|in|mod|ref|type|while|open|open\!)\b/,
39+
regex: /(?:and|as|assert|catch|constraint|downto|else|exception|export|external|false|for|if|import|in|include|lazy|let|module|mutable|of|open|private|switch|to|true|try|type|when|while|with\!)\b/,
3940
token: "keyword"
4041
},
4142
{
42-
regex: /(?:rec)\b/,
43+
regex: /(?:rec|list)\b/,
4344
token: "keyword2"
4445
},
4546
{
4647
regex: /\b(?:char|bool|option|int|string)\b/,
4748
token: "atom"
4849
},
4950
{ regex: /\b(?:true|false)\b/, token: "builtin" },
50-
{
51-
regex: /\b(fun)(\s+)([a-zA-Z_\|][a-zA-Z0-9_]*)/,
52-
token: ["keyword", null, "def"]
53-
},
5451
{
5552
regex: /\b([A-Z][a-zA-Z0-9_]*)(\.)/,
5653
token: ["module", null]
@@ -86,6 +83,10 @@ CodeMirror.defineSimpleMode("rescript", {
8683
//{ regex: /"#+/, token: "string", next: "start" },
8784
//{ regex: /(?:[^"]|"(?!#))*/, token: "string" }
8885
//],
86+
list: [
87+
{ regex: /list{/, token: "keyword2", next: "start" },
88+
{ regex: /[^`]*/, token: "string" }
89+
],
8990
string_interpolation: [
9091
{ regex: /`/, token: "string", next: "start" },
9192
{ regex: /[^`]*/, token: "string" }

plugins/res-syntax-highlightjs.js renamed to plugins/rescript-highlightjs.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
Language: New BS Syntax
3-
Author: Gidi Meir Morris <[email protected]>, Cheng Lou
4-
Category: functional
2+
Language: ReScript
3+
Author: Gidi Meir Morris <[email protected]>, Cheng Lou, Patrick Ecker
4+
Category: common
55
*/
66

77
// Note: Extracted and adapted from the reason-highlightjs package:
@@ -25,19 +25,14 @@ module.exports = function(hljs) {
2525
var RE_MODULE_IDENT = '[A-Z_][0-9a-zA-Z_]*';
2626

2727
var KEYWORDS = {
28-
/* https://github.com/facebook/reason/blob/79e67d5334ef181fdb54bd57bd9e7729f9fe46e7/src/reason-parser/reason_lexer.mll#L94-L154 */
28+
// See: https://github.com/rescript-lang/syntax/blob/4872b983eb023f78a972063eb367339e6897bf16/src/res_token.ml#L166
2929
keyword:
30-
'and as assert begin class constraint done downto exception external fun ' +
31-
'functor include inherit lazy let pub mutable new nonrec ' +
32-
'object of open or pri rec then to type val virtual ' +
33-
'try catch finally do else for if switch while import library export ' +
34-
'module in raise ' +
35-
// invalid
36-
'private',
37-
30+
'and as assert catch constraint downto else exception export external false for' +
31+
'if import in include lazy let module mutable of open private rec switch' +
32+
'to true try type when while with',
3833
// not reliable
39-
// built_in:
40-
// 'array bool bytes char exn|5 float int int32 int64 list lazy_t|5 nativeint|5 ref string unit',
34+
//built_in:
35+
//'array bool bytes char exn|5 float int int32 int64 list lazy_t|5 nativeint|5 ref string unit',
4136
literal:
4237
'true false'
4338
};
@@ -119,13 +114,13 @@ module.exports = function(hljs) {
119114
className: 'literal',
120115
variants: [
121116
{
122-
begin: 'list\\[',
117+
begin: 'list\\{',
123118
},
124119
{
125-
begin: '\\[',
120+
begin: '\\{',
126121
},
127122
{
128-
begin: '\\]',
123+
begin: '\\}',
129124
},
130125
]
131126
};

src/common/App.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common/App.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
let js = require('highlight.js/lib/languages/javascript');
1212
let ocaml = require('highlight.js/lib/languages/ocaml');
1313
let reason = require('plugins/reason-highlightjs');
14-
let res = require('plugins/res-syntax-highlightjs');
14+
let rescript = require('plugins/rescript-highlightjs');
1515
let bash = require('highlight.js/lib/languages/bash');
1616
let json = require('highlight.js/lib/languages/json');
1717
let html = require('highlight.js/lib/languages/xml');
1818
let text = require('highlight.js/lib/languages/plaintext');
1919
let diff = require('highlight.js/lib/languages/diff');
2020
2121
hljs.registerLanguage('reason', reason);
22-
hljs.registerLanguage('res', res);
22+
hljs.registerLanguage('rescript', rescript);
2323
hljs.registerLanguage('javascript', js);
2424
hljs.registerLanguage('ts', js);
2525
hljs.registerLanguage('ocaml', ocaml);

styles/cm.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
}
101101

102102
.cm-s-material .cm-builtin {
103-
color: #FFCB6B;
103+
@apply text-orange-dark;
104104
}
105105

106106
.cm-s-material .cm-decorator {

0 commit comments

Comments
 (0)