2015-11-02 20:04:09 +03:00
|
|
|
/// A list of arguments for the difftool.
|
2015-11-02 19:36:20 +03:00
|
|
|
enum Argument {
|
2015-11-02 19:36:52 +03:00
|
|
|
indirect case File(Source, Argument)
|
2015-11-02 19:44:52 +03:00
|
|
|
indirect case OutputFlag(Output, Argument)
|
2015-11-02 19:36:52 +03:00
|
|
|
case End
|
2015-11-02 19:37:54 +03:00
|
|
|
|
2015-11-02 20:03:51 +03:00
|
|
|
private var rest: Argument? {
|
2015-11-02 19:44:18 +03:00
|
|
|
switch self {
|
|
|
|
case let .File(_, rest):
|
|
|
|
return rest
|
2015-11-02 19:44:52 +03:00
|
|
|
case let .OutputFlag(_, rest):
|
|
|
|
return rest
|
2015-11-02 19:44:18 +03:00
|
|
|
case .End:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-02 19:37:54 +03:00
|
|
|
var files: [Source] {
|
|
|
|
switch self {
|
|
|
|
case let .File(a, rest):
|
|
|
|
return [a] + rest.files
|
2015-11-02 19:44:30 +03:00
|
|
|
default:
|
|
|
|
return rest?.files ?? []
|
2015-11-02 19:37:54 +03:00
|
|
|
}
|
|
|
|
}
|
2015-11-02 19:44:42 +03:00
|
|
|
|
|
|
|
enum Output {
|
|
|
|
case Unified
|
|
|
|
case Split
|
|
|
|
}
|
2015-11-02 19:36:20 +03:00
|
|
|
}
|
2015-11-02 19:35:32 +03:00
|
|
|
|
2015-11-02 19:51:13 +03:00
|
|
|
private let flag: Madness.Parser<[String], Argument.Output>.Function =
|
|
|
|
const(Argument.Output.Unified) <^> satisfy { $0 == "--unified" }
|
|
|
|
<|> const(Argument.Output.Split) <^> satisfy { $0 == "--split" }
|
2015-11-02 19:46:57 +03:00
|
|
|
|
2015-11-02 20:00:11 +03:00
|
|
|
private let source: Madness.Parser<[String], Source>.Function =
|
|
|
|
{ try! Source($0) } <^> satisfy { !$0.hasPrefix("--") }
|
|
|
|
|
2015-11-02 20:01:33 +03:00
|
|
|
let argumentsParser: Madness.Parser<[String], Argument>.Function = fix { rest in
|
2015-11-02 20:03:08 +03:00
|
|
|
(curry(Argument.OutputFlag) <^> flag <|> curry(Argument.File) <^> source)
|
|
|
|
<*> rest
|
2015-11-02 20:03:16 +03:00
|
|
|
<|> pure(Argument.End)
|
2015-11-02 20:01:33 +03:00
|
|
|
}
|
2015-11-02 19:35:41 +03:00
|
|
|
|
|
|
|
import Madness
|
2015-11-02 19:51:13 +03:00
|
|
|
import Prelude
|