1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/highlight.js/lib/languages/haskell.js

174 lines
3.5 KiB
JavaScript
Raw Normal View History

2024-01-16 21:26:16 +08:00
/*
Language: Haskell
Author: Jeremy Hull <sourdrums@gmail.com>
Contributors: Zena Treep <zena.treep@gmail.com>
Website: https://www.haskell.org
Category: functional
*/
function haskell(hljs) {
const COMMENT = {
2023-12-18 13:12:25 +08:00
variants: [
hljs.COMMENT('--', '$'),
hljs.COMMENT(
2024-01-16 21:26:16 +08:00
/\{-/,
/-\}/,
2023-12-18 13:12:25 +08:00
{
contains: ['self']
}
)
]
};
2024-01-16 21:26:16 +08:00
const PRAGMA = {
2023-12-18 13:12:25 +08:00
className: 'meta',
2024-01-16 21:26:16 +08:00
begin: /\{-#/,
end: /#-\}/
2023-12-18 13:12:25 +08:00
};
2024-01-16 21:26:16 +08:00
const PREPROCESSOR = {
2023-12-18 13:12:25 +08:00
className: 'meta',
2024-01-16 21:26:16 +08:00
begin: '^#',
end: '$'
2023-12-18 13:12:25 +08:00
};
2024-01-16 21:26:16 +08:00
const CONSTRUCTOR = {
2023-12-18 13:12:25 +08:00
className: 'type',
begin: '\\b[A-Z][\\w\']*', // TODO: other constructors (build-in, infix).
relevance: 0
};
2024-01-16 21:26:16 +08:00
const LIST = {
begin: '\\(',
end: '\\)',
2023-12-18 13:12:25 +08:00
illegal: '"',
contains: [
PRAGMA,
PREPROCESSOR,
2024-01-16 21:26:16 +08:00
{
className: 'type',
begin: '\\b[A-Z][\\w]*(\\((\\.\\.|,|\\w+)\\))?'
},
hljs.inherit(hljs.TITLE_MODE, {
begin: '[_a-z][\\w\']*'
}),
2023-12-18 13:12:25 +08:00
COMMENT
]
};
2024-01-16 21:26:16 +08:00
const RECORD = {
begin: /\{/,
end: /\}/,
2023-12-18 13:12:25 +08:00
contains: LIST.contains
};
return {
2024-01-16 21:26:16 +08:00
name: 'Haskell',
2023-12-18 13:12:25 +08:00
aliases: ['hs'],
keywords:
'let in if then else case of where do module import hiding ' +
'qualified type data newtype deriving class instance as default ' +
'infix infixl infixr foreign export ccall stdcall cplusplus ' +
'jvm dotnet safe unsafe family forall mdo proc rec',
contains: [
// Top-level constructions.
{
2024-01-16 21:26:16 +08:00
beginKeywords: 'module',
end: 'where',
2023-12-18 13:12:25 +08:00
keywords: 'module where',
2024-01-16 21:26:16 +08:00
contains: [
LIST,
COMMENT
],
2023-12-18 13:12:25 +08:00
illegal: '\\W\\.|;'
},
{
2024-01-16 21:26:16 +08:00
begin: '\\bimport\\b',
end: '$',
2023-12-18 13:12:25 +08:00
keywords: 'import qualified as hiding',
2024-01-16 21:26:16 +08:00
contains: [
LIST,
COMMENT
],
2023-12-18 13:12:25 +08:00
illegal: '\\W\\.|;'
},
{
className: 'class',
2024-01-16 21:26:16 +08:00
begin: '^(\\s*)?(class|instance)\\b',
end: 'where',
2023-12-18 13:12:25 +08:00
keywords: 'class family instance where',
2024-01-16 21:26:16 +08:00
contains: [
CONSTRUCTOR,
LIST,
COMMENT
]
2023-12-18 13:12:25 +08:00
},
{
className: 'class',
2024-01-16 21:26:16 +08:00
begin: '\\b(data|(new)?type)\\b',
end: '$',
2023-12-18 13:12:25 +08:00
keywords: 'data family type newtype deriving',
2024-01-16 21:26:16 +08:00
contains: [
PRAGMA,
CONSTRUCTOR,
LIST,
RECORD,
COMMENT
]
2023-12-18 13:12:25 +08:00
},
{
2024-01-16 21:26:16 +08:00
beginKeywords: 'default',
end: '$',
contains: [
CONSTRUCTOR,
LIST,
COMMENT
]
2023-12-18 13:12:25 +08:00
},
{
2024-01-16 21:26:16 +08:00
beginKeywords: 'infix infixl infixr',
end: '$',
contains: [
hljs.C_NUMBER_MODE,
COMMENT
]
2023-12-18 13:12:25 +08:00
},
{
2024-01-16 21:26:16 +08:00
begin: '\\bforeign\\b',
end: '$',
2023-12-18 13:12:25 +08:00
keywords: 'foreign import export ccall stdcall cplusplus jvm ' +
'dotnet safe unsafe',
2024-01-16 21:26:16 +08:00
contains: [
CONSTRUCTOR,
hljs.QUOTE_STRING_MODE,
COMMENT
]
2023-12-18 13:12:25 +08:00
},
{
className: 'meta',
2024-01-16 21:26:16 +08:00
begin: '#!\\/usr\\/bin\\/env\ runhaskell',
end: '$'
2023-12-18 13:12:25 +08:00
},
// "Whitespaces".
PRAGMA,
PREPROCESSOR,
// Literals and names.
// TODO: characters.
hljs.QUOTE_STRING_MODE,
hljs.C_NUMBER_MODE,
CONSTRUCTOR,
2024-01-16 21:26:16 +08:00
hljs.inherit(hljs.TITLE_MODE, {
begin: '^[_a-z][\\w\']*'
}),
2023-12-18 13:12:25 +08:00
COMMENT,
2024-01-16 21:26:16 +08:00
{ // No markup, relevance booster
begin: '->|<-'
}
2023-12-18 13:12:25 +08:00
]
};
2024-01-16 21:26:16 +08:00
}
module.exports = haskell;