| 1 |
import { l as languages } from "../../index-C1_GGQ8y.js"; |
| 2 |
import { e as extend, i as insertBefore } from "../../language-gdIi4UL0.js"; |
| 3 |
import { b as boolean } from "../../patterns-Cp3h1ylA.js"; |
| 4 |
import { r as re } from "../../shared-Sq5P6lf6.js"; |
| 5 |
import "./c.js"; |
| 6 |
var keyword = /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|char8_t|class|co_await|co_return|co_yield|compl|concept|const|const_cast|consteval|constexpr|constinit|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int16_t|int32_t|int64_t|int8_t|long|module|mutable|namespace|new|noexcept|nullptr|operator|override|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|uint16_t|uint32_t|uint64_t|uint8_t|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/; |
| 7 |
var cpp = languages.cpp = extend("c", { |
| 8 |
"class-name": [ |
| 9 |
{ |
| 10 |
pattern: RegExp(`(\\b(?:class|concept|enum|struct|typename)\\s+)(?!${keyword.source})\\w+`), |
| 11 |
lookbehind: true |
| 12 |
}, |
| 13 |
// This is intended to capture the class name of method implementations like: |
| 14 |
// void foo::bar() const {} |
| 15 |
// However! The `foo` in the above example could also be a namespace, so we only capture the class name if |
| 16 |
// it starts with an uppercase letter. This approximation should give decent results. |
| 17 |
/\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/, |
| 18 |
// This will capture the class name before destructors like: |
| 19 |
// Foo::~Foo() {} |
| 20 |
/\b[a-z_]\w*(?=\s*::\s*~\w+\s*\()/i, |
| 21 |
// This also intends to capture the class name of method implementations but here the class has template |
| 22 |
// parameters, so it can't be a namespace (until C++ adds generic namespaces). |
| 23 |
/\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/ |
| 24 |
], |
| 25 |
"keyword": keyword, |
| 26 |
"number": { |
| 27 |
pattern: /(?:\b0b[01']+|\b0x(?:[a-f\d']+(?:\.[a-f\d']*)?|\.[a-f\d']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/gi, |
| 28 |
greedy: true |
| 29 |
}, |
| 30 |
"operator": /->|--|\+\+|&&|\|\||[?:~]|<=>|>>=?|<<=?|[%&|^!=<>/*+-]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|x?or|x?or_eq)\b/, |
| 31 |
"boolean": boolean |
| 32 |
}); |
| 33 |
insertBefore(cpp, "string", { |
| 34 |
"module": { |
| 35 |
// https://en.cppreference.com/w/cpp/language/modules |
| 36 |
pattern: re( |
| 37 |
'(\\b(?:import|module)\\s+)(?:"(?:\\\\[\\s\\S]|[^\\\\\n"])*"|<[^<>\n]*>|<0>(?:\\s*:\\s*<0>)?|:\\s*<0>)', |
| 38 |
[`\\b(?!${keyword.source})\\w+(?:\\s*\\.\\s*\\w+)*\\b`], |
| 39 |
"g" |
| 40 |
), |
| 41 |
lookbehind: true, |
| 42 |
greedy: true, |
| 43 |
inside: { |
| 44 |
"string": /^[<"][^]+/, |
| 45 |
"operator": /:/, |
| 46 |
"punctuation": /\./ |
| 47 |
} |
| 48 |
}, |
| 49 |
"raw-string": { |
| 50 |
pattern: /R"([^\\() ]{0,16})\([^]*?\)\1"/g, |
| 51 |
greedy: true, |
| 52 |
alias: "string" |
| 53 |
} |
| 54 |
}); |
| 55 |
insertBefore(cpp, "keyword", { |
| 56 |
"generic-function": { |
| 57 |
pattern: /\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i, |
| 58 |
inside: { |
| 59 |
"function": /^\w+/, |
| 60 |
"generic": { |
| 61 |
pattern: /<[^]+/, |
| 62 |
alias: "class-name", |
| 63 |
inside: cpp |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
}); |
| 68 |
insertBefore(cpp, "operator", { |
| 69 |
"double-colon": { |
| 70 |
pattern: /::/, |
| 71 |
alias: "punctuation" |
| 72 |
} |
| 73 |
}); |
| 74 |
var baseClauseInside = Object.assign({}, cpp); |
| 75 |
insertBefore(cpp, "class-name", { |
| 76 |
// the base clause is an optional list of parent classes |
| 77 |
// https://en.cppreference.com/w/cpp/language/class |
| 78 |
"base-clause": { |
| 79 |
pattern: /(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/g, |
| 80 |
lookbehind: true, |
| 81 |
greedy: true, |
| 82 |
inside: baseClauseInside |
| 83 |
} |
| 84 |
}); |
| 85 |
insertBefore(baseClauseInside, "double-colon", { |
| 86 |
// All untokenized words that are not namespaces should be class names |
| 87 |
"class-name": /\b[a-z_]\w*\b(?!\s*::)/i |
| 88 |
}); |
| 89 |
//# sourceMappingURL=cpp.js.map |