basant307/AI_Governance_Project
048
1/*2Language: Haskell3Author: Jeremy Hull <sourdrums@gmail.com>4Contributors: Zena Treep <zena.treep@gmail.com>5Website: https://www.haskell.org6Category: functional7*/8 9function haskell(hljs) {10 11 /* See:12 - https://www.haskell.org/onlinereport/lexemes.html13 - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/binary_literals.html14 - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/numeric_underscores.html15 - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/hex_float_literals.html16 */17 const decimalDigits = '([0-9]_*)+';18 const hexDigits = '([0-9a-fA-F]_*)+';19 const binaryDigits = '([01]_*)+';20 const octalDigits = '([0-7]_*)+';21 const ascSymbol = '[!#$%&*+.\\/<=>?@\\\\^~-]';22 const uniSymbol = '(\\p{S}|\\p{P})'; // Symbol or Punctuation23 const special = '[(),;\\[\\]`|{}]';24 const symbol = `(${ascSymbol}|(?!(${special}|[_:"']))${uniSymbol})`;25 26 const COMMENT = { variants: [27 // Double dash forms a valid comment only if it's not part of legal lexeme.28 // See: Haskell 98 report: https://www.haskell.org/onlinereport/lexemes.html29 //30 // The commented code does the job, but we can't use negative lookbehind,31 // due to poor support by Safari browser.32 // > hljs.COMMENT(`(?<!${symbol})--+(?!${symbol})`, '$'),33 // So instead, we'll add a no-markup rule before the COMMENT rule in the rules list34 // to match the problematic infix operators that contain double dash.35 hljs.COMMENT('--+', '$'),36 hljs.COMMENT(37 /\{-/,38 /-\}/,39 { contains: [ 'self' ] }40 )41 ] };42 43 const PRAGMA = {44 className: 'meta',45 begin: /\{-#/,46 end: /#-\}/47 };48 49 const PREPROCESSOR = {50 className: 'meta',51 begin: '^#',52 end: '$'53 };54 55 const CONSTRUCTOR = {56 className: 'type',57 begin: '\\b[A-Z][\\w\']*', // TODO: other constructors (build-in, infix).58 relevance: 059 };60 61 const LIST = {62 begin: '\\(',63 end: '\\)',64 illegal: '"',65 contains: [66 PRAGMA,67 PREPROCESSOR,68 {69 className: 'type',70 begin: '\\b[A-Z][\\w]*(\\((\\.\\.|,|\\w+)\\))?'71 },72 hljs.inherit(hljs.TITLE_MODE, { begin: '[_a-z][\\w\']*' }),73 COMMENT74 ]75 };76 77 const RECORD = {78 begin: /\{/,79 end: /\}/,80 contains: LIST.contains81 };82 83 const NUMBER = {84 className: 'number',85 relevance: 0,86 variants: [87 // decimal floating-point-literal (subsumes decimal-literal)88 { match: `\\b(${decimalDigits})(\\.(${decimalDigits}))?` + `([eE][+-]?(${decimalDigits}))?\\b` },89 // hexadecimal floating-point-literal (subsumes hexadecimal-literal)90 { match: `\\b0[xX]_*(${hexDigits})(\\.(${hexDigits}))?` + `([pP][+-]?(${decimalDigits}))?\\b` },91 // octal-literal92 { match: `\\b0[oO](${octalDigits})\\b` },93 // binary-literal94 { match: `\\b0[bB](${binaryDigits})\\b` }95 ]96 };97 98 return {99 name: 'Haskell',100 aliases: [ 'hs' ],101 keywords:102 'let in if then else case of where do module import hiding '103 + 'qualified type data newtype deriving class instance as default '104 + 'infix infixl infixr foreign export ccall stdcall cplusplus '105 + 'jvm dotnet safe unsafe family forall mdo proc rec',106 unicodeRegex: true,107 contains: [108 // Top-level constructions.109 {110 beginKeywords: 'module',111 end: 'where',112 keywords: 'module where',113 contains: [114 LIST,115 COMMENT116 ],117 illegal: '\\W\\.|;'118 },119 {120 begin: '\\bimport\\b',121 end: '$',122 keywords: 'import qualified as hiding',123 contains: [124 LIST,125 COMMENT126 ],127 illegal: '\\W\\.|;'128 },129 {130 className: 'class',131 begin: '^(\\s*)?(class|instance)\\b',132 end: 'where',133 keywords: 'class family instance where',134 contains: [135 CONSTRUCTOR,136 LIST,137 COMMENT138 ]139 },140 {141 className: 'class',142 begin: '\\b(data|(new)?type)\\b',143 end: '$',144 keywords: 'data family type newtype deriving',145 contains: [146 PRAGMA,147 CONSTRUCTOR,148 LIST,149 RECORD,150 COMMENT151 ]152 },153 {154 beginKeywords: 'default',155 end: '$',156 contains: [157 CONSTRUCTOR,158 LIST,159 COMMENT160 ]161 },162 {163 beginKeywords: 'infix infixl infixr',164 end: '$',165 contains: [166 hljs.C_NUMBER_MODE,167 COMMENT168 ]169 },170 {171 begin: '\\bforeign\\b',172 end: '$',173 keywords: 'foreign import export ccall stdcall cplusplus jvm '174 + 'dotnet safe unsafe',175 contains: [176 CONSTRUCTOR,177 hljs.QUOTE_STRING_MODE,178 COMMENT179 ]180 },181 {182 className: 'meta',183 begin: '#!\\/usr\\/bin\\/env\ runhaskell',184 end: '$'185 },186 // "Whitespaces".187 PRAGMA,188 PREPROCESSOR,189 190 // Literals and names.191 192 // Single characters.193 {194 scope: 'string',195 begin: /'(?=\\?.')/,196 end: /'/,197 contains: [198 {199 scope: 'char.escape',200 match: /\\./,201 },202 ]203 },204 hljs.QUOTE_STRING_MODE,205 NUMBER,206 CONSTRUCTOR,207 hljs.inherit(hljs.TITLE_MODE, { begin: '^[_a-z][\\w\']*' }),208 // No markup, prevents infix operators from being recognized as comments.209 { begin: `(?!-)${symbol}--+|--+(?!-)${symbol}`},210 COMMENT,211 { // No markup, relevance booster212 begin: '->|<-' }213 ]214 };215}216 217export { haskell as default };218 