Skip to content

Commit

Permalink
Improved Haskell and PureScript (#3020)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Jul 30, 2021
1 parent ce5e0f0 commit 679539e
Show file tree
Hide file tree
Showing 17 changed files with 488 additions and 108 deletions.
43 changes: 34 additions & 9 deletions components/prism-haskell.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,47 @@ Prism.languages.haskell = {
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,
lookbehind: true,
inside: {
'keyword': /\b(?:import|qualified|as|hiding)\b/
'keyword': /\b(?:import|qualified|as|hiding)\b/,
'punctuation': /\./
}
},
// These are builtin variables only. Constructors are highlighted later as a constant.
'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/,
// decimal integers and floating point numbers | octal integers | hexadecimal integers
'number': /\b(?:\d+(?:\.\d+)?(?:e[+-]?\d+)?|0o[0-7]+|0x[0-9a-f]+)\b/i,
// Most of this is needed because of the meaning of a single '.'.
// If it stands alone freely, it is the function composition.
// It may also be a separator between a module name and an identifier => no
// operator. If it comes together with other special characters it is an
// operator too.
'operator': /\s\.\s|[-!#$%*+=?&@|~:<>^\\\/]*\.[-!#$%*+=?&@|~.:<>^\\\/]+|[-!#$%*+=?&@|~.:<>^\\\/]+\.[-!#$%*+=?&@|~:<>^\\\/]*|[-!#$%*+=?&@|~:<>^\\\/]+|`(?:[A-Z][\w']*\.)*[_a-z][\w']*`/,
'operator': [
{
// infix operator
pattern: /`(?:[A-Z][\w']*\.)*[_a-z][\w']*`/,
greedy: true
},
{
// function composition
pattern: /(\s)\.(?=\s)/,
lookbehind: true
},
// Most of this is needed because of the meaning of a single '.'.
// If it stands alone freely, it is the function composition.
// It may also be a separator between a module name and an identifier => no
// operator. If it comes together with other special characters it is an
// operator too.
//
// This regex means: /[-!#$%*+=?&@|~.:<>^\\\/]+/ without /\./.
/[-!#$%*+=?&@|~:<>^\\\/][-!#$%*+=?&@|~.:<>^\\\/]*|\.[-!#$%*+=?&@|~.:<>^\\\/]+/,
],
// In Haskell, nearly everything is a variable, do not highlight these.
'hvariable': /\b(?:[A-Z][\w']*\.)*[_a-z][\w']*\b/,
'constant': /\b(?:[A-Z][\w']*\.)*[A-Z][\w']*\b/,
'hvariable': {
pattern: /\b(?:[A-Z][\w']*\.)*[_a-z][\w']*/,
inside: {
'punctuation': /\./
}
},
'constant': {
pattern: /\b(?:[A-Z][\w']*\.)*[A-Z][\w']*/,
inside: {
'punctuation': /\./
}
},
'punctuation': /[{}[\];(),.:]/
};

Expand Down
2 changes: 1 addition & 1 deletion components/prism-haskell.min.js

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

14 changes: 13 additions & 1 deletion components/prism-purescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@ Prism.languages.purescript = Prism.languages.extend('haskell', {
pattern: /(^[\t ]*)import\s+[A-Z][\w']*(?:\.[A-Z][\w']*)*(?:\s+as\s+[A-Z][\w']*(?:\.[A-Z][\w']*)*)?(?:\s+hiding\b)?/m,
lookbehind: true,
inside: {
'keyword': /\b(?:import|as|hiding)\b/
'keyword': /\b(?:import|as|hiding)\b/,
'punctuation': /\./
}
},

// These are builtin functions only. Constructors are highlighted later as a constant.
'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/,

'operator': [
// Infix operators
Prism.languages.haskell.operator[0],
// ASCII operators
Prism.languages.haskell.operator[2],
// All UTF16 Unicode operator symbols
// This regex is equivalent to /(?=[\x80-\uFFFF])[\p{gc=Math_Symbol}\p{gc=Currency_Symbol}\p{Modifier_Symbol}\p{Other_Symbol}]/u
// See https://github.com/PrismJS/prism/issues/3006 for more details.
/[\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]/
]
});

Prism.languages.purs = Prism.languages.purescript;
2 changes: 1 addition & 1 deletion components/prism-purescript.min.js

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

18 changes: 14 additions & 4 deletions tests/languages/haskell/constant_feature.test
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
Foo
Foo'
Foo.Bar
Baz.Foobar_42

----------------------------------------------------

[
["constant", "Foo"],
["constant", "Foo.Bar"],
["constant", "Baz.Foobar_42"]
["constant", ["Foo"]],
["constant", ["Foo'"]],
["constant", [
"Foo",
["punctuation", "."],
"Bar"
]],
["constant", [
"Baz",
["punctuation", "."],
"Foobar_42"
]]
]

----------------------------------------------------

Checks for constants.
Checks for constants.
18 changes: 14 additions & 4 deletions tests/languages/haskell/hvariable_feature.test
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
foo
foo'
Foo.bar
Baz.foobar_42

----------------------------------------------------

[
["hvariable", "foo"],
["hvariable", "Foo.bar"],
["hvariable", "Baz.foobar_42"]
["hvariable", ["foo"]],
["hvariable", ["foo'"]],
["hvariable", [
"Foo",
["punctuation", "."],
"bar"
]],
["hvariable", [
"Baz",
["punctuation", "."],
"foobar_42"
]]
]

----------------------------------------------------

Checks for hvariables.
Checks for hvariables.
12 changes: 9 additions & 3 deletions tests/languages/haskell/import_statement_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ import Foo.Bar as Foo.Baz hiding
]],
["import-statement", [
["keyword", "import"],
" Foo_42.Bar ",
" Foo_42",
["punctuation", "."],
"Bar ",
["keyword", "as"],
" Foobar"
]],
["import-statement", [
["keyword", "import"],
" Foo.Bar ",
" Foo",
["punctuation", "."],
"Bar ",
["keyword", "as"],
" Foo.Baz ",
" Foo",
["punctuation", "."],
"Baz ",
["keyword", "hiding"]
]]
]
Expand Down
61 changes: 49 additions & 12 deletions tests/languages/haskell/operator_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,58 @@ reverse . sort

[
["operator", ".."],
["builtin", "reverse"], ["operator", " . "], ["builtin", "sort"],

["builtin", "reverse"],
["operator", "."],
["builtin", "sort"],

["operator", "`foo`"],

["operator", "`Foo.bar`"],
["operator", "+"], ["operator", "-"], ["operator", "*"], ["operator", "/"],
["operator", "^"], ["operator", "^^"], ["operator", "**"],
["operator", "&&"], ["operator", "||"],
["operator", "<"], ["operator", "<="], ["operator", "=="], ["operator", "/="],
["operator", ">="], ["operator", ">"], ["operator", "\\"], ["operator", "|"],
["operator", "++"], ["operator", ":"], ["operator", "!!"],
["operator", "\\\\"], ["operator", "<-"], ["operator", "->"],
["operator", "="], ["operator", "::"], ["operator", "=>"],
["operator", ">>"], ["operator", ">>="], ["operator", ">@>"],
["operator", "~"], ["operator", "!"], ["operator", "@"]

["operator", "+"],
["operator", "-"],
["operator", "*"],
["operator", "/"],

["operator", "^"],
["operator", "^^"],
["operator", "**"],

["operator", "&&"],
["operator", "||"],

["operator", "<"],
["operator", "<="],
["operator", "=="],
["operator", "/="],

["operator", ">="],
["operator", ">"],
["operator", "\\"],
["operator", "|"],

["operator", "++"],
["operator", ":"],
["operator", "!!"],

["operator", "\\\\"],
["operator", "<-"],
["operator", "->"],

["operator", "="],
["operator", "::"],
["operator", "=>"],

["operator", ">>"],
["operator", ">>="],
["operator", ">@>"],

["operator", "~"],
["operator", "!"],
["operator", "@"]
]

----------------------------------------------------

Checks for operators.
Checks for operators.
16 changes: 12 additions & 4 deletions tests/languages/idris/constant_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ Baz.Foobar_42
----------------------------------------------------

[
["constant", "Foo"],
["constant", "Foo.Bar"],
["constant", "Baz.Foobar_42"]
["constant", ["Foo"]],
["constant", [
"Foo",
["punctuation", "."],
"Bar"
]],
["constant", [
"Baz",
["punctuation", "."],
"Foobar_42"
]]
]

----------------------------------------------------

Checks for constants.
Checks for constants.
16 changes: 12 additions & 4 deletions tests/languages/idris/hvariable_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ Baz.foobar_42
----------------------------------------------------

[
["hvariable", "foo"],
["hvariable", "Foo.bar"],
["hvariable", "Baz.foobar_42"]
["hvariable", ["foo"]],
["hvariable", [
"Foo",
["punctuation", "."],
"bar"
]],
["hvariable", [
"Baz",
["punctuation", "."],
"foobar_42"
]]
]

----------------------------------------------------

Checks for hvariables.
Checks for hvariables.
2 changes: 1 addition & 1 deletion tests/languages/idris/import_statement_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Foo

[
["keyword", "import"],
["constant", "Foo"]
["constant", ["Foo"]]
]

----------------------------------------------------
Expand Down
Loading

0 comments on commit 679539e

Please sign in to comment.