Last active
March 5, 2019 01:11
-
-
Save Solonarv/a92ba49e29702cdb88c9c1e6a99d4944 to your computer and use it in GitHub Desktop.
Simple parser for the Dyck language https://en.wikipedia.org/wiki/Dyck_language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeFamilies #-} | |
module Dyck where | |
import Control.Applicative hiding (many) | |
import Control.Monad | |
import Data.Void | |
import Text.Megaparsec | |
import Text.Megaparsec.Char | |
newtype Dyck = Some [Dyck] | |
deriving Show | |
pDyck :: (Token s ~ Char, Stream s) => Parsec Void s Dyck | |
pDyck = Some <$> many (char '[' *> pDyck <* char ']') | |
showDyck :: Dyck -> String | |
showDyck (Some xs) = mconcat ["[" ++ w ++ "]" | w <- showDyck xs] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment