diff options
author | Kashif Rasul <kashif.rasul@gmail.com> | 2014-06-05 11:38:37 +0200 |
---|---|---|
committer | Kashif Rasul <kashif.rasul@gmail.com> | 2014-06-05 11:38:37 +0200 |
commit | dfdf0de2da30f0626706c5f3ec9f3c3153c69917 (patch) | |
tree | a3c479dd1cf7eb2960447a40c5ffdc07cfa5806f | |
parent | 18f605604a9d2e2195973282b98feda330b87977 (diff) | |
download | pygments-dfdf0de2da30f0626706c5f3ec9f3c3153c69917.tar.gz |
Initial Swift lexer
-rw-r--r-- | pygments/lexers/_mapping.py | 1 | ||||
-rw-r--r-- | pygments/lexers/compiled.py | 43 | ||||
-rw-r--r-- | tests/examplefiles/test.swift | 65 |
3 files changed, 108 insertions, 1 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index cf7e0952..f773c6d8 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -321,6 +321,7 @@ LEXERS = { 'SquidConfLexer': ('pygments.lexers.text', 'SquidConf', ('squidconf', 'squid.conf', 'squid'), ('squid.conf',), ('text/x-squidconf',)), 'SspLexer': ('pygments.lexers.templates', 'Scalate Server Page', ('ssp',), ('*.ssp',), ('application/x-ssp',)), 'StanLexer': ('pygments.lexers.math', 'Stan', ('stan',), ('*.stan',), ()), + 'SwiftLexer': ('pygments.lexers.compiled', 'Swift', ('swift',), ('*.swift',), ('text/x-swift',)), 'SwigLexer': ('pygments.lexers.compiled', 'SWIG', ('swig',), ('*.swg', '*.i'), ('text/swig',)), 'SystemVerilogLexer': ('pygments.lexers.hdl', 'systemverilog', ('systemverilog', 'sv'), ('*.sv', '*.svh'), ('text/x-systemverilog',)), 'TclLexer': ('pygments.lexers.agile', 'Tcl', ('tcl',), ('*.tcl',), ('text/x-tcl', 'text/x-script.tcl', 'application/x-tcl')), diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py index d52ab950..48a11578 100644 --- a/pygments/lexers/compiled.py +++ b/pygments/lexers/compiled.py @@ -32,7 +32,7 @@ __all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'ECLexer', 'DylanLidLexer', 'DylanConsoleLexer', 'CobolLexer', 'CobolFreeformatLexer', 'LogosLexer', 'ClayLexer', 'PikeLexer', 'ChapelLexer', 'EiffelLexer', 'Inform6Lexer', 'Inform7Lexer', - 'Inform6TemplateLexer', 'MqlLexer'] + 'Inform6TemplateLexer', 'MqlLexer', 'SwiftLexer'] class CFamilyLexer(RegexLexer): @@ -5146,3 +5146,44 @@ class MqlLexer(CppLexer): inherit, ], } + +class SwiftLexer(ObjectiveCLexer): + """ + For `Swift <https://developer.apple.com/swift/>`_ source. + """ + name = 'Swift' + filenames = ['*.swift'] + aliases = ['swift'] + mimetypes = ['text/x-swift'] + + keywords_decl = ['class', 'deinit', 'enum', 'extension', 'func', 'import', + 'init', 'let', 'protocol', 'static', 'struct', 'subscript', + 'typealias', 'var'] + keywords_stmt = ['break', 'case', 'continue', 'default', 'do', 'else', + 'fallthrough', 'if', 'in', 'for', 'return', 'switch', + 'where', 'while'] + keywords_type = ['as', 'dynamicType', 'is', 'new', 'super', 'self', 'Self', + 'Type', '__COLUMN__', '__FILE__', '__FUNCTION__', + '__LINE__'] + keywords_resrv = ['associativity', 'didSet', 'get', 'infix', 'inout', 'left', + 'mutating', 'none', 'nonmutating', 'operator', 'override', + 'postfix', 'precedence', 'prefix', 'right', 'set', + 'unowned', 'unowned(safe)', 'unowned(unsafe)', 'weak', + 'willSet'] + operators = ['->'] + + def get_tokens_unprocessed(self, text): + for index, token, value in \ + ObjectiveCLexer.get_tokens_unprocessed(self, text): + if token is Name: + if value in self.keywords_decl: + token = Keyword + elif value in self.keywords_stmt: + token = Keyword + elif value in self.keywords_type: + token = Keyword.Type + elif value in self.keywords_resrv: + token = Keyword.Reserved + elif value in self.operators: + token = Operator + yield index, token, value diff --git a/tests/examplefiles/test.swift b/tests/examplefiles/test.swift new file mode 100644 index 00000000..8ef19763 --- /dev/null +++ b/tests/examplefiles/test.swift @@ -0,0 +1,65 @@ +// +// test.swift +// from https://github.com/fullstackio/FlappySwift +// +// Created by Nate Murray on 6/2/14. +// Copyright (c) 2014 Fullstack.io. All rights reserved. +// + +import UIKit +import SpriteKit + +extension SKNode { + class func unarchiveFromFile(file : NSString) -> SKNode? { + + let path = NSBundle.mainBundle().pathForResource(file, ofType: "sks") + + var sceneData = NSData.dataWithContentsOfFile(path, options: .DataReadingMappedIfSafe, error: nil) + var archiver = NSKeyedUnarchiver(forReadingWithData: sceneData) + + archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene") + let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as GameScene + archiver.finishDecoding() + return scene + } +} + +class GameViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene { + // Configure the view. + let skView = self.view as SKView + skView.showsFPS = true + skView.showsNodeCount = true + + /* Sprite Kit applies additional optimizations to improve rendering performance */ + skView.ignoresSiblingOrder = true + + /* Set the scale mode to scale to fit the window */ + scene.scaleMode = .AspectFill + + skView.presentScene(scene) + } + } + + override func shouldAutorotate() -> Bool { + return true + } + + override func supportedInterfaceOrientations() -> Int { + if UIDevice.currentDevice().userInterfaceIdiom == .Phone { + return Int(UIInterfaceOrientationMask.AllButUpsideDown.toRaw()) + } else { + return Int(UIInterfaceOrientationMask.All.toRaw()) + } + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Release any cached data, images, etc that aren't in use. + } + +} |