All Projects → soffes → Syntaxkit

soffes / Syntaxkit

Licence: mit
TextMate-style syntax highlighting

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Syntaxkit

Columbus
A feature-rich country picker for iOS, tvOS and watchOS.
Stars: ✭ 23 (-95.03%)
Mutual labels:  watchos, carthage
clevertap-ios-sdk
CleverTap iOS SDK
Stars: ✭ 39 (-91.58%)
Mutual labels:  watchos, carthage
BlockiesSwift
Unique blocky identicons generator for Swift
Stars: ✭ 53 (-88.55%)
Mutual labels:  watchos, carthage
Go-Flashcards
Go Flashcards for iOS and WatchOS - Official repository
Stars: ✭ 60 (-87.04%)
Mutual labels:  watchos, carthage
Functionkit
A framework for functional types and operations designed to fit naturally into Swift.
Stars: ✭ 302 (-34.77%)
Mutual labels:  watchos, carthage
Dots
Lightweight Concurrent Networking Framework
Stars: ✭ 35 (-92.44%)
Mutual labels:  watchos, carthage
SwiftVer
Easily Manage Versioning in MacOS, iOS, watchOS, and tvOS projects.
Stars: ✭ 23 (-95.03%)
Mutual labels:  watchos, carthage
Cocoalumberjack
A fast & simple, yet powerful & flexible logging framework for Mac and iOS
Stars: ✭ 12,584 (+2617.93%)
Mutual labels:  watchos, carthage
Web3.swift
A pure swift Ethereum Web3 library
Stars: ✭ 295 (-36.29%)
Mutual labels:  watchos, carthage
X
Easier cross platform Mac & iOS development with Swift
Stars: ✭ 270 (-41.68%)
Mutual labels:  watchos, carthage
Iso8601
ISO8601 date parser and writer
Stars: ✭ 213 (-54%)
Mutual labels:  watchos, carthage
Xcglogger
A debug log framework for use in Swift projects. Allows you to log details to the console (and optionally a file), just like you would have with NSLog() or print(), but with additional information, such as the date, function name, filename and line number.
Stars: ✭ 3,710 (+701.3%)
Mutual labels:  watchos, carthage
Cache
Swift caching library
Stars: ✭ 210 (-54.64%)
Mutual labels:  watchos, carthage
Mechanica
A cross-platform library of Swift utils to ease your iOS | macOS | watchOS | tvOS and Linux development.
Stars: ✭ 27 (-94.17%)
Mutual labels:  watchos, carthage
L10n Swift
Localization of the application with ability to change language "on the fly" and support for plural form in any language.
Stars: ✭ 177 (-61.77%)
Mutual labels:  watchos, carthage
TermiNetwork
🌏 A zero-dependency networking solution for building modern and secure iOS, watchOS, macOS and tvOS applications.
Stars: ✭ 80 (-82.72%)
Mutual labels:  watchos, carthage
Color
Color utilities for macOS, iOS, tvOS, and watchOS
Stars: ✭ 145 (-68.68%)
Mutual labels:  watchos, carthage
Cdmarkdownkit
An extensive Swift framework providing simple and customizable markdown parsing.
Stars: ✭ 158 (-65.87%)
Mutual labels:  watchos, carthage
Datez
📆 Breeze through Date, DateComponents, and TimeInterval with Swift!
Stars: ✭ 254 (-45.14%)
Mutual labels:  watchos, carthage
Crypto
Swift CommonCrypto wrapper
Stars: ✭ 328 (-29.16%)
Mutual labels:  watchos, carthage

SyntaxKit

Version Carthage compatible CocoaPods compatible

SyntaxKit makes TextMate-style syntax highlighting easy. It works on iOS, watchOS, and OS X.

SyntaxKit was abstracted from Whiskey.

Building

SyntaxKit is written in Swift 2 so Xcode 7 is required. There aren't any dependencies besides system frameworks.

Installation

Carthage is the recommended way to install SyntaxKit. Add the following to your Cartfile:

github "soffes/SyntaxKit"

You can also install with CocoaPods:

pod 'SyntaxKit'

For manual installation, I recommend adding the project as a subproject to your project or workspace and adding the appropriate framework as a target dependency.

Usage

SyntaxKit uses tmLanguage and tmTheme files to highlight source code. None are provided with SyntaxKit. Thankfully, there are tons available at TextMate's GitHub org.

Basic Parsing

Once you have a language, you can get started:

import SyntaxKit

let path = "path to your .tmLanguage file"
let plist = NSDictionary(contentsOfFile: path)! as [NSObject: AnyObject]
let yaml = Language(dictionary: plist)

let parser = Parser(language: yaml)

Parser is a very simple class that just calls a block when it finds something the language file knows about. Let's print all of the elements in this string:

let input = "title: \"Hello World\"\n"
parser.parse(input) { scope, range in
    print("\(scope) - \(range)")
}

scope is the name of an element. This is something like "string" or "constant.numeric". range is an NSRange struct representing where the scope falls in the input string.

Working with Attributed Strings

SyntaxKit also comes with AttributedParser. This is a simple subclass of Parser that knows how to work with themes.

let tomorrow = Theme(dictionary: themePlist)
let attributedParser = AttributedParser(language: yaml, theme: tomorrow)

attributedParser.parse(input) { scope, range, attributes in
    print("\(scope) - \(range) - \(attributes)")
}

Notice that attributes is the third paramenter to the block now. This is a dictionary of attributes you can give to NSAttributedString. Other values may be included here that don't work with NSAttributedString. You can do your own inspection and do something custom if you want.

AttributedParser includes a convenience method for turning a String of source code into an NSAttributedString:

let attributedString = attributedParser.attributedStringForString(input)

Easy as that. This method takes an optional baseAttributes parameter to customize how the string is created. This is great if you want to specify a font, etc.

Custom Parsers

If you want to build your own parser (for example, to generate HTML) you can subclass whichever one meets your needs. Go wild.

Enjoy.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].