l0bsterssg

node.js static responsive blog post generator
Log | Files | Refs | README

haskell.js (3109B)


      1 /*
      2 Language: Haskell
      3 Author: Jeremy Hull <sourdrums@gmail.com>
      4 Contributors: Zena Treep <zena.treep@gmail.com>
      5 Website: https://www.haskell.org
      6 Category: functional
      7 */
      8 
      9 function haskell(hljs) {
     10   var COMMENT = {
     11     variants: [
     12       hljs.COMMENT('--', '$'),
     13       hljs.COMMENT(
     14         '{-',
     15         '-}',
     16         {
     17           contains: ['self']
     18         }
     19       )
     20     ]
     21   };
     22 
     23   var PRAGMA = {
     24     className: 'meta',
     25     begin: '{-#', end: '#-}'
     26   };
     27 
     28   var PREPROCESSOR = {
     29     className: 'meta',
     30     begin: '^#', end: '$'
     31   };
     32 
     33   var CONSTRUCTOR = {
     34     className: 'type',
     35     begin: '\\b[A-Z][\\w\']*', // TODO: other constructors (build-in, infix).
     36     relevance: 0
     37   };
     38 
     39   var LIST = {
     40     begin: '\\(', end: '\\)',
     41     illegal: '"',
     42     contains: [
     43       PRAGMA,
     44       PREPROCESSOR,
     45       {className: 'type', begin: '\\b[A-Z][\\w]*(\\((\\.\\.|,|\\w+)\\))?'},
     46       hljs.inherit(hljs.TITLE_MODE, {begin: '[_a-z][\\w\']*'}),
     47       COMMENT
     48     ]
     49   };
     50 
     51   var RECORD = {
     52     begin: '{', end: '}',
     53     contains: LIST.contains
     54   };
     55 
     56   return {
     57     name: 'Haskell',
     58     aliases: ['hs'],
     59     keywords:
     60       'let in if then else case of where do module import hiding ' +
     61       'qualified type data newtype deriving class instance as default ' +
     62       'infix infixl infixr foreign export ccall stdcall cplusplus ' +
     63       'jvm dotnet safe unsafe family forall mdo proc rec',
     64     contains: [
     65 
     66       // Top-level constructions.
     67 
     68       {
     69         beginKeywords: 'module', end: 'where',
     70         keywords: 'module where',
     71         contains: [LIST, COMMENT],
     72         illegal: '\\W\\.|;'
     73       },
     74       {
     75         begin: '\\bimport\\b', end: '$',
     76         keywords: 'import qualified as hiding',
     77         contains: [LIST, COMMENT],
     78         illegal: '\\W\\.|;'
     79       },
     80 
     81       {
     82         className: 'class',
     83         begin: '^(\\s*)?(class|instance)\\b', end: 'where',
     84         keywords: 'class family instance where',
     85         contains: [CONSTRUCTOR, LIST, COMMENT]
     86       },
     87       {
     88         className: 'class',
     89         begin: '\\b(data|(new)?type)\\b', end: '$',
     90         keywords: 'data family type newtype deriving',
     91         contains: [PRAGMA, CONSTRUCTOR, LIST, RECORD, COMMENT]
     92       },
     93       {
     94         beginKeywords: 'default', end: '$',
     95         contains: [CONSTRUCTOR, LIST, COMMENT]
     96       },
     97       {
     98         beginKeywords: 'infix infixl infixr', end: '$',
     99         contains: [hljs.C_NUMBER_MODE, COMMENT]
    100       },
    101       {
    102         begin: '\\bforeign\\b', end: '$',
    103         keywords: 'foreign import export ccall stdcall cplusplus jvm ' +
    104                   'dotnet safe unsafe',
    105         contains: [CONSTRUCTOR, hljs.QUOTE_STRING_MODE, COMMENT]
    106       },
    107       {
    108         className: 'meta',
    109         begin: '#!\\/usr\\/bin\\/env\ runhaskell', end: '$'
    110       },
    111 
    112       // "Whitespaces".
    113 
    114       PRAGMA,
    115       PREPROCESSOR,
    116 
    117       // Literals and names.
    118 
    119       // TODO: characters.
    120       hljs.QUOTE_STRING_MODE,
    121       hljs.C_NUMBER_MODE,
    122       CONSTRUCTOR,
    123       hljs.inherit(hljs.TITLE_MODE, {begin: '^[_a-z][\\w\']*'}),
    124 
    125       COMMENT,
    126 
    127       {begin: '->|<-'} // No markup, relevance booster
    128     ]
    129   };
    130 }
    131 
    132 module.exports = haskell;