# HG changeset patch # User unc0rr # Date 1336848279 -14400 # Node ID f98ec3aecf4e40d5418f33a321952d47762caad3 # Parent 12cc2bd84b0bc1b54ccc9be39be801396eee7988 A solution to char vs string problem: mark single-letter strings with _S macro diff -r 12cc2bd84b0b -r f98ec3aecf4e hedgewars/options.inc --- 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:=} diff -r 12cc2bd84b0b -r f98ec3aecf4e hedgewars/uGearsHedgehog.pas --- 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 diff -r 12cc2bd84b0b -r f98ec3aecf4e tools/PascalParser.hs --- 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 diff -r 12cc2bd84b0b -r f98ec3aecf4e tools/PascalPreprocessor.hs --- 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 diff -r 12cc2bd84b0b -r f98ec3aecf4e tools/pas2c.hs --- 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