Commits

Tim Hatch  committed 944a0b5 Merge

Merge with pygments-main

  • Participants
  • Parent commits d89721e, 576b984

Comments (0)

Files changed (3)

File pygments/lexers/_mapping.py

     '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')),

File pygments/lexers/compiled.py

            'DylanLidLexer', 'DylanConsoleLexer', 'CobolLexer',
            'CobolFreeformatLexer', 'LogosLexer', 'ClayLexer', 'PikeLexer',
            'ChapelLexer', 'EiffelLexer', 'Inform6Lexer', 'Inform7Lexer',
-           'Inform6TemplateLexer', 'MqlLexer']
+           'Inform6TemplateLexer', 'MqlLexer', 'SwiftLexer']
 
 
 class CFamilyLexer(RegexLexer):
             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

File tests/examplefiles/test.swift

+//
+//  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.
+    }
+    
+}