1
0
Fork 0
arangodb/js/node/node_modules/highlight.js/lib/languages/cpp.js

112 lines
4.1 KiB
JavaScript

module.exports = function(hljs) {
var CPP_PRIMATIVE_TYPES = {
className: 'keyword',
begin: '[a-z\\d_]*_t'
};
var CPP_KEYWORDS = {
keyword: 'false int float while private char catch export virtual operator sizeof ' +
'dynamic_cast|10 typedef const_cast|10 const struct for static_cast|10 union namespace ' +
'unsigned long volatile static protected bool template mutable if public friend ' +
'do goto auto void enum else break extern using true class asm case typeid ' +
'short reinterpret_cast|10 default double register explicit signed typename try this ' +
'switch continue inline delete alignof constexpr decltype ' +
'noexcept nullptr static_assert thread_local restrict _Bool complex _Complex _Imaginary ' +
'atomic_bool atomic_char atomic_schar ' +
'atomic_uchar atomic_short atomic_ushort atomic_int atomic_uint atomic_long atomic_ulong atomic_llong ' +
'atomic_ullong',
built_in: 'std string cin cout cerr clog stringstream istringstream ostringstream ' +
'auto_ptr deque list queue stack vector map set bitset multiset multimap unordered_set ' +
'unordered_map unordered_multiset unordered_multimap array shared_ptr abort abs acos ' +
'asin atan2 atan calloc ceil cosh cos exit exp fabs floor fmod fprintf fputs free frexp ' +
'fscanf isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper ' +
'isxdigit tolower toupper labs ldexp log10 log malloc memchr memcmp memcpy memset modf pow ' +
'printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp ' +
'strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan ' +
'vfprintf vprintf vsprintf'
};
return {
aliases: ['c', 'cc', 'h', 'c++', 'h++', 'hpp'],
keywords: CPP_KEYWORDS,
illegal: '</',
contains: [
CPP_PRIMATIVE_TYPES,
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
{
className: 'string',
variants: [
hljs.inherit(hljs.QUOTE_STRING_MODE, { begin: '((u8?|U)|L)?"' }),
{
begin: '(u8?|U)?R"', end: '"',
contains: [hljs.BACKSLASH_ESCAPE]
},
{
begin: '\'\\\\?.', end: '\'',
illegal: '.'
}
]
},
{
className: 'number',
begin: '\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)'
},
hljs.C_NUMBER_MODE,
{
className: 'preprocessor',
begin: '#', end: '$',
keywords: 'if else elif endif define undef warning error line pragma',
contains: [
{
begin: /\\\n/, relevance: 0
},
{
begin: 'include\\s*[<"]', end: '[>"]',
keywords: 'include',
illegal: '\\n'
},
hljs.C_LINE_COMMENT_MODE
]
},
{
begin: '\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*<', end: '>',
keywords: CPP_KEYWORDS,
contains: ['self', CPP_PRIMATIVE_TYPES]
},
{
begin: hljs.IDENT_RE + '::',
keywords: CPP_KEYWORDS
},
{
// Expression keywords prevent 'keyword Name(...) or else if(...)' from
// being recognized as a function definition
beginKeywords: 'new throw return else',
relevance: 0
},
{
className: 'function',
begin: '(' + hljs.IDENT_RE + '\\s+)+' + hljs.IDENT_RE + '\\s*\\(', returnBegin: true, end: /[{;=]/,
excludeEnd: true,
keywords: CPP_KEYWORDS,
contains: [
{
begin: hljs.IDENT_RE + '\\s*\\(', returnBegin: true,
contains: [hljs.TITLE_MODE],
relevance: 0
},
{
className: 'params',
begin: /\(/, end: /\)/,
keywords: CPP_KEYWORDS,
relevance: 0,
contains: [
hljs.C_BLOCK_COMMENT_MODE
]
},
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE
]
}
]
};
};