Skip to content

Instantly share code, notes, and snippets.

@dminuoso

dminuoso/f.hs Secret

Created December 9, 2022 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dminuoso/3f8272c66fed64349f28c171deafdefa to your computer and use it in GitHub Desktop.
Save dminuoso/3f8272c66fed64349f28c171deafdefa to your computer and use it in GitHub Desktop.
sepBy1 :: Parser a -> Parser b -> Parser [a]
sepBy1 p s = liftA2 (:) p (FP.many (s >> p))
crate :: Parser MCrate
crate = do
b <- FP.lookahead FP.anyWord8
case BS.w2c b of
' ' -> Nothing <$ $(FP.string " ")
'[' -> FP.skip 1 >> (Just <$> FP.anyCharASCII) <* $(FP.char ']')
'\n' -> FP.empty
_ -> FP.err "bad input"
eol :: Parser ()
eol = $(FP.char '\n')
hstack :: Parser [MCrate]
hstack = sepBy1 crate $(FP.char ' ') <* eol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment