# HG changeset patch # User unc0rr # Date 1321538265 -14400 # Node ID bd5851ab31573abc2053b346d5e0846569ac87ed # Parent 3807d4cad077c979cf898d7a74f801bedeefcf80 - Parse sets initialization - Render interface part of unit; diff -r 3807d4cad077 -r bd5851ab3157 tools/PascalParser.hs --- a/tools/PascalParser.hs Wed Nov 16 16:36:17 2011 -0500 +++ b/tools/PascalParser.hs Thu Nov 17 17:57:45 2011 +0400 @@ -85,6 +85,7 @@ | InitString String | InitChar String | BuiltInFunction String [InitExpression] + | InitSet [Identifier] | InitNull deriving Show @@ -577,6 +578,7 @@ where term = comments >> choice [ liftM (uncurry BuiltInFunction) $ builtInFunction initExpression + , try $ brackets pas (commaSep pas $ iD) >>= return . InitSet , try $ parens pas (commaSep pas $ initExpression) >>= return . InitArray , parens pas (semiSep pas $ recField) >>= return . InitRecord , try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . InitNumber . show) i diff -r 3807d4cad077 -r bd5851ab3157 tools/pas2c.hs --- a/tools/pas2c.hs Wed Nov 16 16:36:17 2011 -0500 +++ b/tools/pas2c.hs Thu Nov 17 17:57:45 2011 +0400 @@ -15,8 +15,13 @@ (Right a) -> (return . render . pascal2C) a pascal2C :: PascalUnit -> Doc -pascal2C (Unit unitName interface implementation init fin) = implementation2C implementation +pascal2C (Unit unitName interface implementation init fin) = + interface2C interface + $+$ + implementation2C implementation +interface2C :: Interface -> Doc +interface2C (Interface uses tvars) = typesAndVars2C tvars implementation2C :: Implementation -> Doc implementation2C (Implementation uses tvars) = typesAndVars2C tvars @@ -48,7 +53,15 @@ initExpr Nothing = empty initExpr (Just e) = text "=" <+> initExpr2C e -initExpr2C :: InitExpression -> Doc +initExpr2C :: InitExpression -> Doc +initExpr2C (InitBinOp op expr1 expr2) = parens $ (initExpr2C expr1) <+> op2C op <+> (initExpr2C expr2) +initExpr2C (InitNumber s) = text s +initExpr2C (InitFloat s) = text s +initExpr2C (InitHexNumber s) = text "0x" <> (text . map toLower $ s) +initExpr2C (InitString s) = doubleQuotes $ text s +initExpr2C (InitReference (Identifier i)) = text i + + initExpr2C _ = text "<>" type2C :: TypeDecl -> Doc