docopt / docopt.swift

A command-line interface description language and parser that will make you smile http://docopt.org/
MIT License
52 stars 18 forks source link

upgrade to swift 2.0 syntax; target 10.10 #3

Closed ttilley closed 9 years ago

ttilley commented 9 years ago

all tests pass :relieved:

Not everything is converted to be idiomatic swift 2.0. There's still some weird syntax in a few places that could be improved by additions to the language, and the new error handling syntax isn't used... I think that Docopt.parse should throw rather than exiting or raising an NSException to enable recovery as well as making it much more friendly to use in xcode playgrounds. As a matter of fact, I would like to use an xcode playground as documentation, which would require sane handling (and thus display) of error cases without exiting.

Additionally, since I'm using a case sensitive filesystem (to avoid a particularly nasty fsevents bug that has persisted for over 4 years now), I had to rename a few things to fix case sensitivity issues.

Even though this project targets 10.10, it has to use the 10.11 SDK for reasons I'm not entirely sure of. I can use the xcode7 swift 2.0 REPL on 10.10 no problem, but some projects simply fail to link when compiled on 10.10. :hankey:

Since I have a personal interest in swift on linux, and thus attempting to not import Foundation, there's not much more I can do without native regex functionality. I'm debating a native binding to icu4c, as that's what's in use by NSRegularExpression behind the scenes... only with native =~ syntax and making it a StringLiteralConvertible so that it feels like a part of swift. Would you be willing to merge such a dependency, perhaps guarded by an #if os(linux)?

I'm also debating the usefulness of parsing the usage text, and then serializing that so that parsing can become a build step that happens once. In a compiled language, I don't see the benefit of re-parsing a static, compiled-in, string on every run.

Any feedback is appreciated.

ttilley commented 9 years ago

I just noticed that you responded to this 15 hours ago. I'll attempt to address these concerns tomorrow.

What's your input on other musings made in the request?

kovpas commented 9 years ago

The rest looks nice, thanks! Regarding linux version: I don't mind, but of course let's wait for linux support in swift :)

I'll install xcode beta today and will merge this pull request. Thank you for your contribution!

ttilley commented 9 years ago

getting regular expression support without Foundation is proving to be painful anyways, so I might put that on hold until I can see the swift source code and extend swift itself in C++ (I hear swift is implemented in C++ anyways). interfacing with icu4c via swift 2.0, without any C/ObjC, is like smashing my balls with a sledgehammer. repeatedly. mapping over utf16 character values, unsafe this and unsafe that, having most "unsafe" things only last the duration of a block, having things that LOOK like closures but are actually function pointers behind the scenes so they don't capture any outside state... ugh.

so, while it's theoretically possible to have a "pure swift" interface to OSX's included libicucore, and also have that work with the non-monolithic icu4c libs on linux... I might need to get really drunk to endure the pain of writing that code.

ttilley commented 9 years ago

are there further modifications you would like to see here? (note that lack of NSRegularExpression would prevent cocoa-free use here, though i am working on pure swift ICU support (the same library backing that functionality on both apple and gnustep)). working on a foundation-free version is completely unrelated to this update.

kovpas commented 9 years ago

Sorry, for some reason I was sure that I answered to your previous post. Terribly sorry.

I first decided to wait until Xcode 7 release, because I was sure that Swift 2 syntax is going to change. And indeed, I wasn't able to compile the project without cosmetic changes: https://github.com/docopt/docopt.swift/commit/ce5d963c670cf89553f16b51b796a2528731c664

Anyways, it was easy enough. Thanks a lot for your contribution!

I updated podspec with version 0.6.3, so it's now available through cocoapods as well.

Thanks again :)