A solution to char vs string problem: mark single-letter strings with _S macro
authorunc0rr
Sat, 12 May 2012 22:44:39 +0400
changeset 7067 f98ec3aecf4e
parent 7066 12cc2bd84b0b
child 7068 b1b7eb9c8cc9
A solution to char vs string problem: mark single-letter strings with _S macro
hedgewars/options.inc
hedgewars/uGearsHedgehog.pas
tools/PascalParser.hs
tools/PascalPreprocessor.hs
tools/pas2c.hs
--- a/hedgewars/options.inc	Sat May 12 22:13:56 2012 +0400
+++ b/hedgewars/options.inc	Sat May 12 22:44:39 2012 +0400
@@ -74,4 +74,6 @@
 {$IFDEF PAS2C}
     {$DEFINE NOCONSOLE}
     {$DEFINE USE_SDLTHREADS}
-{$ENDIF}
\ No newline at end of file
+{$ENDIF}
+
+{$DEFINE _S:=}
--- a/hedgewars/uGearsHedgehog.pas	Sat May 12 22:13:56 2012 +0400
+++ b/hedgewars/uGearsHedgehog.pas	Sat May 12 22:44:39 2012 +0400
@@ -440,7 +440,7 @@
             begin
             if not CurrentTeam^.ExtDriven
             and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_Power) <> 0) then
-                SendIPC('a');
+                SendIPC(_S'a');
             AfterAttack;
             end
         end
--- a/tools/PascalParser.hs	Sat May 12 22:13:56 2012 +0400
+++ b/tools/PascalParser.hs	Sat May 12 22:44:39 2012 +0400
@@ -10,6 +10,7 @@
 import Text.Parsec.String
 import Control.Monad
 import Data.Maybe
+import Data.Char
 
 import PascalBasics
 import PascalUnitSyntaxTree
@@ -355,7 +356,8 @@
         , try $ natural pas >>= \i -> notFollowedBy (char '.') >> (return . NumberLiteral . show) i
         , float pas >>= return . FloatLiteral . show
         , natural pas >>= return . NumberLiteral . show
-        , stringLiteral pas >>= return . StringLiteral
+        , try (string "_S" >> stringLiteral pas) >>= return . StringLiteral
+        , stringLiteral pas >>= return . strOrChar
         , try (string "#$") >> many hexDigit >>= \c -> comments >> return (HexCharCode c)
         , char '#' >> many digit >>= \c -> comments >> return (CharCode c)
         , char '$' >> many hexDigit >>=  \h -> comments >> return (HexNumber h)
@@ -390,6 +392,8 @@
            , Infix (try $ string "xor" >> return (BinOp "xor")) AssocLeft
           ]
         ]
+    strOrChar [a] = CharCode . show . ord $ a
+    strOrChar a = StringLiteral a    
     
 phrasesBlock = do
     try $ string "begin"
@@ -613,4 +617,3 @@
     string "var"
     v <- varsDecl True
     return $ System (t ++ v)
-  
\ No newline at end of file
--- a/tools/PascalPreprocessor.hs	Sat May 12 22:13:56 2012 +0400
+++ b/tools/PascalPreprocessor.hs	Sat May 12 22:44:39 2012 +0400
@@ -121,7 +121,7 @@
         i <- identifier        
         d <- ((string ":=" >> return ())<|> spaces) >> many (noneOf "}")
         char '}'
-        updateState $ \(m, b) -> (if and b then Map.insert i d m else m, b)
+        updateState $ \(m, b) -> (if (and b) && (head i /= '_') then Map.insert i d m else m, b)
         return ""
     replace s = do
         (m, _) <- getState
--- a/tools/pas2c.hs	Sat May 12 22:13:56 2012 +0400
+++ b/tools/pas2c.hs	Sat May 12 22:44:39 2012 +0400
@@ -718,12 +718,12 @@
     return $ text s
 expr2C (FloatLiteral s) = return $ text s
 expr2C (HexNumber s) = return $ text "0x" <> (text . map toLower $ s)
-expr2C (StringLiteral [a]) = do
+{-expr2C (StringLiteral [a]) = do
     modify(\s -> s{lastType = BTChar})
     return . quotes . text $ escape a
     where
         escape '\'' = "\\\'"
-        escape a = [a]
+        escape a = [a]-}
 expr2C (StringLiteral s) = addStringConst s
 expr2C (Reference ref) = ref2CF ref
 expr2C (PrefixOp op expr) = do