wallet-core/node_modules/highlight.js/lib/languages/swift.js

116 lines
4.4 KiB
JavaScript
Raw Normal View History

2017-05-24 15:10:37 +02:00
module.exports = function(hljs) {
var SWIFT_KEYWORDS = {
keyword: '__COLUMN__ __FILE__ __FUNCTION__ __LINE__ as as! as? associativity ' +
'break case catch class continue convenience default defer deinit didSet do ' +
2017-08-14 05:01:11 +02:00
'dynamic dynamicType else enum extension fallthrough false fileprivate final for func ' +
2017-05-24 15:10:37 +02:00
'get guard if import in indirect infix init inout internal is lazy left let ' +
2017-08-14 05:01:11 +02:00
'mutating nil none nonmutating open operator optional override postfix precedence ' +
2017-05-24 15:10:37 +02:00
'prefix private protocol Protocol public repeat required rethrows return ' +
'right self Self set static struct subscript super switch throw throws true ' +
'try try! try? Type typealias unowned var weak where while willSet',
literal: 'true false nil',
built_in: 'abs advance alignof alignofValue anyGenerator assert assertionFailure ' +
'bridgeFromObjectiveC bridgeFromObjectiveCUnconditional bridgeToObjectiveC ' +
'bridgeToObjectiveCUnconditional c contains count countElements countLeadingZeros ' +
'debugPrint debugPrintln distance dropFirst dropLast dump encodeBitsAsWords ' +
'enumerate equal fatalError filter find getBridgedObjectiveCType getVaList ' +
'indices insertionSort isBridgedToObjectiveC isBridgedVerbatimToObjectiveC ' +
'isUniquelyReferenced isUniquelyReferencedNonObjC join lazy lexicographicalCompare ' +
'map max maxElement min minElement numericCast overlaps partition posix ' +
'precondition preconditionFailure print println quickSort readLine reduce reflect ' +
'reinterpretCast reverse roundUpToAlignment sizeof sizeofValue sort split ' +
'startsWith stride strideof strideofValue swap toString transcode ' +
'underestimateCount unsafeAddressOf unsafeBitCast unsafeDowncast unsafeUnwrap ' +
'unsafeReflect withExtendedLifetime withObjectAtPlusZero withUnsafePointer ' +
'withUnsafePointerToObject withUnsafeMutablePointer withUnsafeMutablePointers ' +
'withUnsafePointer withUnsafePointers withVaList zip'
};
var TYPE = {
className: 'type',
begin: '\\b[A-Z][\\w\u00C0-\u02B8\']*',
relevance: 0
};
var BLOCK_COMMENT = hljs.COMMENT(
'/\\*',
'\\*/',
{
contains: ['self']
}
);
var SUBST = {
className: 'subst',
begin: /\\\(/, end: '\\)',
keywords: SWIFT_KEYWORDS,
contains: [] // assigned later
};
var NUMBERS = {
className: 'number',
begin: '\\b([\\d_]+(\\.[\\deE_]+)?|0x[a-fA-F0-9_]+(\\.[a-fA-F0-9p_]+)?|0b[01_]+|0o[0-7_]+)\\b',
relevance: 0
};
var QUOTE_STRING_MODE = hljs.inherit(hljs.QUOTE_STRING_MODE, {
contains: [SUBST, hljs.BACKSLASH_ESCAPE]
});
SUBST.contains = [NUMBERS];
return {
keywords: SWIFT_KEYWORDS,
contains: [
QUOTE_STRING_MODE,
hljs.C_LINE_COMMENT_MODE,
BLOCK_COMMENT,
TYPE,
NUMBERS,
{
className: 'function',
beginKeywords: 'func', end: '{', excludeEnd: true,
contains: [
hljs.inherit(hljs.TITLE_MODE, {
begin: /[A-Za-z$_][0-9A-Za-z$_]*/
}),
{
begin: /</, end: />/
},
{
className: 'params',
begin: /\(/, end: /\)/, endsParent: true,
keywords: SWIFT_KEYWORDS,
contains: [
'self',
NUMBERS,
QUOTE_STRING_MODE,
hljs.C_BLOCK_COMMENT_MODE,
{begin: ':'} // relevance booster
],
illegal: /["']/
}
],
illegal: /\[|%/
},
{
className: 'class',
beginKeywords: 'struct protocol class extension enum',
keywords: SWIFT_KEYWORDS,
end: '\\{',
excludeEnd: true,
contains: [
hljs.inherit(hljs.TITLE_MODE, {begin: /[A-Za-z$_][\u00C0-\u02B80-9A-Za-z$_]*/})
]
},
{
className: 'meta', // @attributes
begin: '(@warn_unused_result|@exported|@lazy|@noescape|' +
'@NSCopying|@NSManaged|@objc|@convention|@required|' +
'@noreturn|@IBAction|@IBDesignable|@IBInspectable|@IBOutlet|' +
'@infix|@prefix|@postfix|@autoclosure|@testable|@available|' +
'@nonobjc|@NSApplicationMain|@UIApplicationMain)'
},
{
beginKeywords: 'import', end: /$/,
contains: [hljs.C_LINE_COMMENT_MODE, BLOCK_COMMENT]
}
]
};
};