Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Syntax Highlighter for Swift 2.0 and Objective-C in 2015 #46

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions third-party-brushes/shBrushObjC.js
Original file line number Diff line number Diff line change
@@ -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
*
Expand All @@ -16,31 +21,45 @@

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(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
{ regex: new RegExp('@"(?:\\.|(\\\\\\")|[^\\""\\n])*"', 'g'), css: 'string' } // objc string
];

}
Expand Down
67 changes: 67 additions & 0 deletions third-party-brushes/shBrushSwift.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* 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
*
* 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 = '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'
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';

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 operators = '++ -- ~ + - << >> * / % &* & &+ &- | ^ ..< ... as? as! ?? < <= > >= == != === !== ~= && || ?: = *= /= %= += -= <<= >>= &= |= ^= &&= ||='

var attributes = '@availability @autoclosure @noescape @noreturn @NSApplicationMain @NSCopying @NSManaged @objc';
attributes += ' @UIApplicationMain';

var otherKeywords = 'IBAction IBOutlet IBOutletCollection IBInspectable IBDesignable';

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(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
];
}

SyntaxHighlighter.brushes.Swift.prototype = new SyntaxHighlighter.Highlighter();
SyntaxHighlighter.brushes.Swift.aliases = ['swift'];