Parsing with Haskell
serokell.io
serokell.io
We also cover parser combinators on our blog for the interested: https://serokell.io/blog/parser-combinators-in-haskell
And if you want to see what are the benefits of this approach over parser combinators, the second part of this series covers a little bit of that: https://serokell.io/blog/parsing-with-happy#happy-vs.-megapa...
https://markkarpov.com/tutorial/megaparsec.html https://hackage.haskell.org/package/megaparsec
However it does rely on some GHC extensions, which makes things a bit more complicated for beginners, so for simplicity's sake it might be easier to start with Parsec and one of the old papers that goes with it.
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
And you do have to understand TypeFamilies to use Megaparsec.This is only the case if you're using custom input streams, right? Writing a parser that just operates on ByteString/Text seems like a pretty gentle/reasonable introduction to this style of parsing and doesn't require any understanding of TypeFamilies as far as I can tell (I certainly didn't understand TypeFamilies when I learned to use megaparsec).
1. You might not know a priori that the lexical analysis can be done without any knowledge of the surrounding grammatical context.
2. You may be able to give more informative error messages if you know the grammatical context.