@@ -15,18 +15,29 @@ type Path = Text
15
15
16
16
type Indent = Int
17
17
18
+ data Package = Package Name [Component ]
19
+ deriving (Show , Eq , Ord )
20
+
18
21
data Component = Lib Path | Exe Name Path | Test Name Path
19
22
deriving (Show , Eq , Ord )
20
23
21
- parseComponents :: Parser [Component ]
22
- parseComponents =
24
+ parseName :: Parser Text
25
+ parseName = " name" >> skipSpace >> char ' :' >> parseString
26
+
27
+ parseSec :: Parser Package
28
+ parseSec =
23
29
( do
24
- h <- parseComponent 0
25
- t <- parseComponents
26
- pure $ h : t
30
+ n <- parseName
31
+ ( Package _ t) <- parseSec
32
+ pure $ Package n t
27
33
)
28
- <|> (skipToNextLine >> parseComponents)
29
- <|> pure []
34
+ <|> ( do
35
+ h <- parseComponent 0
36
+ (Package n t) <- parseSec
37
+ pure $ Package n (h : t)
38
+ )
39
+ <|> (skipToNextLine >> parseSec)
40
+ <|> pure (Package " " [] )
30
41
31
42
parseComponent :: Indent -> Parser Component
32
43
parseComponent i =
@@ -41,18 +52,23 @@ parseLib i =
41
52
>> skipToNextLine
42
53
>> Lib <$> parsePath (i + 1 )
43
54
44
- parseComponentName :: Parser Name
45
- parseComponentName = do
55
+ parseQuoted :: Parser Text
56
+ parseQuoted = do
57
+ q <- char ' "' <|> char ' \' '
58
+ takeTill (== q)
59
+
60
+ parseString :: Parser Name
61
+ parseString = do
46
62
skipSpace
47
- takeWhile1 (not . isSpace)
63
+ parseQuoted <|> takeWhile1 (not . isSpace)
48
64
49
65
parseNamed :: Indent -> Text -> (Name -> Path -> Component ) -> Parser Component
50
66
parseNamed i compType compCon =
51
67
do
52
68
indent i
53
69
_ <- asciiCI compType <?> " asciiCI " <> T. unpack compType
54
70
_ <- skipSpace <?> " skipSpace"
55
- n <- parseComponentName <?> " N"
71
+ n <- parseString <?> " N"
56
72
skipToNextLine
57
73
compCon n <$> parsePath (i + 1 )
58
74
<?> T. unpack (" parseNamed " <> compType)
@@ -78,7 +94,7 @@ parsePath i =
78
94
skipSpace
79
95
_ <- char ' :'
80
96
-- FIXME paths can be in quotes
81
- p <- parseComponentName
97
+ p <- parseString
82
98
skipToNextLine
83
99
skipBlock i
84
100
pure p
0 commit comments