]> git.rmz.io Git - my-scheme.git/commitdiff
Ignore spaces
authorSamir Benmendil <me@rmz.io>
Sat, 13 Jan 2018 23:24:30 +0000 (23:24 +0000)
committerSamir Benmendil <me@rmz.io>
Sat, 13 Jan 2018 23:24:30 +0000 (23:24 +0000)
We add the spaces `Parser` which returns nothing `()` and skips any
spaces.

`spaces` is already defined in Parsec, but does not do exactly what we
want, we can hide it from the import.

`skipMany a` matches 0 or more `a` and skips them.

`>>` is the **bind** operator. It may have completely different meanings
depending on the monad you use. In the Parser monad in means "try the
first parameter, then try the second with anything that is left", i.e.
"first skip all the spaces, then match the symbol".

app/Main.hs

index a94dc2ce2355835c62533047f14994df94f28319..852089135df8fa8b9ccef54f9699d95bc41d8df2 100644 (file)
@@ -1,12 +1,15 @@
 module Main where
-import Text.ParserCombinators.Parsec
+import Text.ParserCombinators.Parsec hiding (spaces)
 import System.Environment
 
 symbol :: Parser Char
 symbol = oneOf "!#$%&|*+-/:<=>?@^_~"
 
+spaces :: Parser ()
+spaces = skipMany space
+
 readExpr :: String -> String
-readExpr input = case parse symbol "lisp" input of
+readExpr input = case parse (spaces >> symbol) "lisp" input of
     Left err -> "No match: " ++ show err
     Right val -> "Found value"