Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module SExpr where
  2.  
  3. import           AParser
  4. import           Control.Applicative
  5. import           Data.Char
  6.  
  7. zeroOrMore :: Parser a -> Parser [a]
  8. zeroOrMore p = oneOrMore p <|> pure []
  9.  
  10. oneOrMore :: Parser a -> Parser [a]
  11. oneOrMore p = (:) <$> p <*> zeroOrMore p
  12.  
  13. spaces :: Parser String
  14. spaces = zeroOrMore $ satisfy isSpace
  15.  
  16. ident :: Parser String
  17. ident = (:) <$> satisfy isAlpha <*> zeroOrMore (satisfy isAlphaNum)
  18.  
  19. -------------------- when evaluated i the results well -------------------------
  20. -- >>> runParser ident "foobar baz"
  21. -- Just ("foobar"," baz")
  22. -- >>> runParser ident "foo33fA"
  23. -- Just ("foo33fA","")
  24. -- >>> runParser ident "2bad"
  25. -- Nothing
  26. -- >>> runParser ident ""
  27. -- Nothing
  28.  
  29.  
  30. -------------------- when evaluated sometimes i get them with these exceptions -------------------------
  31.  
  32. -- >>> runParser ident "foobar baz"
  33. -- <interactive>:338:2-10: error:
  34. --     Variable not in scope:
  35. --       runParser :: AParser.Parser String -> [Char] -> t
  36. -- >>> runParser ident "foo33fA"
  37. -- <interactive>:339:2-10: error:
  38. --     Variable not in scope:
  39. --       runParser :: AParser.Parser String -> [Char] -> t
  40. -- >>> runParser ident "2bad"
  41. -- <interactive>:340:2-10: error:
  42. --     Variable not in scope:
  43. --       runParser :: AParser.Parser String -> [Char] -> t
  44. -- >>> runParser ident ""
  45. -- <interactive>:341:2-10: error:
  46. --     Variable not in scope:
  47. --       runParser :: AParser.Parser String -> [Char] -> t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement