added comments
This commit is contained in:
@@ -12,6 +12,7 @@ data ZorthExpr = ZorthASTInteger Int
|
||||
| ZorthASTWordDecl (String,ZorthAST)
|
||||
| ZorthASTIfElse (ZorthAST,ZorthAST)
|
||||
| ZorthASTWhile (ZorthAST,ZorthAST)
|
||||
| ZorthASTComment String
|
||||
deriving Show
|
||||
|
||||
word1 :: Parser String
|
||||
@@ -47,7 +48,9 @@ pZorthInteger = do
|
||||
pZorthWord :: Parser ZorthExpr
|
||||
pZorthWord = do
|
||||
skipNonsenseSymbols
|
||||
ZorthASTWord <$> word1
|
||||
w <- word1
|
||||
eof <|> (nonsenseSymbol >> return ())
|
||||
return $ ZorthASTWord w
|
||||
|
||||
pZorthWordDecl :: Parser ZorthExpr
|
||||
pZorthWordDecl = do
|
||||
@@ -56,7 +59,6 @@ pZorthWordDecl = do
|
||||
xs <- manyTill pZorthExpr (do { ZorthASTWord ";" <- pZorthWord; return () })
|
||||
return $ ZorthASTWordDecl (name,xs)
|
||||
|
||||
|
||||
pZorthIfElse :: Parser ZorthExpr
|
||||
pZorthIfElse = do
|
||||
ZorthASTWord "if" <- pZorthWord
|
||||
@@ -71,8 +73,14 @@ pZorthWhile = do
|
||||
body <- manyTill pZorthExpr (do { ZorthASTWord "repeat" <- pZorthWord; return () })
|
||||
return $ ZorthASTWhile (condition,body)
|
||||
|
||||
pZorthComment :: Parser ZorthExpr
|
||||
pZorthComment = do
|
||||
ZorthASTWord "(" <- pZorthWord
|
||||
body <- manyTill get (do { ZorthASTWord ")" <- pZorthWord; return () })
|
||||
return $ ZorthASTComment body
|
||||
|
||||
pZorthExpr :: Parser ZorthExpr
|
||||
pZorthExpr = pZorthWhile <|> pZorthIfElse <|> pZorthWordDecl <++ pZorthInteger <++ pZorthWord
|
||||
pZorthExpr = pZorthComment <|> pZorthWhile <|> pZorthIfElse <|> pZorthWordDecl <++ pZorthInteger <++ pZorthWord
|
||||
|
||||
pZorth :: Parser ZorthAST
|
||||
pZorth = some pZorthExpr
|
||||
|
||||
Reference in New Issue
Block a user