Skip to content

Instantly share code, notes, and snippets.

@rightfold
Created April 18, 2014 19:29
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 rightfold/889ba0307e5be0107057 to your computer and use it in GitHub Desktop.
Save rightfold/889ba0307e5be0107057 to your computer and use it in GitHub Desktop.
ecmascript :: Parser String
ecmascript = lexeme $ char '{' *> ecmascript' 0
where ecmascript' n = do
c <- anyChar
case c of
'{' -> ('{' :) <$> ecmascript' (succ n)
'}' -> if n == 0
then return ""
else ('}' :) <$> ecmascript' (pred n)
_ -> (c :) <$> ecmascript' n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment