Skip to content

Commit

Permalink
feature: Liberalize record/array literals parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
supki committed Oct 8, 2024
1 parent 0992246 commit 8990799
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/T/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,10 @@ litP = do
map String stringLiteral
arrayP =
map (Array . Vector.fromList)
(brackets (Unspaced (sepBy expP (symbol ","))))
(brackets (spaces *> Unspaced (sepBy expP (symbol ","))))
recordP =
map (Record . HashMap.fromList)
(braces (Unspaced (sepBy kv (symbol ","))))
(braces (spaces *> Unspaced (sepBy kv (symbol ","))))
where
kv = do
k <- map fromString (some letter)
Expand Down
30 changes: 30 additions & 0 deletions test/T/ParseSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,36 @@ spec =
\ foo =\n\
\ 4\n\
\%}" `shouldParseTo` Tmpl.Set [Tmpl.Assign (var "foo") (int 4)]
"{% set\n\
\ arr =\n\
\ [ 4\n\
\ , 7\n\
\ , 42\n\
\ ]\n\
\%}" `shouldParseTo` Tmpl.Set
[ Tmpl.Assign
(var "arr")
(array
[ int 4
, int 7
, int 42
])
]
"{% set\n\
\ rec =\n\
\ { foo: 4\n\
\ , bar: 7\n\
\ , baz: 42\n\
\ }\n\
\%}" `shouldParseTo` Tmpl.Set
[ Tmpl.Assign
(var "rec")
(record
[ ("foo", int 4)
, ("bar", int 7)
, ("baz", int 42)
])
]

context "multi-*" $ do
it "multi-sets" $ do
Expand Down

0 comments on commit 8990799

Please sign in to comment.