summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Hatch <tim@timhatch.com>2014-06-07 08:36:10 -0700
committerTim Hatch <tim@timhatch.com>2014-06-07 08:36:10 -0700
commit68c8011b8980c91a74f4625a96fa0fa946fb7b67 (patch)
treed17f8158bc8c68d618bdc629633aa5e4cdbb0ea5
parentb05fda6cc9c6e65419b0993f28091b2eb5a1d9b7 (diff)
parent32ceb8d947ab8efa9a37543a88a9428aaeacc8a9 (diff)
downloadpygments-68c8011b8980c91a74f4625a96fa0fa946fb7b67.tar.gz
Merge with pygments-main
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/compiled.py43
-rw-r--r--tests/examplefiles/test.swift65
3 files changed, 108 insertions, 1 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index 39439d1c..f8454357 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -323,6 +323,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 46990510..25c7a4d8 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):
@@ -5149,3 +5149,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.
+ }
+
+}