Skip to content

Instantly share code, notes, and snippets.

@Solonarv
Last active March 5, 2019 01:11
Show Gist options
  • Save Solonarv/a92ba49e29702cdb88c9c1e6a99d4944 to your computer and use it in GitHub Desktop.
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
{-# 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