Skip to content

Commit

Permalink
Some parsing fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
augustss committed Jul 26, 2024
1 parent 5b49dfb commit 04ace11
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/MicroCabal/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import MicroCabal.Unix
--import MicroCabal.YAML

version :: String
version = "MicroCabal 0.1.0.0"
version = "MicroCabal 0.1.1.0"

main :: IO ()
main = do
Expand Down
15 changes: 13 additions & 2 deletions src/MicroCabal/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ parseSnapshots fn rfile = runP pSnapshotsTop fn rfile

runP :: P a -> FilePath -> String -> a
runP prsr fn file =
case runPrsr prsr (initLexState file) of
case runPrsr prsr (initLexState (preLex file)) of
Left (LastFail n ts msgs) -> error $ "\n" ++
" found: " ++ (map show ts ++ ["EOF"]) !! 0 ++ "\n" ++
" expected: " ++ unwords (nub msgs) ++ "\n" ++
Expand All @@ -37,6 +37,17 @@ runP prsr fn file =
Right (a:_) -> a
Right [] -> undefined -- impossible

-- Fixup of '\r' and '\t'
preLex :: [Char] -> [Char]
preLex = loop 0
where
loop :: Int -> [Char] -> [Char]
loop _ [] = []
loop _ ('\n':cs) = '\n' : loop 0 cs
loop _ ('\r':cs) = loop 0 cs
loop n ('\t':cs) = replicate k ' ' ++ loop 0 cs
where k = 8 - n `rem` 8
loop n (c:cs) = c : loop (n+1) cs

------------------------------

Expand Down Expand Up @@ -207,7 +218,7 @@ pComma :: P ()
pComma = pWhite *> pChar ','

pCommaList :: P a -> P [a]
pCommaList p = (pStr "," *> esepBy1 p pComma)
pCommaList p = (pStrW "," *> esepBy1 p pComma)
<|< pCommaList' p

pCommaList' :: P a -> P [a]
Expand Down

0 comments on commit 04ace11

Please sign in to comment.