print (VarExpr _ vd) = print vd
print (Op2Expr _ e1 o e2) = ["(":print e1] ++ [" ",case o of
BiPlus = "+"; BiMinus = "-"; BiTimes = "*"; BiDivide = "/"
- BiMod = "%"; BiEquals = "="; BiLesser = "<"; BiGreater = ">"
+ BiMod = "%"; BiEquals = "=="; BiLesser = "<"; BiGreater = ">"
BiLesserEq = "<="; BiGreaterEq = ">="; BiUnEqual = "!=";
BiAnd = "&&"; BiOr = "||"; BiCons = ":"
," ":print e2] ++ [")"]
If `help2man` is installed you can generate a manpage by running `make man`.
For full instruction see `man ./spl.1` or run `./spl --help`.
+## Fun
+You can verify the parser and pretty printer by running:
+```
+diff -s <(./spl examples/example.spl | ./spl) <(./spl examples/example.spl)
+```
+
## `LICENCE`
See `LICENCE` file.
parseFunDecl = liftM6 FunDecl
(peekPos)
(parseIdent)
- (satTok BraceOpenToken *> parseSepList CommaToken parseIdent <* satTok BraceCloseToken)
- (optional parseFunType <* satTok CBraceOpenToken)
- (many parseVarDecl)
+ (parseBBraces $ parseSepList CommaToken parseIdent)
+ (optional parseFunType)
+ (satTok CBraceOpenToken *> many parseVarDecl)
(many parseStmt <* satTok CBraceCloseToken)
parseStmt :: Parser Token Stmt
parseStmt = parseIfStmt <|> parseWhileStmt <|>
parseSColon parseAssStmt <|> parseSColon parseReturnStmt <|>
- (liftM FunStmt (parseSColon parseFunCall))
+ (FunStmt <$> parseSColon parseFunCall)
where
parseSColon :: (Parser Token a) -> Parser Token a
parseSColon p = p <* satTok SColonToken
(optional (satTok ElseToken *> (parseBlock<|> parseOneLine))))
parseWhileStmt :: Parser Token Stmt
- parseWhileStmt = satTok WhileToken *>
- (WhileStmt <$> (parseBBraces parseExpr) <*> parseBlock)
+ parseWhileStmt = satTok WhileToken *> (WhileStmt <$>
+ (parseBBraces parseExpr) <*> (parseBlock <|> parseOneLine))
parseBlock :: Parser Token [Stmt]
parseBlock = parseBCBraces (many parseStmt)
parseIdent = trans2 (IdentToken "") (\(IdentToken e).toString e)
//liftM only goes to liftM5
-liftM6 f m1 m2 m3 m4 m5 m6 = f <$> m1 <*> m2 <*> m3 <*> m4 <*> m5 <*> m6
\ No newline at end of file
+liftM6 f m1 m2 m3 m4 m5 m6 = f <$> m1 <*> m2 <*> m3 <*> m4 <*> m5 <*> m6