# HG changeset patch # User unc0rr # Date 1322331143 -10800 # Node ID 23364a5fcc86fc008a5ed332b7d3c4adb9fa77f0 # Parent e6e409d9d6dba72265c3c9631daa055428007217 - Help parser by dropping that insane formatting syntax in str function - Parse operators diff -r e6e409d9d6db -r 23364a5fcc86 hedgewars/uFloat.pas --- a/hedgewars/uFloat.pas Sat Nov 26 12:01:13 2011 -0500 +++ b/hedgewars/uFloat.pas Sat Nov 26 21:12:23 2011 +0300 @@ -322,9 +322,9 @@ str(z.Round, cstr); if z.Frac <> 0 then begin - str(z.Frac / $100000000:1:10, tmpstr); + str(z.Frac / $100000000, tmpstr); delete(tmpstr, 1, 2); - cstr:= cstr + '.' + tmpstr + cstr:= cstr + '.' + copy(tmpstr, 1, 10) end; if z.isNegative then cstr:= '-' + cstr end; diff -r e6e409d9d6db -r 23364a5fcc86 tools/PascalParser.hs --- a/tools/PascalParser.hs Sat Nov 26 12:01:13 2011 -0500 +++ b/tools/PascalParser.hs Sat Nov 26 21:12:23 2011 +0300 @@ -28,6 +28,7 @@ data TypeVarDeclaration = TypeDeclaration Identifier TypeDecl | VarDeclaration Bool ([Identifier], TypeDecl) (Maybe InitExpression) | FunctionDeclaration Identifier TypeDecl [TypeVarDeclaration] (Maybe (TypesAndVars, Phrase)) + | OperatorDeclaration String Identifier TypeDecl [TypeVarDeclaration] (Maybe (TypesAndVars, Phrase)) deriving Show data TypeDecl = SimpleType Identifier | RangeType Range @@ -173,7 +174,7 @@ where aConstDecl = do comments - i <- iD "const declaration" + i <- iD optional $ do char ':' comments @@ -295,30 +296,56 @@ varSection, constSection, typeSection, - funcDecl + funcDecl, + operatorDecl ] where varSection = do try $ string "var" comments - v <- varsDecl1 True + v <- varsDecl1 True "variable declaration" comments return v constSection = do try $ string "const" comments - c <- constsDecl + c <- constsDecl "const declaration" comments return c typeSection = do try $ string "type" comments - t <- typesDecl + t <- typesDecl "type declaration" comments return t + operatorDecl = do + try $ string "operator" + comments + i <- manyTill anyChar space + comments + vs <- parens pas $ varsDecl False + comments + rid <- iD + comments + char ':' + comments + ret <- typeDecl + comments + return ret + char ';' + comments + forward <- liftM isJust $ optionMaybe (try (string "forward;") >> comments) + many functionDecorator + b <- if isImpl && (not forward) then + liftM Just functionBody + else + return Nothing + return $ [OperatorDeclaration i rid ret vs b] + + funcDecl = do fp <- try (string "function") <|> try (string "procedure") comments @@ -342,11 +369,14 @@ else return Nothing return $ [FunctionDeclaration i ret vs b] + functionDecorator = choice [ try $ string "inline;" , try $ string "cdecl;" , try (string "external") >> comments >> iD >> optional (string "name" >> comments >> stringLiteral pas)>> string ";" ] >> comments + + program = do string "program" comments