- Help parser by dropping that insane formatting syntax in str function
authorunc0rr
Sat, 26 Nov 2011 21:12:23 +0300
changeset 6443 23364a5fcc86
parent 6442 e6e409d9d6db
child 6444 eddc1e9bcd81
- Help parser by dropping that insane formatting syntax in str function - Parse operators
hedgewars/uFloat.pas
tools/PascalParser.hs
--- 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;
--- 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