Swiftformat: Linux support?

Created on 5 Apr 2018  路  6Comments  路  Source: nicklockwood/SwiftFormat

We're making an index of cool Swift cross-platform tools and libraries. Is SwiftFormat intended for use in Linux as well? If so, how can I compile it? I tried swift build and it says warning: no targets to build in package x3

Thank you for the help, and have a good day :)

Most helpful comment

@felix91gr FYI, SwiftFormat now works on Linux (including tests).

All 6 comments

@felix91gr SwiftFormat only works on macOS at the moment, as it relies on the Objective-C runtime (I'll consider refactoring to remove that requirement if there's a lot of interest in Linux support though).

You might want to check out my Expression and Consumer libs though, which both support Linux :-)

I'll consider refactoring to remove that requirement if there's a lot of interest in Linux support though

Okay! Let's see what happens then :)

Atm I'm mainly focusing on helping make SourceKittenDaemon and langserver-swift a reality on Linux. Any of those are required for a sane developing experience (IDE, autocomplete, etc). Therefore, I don't have a use case for formatting right now, and probably other Linux devs don't either. But maybe in the future that will change.

You might want to check out my Expression and Consumer libs though, which both support Linux :-)

Consumer looks really cool! Can you really parse like, CSS with it? What kind of syntaxes are supported? I'm guessing up to Context-Free Grammars, more or less?

Expression is also interesting, but I don't quite understand the full scope of it. Does it evaluate arithmetic? How does it do so? Can you express other kinds of expressions there?

Also: in none of them you have Linux tests. Don't worry; that's normal since XCTest support for Linux is kinda weird. You'll see what I mean when I open a PR there :)

Consumer looks really cool! Can you really parse like, CSS with it? What kind of syntaxes are supported? I'm guessing up to Context-Free Grammars, more or less?

It鈥檚 a parser combinator framework, so it鈥檚 not limited to context free grammars - in theory it can parse just about anything - you just have to define the rules.

Expression is also interesting, but I don't quite understand the full scope of it. Does it evaluate arithmetic? How does it do so? Can you express other kinds of expressions there?

Out of the box it can evaluate arithmetic or boolean expressions, but it can be extended with custom variables or symbols, and it can work with arbitrary types, so it can be used for any kind of expression. It鈥檚 good for something like a calculator or a complex configuration file. It鈥檚 used heavily by my iOS Layout UI framework.

It only works with pure/functional expressions though - it鈥檚 not designed for creating imperative programming languages (for that you can use Consumer instead).

I couldn't make Expression work, because you're importing CoreGraphics somewhere. Are you sure it runs on Linux? Well, I was trying to make swift test work after all so maybe it _does_ work but tests don't :thinking:

@felix91gr correct - the framework works on Linux but the tests don鈥檛.

@felix91gr FYI, SwiftFormat now works on Linux (including tests).

Was this page helpful?
0 / 5 - 0 ratings