]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/haskell.js
1 /*! `haskell` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar
= (function () {
7 Author: Jeremy Hull <sourdrums@gmail.com>
8 Contributors: Zena Treep <zena.treep@gmail.com>
9 Website: https://www.haskell.org
13 function haskell(hljs
) {
16 - https://www.haskell.org/onlinereport/lexemes.html
17 - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/binary_literals.html
18 - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/numeric_underscores.html
19 - https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/hex_float_literals.html
21 const decimalDigits
= '([0-9]_*)+';
22 const hexDigits
= '([0-9a-fA-F]_*)+';
23 const binaryDigits
= '([01]_*)+';
24 const octalDigits
= '([0-7]_*)+';
25 const ascSymbol
= '[!#$%&*+.\\/<=>?@\\\\^~-]';
26 const uniSymbol
= '(\\p{S}|\\p{P})'; // Symbol or Punctuation
27 const special
= '[(),;\\[\\]`|{}]';
28 const symbol
= `(${ascSymbol}|(?!(${special}|[_:"']))${uniSymbol})`;
30 const COMMENT
= { variants: [
31 // Double dash forms a valid comment only if it's not part of legal lexeme.
32 // See: Haskell 98 report: https://www.haskell.org/onlinereport/lexemes.html
34 // The commented code does the job, but we can't use negative lookbehind,
35 // due to poor support by Safari browser.
36 // > hljs.COMMENT(`(?<!${symbol})--+(?!${symbol})`, '$'),
37 // So instead, we'll add a no-markup rule before the COMMENT rule in the rules list
38 // to match the problematic infix operators that contain double dash.
39 hljs
.COMMENT('--+', '$'),
43 { contains: [ 'self' ] }
53 const PREPROCESSOR
= {
61 begin: '\\b[A-Z][\\w\']*', // TODO: other constructors (build-in, infix).
74 begin: '\\b[A-Z][\\w]*(\\((\\.\\.|,|\\w+)\\))?'
76 hljs
.inherit(hljs
.TITLE_MODE
, { begin: '[_a-z][\\w\']*' }),
84 contains: LIST
.contains
91 // decimal floating-point-literal (subsumes decimal-literal)
92 { match: `\\b(${decimalDigits})(\\.(${decimalDigits}))?` + `([eE][+-]?(${decimalDigits}))?\\b` },
93 // hexadecimal floating-point-literal (subsumes hexadecimal-literal)
94 { match: `\\b0[xX]_*(${hexDigits})(\\.(${hexDigits}))?` + `([pP][+-]?(${decimalDigits}))?\\b` },
96 { match: `\\b0[oO](${octalDigits})\\b` },
98 { match: `\\b0[bB](${binaryDigits})\\b` }
106 'let in if then else case of where do module import hiding '
107 + 'qualified type data newtype deriving class instance as default '
108 + 'infix infixl infixr foreign export ccall stdcall cplusplus '
109 + 'jvm dotnet safe unsafe family forall mdo proc rec',
112 // Top-level constructions.
114 beginKeywords: 'module',
116 keywords: 'module where',
124 begin: '\\bimport\\b',
126 keywords: 'import qualified as hiding',
135 begin: '^(\\s*)?(class|instance)\\b',
137 keywords: 'class family instance where',
146 begin: '\\b(data|(new)?type)\\b',
148 keywords: 'data family type newtype deriving',
158 beginKeywords: 'default',
167 beginKeywords: 'infix infixl infixr',
175 begin: '\\bforeign\\b',
177 keywords: 'foreign import export ccall stdcall cplusplus jvm '
178 + 'dotnet safe unsafe',
181 hljs
.QUOTE_STRING_MODE
,
187 begin: '#!\\/usr\\/bin\\/env\ runhaskell',
194 // Literals and names.
196 // Single characters.
203 scope: 'char.escape
',
208 hljs.QUOTE_STRING_MODE,
211 hljs.inherit(hljs.TITLE_MODE, { begin: '^[_a
-z
][\\w
\']*' }),
212 // No markup, prevents infix operators from being recognized as comments.
213 { begin: `(?!-)${symbol}--+|--+(?!-)${symbol}`},
215 { // No markup, relevance booster
225 export default hljsGrammar;