mirror of
https://github.com/zoriya/HAL.git
synced 2026-06-03 22:20:52 +00:00
Handling quoted read syntax
This commit is contained in:
+1
-1
@@ -13,7 +13,7 @@ main = runInputT defaultSettings (loop $ [])
|
||||
where
|
||||
loop :: LispEnv -> InputT IO ()
|
||||
loop env = do
|
||||
minput <- getInputLine " > "
|
||||
minput <- getInputLine "> "
|
||||
case minput of
|
||||
Nothing -> return ()
|
||||
Just "exit" -> return ()
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
module BasicParser where
|
||||
|
||||
import Control.Applicative ( Alternative(..) )
|
||||
import Data.Char ( isDigit, isNumber, isSpace )
|
||||
import Data.Char ( isDigit, isNumber, isSpace, isAlphaNum )
|
||||
import Text.Read ( readMaybe )
|
||||
|
||||
data Parser a = Parser {
|
||||
@@ -64,7 +64,7 @@ pString (x:xs) = do
|
||||
pString [] = pure ""
|
||||
|
||||
pToken :: Parser String
|
||||
pToken = pUntil $ \x -> isSpace x || x == ')' || x == '('
|
||||
pToken = pUntil (not . isAlphaNum)
|
||||
|
||||
pDigit :: Parser Char
|
||||
pDigit = pCharIf isDigit
|
||||
|
||||
+19
-1
@@ -4,6 +4,7 @@ import BasicParser
|
||||
( Parser, pCharIf, pUntil, pInt, pFloat, tokenify, pToken, pString )
|
||||
import Expressions ( SExpr(..), Atom(..), Statement(..) )
|
||||
import Control.Applicative ( Alternative(some, (<|>)) )
|
||||
import Debug.Trace
|
||||
|
||||
_pAtom :: Parser Atom
|
||||
_pAtom = AInt <$> pInt
|
||||
@@ -28,9 +29,26 @@ pAtom = (pCharIf (== '\'') *> pQuotedAtom)
|
||||
-- but I believe that this is not really a feature.
|
||||
pQuotedAtom :: Parser Atom
|
||||
pQuotedAtom = ANil <$ pString "()"
|
||||
<|> pCharIf (== '\'') *> ((\x -> ACons (ASymbol "quote") (ACons x ANil)) <$> pQuotedAtom)
|
||||
<|> pCharIf (== '\'') *>
|
||||
((\x -> ACons (ASymbol "quote") (ACons x ANil)) <$> pQuotedAtom)
|
||||
<|> pCharIf (== '(') *> pConsReadExpr <*pCharIf (== ')')
|
||||
<|> AQuote <$> _pAtom
|
||||
|
||||
pConsReadExpr :: Parser Atom
|
||||
pConsReadExpr =
|
||||
do
|
||||
fs <- tokenify pQuotedAtom
|
||||
se <- tokenify pConsReadExpr
|
||||
return $ ACons fs se
|
||||
<|> do
|
||||
fs <- tokenify pQuotedAtom
|
||||
tokenify $ pCharIf (== '.')
|
||||
se <- tokenify pQuotedAtom
|
||||
return $ ACons fs se
|
||||
<|> do
|
||||
fs <- tokenify pQuotedAtom
|
||||
return $ ACons fs ANil
|
||||
|
||||
pSExpr :: Parser SExpr
|
||||
pSExpr = pCharIf (== '(') *> (SExpr <$> some (tokenify pStatement)) <* pCharIf (== ')')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user