]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/haskell.js
1 /*! `haskell` grammar compiled for Highlight.js 11.11.1 */
3 var hljsGrammar
= (function () {
8 Author: Jeremy Hull <sourdrums@gmail.com>
9 Contributors: Zena Treep <zena.treep@gmail.com>
10 Website: https://www.haskell.org
14 function haskell(hljs
) {
17 - https://www.haskell.org/onlinereport/lexemes.html
18 - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/binary_literals.html
19 - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/numeric_underscores.html
20 - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/hex_float_literals.html
22 const decimalDigits
= '([0-9]_*)+';
23 const hexDigits
= '([0-9a-fA-F]_*)+';
24 const binaryDigits
= '([01]_*)+';
25 const octalDigits
= '([0-7]_*)+';
26 const ascSymbol
= '[!#$%&*+.\\/<=>?@\\\\^~-]';
27 const uniSymbol
= '(\\p{S}|\\p{P})'; // Symbol or Punctuation
28 const special
= '[(),;\\[\\]`|{}]';
29 const symbol
= `(${ascSymbol}|(?!(${special}|[_:"']))${uniSymbol})`;
31 const COMMENT
= { variants: [
32 // Double dash forms a valid comment only if it's not part of legal lexeme.
33 // See: Haskell 98 report: https://www.haskell.org/onlinereport/lexemes.html
35 // The commented code does the job, but we can't use negative lookbehind,
36 // due to poor support by Safari browser.
37 // > hljs.COMMENT(`(?<!${symbol})--+(?!${symbol})`, '$'),
38 // So instead, we'll add a no-markup rule before the COMMENT rule in the rules list
39 // to match the problematic infix operators that contain double dash.
40 hljs
.COMMENT('--+', '$'),
44 { contains: [ 'self' ] }
54 const PREPROCESSOR
= {
62 begin: '\\b[A-Z][\\w\']*', // TODO: other constructors (build-in, infix).
75 begin: '\\b[A-Z][\\w]*(\\((\\.\\.|,|\\w+)\\))?'
77 hljs
.inherit(hljs
.TITLE_MODE
, { begin: '[_a-z][\\w\']*' }),
85 contains: LIST
.contains
92 // decimal floating-point-literal (subsumes decimal-literal)
93 { match: `\\b(${decimalDigits})(\\.(${decimalDigits}))?` + `([eE][+-]?(${decimalDigits}))?\\b` },
94 // hexadecimal floating-point-literal (subsumes hexadecimal-literal)
95 { match: `\\b0[xX]_*(${hexDigits})(\\.(${hexDigits}))?` + `([pP][+-]?(${decimalDigits}))?\\b` },
97 { match: `\\b0[oO](${octalDigits})\\b` },
99 { match: `\\b0[bB](${binaryDigits})\\b` }
107 'let in if then else case of where do module import hiding '
108 + 'qualified type data newtype deriving class instance as default '
109 + 'infix infixl infixr foreign export ccall stdcall cplusplus '
110 + 'jvm dotnet safe unsafe family forall mdo proc rec',
113 // Top-level constructions.
115 beginKeywords: 'module',
117 keywords: 'module where',
125 begin: '\\bimport\\b',
127 keywords: 'import qualified as hiding',
136 begin: '^(\\s*)?(class|instance)\\b',
138 keywords: 'class family instance where',
147 begin: '\\b(data|(new)?type)\\b',
149 keywords: 'data family type newtype deriving',
159 beginKeywords: 'default',
168 beginKeywords: 'infix infixl infixr',
176 begin: '\\bforeign\\b',
178 keywords: 'foreign import export ccall stdcall cplusplus jvm '
179 + 'dotnet safe unsafe',
182 hljs
.QUOTE_STRING_MODE
,
188 begin: '#!\\/usr\\/bin\\/env\ runhaskell',
195 // Literals and names.
197 // Single characters.
204 scope: 'char.escape
',
209 hljs.QUOTE_STRING_MODE,
212 hljs.inherit(hljs.TITLE_MODE, { begin: '^[_a
-z
][\\w
\']*' }),
213 // No markup, prevents infix operators from being recognized as comments.
214 { begin: `(?!-)${symbol}--+|--+(?!-)${symbol}`},
216 { // No markup, relevance booster
226 hljs.registerLanguage('haskell
', hljsGrammar);