mirror of
https://github.com/github/semantic.git
synced 2024-12-18 20:31:55 +03:00
7b9e6e778f
This currently asserts the lack of errors, which we’ll have to correct. I just don’t know what the right pattern for that should be.
45 lines
948 B
Swift
45 lines
948 B
Swift
enum Argument {
|
|
indirect case File(Source, Argument)
|
|
indirect case OutputFlag(Output, Argument)
|
|
case End
|
|
|
|
var rest: Argument? {
|
|
switch self {
|
|
case let .File(_, rest):
|
|
return rest
|
|
case let .OutputFlag(_, rest):
|
|
return rest
|
|
case .End:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
var files: [Source] {
|
|
switch self {
|
|
case let .File(a, rest):
|
|
return [a] + rest.files
|
|
default:
|
|
return rest?.files ?? []
|
|
}
|
|
}
|
|
|
|
enum Output {
|
|
case Unified
|
|
case Split
|
|
}
|
|
}
|
|
|
|
private let flag: Madness.Parser<[String], Argument.Output>.Function =
|
|
const(Argument.Output.Unified) <^> satisfy { $0 == "--unified" }
|
|
<|> const(Argument.Output.Split) <^> satisfy { $0 == "--split" }
|
|
|
|
private let source: Madness.Parser<[String], Source>.Function =
|
|
{ try! Source($0) } <^> satisfy { !$0.hasPrefix("--") }
|
|
|
|
let argumentsParser: Madness.Parser<[String], Argument>.Function =
|
|
curry(Argument.OutputFlag) <^> flag <*> pure(Argument.End)
|
|
|
|
|
|
import Madness
|
|
import Prelude
|