Coder Social home page Coder Social logo

swift.tmbundle's Introduction

Important

This repository is not actively maintained. See jtbandes/swift-tmlanguage for the latest Swift grammar.

Installation

You can install this bundle in TextMate by opening the preferences and going to the bundles tab. After installation it will be automatically updated for you.

General

License

If not otherwise specified (see below), files in this repository fall under the following license:

Permission to copy, use, modify, sell and distribute this
software is granted. This software is provided "as is" without
express or implied warranty, and with no claim as to its
suitability for any purpose.

An exception is made for files in readable text which contain their own license information, or files where an accompanying file exists (in the same directory) with a “-license” suffix added to the base-name name of the original file, and an extension of txt, html, or similar. For example “tidy” is accompanied by “tidy-license.txt”.

swift.tmbundle's People

Contributors

balestrapatrick avatar davidgoldman avatar dkonst avatar infininight avatar jtbandes avatar macavon avatar mkhl avatar natecook1000 avatar nschum avatar regnerjr avatar sanssecours avatar sorbits avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift.tmbundle's Issues

Complex sequences break highlighting

Some Swift sequences cause the syntax highlighter to quit its job. I can't tell ifit is caused by chains of closures or uncommon sequences of double quotes. This can be observed at the end of https://github.com/idrougge/advent_of_code_2016/blob/master/idrougge-swift/day5/md5.swift where the text turns a uniform blue in the last portion of the code. It seems to be triggered by this line:
c.h.forEach{hh+=String(format:"%08X\($0.distanceTo(c.h.last!)==0 ? "":" ")",$0.bigEndian)}

Incorrect syntax highlighting

This file has incorrect syntax highlighting after this line:

print("Message ID: \(userInfo["gcm.message_id"]!)")

This might be caused by the quotes inside the quotes.

Highlighting issue after associated type with no default

The following code sample shows a highlighting bug:

protocol Collection : Sequence {
    // highlighting stops from the end of the next line until the following '=':
    associatedtype IndexDistance : SignedInteger
    associatedtype Iterator : IteratorProtocol = IndexingIterator<Self>
}

The second associatedtype line should be highlighted like the first:

protocol Collection : Sequence {
    associatedtype IndexDistance : SignedInteger = Int
    associatedtype Iterator : IteratorProtocol = IndexingIterator<Self>
}

Auto-completion and documentation look-up

If Textmate is to be seen as a serious alternative to Xcode for editing Swift, this bundle needs to provide comparable auto-completion and documentation look-ups, the way the Objective-C bundle does for that language.

I think that someone who knew their way around the Obj-C bundle shouldn't find it too difficult to adapt the code to index a project and perform these operations within it, but there seems to be a problem with the built-in frameworks – I can't get at the relevant declarations. The trick described in http://ericasadun.com/2014/08/20/swift-xcode-beta-6-accessing-swift-native-definitions/, which worked with Xcode 6 beta doesn't seem to work with the current release version. I can't get it to work, anyway.

I may get a chance to look into this myself later, but I don't presently understand how the existing scripts work, so this is really a request for anybody who is deeper into bundle development to give it a go, please.

I'm not trying to start an editor war over whether Xcode or TM gets to be the Swift editor of choice, but I can't be the only one who is more comfortable in TM, so it would be nice to be able to use it for as much Swift work as possible. Especially as Swift editing in Xcode seems to be perenially borked, judging from what I read in the Apple Developer forums.

Floating-Point Literals not Parsing Correctly

It seems like floating-point literals are not being parsed correctly.

For example, taken from the Swift Programming Language book:

let decimalDouble = 12.1875
let exponentDouble = 1.21875p1
let hexadecimalDouble = 0xC.3p0

The decimalDouble variable appears to be parsing correctly at first, but after trying to figure out why exponentDouble and hexadecimalDouble were not being parsed, i realized the following: All floating-point literals are being parsed as two integer.decimal's separated by a operator.custom.postfix.unary. Basically, the decimal is always being parsed as a operator.custom.postfix.unary scope, therefore exponentDouble and hexadecimalDouble aren't highlighted.

The bizarre thing is that the regex for the three floating-point-literal scopes are correct — or, they would parse all three of these variables (tested in Patterns.app). And as far as I can tell, the #literal patterns have a higher precedence than the #operators patterns.

I tried to fix this but was unsuccessful. Looking for any tips.

Support for raw string literals

Support for raw string literals

SE-0200, implemented in Swift 5, added support for raw string literals, which are string literals that add # characters to their delimiters, and that partially ignore escape sequences like \n and \\. The above-linked Swift Evolution proposal goes into greater detail about their design, but a quick overview follows.

Overview of raw string literals

Traditional string literals interpret character sequences beginning with \ as escape sequences, but raw string literals interpret these as literal characters:

"\n" // newline
#"\n"# // backslash, n

"\\n" // backslash, n
#"\\n"# // backslash, backslash, n

"\u{2603}" // ☃
#"\u{2603}"# // backslash, u, opening brace, 2, 6, 0, 3, closing brace

"\\u{2603}" // backslash, u, opening brace, 2, 6, 0, 3, closing brace
#"\\u{2603}"# // backslash, backslash, u, opening brace, 2, 6, 0, 3, closing brace

let num = 42
"\(num)" // 42
#"\(num)"# // backslash, opening parenthesis, n, u, m, closing parenthesis
"\\(num)" // 42
#"\\(num)"# // backslash, backslash, opening parenthesis, n, u, m, closing parenthesis

You can use any number of # characters as the delimiters of a raw string literal:

// All of the following strings are equivalent:
"good morning"
#"good morning"#
##"good morning"##
###"good morning"###
// et cetera

If you want to use an escape sequence in a raw string literal, the escape sequence includes the same number of # characters as the delimiters:

// All of the following strings are equivalent:
"\n" // newline
#"\#n"#
##"\##n"##

// All of the following strings are equivalent:
"\u{2603}" // ☃
#"\#u{2603}"#
##"\##u{2603}"##

// All of the following strings are equivalent:
"\(num)" // 42
#"\#(num)"#
##"\##(num)"##

Note, the reason you can use any number of # characters is to allow literal \# sequences in a raw string literal without escaping:

// All of the following strings are equivalent:
"\\#n" // backslash, hash, n (need to escape \\ to get \)
#"\#\#n"# // (need to escape \#\ to get \ before #)
##"\#n"## // (no need to escape)

Swift also allows combining raw string literals with multiline string literals:

// All of the following strings are equivalent
let one = "good\\n\nmorning" // g, o, o, d, backslash, n, newline, m, o, r, n, i, n, g
let two = """
    good\\n
    morning
    """
let three = #"""
    good\n
    morning
    """#

The issue: swift.tmbundle doesn’t support raw string literals

As seen in some of the examples above, swift.tmbundle highlights raw string literals as if they were traditional string literals. That means that some valid sequences involving \ characters are marked as invalid, and some invalid sequences involving \ characters are only partially marked as invalid:

"\d" // invalid escape sequence \d (correctly marked)
#"\d"# // backslash, d (incorrectly marked as invalid escape sequence \d)
#"\#d"# // invalid escape sequence \#d (incorrectly marked as shorter invalid escape sequence \#)
##"\#d"## // backslash, hash, d (incorrectly marked as invalid escape sequence \#`)
##"\##d"## // invalid escape sequence \##d (incorrectly marked as shorter invalid escape sequence \#)

Bundle Does Not Work In Atom & Sublime Text

When trying to use this bundle in Atom or Sublime, it does not work.

In Atom, after converting the package through Atom’s package manager with the command, apm init --package language-swift --convert https://github.com/textmate/swift.tmbundle, moving it to Atom's packages directory and opening a swift file, I receive a “Uncaught Error: invalid pattern in look-behind” and I cannot type at all in the file.

In Sublime Text 2, after moving the bundle to the packages directory, I receive a "Error loading syntax file "Packages/swift.tmbundle/Syntaxes/Swift.tmLanguage”: Unexpected capture value" and syntax highlighting, snippets etc. do not work.

In Sublime Text 3, after moving the bundle to the packages directory, Sublime does not even acknowledge the package.

It would be appreciated if this could be addressed as it is, as far as I can tell, the most complete and up to date package for swift support in other textmate and other editors.

Not Appearing in TM2 Latest Release

The Swift bundle is not appearing under the bundles tab in preferences in the latest version of Textmate 2 (Alpha 9547). How do I install otherwise?

Thanks

Wrong color for parameter named "continue"

First of all, I noticed this in VS Code with the default syntax highlighting, terribly sorry if this is not the correct repo to report to 🙈

screen shot 2018-04-20 at 11 35 51

Pasted in the following:

optional func application(_ application: UIApplication, 
                 continue userActivity: NSUserActivity, 
       restorationHandler: @escaping ([Any]?) -> Void) -> Bool

and started googling what the continue keyword meant for a function parameter 😂

Enums with _ associated value labels are marked invalid

GitHub’s syntax highlighting uses github/liguist, which in turn uses swift.tmbundle. This combination of software incorrectly considers enum cases that use _ x as an associated value label (where x can be any valid identifier) as invalid Swift code (highlighted with a red background).

_ x is valid as an enum associated value in Swift, but x y is not valid, which might be the source of the issue.

Steps to reproduce

Option A:

  1. Create a .swift file in a GitHub repo
  2. Add an enum with a case with an associated value to the file
  3. Label that associated value _ foo, where foo can be any valid identifier (see example below)

Option B:

  1. Create an issue like this one (or other Markdown document) on GitHub
  2. Embed an enum with a case with an associated value in the document surrounded by ```swift and ```
  3. Label that associated value _ foo, where foo can be any valid identifier (see example below)
enum Foo {
    case one(_ x: Int) // no error, but marked as invalid
    case two(_: Int)
    case three(x y: Int) // error: enum case cannot have keyword arguments
    case four(x: Int)
    case five(__ x: Int) // error: enum case cannot have keyword arguments
}

Note the following:

  • case one(_ x: Int) is valid, but is incorrectly marked invalid
  • case two(_: Int) is valid, and marked valid
  • case three(x y: Int) is invalid, and marked invalid
  • case four(x: Int) is valid, and marked valid
  • case five(__ x: Int) (two _s) is invalid, and marked invalid

Expected results

case one(_ x: Int) should be considered valid Swift code.

Actual results

case one(_ x: Int) is marked as invalid Swift code (highlighted with a red background).

Environment

GitHub, using (presumably) the latest version of Linguist, using (presumably) a recent version of swift.tmbundle.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.