Skip to content

Commit

Permalink
Haskell: Improvements (#2535)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Aug 28, 2020
1 parent c51abab commit e023044
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
13 changes: 8 additions & 5 deletions components/prism-haskell.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
Prism.languages.haskell = {
'comment': {
pattern: /(^|[^-!#$%*+=?&@|~.:<>^\\\/])(?:--[^-!#$%*+=?&@|~.:<>^\\\/].*|{-[\s\S]*?-})/m,
pattern: /(^|[^-!#$%*+=?&@|~.:<>^\\\/])(?:--(?:(?=.)[^-!#$%*+=?&@|~.:<>^\\\/].*|$)|{-[\s\S]*?-})/m,
lookbehind: true
},
'char': /'(?:[^\\']|\\(?:[abfnrtv\\"'&]|\^[A-Z@[\]^_]|NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS|HT|LF|VT|FF|CR|SO|SI|DLE|DC1|DC2|DC3|DC4|NAK|SYN|ETB|CAN|EM|SUB|ESC|FS|GS|RS|US|SP|DEL|\d+|o[0-7]+|x[0-9a-fA-F]+))'/,
'char': {
pattern: /'(?:[^\\']|\\(?:[abfnrtv\\"'&]|\^[A-Z@[\]^_]|NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS|HT|LF|VT|FF|CR|SO|SI|DLE|DC1|DC2|DC3|DC4|NAK|SYN|ETB|CAN|EM|SUB|ESC|FS|GS|RS|US|SP|DEL|\d+|o[0-7]+|x[0-9a-fA-F]+))'/,
alias: 'string'
},
'string': {
pattern: /"(?:[^\\"]|\\(?:[abfnrtv\\"'&]|\^[A-Z@[\]^_]|NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS|HT|LF|VT|FF|CR|SO|SI|DLE|DC1|DC2|DC3|DC4|NAK|SYN|ETB|CAN|EM|SUB|ESC|FS|GS|RS|US|SP|DEL|\d+|o[0-7]+|x[0-9a-fA-F]+)|\\\s+\\)*"/,
pattern: /"(?:[^\\"]|\\(?:\S|\s+\\))*"/,
greedy: true
},
'keyword': /\b(?:case|class|data|deriving|do|else|if|in|infixl|infixr|instance|let|module|newtype|of|primitive|then|type|where)\b/,
'import_statement': {
'import-statement': {
// The imported or hidden names are not included in this import
// statement. This is because we want to highlight those exactly like
// we do for the names in the program.
pattern: /((?:\r?\n|\r|^)\s*)import\s+(?:qualified\s+)?(?:[A-Z][\w']*)(?:\.[A-Z][\w']*)*(?:\s+as\s+(?:[A-Z][_a-zA-Z0-9']*)(?:\.[A-Z][\w']*)*)?(?:\s+hiding\b)?/m,
pattern: /(^\s*)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/
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.

8 changes: 6 additions & 2 deletions tests/languages/haskell/comment_feature.test
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
--
-- foo
{- foo
bar -}
{--}

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

[
["comment", "--"],
["comment", "-- foo"],
["comment", "{- foo\r\nbar -}"]
["comment", "{- foo\r\nbar -}"],
["comment", "{--}"]
]

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

Checks for single-line and multi-line comments.
Checks for single-line and multi-line comments.
10 changes: 5 additions & 5 deletions tests/languages/haskell/import_statement_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import Foo.Bar as Foo.Baz hiding
----------------------------------------------------

[
["import_statement", [
["import-statement", [
["keyword", "import"],
" Foo"
]],
["import_statement", [
["import-statement", [
["keyword", "import"],
["keyword", "qualified"],
" Foobar"
]],
["import_statement", [
["import-statement", [
["keyword", "import"],
" Foo_42.Bar ",
["keyword", "as"],
" Foobar"
]],
["import_statement", [
["import-statement", [
["keyword", "import"],
" Foo.Bar ",
["keyword", "as"],
Expand All @@ -32,4 +32,4 @@ import Foo.Bar as Foo.Baz hiding

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

Checks for import statement.
Checks for import statement.

0 comments on commit e023044

Please sign in to comment.