From 6e3ffc215a4ea5ce5b95672bf39ca15412204d1c Mon Sep 17 00:00:00 2001 From: Dal Rupnik Date: Tue, 15 Sep 2015 21:14:23 +0200 Subject: [PATCH 01/10] Create shBrushSwift.js --- third-party-brushes/shBrushSwift.js | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 third-party-brushes/shBrushSwift.js diff --git a/third-party-brushes/shBrushSwift.js b/third-party-brushes/shBrushSwift.js new file mode 100644 index 0000000..9209590 --- /dev/null +++ b/third-party-brushes/shBrushSwift.js @@ -0,0 +1,47 @@ +/** + * Wordpress SyntaxHighlighter brush for Swift + * By Dal Rupnik, unifiedsense.com + * + * Copyright (C) 2015 Dal Rupnik + * + * Adapted from: + * Wordpress SyntaxHighlighter brush for Objective-C + * By Matej Bukovinski, www.bukovinski.com + * + * Copyright (C) 2009 Matej Bukovinski + * + * Licensed under a GNU Lesser General Public License. + * http://creativecommons.org/licenses/LGPL/2.1/ + * + */ + +SyntaxHighlighter.brushes.Swift = function() { + + var datatypes = 'char bool BOOL double float int long short id void'; + + var keywords = 'IBAction IBOutlet SEL YES NO readwrite readonly nonatomic nil NULL '; + keywords += 'super self copy '; + keywords += 'break case catch class const copy __finally __exception __try '; + keywords += 'const_cast continue private public protected __declspec '; + keywords += 'default delete deprecated dllexport dllimport do dynamic_cast '; + keywords += 'else enum explicit extern if for friend goto inline '; + keywords += 'mutable naked namespace new noinline noreturn nothrow '; + keywords += 'register reinterpret_cast return selectany '; + keywords += 'sizeof static static_cast struct switch template this '; + keywords += 'thread throw true false try typedef typeid typename union '; + keywords += 'using uuid virtual volatile whcar_t while'; + + this.regexList = [ + { regex: SyntaxHighlighter.regexLib.singleLineCComments, css: 'comment' }, // one line comments + { regex: SyntaxHighlighter.regexLib.multiLineCComments, css: 'comment' }, // multiline comments + { regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' }, // double quoted strings + { regex: new RegExp('^ *#.*', 'gm'), css: 'preprocessor' }, // preprocessor + { regex: new RegExp(this.getKeywords(datatypes), 'gm'), css: 'datatypes' }, // datatypes + { regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' }, // keyword + { regex: new RegExp('\\bNS\\w+\\b', 'g'), css: 'keyword' }, // keyword + { regex: new RegExp('@\\w+\\b', 'g'), css: 'keyword' } // keyword + ]; +} + +SyntaxHighlighter.brushes.Swift.prototype = new SyntaxHighlighter.Highlighter(); +SyntaxHighlighter.brushes.Swift.aliases = ['swift']; From 49573faeaff826ed4e5adf98b62ca37268c8bc4c Mon Sep 17 00:00:00 2001 From: Dal Rupnik Date: Tue, 15 Sep 2015 21:22:01 +0200 Subject: [PATCH 02/10] Update shBrushSwift.js --- third-party-brushes/shBrushSwift.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/third-party-brushes/shBrushSwift.js b/third-party-brushes/shBrushSwift.js index 9209590..b0a607b 100644 --- a/third-party-brushes/shBrushSwift.js +++ b/third-party-brushes/shBrushSwift.js @@ -1,9 +1,12 @@ /** - * Wordpress SyntaxHighlighter brush for Swift + * Wordpress SyntaxHighlighter brush for Swift 2.0 * By Dal Rupnik, unifiedsense.com * * Copyright (C) 2015 Dal Rupnik * + * Source for Lexical Structure: + * https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html + * * Adapted from: * Wordpress SyntaxHighlighter brush for Objective-C * By Matej Bukovinski, www.bukovinski.com @@ -19,6 +22,16 @@ SyntaxHighlighter.brushes.Swift = function() { var datatypes = 'char bool BOOL double float int long short id void'; + var declarations = 'class deinit enum extension func import init inout internal let operator private protocol public static struct subscript typealias var'; + + var statements = 'break case continue default defer do else fallthrough for guard if in repeat return switch where while.'; + + var expressions = 'as catch dynamicType false is nil rethrows super self Self throw throws true try __COLUMN__ __FILE__ __FUNCTION__ __LINE__' + + var specificContexts = 'associativity convenience dynamic didSet final get infix indirect lazy left mutating none nonmutating optional override postfix precedence prefix Protocol required right set Type unowned weak willSet'; + + var punctuation = '( ) { } [ ] . , : ; = @ # & ( -> ` ? !'; + var keywords = 'IBAction IBOutlet SEL YES NO readwrite readonly nonatomic nil NULL '; keywords += 'super self copy '; keywords += 'break case catch class const copy __finally __exception __try '; From bf3f3aab5a9e0ba35aa84044048cb21748d88b30 Mon Sep 17 00:00:00 2001 From: Dal Rupnik Date: Tue, 15 Sep 2015 21:30:25 +0200 Subject: [PATCH 03/10] Update shBrushSwift.js --- third-party-brushes/shBrushSwift.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/third-party-brushes/shBrushSwift.js b/third-party-brushes/shBrushSwift.js index b0a607b..da1d7c2 100644 --- a/third-party-brushes/shBrushSwift.js +++ b/third-party-brushes/shBrushSwift.js @@ -20,7 +20,10 @@ SyntaxHighlighter.brushes.Swift = function() { - var datatypes = 'char bool BOOL double float int long short id void'; + var datatypes = 'Array Bool Character Dictionary Double Float Int Int16 Int32 Int64 Int8 Range Set String'; + datatypes += ' UInt UInt16 UInt32 UInt64 UInt8 Unmanaged UnsafeBufferPointer UnsafePointer Optional' + datatypes += ' AnyObject BooleanType CollectionType Comparable ErrorType Equatable Hashable Indexable' + datatypes += ' IntegerType OptionSetType SequenceType UnsignedIntegerType' var declarations = 'class deinit enum extension func import init inout internal let operator private protocol public static struct subscript typealias var'; @@ -30,9 +33,9 @@ SyntaxHighlighter.brushes.Swift = function() { var specificContexts = 'associativity convenience dynamic didSet final get infix indirect lazy left mutating none nonmutating optional override postfix precedence prefix Protocol required right set Type unowned weak willSet'; - var punctuation = '( ) { } [ ] . , : ; = @ # & ( -> ` ? !'; + var punctuation = '( ) { } [ ] . , : ; = @ # & ( -> ` ? ! _'; - var keywords = 'IBAction IBOutlet SEL YES NO readwrite readonly nonatomic nil NULL '; + var otherKeywords = 'IBAction IBOutlet Selector @availability @objc'; keywords += 'super self copy '; keywords += 'break case catch class const copy __finally __exception __try '; keywords += 'const_cast continue private public protected __declspec '; From 08a5411842dbf3a25d50120d887b73b8ef895388 Mon Sep 17 00:00:00 2001 From: Dal Rupnik Date: Tue, 15 Sep 2015 21:33:30 +0200 Subject: [PATCH 04/10] Update shBrushSwift.js --- third-party-brushes/shBrushSwift.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/third-party-brushes/shBrushSwift.js b/third-party-brushes/shBrushSwift.js index da1d7c2..c1c01c3 100644 --- a/third-party-brushes/shBrushSwift.js +++ b/third-party-brushes/shBrushSwift.js @@ -35,6 +35,8 @@ SyntaxHighlighter.brushes.Swift = function() { var punctuation = '( ) { } [ ] . , : ; = @ # & ( -> ` ? ! _'; + var operators = '++ -- ~ + - << >> * / % &* & &+ &- | ^ ..< ... as? as! ?? < <= > >= == != === !== ~= && || ?: = *= /= %= += -= <<= >>= &= |= ^= &&= ||=' + var otherKeywords = 'IBAction IBOutlet Selector @availability @objc'; keywords += 'super self copy '; keywords += 'break case catch class const copy __finally __exception __try '; From 04b79ebaab75f84a761ce3e8e9b4c436d0ee4727 Mon Sep 17 00:00:00 2001 From: Dal Rupnik Date: Tue, 15 Sep 2015 21:36:01 +0200 Subject: [PATCH 05/10] Update shBrushSwift.js --- third-party-brushes/shBrushSwift.js | 1 + 1 file changed, 1 insertion(+) diff --git a/third-party-brushes/shBrushSwift.js b/third-party-brushes/shBrushSwift.js index c1c01c3..d644fee 100644 --- a/third-party-brushes/shBrushSwift.js +++ b/third-party-brushes/shBrushSwift.js @@ -24,6 +24,7 @@ SyntaxHighlighter.brushes.Swift = function() { datatypes += ' UInt UInt16 UInt32 UInt64 UInt8 Unmanaged UnsafeBufferPointer UnsafePointer Optional' datatypes += ' AnyObject BooleanType CollectionType Comparable ErrorType Equatable Hashable Indexable' datatypes += ' IntegerType OptionSetType SequenceType UnsignedIntegerType' + datatypes += ' AnyObject? T T? Element Key Value ArraySlice'; var declarations = 'class deinit enum extension func import init inout internal let operator private protocol public static struct subscript typealias var'; From fd2dc45c4e9df6ddb06c2e54bc55408c1326de88 Mon Sep 17 00:00:00 2001 From: Dal Rupnik Date: Tue, 15 Sep 2015 21:40:03 +0200 Subject: [PATCH 06/10] Update shBrushSwift.js --- third-party-brushes/shBrushSwift.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/third-party-brushes/shBrushSwift.js b/third-party-brushes/shBrushSwift.js index d644fee..820cf8f 100644 --- a/third-party-brushes/shBrushSwift.js +++ b/third-party-brushes/shBrushSwift.js @@ -24,7 +24,7 @@ SyntaxHighlighter.brushes.Swift = function() { datatypes += ' UInt UInt16 UInt32 UInt64 UInt8 Unmanaged UnsafeBufferPointer UnsafePointer Optional' datatypes += ' AnyObject BooleanType CollectionType Comparable ErrorType Equatable Hashable Indexable' datatypes += ' IntegerType OptionSetType SequenceType UnsignedIntegerType' - datatypes += ' AnyObject? T T? Element Key Value ArraySlice'; + datatypes += ' AnyObject? T T? Element Key Value ArraySlice ImplicitlyUnwrappedOptional Selector'; var declarations = 'class deinit enum extension func import init inout internal let operator private protocol public static struct subscript typealias var'; @@ -38,7 +38,10 @@ SyntaxHighlighter.brushes.Swift = function() { var operators = '++ -- ~ + - << >> * / % &* & &+ &- | ^ ..< ... as? as! ?? < <= > >= == != === !== ~= && || ?: = *= /= %= += -= <<= >>= &= |= ^= &&= ||=' - var otherKeywords = 'IBAction IBOutlet Selector @availability @objc'; + var attributes = '@availability @autoclosure @noescape @noreturn @NSApplicationMain @NSCopying @NSManaged @objc'; + attributes += ' @UIApplicationMain'; + + var otherKeywords = 'IBAction IBOutlet IBInspectable IBDesignable'; keywords += 'super self copy '; keywords += 'break case catch class const copy __finally __exception __try '; keywords += 'const_cast continue private public protected __declspec '; From d70d79a2cc4e4667df93faccafb29815ee2953f9 Mon Sep 17 00:00:00 2001 From: Dal Rupnik Date: Tue, 15 Sep 2015 21:48:49 +0200 Subject: [PATCH 07/10] Update shBrushSwift.js --- third-party-brushes/shBrushSwift.js | 34 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/third-party-brushes/shBrushSwift.js b/third-party-brushes/shBrushSwift.js index 820cf8f..a0fc7de 100644 --- a/third-party-brushes/shBrushSwift.js +++ b/third-party-brushes/shBrushSwift.js @@ -42,26 +42,24 @@ SyntaxHighlighter.brushes.Swift = function() { attributes += ' @UIApplicationMain'; var otherKeywords = 'IBAction IBOutlet IBInspectable IBDesignable'; - keywords += 'super self copy '; - keywords += 'break case catch class const copy __finally __exception __try '; - keywords += 'const_cast continue private public protected __declspec '; - keywords += 'default delete deprecated dllexport dllimport do dynamic_cast '; - keywords += 'else enum explicit extern if for friend goto inline '; - keywords += 'mutable naked namespace new noinline noreturn nothrow '; - keywords += 'register reinterpret_cast return selectany '; - keywords += 'sizeof static static_cast struct switch template this '; - keywords += 'thread throw true false try typedef typeid typename union '; - keywords += 'using uuid virtual volatile whcar_t while'; this.regexList = [ - { regex: SyntaxHighlighter.regexLib.singleLineCComments, css: 'comment' }, // one line comments - { regex: SyntaxHighlighter.regexLib.multiLineCComments, css: 'comment' }, // multiline comments - { regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' }, // double quoted strings - { regex: new RegExp('^ *#.*', 'gm'), css: 'preprocessor' }, // preprocessor - { regex: new RegExp(this.getKeywords(datatypes), 'gm'), css: 'datatypes' }, // datatypes - { regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' }, // keyword - { regex: new RegExp('\\bNS\\w+\\b', 'g'), css: 'keyword' }, // keyword - { regex: new RegExp('@\\w+\\b', 'g'), css: 'keyword' } // keyword + { regex: SyntaxHighlighter.regexLib.singleLineCComments, css: 'comment' }, // One line comments + { regex: SyntaxHighlighter.regexLib.multiLineCComments, css: 'comment' }, // Multiline comments + { regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' }, // Double quoted strings + { regex: new RegExp('^ *#.*', 'gm'), css: 'preprocessor' }, // Preprocessor + { regex: new RegExp(this.getKeywords(datatypes), 'gm'), css: 'datatypes' }, // Datatypes + { regex: new RegExp(this.getKeywords(declarations), 'gm'), css: 'keyword' }, // Declarations + { regex: new RegExp(this.getKeywords(statements), 'gm'), css: 'keyword' }, // Statements + { regex: new RegExp(this.getKeywords(expressions), 'gm'), css: 'keyword' }, // Expressions + { regex: new RegExp(this.getKeywords(specificContexts), 'gm'), css: 'keyword' }, // Specific Contexts + //{ regex: new RegExp(this.getKeywords(punctuation), 'gm'), css: 'constants' }, // Declarations + //{ regex: new RegExp(this.getKeywords(operators), 'gm'), css: 'constants' }, // Declarations + { regex: new RegExp(this.getKeywords(attributes), 'gm'), css: 'keyword' }, // Attributes + { regex: new RegExp(this.getKeywords(otherKeywords), 'gm'), css: 'keyword' }, // Other keywords + { regex: new RegExp('\\bNS\\w+\\b', 'g'), css: 'datatypes' }, // Foundation classes + { regex: new RegExp('\\bUI\\w+\\b', 'g'), css: 'datatypes' }, // UIKit classes + { regex: new RegExp('@\\w+\\b', 'g'), css: 'keyword' } // keyword ]; } From 727db33dd00bcdcf5eab81cd32eb6da0de9ca1b3 Mon Sep 17 00:00:00 2001 From: Dal Rupnik Date: Tue, 15 Sep 2015 22:01:35 +0200 Subject: [PATCH 08/10] Update shBrushSwift.js --- third-party-brushes/shBrushSwift.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/third-party-brushes/shBrushSwift.js b/third-party-brushes/shBrushSwift.js index a0fc7de..0a95741 100644 --- a/third-party-brushes/shBrushSwift.js +++ b/third-party-brushes/shBrushSwift.js @@ -41,7 +41,7 @@ SyntaxHighlighter.brushes.Swift = function() { var attributes = '@availability @autoclosure @noescape @noreturn @NSApplicationMain @NSCopying @NSManaged @objc'; attributes += ' @UIApplicationMain'; - var otherKeywords = 'IBAction IBOutlet IBInspectable IBDesignable'; + var otherKeywords = 'IBAction IBOutlet IBOutletCollection IBInspectable IBDesignable'; this.regexList = [ { regex: SyntaxHighlighter.regexLib.singleLineCComments, css: 'comment' }, // One line comments @@ -58,8 +58,8 @@ SyntaxHighlighter.brushes.Swift = function() { { regex: new RegExp(this.getKeywords(attributes), 'gm'), css: 'keyword' }, // Attributes { regex: new RegExp(this.getKeywords(otherKeywords), 'gm'), css: 'keyword' }, // Other keywords { regex: new RegExp('\\bNS\\w+\\b', 'g'), css: 'datatypes' }, // Foundation classes - { regex: new RegExp('\\bUI\\w+\\b', 'g'), css: 'datatypes' }, // UIKit classes - { regex: new RegExp('@\\w+\\b', 'g'), css: 'keyword' } // keyword + { regex: new RegExp('\\bUI\\w+\\b', 'g') css: 'datatypes' }, // UIKit classes + //{ regex: new RegExp('@\\w+\\b', 'g'), css: 'keyword' } // keyword ]; } From c15081d6233dd40f4c8038ca9fa48a489bb4d97a Mon Sep 17 00:00:00 2001 From: Dal Rupnik Date: Tue, 15 Sep 2015 22:05:01 +0200 Subject: [PATCH 09/10] Update shBrushObjC.js --- third-party-brushes/shBrushObjC.js | 33 ++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/third-party-brushes/shBrushObjC.js b/third-party-brushes/shBrushObjC.js index 42c5731..bd1249c 100644 --- a/third-party-brushes/shBrushObjC.js +++ b/third-party-brushes/shBrushObjC.js @@ -1,4 +1,9 @@ /** + * Updated for Objective-C as of iOS 9 + * By Dal Rupnik, unifiedsense.com + * + * Copyright (C) 2015 Unified Sense + * * Wordpress SyntaxHighlighter brush for Objective-C * By Matej Bukovinski, www.bukovinski.com * @@ -16,31 +21,43 @@ SyntaxHighlighter.brushes.ObjC = function() { - var datatypes = 'char bool BOOL double float int long short id void'; + var datatypes = 'char bool BOOL double float int long short id instancetype void '; + dataTypes += ' Class IMP SEL _cmd'; - var keywords = 'IBAction IBOutlet SEL YES NO readwrite readonly nonatomic nil NULL '; + var keywords = 'YES NO readwrite readonly nonatomic nil NULL '; keywords += 'super self copy '; keywords += 'break case catch class const copy __finally __exception __try '; keywords += 'const_cast continue private public protected __declspec '; keywords += 'default delete deprecated dllexport dllimport do dynamic_cast '; keywords += 'else enum explicit extern if for friend goto inline '; keywords += 'mutable naked namespace new noinline noreturn nothrow '; - keywords += 'register reinterpret_cast return selectany '; + keywords += 'register reinterpret_cast return retain selectany '; keywords += 'sizeof static static_cast struct switch template this '; keywords += 'thread throw true false try typedef typeid typename union '; - keywords += 'using uuid virtual volatile whcar_t while'; + keywords += 'using uuid virtual volatile whcar_t while '; + keywords += 'nonnull nullable null_unspecified '; + keywords += '_Nullable _Nonnull _Null_unspecified '; + keywords += '__nullable __nonnull __null_unspecified '; + keywords += '__kindof in inout out '; + keywords += 'bycopy byref' + + var modifiers = 'NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_END' + + var otherKeywords = 'IBAction IBOutlet IBOutletCollection IBInspectable IBDesignable '; + otherKeywords = ' Protocol'; this.regexList = [ { regex: SyntaxHighlighter.regexLib.singleLineCComments, css: 'comment' }, // one line comments { regex: SyntaxHighlighter.regexLib.multiLineCComments, css: 'comment' }, // multiline comments { regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' }, // double quoted strings { regex: SyntaxHighlighter.regexLib.singleQuotedString, css: 'string' }, // single quoted strings - { regex: new RegExp('^ *#.*', 'gm'), css: 'preprocessor' }, // preprocessor + { regex: new RegExp('^ *#.*', 'gm'), css: 'preprocessor' }, // preprocessor { regex: new RegExp(this.getKeywords(datatypes), 'gm'), css: 'datatypes' }, // datatypes { regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' }, // keyword - { regex: new RegExp('\\bNS\\w+\\b', 'g'), css: 'keyword' }, // keyword - { regex: new RegExp('@\\w+\\b', 'g'), css: 'keyword' }, // keyword - { regex: new RegExp('@"(?:\\.|(\\\\\\")|[^\\""\\n])*"', 'g'), css: 'string' } // objc string + { regex: new RegExp('\\bNS\\w+\\b', 'g'), css: 'keyword' }, // keyword + { regex: new RegExp('\\bUI\\w+\\b', 'g'), css: 'keyword' }, // keyword + { regex: new RegExp('@\\w+\\b', 'g'), css: 'keyword' }, // keyword + { regex: new RegExp('@"(?:\\.|(\\\\\\")|[^\\""\\n])*"', 'g'), css: 'string' } // objc string ]; } From 6350620fd90f408b5abf05112abb30d5636402b8 Mon Sep 17 00:00:00 2001 From: Dal Rupnik Date: Tue, 15 Sep 2015 22:06:03 +0200 Subject: [PATCH 10/10] Update shBrushObjC.js --- third-party-brushes/shBrushObjC.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/third-party-brushes/shBrushObjC.js b/third-party-brushes/shBrushObjC.js index bd1249c..a65c891 100644 --- a/third-party-brushes/shBrushObjC.js +++ b/third-party-brushes/shBrushObjC.js @@ -54,6 +54,8 @@ SyntaxHighlighter.brushes.ObjC = function() { { regex: new RegExp('^ *#.*', 'gm'), css: 'preprocessor' }, // preprocessor { regex: new RegExp(this.getKeywords(datatypes), 'gm'), css: 'datatypes' }, // datatypes { regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' }, // keyword + { regex: new RegExp(this.getKeywords(modifiers), 'gm'), css: 'constants' }, + { regex: new RegExp(this.getKeywords(otherKeywords), 'gm'), css: 'keyword' }, { regex: new RegExp('\\bNS\\w+\\b', 'g'), css: 'keyword' }, // keyword { regex: new RegExp('\\bUI\\w+\\b', 'g'), css: 'keyword' }, // keyword { regex: new RegExp('@\\w+\\b', 'g'), css: 'keyword' }, // keyword