-
Notifications
You must be signed in to change notification settings - Fork 20
/
Spec.hs
86 lines (64 loc) · 2.01 KB
/
Spec.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{-# LANGUAGE OverloadedStrings #-}
-- | The precisely-typed version of Hawk's command-line arguments.
module System.Console.Hawk.Args.Spec where
import Data.ByteString (ByteString)
data HawkSpec
= Help
| Version
| Eval ExprSpec OutputSpec
| Apply ExprSpec InputSpec OutputSpec
| Map ExprSpec InputSpec OutputSpec
deriving (Show, Eq)
data InputSpec = InputSpec
{ inputSource :: InputSource
, inputFormat :: InputFormat
}
deriving (Show, Eq)
data OutputSpec = OutputSpec
{ outputSink :: OutputSink
, outputFormat :: OutputFormat
}
deriving (Show, Eq)
data InputSource
= NoInput
| UseStdin
| InputFile FilePath
deriving (Show, Eq)
data OutputSink
= UseStdout
-- OutputFile FilePath -- we might want to implement --in-place
-- in the future
deriving (Show, Eq)
data InputFormat
= RawStream
| Lines Separator LineFormat
deriving (Show, Eq)
data LineFormat
= RawLine
| Words Separator
deriving (Show, Eq)
-- We can't know ahead of time whether it's going to be a raw stream
-- or raw lines or words, it depends on the type of the user expression.
data OutputFormat = OutputFormat
{ lineDelimiter :: Separator
, wordDelimiter :: Separator
}
deriving (Show, Eq)
type Separator = ByteString
data ExprSpec = ExprSpec
{ userContextDirectory :: FilePath
, userExpression :: String
}
deriving (Show, Eq)
defaultInputSpec, noInput :: InputSpec
defaultInputSpec = InputSpec UseStdin defaultInputFormat
noInput = InputSpec NoInput defaultInputFormat
defaultOutputSpec :: OutputSpec
defaultOutputSpec = OutputSpec UseStdout defaultOutputFormat
defaultInputFormat :: InputFormat
defaultInputFormat = Lines defaultLineSeparator (Words defaultWordSeparator)
defaultOutputFormat :: OutputFormat
defaultOutputFormat = OutputFormat defaultLineSeparator defaultWordSeparator
defaultLineSeparator, defaultWordSeparator :: Separator
defaultLineSeparator = "\n"
defaultWordSeparator = " "