Skip to content

Commit 679539e

Browse files
Improved Haskell and PureScript (#3020)
1 parent ce5e0f0 commit 679539e

17 files changed

+488
-108
lines changed

components/prism-haskell.js

+34-9
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,47 @@ Prism.languages.haskell = {
1919
pattern: /(^[\t ]*)import\s+(?:qualified\s+)?(?:[A-Z][\w']*)(?:\.[A-Z][\w']*)*(?:\s+as\s+(?:[A-Z][\w']*)(?:\.[A-Z][\w']*)*)?(?:\s+hiding\b)?/m,
2020
lookbehind: true,
2121
inside: {
22-
'keyword': /\b(?:import|qualified|as|hiding)\b/
22+
'keyword': /\b(?:import|qualified|as|hiding)\b/,
23+
'punctuation': /\./
2324
}
2425
},
2526
// These are builtin variables only. Constructors are highlighted later as a constant.
2627
'builtin': /\b(?:abs|acos|acosh|all|and|any|appendFile|approxRational|asTypeOf|asin|asinh|atan|atan2|atanh|basicIORun|break|catch|ceiling|chr|compare|concat|concatMap|const|cos|cosh|curry|cycle|decodeFloat|denominator|digitToInt|div|divMod|drop|dropWhile|either|elem|encodeFloat|enumFrom|enumFromThen|enumFromThenTo|enumFromTo|error|even|exp|exponent|fail|filter|flip|floatDigits|floatRadix|floatRange|floor|fmap|foldl|foldl1|foldr|foldr1|fromDouble|fromEnum|fromInt|fromInteger|fromIntegral|fromRational|fst|gcd|getChar|getContents|getLine|group|head|id|inRange|index|init|intToDigit|interact|ioError|isAlpha|isAlphaNum|isAscii|isControl|isDenormalized|isDigit|isHexDigit|isIEEE|isInfinite|isLower|isNaN|isNegativeZero|isOctDigit|isPrint|isSpace|isUpper|iterate|last|lcm|length|lex|lexDigits|lexLitChar|lines|log|logBase|lookup|map|mapM|mapM_|max|maxBound|maximum|maybe|min|minBound|minimum|mod|negate|not|notElem|null|numerator|odd|or|ord|otherwise|pack|pi|pred|primExitWith|print|product|properFraction|putChar|putStr|putStrLn|quot|quotRem|range|rangeSize|read|readDec|readFile|readFloat|readHex|readIO|readInt|readList|readLitChar|readLn|readOct|readParen|readSigned|reads|readsPrec|realToFrac|recip|rem|repeat|replicate|return|reverse|round|scaleFloat|scanl|scanl1|scanr|scanr1|seq|sequence|sequence_|show|showChar|showInt|showList|showLitChar|showParen|showSigned|showString|shows|showsPrec|significand|signum|sin|sinh|snd|sort|span|splitAt|sqrt|subtract|succ|sum|tail|take|takeWhile|tan|tanh|threadToIOResult|toEnum|toInt|toInteger|toLower|toRational|toUpper|truncate|uncurry|undefined|unlines|until|unwords|unzip|unzip3|userError|words|writeFile|zip|zip3|zipWith|zipWith3)\b/,
2728
// decimal integers and floating point numbers | octal integers | hexadecimal integers
2829
'number': /\b(?:\d+(?:\.\d+)?(?:e[+-]?\d+)?|0o[0-7]+|0x[0-9a-f]+)\b/i,
29-
// Most of this is needed because of the meaning of a single '.'.
30-
// If it stands alone freely, it is the function composition.
31-
// It may also be a separator between a module name and an identifier => no
32-
// operator. If it comes together with other special characters it is an
33-
// operator too.
34-
'operator': /\s\.\s|[-!#$%*+=?&@|~:<>^\\\/]*\.[-!#$%*+=?&@|~.:<>^\\\/]+|[-!#$%*+=?&@|~.:<>^\\\/]+\.[-!#$%*+=?&@|~:<>^\\\/]*|[-!#$%*+=?&@|~:<>^\\\/]+|`(?:[A-Z][\w']*\.)*[_a-z][\w']*`/,
30+
'operator': [
31+
{
32+
// infix operator
33+
pattern: /`(?:[A-Z][\w']*\.)*[_a-z][\w']*`/,
34+
greedy: true
35+
},
36+
{
37+
// function composition
38+
pattern: /(\s)\.(?=\s)/,
39+
lookbehind: true
40+
},
41+
// Most of this is needed because of the meaning of a single '.'.
42+
// If it stands alone freely, it is the function composition.
43+
// It may also be a separator between a module name and an identifier => no
44+
// operator. If it comes together with other special characters it is an
45+
// operator too.
46+
//
47+
// This regex means: /[-!#$%*+=?&@|~.:<>^\\\/]+/ without /\./.
48+
/[-!#$%*+=?&@|~:<>^\\\/][-!#$%*+=?&@|~.:<>^\\\/]*|\.[-!#$%*+=?&@|~.:<>^\\\/]+/,
49+
],
3550
// In Haskell, nearly everything is a variable, do not highlight these.
36-
'hvariable': /\b(?:[A-Z][\w']*\.)*[_a-z][\w']*\b/,
37-
'constant': /\b(?:[A-Z][\w']*\.)*[A-Z][\w']*\b/,
51+
'hvariable': {
52+
pattern: /\b(?:[A-Z][\w']*\.)*[_a-z][\w']*/,
53+
inside: {
54+
'punctuation': /\./
55+
}
56+
},
57+
'constant': {
58+
pattern: /\b(?:[A-Z][\w']*\.)*[A-Z][\w']*/,
59+
inside: {
60+
'punctuation': /\./
61+
}
62+
},
3863
'punctuation': /[{}[\];(),.:]/
3964
};
4065

components/prism-haskell.min.js

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

components/prism-purescript.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,24 @@ Prism.languages.purescript = Prism.languages.extend('haskell', {
88
pattern: /(^[\t ]*)import\s+[A-Z][\w']*(?:\.[A-Z][\w']*)*(?:\s+as\s+[A-Z][\w']*(?:\.[A-Z][\w']*)*)?(?:\s+hiding\b)?/m,
99
lookbehind: true,
1010
inside: {
11-
'keyword': /\b(?:import|as|hiding)\b/
11+
'keyword': /\b(?:import|as|hiding)\b/,
12+
'punctuation': /\./
1213
}
1314
},
1415

1516
// These are builtin functions only. Constructors are highlighted later as a constant.
1617
'builtin': /\b(?:absurd|add|ap|append|apply|between|bind|bottom|clamp|compare|comparing|compose|conj|const|degree|discard|disj|div|eq|flap|flip|gcd|identity|ifM|join|lcm|liftA1|liftM1|map|max|mempty|min|mod|mul|negate|not|notEq|one|otherwise|recip|show|sub|top|unit|unless|unlessM|void|when|whenM|zero)\b/,
18+
19+
'operator': [
20+
// Infix operators
21+
Prism.languages.haskell.operator[0],
22+
// ASCII operators
23+
Prism.languages.haskell.operator[2],
24+
// All UTF16 Unicode operator symbols
25+
// This regex is equivalent to /(?=[\x80-\uFFFF])[\p{gc=Math_Symbol}\p{gc=Currency_Symbol}\p{Modifier_Symbol}\p{Other_Symbol}]/u
26+
// See https://github.com/PrismJS/prism/issues/3006 for more details.
27+
/[\xa2-\xa6\xa8\xa9\xac\xae-\xb1\xb4\xb8\xd7\xf7\u02c2-\u02c5\u02d2-\u02df\u02e5-\u02eb\u02ed\u02ef-\u02ff\u0375\u0384\u0385\u03f6\u0482\u058d-\u058f\u0606-\u0608\u060b\u060e\u060f\u06de\u06e9\u06fd\u06fe\u07f6\u07fe\u07ff\u09f2\u09f3\u09fa\u09fb\u0af1\u0b70\u0bf3-\u0bfa\u0c7f\u0d4f\u0d79\u0e3f\u0f01-\u0f03\u0f13\u0f15-\u0f17\u0f1a-\u0f1f\u0f34\u0f36\u0f38\u0fbe-\u0fc5\u0fc7-\u0fcc\u0fce\u0fcf\u0fd5-\u0fd8\u109e\u109f\u1390-\u1399\u166d\u17db\u1940\u19de-\u19ff\u1b61-\u1b6a\u1b74-\u1b7c\u1fbd\u1fbf-\u1fc1\u1fcd-\u1fcf\u1fdd-\u1fdf\u1fed-\u1fef\u1ffd\u1ffe\u2044\u2052\u207a-\u207c\u208a-\u208c\u20a0-\u20bf\u2100\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211e-\u2123\u2125\u2127\u2129\u212e\u213a\u213b\u2140-\u2144\u214a-\u214d\u214f\u218a\u218b\u2190-\u2307\u230c-\u2328\u232b-\u2426\u2440-\u244a\u249c-\u24e9\u2500-\u2767\u2794-\u27c4\u27c7-\u27e5\u27f0-\u2982\u2999-\u29d7\u29dc-\u29fb\u29fe-\u2b73\u2b76-\u2b95\u2b97-\u2bff\u2ce5-\u2cea\u2e50\u2e51\u2e80-\u2e99\u2e9b-\u2ef3\u2f00-\u2fd5\u2ff0-\u2ffb\u3004\u3012\u3013\u3020\u3036\u3037\u303e\u303f\u309b\u309c\u3190\u3191\u3196-\u319f\u31c0-\u31e3\u3200-\u321e\u322a-\u3247\u3250\u3260-\u327f\u328a-\u32b0\u32c0-\u33ff\u4dc0-\u4dff\ua490-\ua4c6\ua700-\ua716\ua720\ua721\ua789\ua78a\ua828-\ua82b\ua836-\ua839\uaa77-\uaa79\uab5b\uab6a\uab6b\ufb29\ufbb2-\ufbc1\ufdfc\ufdfd\ufe62\ufe64-\ufe66\ufe69\uff04\uff0b\uff1c-\uff1e\uff3e\uff40\uff5c\uff5e\uffe0-\uffe6\uffe8-\uffee\ufffc\ufffd]/
28+
]
1729
});
1830

1931
Prism.languages.purs = Prism.languages.purescript;

components/prism-purescript.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+14-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
Foo
2+
Foo'
23
Foo.Bar
34
Baz.Foobar_42
45

56
----------------------------------------------------
67

78
[
8-
["constant", "Foo"],
9-
["constant", "Foo.Bar"],
10-
["constant", "Baz.Foobar_42"]
9+
["constant", ["Foo"]],
10+
["constant", ["Foo'"]],
11+
["constant", [
12+
"Foo",
13+
["punctuation", "."],
14+
"Bar"
15+
]],
16+
["constant", [
17+
"Baz",
18+
["punctuation", "."],
19+
"Foobar_42"
20+
]]
1121
]
1222

1323
----------------------------------------------------
1424

15-
Checks for constants.
25+
Checks for constants.
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
foo
2+
foo'
23
Foo.bar
34
Baz.foobar_42
45

56
----------------------------------------------------
67

78
[
8-
["hvariable", "foo"],
9-
["hvariable", "Foo.bar"],
10-
["hvariable", "Baz.foobar_42"]
9+
["hvariable", ["foo"]],
10+
["hvariable", ["foo'"]],
11+
["hvariable", [
12+
"Foo",
13+
["punctuation", "."],
14+
"bar"
15+
]],
16+
["hvariable", [
17+
"Baz",
18+
["punctuation", "."],
19+
"foobar_42"
20+
]]
1121
]
1222

1323
----------------------------------------------------
1424

15-
Checks for hvariables.
25+
Checks for hvariables.

tests/languages/haskell/import_statement_feature.test

+9-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,21 @@ import Foo.Bar as Foo.Baz hiding
1717
]],
1818
["import-statement", [
1919
["keyword", "import"],
20-
" Foo_42.Bar ",
20+
" Foo_42",
21+
["punctuation", "."],
22+
"Bar ",
2123
["keyword", "as"],
2224
" Foobar"
2325
]],
2426
["import-statement", [
2527
["keyword", "import"],
26-
" Foo.Bar ",
28+
" Foo",
29+
["punctuation", "."],
30+
"Bar ",
2731
["keyword", "as"],
28-
" Foo.Baz ",
32+
" Foo",
33+
["punctuation", "."],
34+
"Baz ",
2935
["keyword", "hiding"]
3036
]]
3137
]

tests/languages/haskell/operator_feature.test

+49-12
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,58 @@ reverse . sort
1717

1818
[
1919
["operator", ".."],
20-
["builtin", "reverse"], ["operator", " . "], ["builtin", "sort"],
20+
21+
["builtin", "reverse"],
22+
["operator", "."],
23+
["builtin", "sort"],
24+
2125
["operator", "`foo`"],
26+
2227
["operator", "`Foo.bar`"],
23-
["operator", "+"], ["operator", "-"], ["operator", "*"], ["operator", "/"],
24-
["operator", "^"], ["operator", "^^"], ["operator", "**"],
25-
["operator", "&&"], ["operator", "||"],
26-
["operator", "<"], ["operator", "<="], ["operator", "=="], ["operator", "/="],
27-
["operator", ">="], ["operator", ">"], ["operator", "\\"], ["operator", "|"],
28-
["operator", "++"], ["operator", ":"], ["operator", "!!"],
29-
["operator", "\\\\"], ["operator", "<-"], ["operator", "->"],
30-
["operator", "="], ["operator", "::"], ["operator", "=>"],
31-
["operator", ">>"], ["operator", ">>="], ["operator", ">@>"],
32-
["operator", "~"], ["operator", "!"], ["operator", "@"]
28+
29+
["operator", "+"],
30+
["operator", "-"],
31+
["operator", "*"],
32+
["operator", "/"],
33+
34+
["operator", "^"],
35+
["operator", "^^"],
36+
["operator", "**"],
37+
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", "++"],
52+
["operator", ":"],
53+
["operator", "!!"],
54+
55+
["operator", "\\\\"],
56+
["operator", "<-"],
57+
["operator", "->"],
58+
59+
["operator", "="],
60+
["operator", "::"],
61+
["operator", "=>"],
62+
63+
["operator", ">>"],
64+
["operator", ">>="],
65+
["operator", ">@>"],
66+
67+
["operator", "~"],
68+
["operator", "!"],
69+
["operator", "@"]
3370
]
3471

3572
----------------------------------------------------
3673

37-
Checks for operators.
74+
Checks for operators.

tests/languages/idris/constant_feature.test

+12-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@ Baz.Foobar_42
55
----------------------------------------------------
66

77
[
8-
["constant", "Foo"],
9-
["constant", "Foo.Bar"],
10-
["constant", "Baz.Foobar_42"]
8+
["constant", ["Foo"]],
9+
["constant", [
10+
"Foo",
11+
["punctuation", "."],
12+
"Bar"
13+
]],
14+
["constant", [
15+
"Baz",
16+
["punctuation", "."],
17+
"Foobar_42"
18+
]]
1119
]
1220

1321
----------------------------------------------------
1422

15-
Checks for constants.
23+
Checks for constants.

tests/languages/idris/hvariable_feature.test

+12-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@ Baz.foobar_42
55
----------------------------------------------------
66

77
[
8-
["hvariable", "foo"],
9-
["hvariable", "Foo.bar"],
10-
["hvariable", "Baz.foobar_42"]
8+
["hvariable", ["foo"]],
9+
["hvariable", [
10+
"Foo",
11+
["punctuation", "."],
12+
"bar"
13+
]],
14+
["hvariable", [
15+
"Baz",
16+
["punctuation", "."],
17+
"foobar_42"
18+
]]
1119
]
1220

1321
----------------------------------------------------
1422

15-
Checks for hvariables.
23+
Checks for hvariables.

tests/languages/idris/import_statement_feature.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Foo
44

55
[
66
["keyword", "import"],
7-
["constant", "Foo"]
7+
["constant", ["Foo"]]
88
]
99

1010
----------------------------------------------------

0 commit comments

Comments
 (0)