Skip to content

Commit 93e0e3e

Browse files
committed
Allow one-line grouping using "." in idents
Fixes bos#19
1 parent ff6d476 commit 93e0e3e

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/dist/

Data/Configurator/Parser.hs

+19-6
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ topLevel = directives <* skipLWS <* endOfInput
3434

3535
directive :: Parser Directive
3636
directive =
37-
mconcat [
38-
string "import" *> skipLWS *> (Import <$> string_)
39-
, Bind <$> try (ident <* skipLWS <* char '=' <* skipLWS) <*> value
40-
, Group <$> try (ident <* skipLWS <* char '{' <* skipLWS)
41-
<*> directives <* skipLWS <* char '}'
42-
]
37+
string "import" *> skipLWS *> (Import <$> string_)
38+
<|> do
39+
ids <- idents
40+
skipLWS
41+
groupIdents (\n -> bind n <|> group n) ids
4342

4443
directives :: Parser [Directive]
4544
directives = (skipLWS *> directive <* skipHWS) `sepBy`
@@ -77,6 +76,14 @@ ident = do
7776
where
7877
isCont c = isAlphaNum c || c == '_' || c == '-'
7978

79+
idents :: Parser [Name]
80+
idents = sepBy1 ident (char '.')
81+
82+
groupIdents :: (Name -> Parser Directive) -> [Name] -> Parser Directive
83+
groupIdents p [n] = p n
84+
groupIdents p (g:n) = Group g . return <$> groupIdents p n
85+
groupIdents p [] = p (error "empty ident")
86+
8087
value :: Parser Value
8188
value = mconcat [
8289
string "on" *> pure (Bool True)
@@ -89,6 +96,12 @@ value = mconcat [
8996
((value <* skipLWS) `sepBy` (char ',' <* skipLWS))
9097
]
9198

99+
bind :: Name -> Parser Directive
100+
bind n = char '=' >> skipLWS >> Bind n <$> value
101+
102+
group :: Name -> Parser Directive
103+
group n = brackets '{' '}' $ Group n <$> directives <* skipLWS
104+
92105
string_ :: Parser Text
93106
string_ = do
94107
s <- char '"' *> scan False isChar <* char '"'

tests/resources/interp.cfg

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services = "$(HOME)/services"
22
root = "can be overwritten by inner block."
3+
myprogram.name="myprogram"
34
myprogram {
4-
name = "myprogram"
55
root = "$(services)/$(name)"
66
exec = "$(root)/$(name)"
77
stdout = "$(root)/stdout"
@@ -13,8 +13,6 @@ top {
1313
dir = "$(dir)/top"
1414
layer1 {
1515
dir = "$(dir)/layer1"
16-
layer2 {
17-
dir = "$(dir)/layer2"
18-
}
16+
layer2.dir ="$(dir)/layer2"
1917
}
2018
}

tests/resources/pathological.cfg

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ af
3030
#baz
3131
]#quux
3232

33-
ag { q-e { i_u9 { a=false}}}
33+
ag { q-e { i_u9 { a=true}}}
3434

3535
ba = "$(HOME)"
3636

3737
xs = [1,2,3]
3838

3939
c = "x"
40+
41+
ag.q-e.i_u9.a=false

0 commit comments

Comments
 (0)