<NME> haskell.js
<BEF> /*
Language: Haskell
Author: Jeremy Hull <sourdrums@gmail.com>
Contributors: Zena Treep <zena.treep@gmail.com>
Website: https://www.haskell.org
Category: functional
*/

export default function(hljs) {
  const COMMENT = { variants: [
    hljs.COMMENT('--', '$'),
    hljs.COMMENT(
      /\{-/,
      /-\}/,
      { contains: [ 'self' ] }
    )
  ] };

  const PRAGMA = {
    className: 'meta',
    begin: /\{-#/,
    end: /#-\}/
  };

  const PREPROCESSOR = {
    className: 'meta',
    begin: '^#',
    end: '$'
  };

  const CONSTRUCTOR = {
    className: 'type',
    begin: '\\b[A-Z][\\w\']*', // TODO: other constructors (build-in, infix).
  // Value, type, class constructors.
  var CONSTRUCTOR = {
    className: 'haskell_constructor',
    begin: '\\b[A-Z][\\w\']*',
    relevance: 0
  };

    contains: [
      PRAGMA,
      PREPROCESSOR,
      {
        className: 'type',
        begin: '\\b[A-Z][\\w]*(\\((\\.\\.|,|\\w+)\\))?'
      },
      hljs.inherit(hljs.TITLE_MODE, { begin: '[_a-z][\\w\']*' }),
      COMMENT
    ]
  };

  const RECORD = {
    begin: /\{/,
    end: /\}/,
    contains: LIST.contains
  };

  /* See:

     - https://www.haskell.org/onlinereport/lexemes.html
     - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/binary_literals.html
     - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/numeric_underscores.html
     - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/hex_float_literals.html

  */
  const decimalDigits = '([0-9]_*)+';
  const hexDigits = '([0-9a-fA-F]_*)+';
  const binaryDigits = '([01]_*)+';
  const octalDigits = '([0-7]_*)+';

      {
        className: 'haskell_module',
        begin: '\\bmodule', end: 'where',
        keywords: 'module where',
        contains: [LIST, COMMENT2],
        illegal: '\\W\\.|;'
      },
      {
        className: 'haskell_import',
        begin: '\\bimport', end: '$',
        keywords: 'import qualified as hiding',
        contains: [LIST, COMMENT1, COMMENT2],
        illegal: '\\W\\.|;'
  };

      {
        className: 'haskell_class',
        begin: '\\b(class|instance)', end: 'where',
        keywords: 'class family instance where',
        contains: [CONSTRUCTOR, LIST, COMMENT2]
      },
      {
        className: 'haskell_type',
        begin: '\\b(data|(new)?type)', end: '$',
        keywords: 'data family type newtype deriving',
        contains: [CONSTRUCTOR, LIST, RECORD, COMMENT1, COMMENT2]
      },
      {
        className: 'haskell_default',
        begin: '\\bdefault', end: '$',
        keywords: 'default',
        contains: [CONSTRUCTOR, LIST, COMMENT1, COMMENT2]
      },
      {
        className: 'haskell_infix',
        begin: '\\b(infix|infixl|infixr)', end: '$',
        keywords: 'infix infixl infixr',
        contains: [hljs.C_NUMBER_MODE, COMMENT1, COMMENT2]
      },
      {
        className: 'haskell_foreign',
        begin: '\\bforeign', end: '$',
        keywords: 'foreign import export ccall stdcall cplusplus jvm dotnet safe unsafe',
        contains: [CONSTRUCTOR, hljs.QUOTE_STRING_MODE, COMMENT1, COMMENT2]
      },
      {
        className: 'class',
        begin: '^(\\s*)?(class|instance)\\b',
        end: 'where',
        keywords: 'class family instance where',
        contains: [
          CONSTRUCTOR,
          LIST,
          COMMENT
        ]
      },

      // Literals and names.

      {
        className: 'haskell_char',
        begin: '\\s+\'', end: '\'',
        contains: [hljs.BACKSLASH_ESCAPE],
        relevance: 0
      },
      hljs.QUOTE_STRING_MODE,
      hljs.C_NUMBER_MODE,
      CONSTRUCTOR,
          CONSTRUCTOR,
          LIST,
          RECORD,
          COMMENT
        ]
      },
      {
        beginKeywords: 'default',
        end: '$',
        contains: [
          CONSTRUCTOR,
          LIST,
          COMMENT
        ]
      },
      {
        beginKeywords: 'infix infixl infixr',
        end: '$',
        contains: [
          hljs.C_NUMBER_MODE,
          COMMENT
        ]
      },
      {
        begin: '\\bforeign\\b',
        end: '$',
        keywords: 'foreign import export ccall stdcall cplusplus jvm '
                  + 'dotnet safe unsafe',
        contains: [
          CONSTRUCTOR,
          hljs.QUOTE_STRING_MODE,
          COMMENT
        ]
      },
      {
        className: 'meta',
        begin: '#!\\/usr\\/bin\\/env\ runhaskell',
        end: '$'
      },
      // "Whitespaces".
      PRAGMA,
      PREPROCESSOR,

      // Literals and names.

      // TODO: characters.
      hljs.QUOTE_STRING_MODE,
      NUMBER,
      CONSTRUCTOR,
      hljs.inherit(hljs.TITLE_MODE, { begin: '^[_a-z][\\w\']*' }),
      COMMENT,
      { // No markup, relevance booster
        begin: '->|<-' }
    ]
  };
}

<MSG> Haskell: bug fixes.

  1. `moduleA`, `importA`, etc. highlighted as `module`, `import`, etc.
  2. Characters don't working (deleted).

<DFF> @@ -34,7 +34,7 @@ function(hljs) {
   // Value, type, class constructors.
   var CONSTRUCTOR = {
     className: 'haskell_constructor',
-    begin: '\\b[A-Z][\\w\']*',
+    begin: '\\b[A-Z][\\w\']*', // TODO: other constructors.
     relevance: 0
   };
 
@@ -71,14 +71,14 @@ function(hljs) {
 
       {
         className: 'haskell_module',
-        begin: '\\bmodule', end: 'where',
+        begin: '\\bmodule\ ', end: 'where',
         keywords: 'module where',
         contains: [LIST, COMMENT2],
         illegal: '\\W\\.|;'
       },
       {
         className: 'haskell_import',
-        begin: '\\bimport', end: '$',
+        begin: '\\bimport\ ', end: '$',
         keywords: 'import qualified as hiding',
         contains: [LIST, COMMENT1, COMMENT2],
         illegal: '\\W\\.|;'
@@ -86,31 +86,31 @@ function(hljs) {
 
       {
         className: 'haskell_class',
-        begin: '\\b(class|instance)', end: 'where',
+        begin: '\\b(class\ |instance\ )', end: 'where',
         keywords: 'class family instance where',
         contains: [CONSTRUCTOR, LIST, COMMENT2]
       },
       {
         className: 'haskell_type',
-        begin: '\\b(data|(new)?type)', end: '$',
+        begin: '\\b(data\ |(new)?type\ )', end: '$',
         keywords: 'data family type newtype deriving',
         contains: [CONSTRUCTOR, LIST, RECORD, COMMENT1, COMMENT2]
       },
       {
         className: 'haskell_default',
-        begin: '\\bdefault', end: '$',
+        begin: '\\bdefault\ ', end: '$',
         keywords: 'default',
         contains: [CONSTRUCTOR, LIST, COMMENT1, COMMENT2]
       },
       {
         className: 'haskell_infix',
-        begin: '\\b(infix|infixl|infixr)', end: '$',
+        begin: '\\b(infix\ |infixl\ |infixr\ )', end: '$',
         keywords: 'infix infixl infixr',
         contains: [hljs.C_NUMBER_MODE, COMMENT1, COMMENT2]
       },
       {
         className: 'haskell_foreign',
-        begin: '\\bforeign', end: '$',
+        begin: '\\bforeign\ ', end: '$',
         keywords: 'foreign import export ccall stdcall cplusplus jvm dotnet safe unsafe',
         contains: [CONSTRUCTOR, hljs.QUOTE_STRING_MODE, COMMENT1, COMMENT2]
       },
@@ -128,12 +128,7 @@ function(hljs) {
 
       // Literals and names.
 
-      {
-        className: 'haskell_char',
-        begin: '\\s+\'', end: '\'',
-        contains: [hljs.BACKSLASH_ESCAPE],
-        relevance: 0
-      },
+      // TODO: characters.
       hljs.QUOTE_STRING_MODE,
       hljs.C_NUMBER_MODE,
       CONSTRUCTOR,

{'commit': "diff --git a/src/languages/haskell.js b/src/languages/haskell.js\nindex d196595a..0167609c 100644\n--- a/src/languages/haskell.js\n+++ b/src/languages/haskell.js\n@@ -34,7 +34,7 @@ function(hljs) {\n   // Value, type, class constructors.\n   var CONSTRUCTOR = {\n     className: 'haskell_constructor',\n-    begin: '\\\\b[A-Z][\\\\w\\']*',\n+    begin: '\\\\b[A-Z][\\\\w\\']*', // TODO: other constructors.\n     relevance: 0\n   };\n \n@@ -71,14 +71,14 @@ function(hljs) {\n \n       {\n         className: 'haskell_module',\n-        begin: '\\\\bmodule', end: 'where',\n+        begin: '\\\\bmodule\\ ', end: 'where',\n         keywords: 'module where',\n         contains: [LIST, COMMENT2],\n         illegal: '\\\\W\\\\.|;'\n       },\n       {\n         className: 'haskell_import',\n-        begin: '\\\\bimport', end: '$',\n+        begin: '\\\\bimport\\ ', end: '$',\n         keywords: 'import qualified as hiding',\n         contains: [LIST, COMMENT1, COMMENT2],\n         illegal: '\\\\W\\\\.|;'\n@@ -86,31 +86,31 @@ function(hljs) {\n \n       {\n         className: 'haskell_class',\n-        begin: '\\\\b(class|instance)', end: 'where',\n+        begin: '\\\\b(class\\ |instance\\ )', end: 'where',\n         keywords: 'class family instance where',\n         contains: [CONSTRUCTOR, LIST, COMMENT2]\n       },\n       {\n         className: 'haskell_type',\n-        begin: '\\\\b(data|(new)?type)', end: '$',\n+        begin: '\\\\b(data\\ |(new)?type\\ )', end: '$',\n         keywords: 'data family type newtype deriving',\n         contains: [CONSTRUCTOR, LIST, RECORD, COMMENT1, COMMENT2]\n       },\n       {\n         className: 'haskell_default',\n-        begin: '\\\\bdefault', end: '$',\n+        begin: '\\\\bdefault\\ ', end: '$',\n         keywords: 'default',\n         contains: [CONSTRUCTOR, LIST, COMMENT1, COMMENT2]\n       },\n       {\n         className: 'haskell_infix',\n-        begin: '\\\\b(infix|infixl|infixr)', end: '$',\n+        begin: '\\\\b(infix\\ |infixl\\ |infixr\\ )', end: '$',\n         keywords: 'infix infixl infixr',\n         contains: [hljs.C_NUMBER_MODE, COMMENT1, COMMENT2]\n       },\n       {\n         className: 'haskell_foreign',\n-        begin: '\\\\bforeign', end: '$',\n+        begin: '\\\\bforeign\\ ', end: '$',\n         keywords: 'foreign import export ccall stdcall cplusplus jvm dotnet safe unsafe',\n         contains: [CONSTRUCTOR, hljs.QUOTE_STRING_MODE, COMMENT1, COMMENT2]\n       },\n@@ -128,12 +128,7 @@ function(hljs) {\n \n       // Literals and names.\n \n-      {\n-        className: 'haskell_char',\n-        begin: '\\\\s+\\'', end: '\\'',\n-        contains: [hljs.BACKSLASH_ESCAPE],\n-        relevance: 0\n-      },\n+      // TODO: characters.\n       hljs.QUOTE_STRING_MODE,\n       hljs.C_NUMBER_MODE,\n       CONSTRUCTOR,\n", 'commit_subject': 'Haskell: bug fixes.', 'repo_name': 'highlightjs/highlight.js', 'committer': {'name': 'Heka Treep', 'email': '75c4f181307bad60a905538b9bad29623efce03d@gmail.com', 'time_sec': '1377344419', 'tz_offset': '240', 'date': {'seconds': '1377344419'}}, 'commit_tree': '7b2b636972d6c9e373c2c18e536d8d826ff9c461', 'commit_message': "Haskell: bug fixes.\n\n  1. `moduleA`, `importA`, etc. highlighted as `module`, `import`, etc.\n  2. Characters don't working (deleted).\n", 'language_name': 'R', 'license': 'bsd-3-clause', 'hunks': "@@ -34,7 +34,7 @@ function(hljs) {\n   // Value, type, class constructors.\n   var CONSTRUCTOR = {\n     className: 'haskell_constructor',\n-    begin: '\\\\b[A-Z][\\\\w\\']*',\n+    begin: '\\\\b[A-Z][\\\\w\\']*', // TODO: other constructors.\n     relevance: 0\n   };\n \n@@ -71,14 +71,14 @@ function(hljs) {\n \n       {\n         className: 'haskell_module',\n-        begin: '\\\\bmodule', end: 'where',\n+        begin: '\\\\bmodule\\ ', end: 'where',\n         keywords: 'module where',\n         contains: [LIST, COMMENT2],\n         illegal: '\\\\W\\\\.|;'\n       },\n       {\n         className: 'haskell_import',\n-        begin: '\\\\bimport', end: '$',\n+        begin: '\\\\bimport\\ ', end: '$',\n         keywords: 'import qualified as hiding',\n         contains: [LIST, COMMENT1, COMMENT2],\n         illegal: '\\\\W\\\\.|;'\n@@ -86,31 +86,31 @@ function(hljs) {\n \n       {\n         className: 'haskell_class',\n-        begin: '\\\\b(class|instance)', end: 'where',\n+        begin: '\\\\b(class\\ |instance\\ )', end: 'where',\n         keywords: 'class family instance where',\n         contains: [CONSTRUCTOR, LIST, COMMENT2]\n       },\n       {\n         className: 'haskell_type',\n-        begin: '\\\\b(data|(new)?type)', end: '$',\n+        begin: '\\\\b(data\\ |(new)?type\\ )', end: '$',\n         keywords: 'data family type newtype deriving',\n         contains: [CONSTRUCTOR, LIST, RECORD, COMMENT1, COMMENT2]\n       },\n       {\n         className: 'haskell_default',\n-        begin: '\\\\bdefault', end: '$',\n+        begin: '\\\\bdefault\\ ', end: '$',\n         keywords: 'default',\n         contains: [CONSTRUCTOR, LIST, COMMENT1, COMMENT2]\n       },\n       {\n         className: 'haskell_infix',\n-        begin: '\\\\b(infix|infixl|infixr)', end: '$',\n+        begin: '\\\\b(infix\\ |infixl\\ |infixr\\ )', end: '$',\n         keywords: 'infix infixl infixr',\n         contains: [hljs.C_NUMBER_MODE, COMMENT1, COMMENT2]\n       },\n       {\n         className: 'haskell_foreign',\n-        begin: '\\\\bforeign', end: '$',\n+        begin: '\\\\bforeign\\ ', end: '$',\n         keywords: 'foreign import export ccall stdcall cplusplus jvm dotnet safe unsafe',\n         contains: [CONSTRUCTOR, hljs.QUOTE_STRING_MODE, COMMENT1, COMMENT2]\n       },\n@@ -128,12 +128,7 @@ function(hljs) {\n \n       // Literals and names.\n \n-      {\n-        className: 'haskell_char',\n-        begin: '\\\\s+\\'', end: '\\'',\n-        contains: [hljs.BACKSLASH_ESCAPE],\n-        relevance: 0\n-      },\n+      // TODO: characters.\n       hljs.QUOTE_STRING_MODE,\n       hljs.C_NUMBER_MODE,\n       CONSTRUCTOR,\n", 'addition_count': 9, 'deletion_count': 14, 'src_file': 'a/src/languages/haskell.js', 'tgt_file': 'b/src/languages/haskell.js', 'file_extension': '.js', 'before_file': '/*\nLanguage: Haskell\nAuthor: Jeremy Hull <sourdrums@gmail.com>\nContributors: Zena Treep <zena.treep@gmail.com>\nWebsite: https://www.haskell.org\nCategory: functional\n*/\n\nexport default function(hljs) {\n  const COMMENT = { variants: [\n    hljs.COMMENT(\'--\', \'$\'),\n    hljs.COMMENT(\n      /\\{-/,\n      /-\\}/,\n      { contains: [ \'self\' ] }\n    )\n  ] };\n\n  const PRAGMA = {\n    className: \'meta\',\n    begin: /\\{-#/,\n    end: /#-\\}/\n  };\n\n  const PREPROCESSOR = {\n    className: \'meta\',\n    begin: \'^#\',\n    end: \'$\'\n  };\n\n  const CONSTRUCTOR = {\n    className: \'type\',\n    begin: \'\\\\b[A-Z][\\\\w\\\']*\', // TODO: other constructors (build-in, infix).\n  // Value, type, class constructors.\n  var CONSTRUCTOR = {\n    className: \'haskell_constructor\',\n    begin: \'\\\\b[A-Z][\\\\w\\\']*\',\n    relevance: 0\n  };\n\n    contains: [\n      PRAGMA,\n      PREPROCESSOR,\n      {\n        className: \'type\',\n        begin: \'\\\\b[A-Z][\\\\w]*(\\\\((\\\\.\\\\.|,|\\\\w+)\\\\))?\'\n      },\n      hljs.inherit(hljs.TITLE_MODE, { begin: \'[_a-z][\\\\w\\\']*\' }),\n      COMMENT\n    ]\n  };\n\n  const RECORD = {\n    begin: /\\{/,\n    end: /\\}/,\n    contains: LIST.contains\n  };\n\n  /* See:\n\n     - https://www.haskell.org/onlinereport/lexemes.html\n     - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/binary_literals.html\n     - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/numeric_underscores.html\n     - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/hex_float_literals.html\n\n  */\n  const decimalDigits = \'([0-9]_*)+\';\n  const hexDigits = \'([0-9a-fA-F]_*)+\';\n  const binaryDigits = \'([01]_*)+\';\n  const octalDigits = \'([0-7]_*)+\';\n\n      {\n        className: \'haskell_module\',\n        begin: \'\\\\bmodule\', end: \'where\',\n        keywords: \'module where\',\n        contains: [LIST, COMMENT2],\n        illegal: \'\\\\W\\\\.|;\'\n      },\n      {\n        className: \'haskell_import\',\n        begin: \'\\\\bimport\', end: \'$\',\n        keywords: \'import qualified as hiding\',\n        contains: [LIST, COMMENT1, COMMENT2],\n        illegal: \'\\\\W\\\\.|;\'\n  };\n\n      {\n        className: \'haskell_class\',\n        begin: \'\\\\b(class|instance)\', end: \'where\',\n        keywords: \'class family instance where\',\n        contains: [CONSTRUCTOR, LIST, COMMENT2]\n      },\n      {\n        className: \'haskell_type\',\n        begin: \'\\\\b(data|(new)?type)\', end: \'$\',\n        keywords: \'data family type newtype deriving\',\n        contains: [CONSTRUCTOR, LIST, RECORD, COMMENT1, COMMENT2]\n      },\n      {\n        className: \'haskell_default\',\n        begin: \'\\\\bdefault\', end: \'$\',\n        keywords: \'default\',\n        contains: [CONSTRUCTOR, LIST, COMMENT1, COMMENT2]\n      },\n      {\n        className: \'haskell_infix\',\n        begin: \'\\\\b(infix|infixl|infixr)\', end: \'$\',\n        keywords: \'infix infixl infixr\',\n        contains: [hljs.C_NUMBER_MODE, COMMENT1, COMMENT2]\n      },\n      {\n        className: \'haskell_foreign\',\n        begin: \'\\\\bforeign\', end: \'$\',\n        keywords: \'foreign import export ccall stdcall cplusplus jvm dotnet safe unsafe\',\n        contains: [CONSTRUCTOR, hljs.QUOTE_STRING_MODE, COMMENT1, COMMENT2]\n      },\n      {\n        className: \'class\',\n        begin: \'^(\\\\s*)?(class|instance)\\\\b\',\n        end: \'where\',\n        keywords: \'class family instance where\',\n        contains: [\n          CONSTRUCTOR,\n          LIST,\n          COMMENT\n        ]\n      },\n\n      // Literals and names.\n\n      {\n        className: \'haskell_char\',\n        begin: \'\\\\s+\\\'\', end: \'\\\'\',\n        contains: [hljs.BACKSLASH_ESCAPE],\n        relevance: 0\n      },\n      hljs.QUOTE_STRING_MODE,\n      hljs.C_NUMBER_MODE,\n      CONSTRUCTOR,\n          CONSTRUCTOR,\n          LIST,\n          RECORD,\n          COMMENT\n        ]\n      },\n      {\n        beginKeywords: \'default\',\n        end: \'$\',\n        contains: [\n          CONSTRUCTOR,\n          LIST,\n          COMMENT\n        ]\n      },\n      {\n        beginKeywords: \'infix infixl infixr\',\n        end: \'$\',\n        contains: [\n          hljs.C_NUMBER_MODE,\n          COMMENT\n        ]\n      },\n      {\n        begin: \'\\\\bforeign\\\\b\',\n        end: \'$\',\n        keywords: \'foreign import export ccall stdcall cplusplus jvm \'\n                  + \'dotnet safe unsafe\',\n        contains: [\n          CONSTRUCTOR,\n          hljs.QUOTE_STRING_MODE,\n          COMMENT\n        ]\n      },\n      {\n        className: \'meta\',\n        begin: \'#!\\\\/usr\\\\/bin\\\\/env\\ runhaskell\',\n        end: \'$\'\n      },\n      // "Whitespaces".\n      PRAGMA,\n      PREPROCESSOR,\n\n      // Literals and names.\n\n      // TODO: characters.\n      hljs.QUOTE_STRING_MODE,\n      NUMBER,\n      CONSTRUCTOR,\n      hljs.inherit(hljs.TITLE_MODE, { begin: \'^[_a-z][\\\\w\\\']*\' }),\n      COMMENT,\n      { // No markup, relevance booster\n        begin: \'->|<-\' }\n    ]\n  };\n}\n', 'message': "Haskell: bug fixes.\n\n  1. `moduleA`, `importA`, etc. highlighted as `module`, `import`, etc.\n  2. Characters don't working (deleted).\n", 'author_name': 'Heka Treep', 'lang': 'js'}