1
1
mirror of https://github.com/github/semantic.git synced 2024-12-30 02:14:20 +03:00
semantic/prototype/doubt-difftool/Argument.swift

44 lines
1.0 KiB
Swift
Raw Normal View History

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:44:52 +03:00
indirect case OutputFlag(Output, Argument)
2015-11-02 21:06:23 +03:00
case Sources(Source, Source)
2015-11-02 19:37:54 +03:00
2015-11-02 21:06:23 +03:00
var sources: (Source, Source) {
2015-11-02 19:37:54 +03:00
switch self {
2015-11-02 21:06:23 +03:00
case let .Sources(a, b):
return (a, b)
2015-11-02 21:06:23 +03:00
case let .OutputFlag(_, rest):
return rest.sources
2015-11-02 19:37:54 +03:00
}
}
2015-11-02 19:44:42 +03:00
2015-11-02 20:07:38 +03:00
var output: Output {
2015-11-02 21:07:24 +03:00
switch self {
case let .OutputFlag(output, _):
return output
default:
return .Split
2015-11-02 20:07:38 +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 20:57:41 +03:00
<|> pure(Argument.Output.Split)
2015-11-02 19:46:57 +03:00
private let source: Madness.Parser<[String], Source>.Function =
{ try! Source($0) } <^> satisfy { !$0.hasPrefix("--") }
let argumentsParser: Madness.Parser<[String], Argument>.Function = any // skip the path to the difftool
*> (curry(Argument.OutputFlag) <^> flag)
2015-11-02 21:06:23 +03:00
<*> (curry(Argument.Sources) <^> source <*> source)
2015-11-02 19:35:41 +03:00
import Madness
2015-11-02 19:51:13 +03:00
import Prelude