tools/PascalParser.hs
changeset 7317 3534a264b27a
parent 7315 59b5b19e6604
child 7429 fcf13e40d6b6
equal deleted inserted replaced
7315:59b5b19e6604 7317:3534a264b27a
    70 varsParser m endsWithSemi = do
    70 varsParser m endsWithSemi = do
    71     vs <- m (aVarDecl endsWithSemi) (semi pas)
    71     vs <- m (aVarDecl endsWithSemi) (semi pas)
    72     return vs
    72     return vs
    73 
    73 
    74 aVarDecl endsWithSemi = do
    74 aVarDecl endsWithSemi = do
    75     unless endsWithSemi $
    75     isVar <- liftM (== Just "var") $
    76         optional $ choice [
    76         if not endsWithSemi then
    77             try $ string "var"
    77             optionMaybe $ choice [
    78             , try $ string "const"
    78                 try $ string "var"
    79             , try $ string "out"
    79                 , try $ string "const"
    80             ]
    80                 , try $ string "out"
       
    81                 ]
       
    82             else
       
    83                 return Nothing
    81     comments
    84     comments
    82     ids <- do
    85     ids <- do
    83         i <- (commaSep1 pas) $ (try iD <?> "variable declaration")
    86         i <- (commaSep1 pas) $ (try iD <?> "variable declaration")
    84         char ':'
    87         char ':'
    85         return i
    88         return i
    90         char '='
    93         char '='
    91         comments
    94         comments
    92         e <- initExpression
    95         e <- initExpression
    93         comments
    96         comments
    94         return (Just e)
    97         return (Just e)
    95     return $ VarDeclaration False (ids, t) init
    98     return $ VarDeclaration isVar False (ids, t) init
    96 
    99 
    97 
   100 
    98 constsDecl = do
   101 constsDecl = do
    99     vs <- many1 (try (aConstDecl >>= \i -> semi pas >> return i) >>= \i -> comments >> return i)
   102     vs <- many1 (try (aConstDecl >>= \i -> semi pas >> return i) >>= \i -> comments >> return i)
   100     comments
   103     comments
   111             return t
   114             return t
   112         char '='
   115         char '='
   113         comments
   116         comments
   114         e <- initExpression
   117         e <- initExpression
   115         comments
   118         comments
   116         return $ VarDeclaration (isNothing t) ([i], fromMaybe (DeriveType e) t) (Just e)
   119         return $ VarDeclaration False (isNothing t) ([i], fromMaybe (DeriveType e) t) (Just e)
   117 
   120 
   118 typeDecl = choice [
   121 typeDecl = choice [
   119     char '^' >> typeDecl >>= return . PointerTo
   122     char '^' >> typeDecl >>= return . PointerTo
   120     , try (string "shortstring") >> return (String 255)
   123     , try (string "shortstring") >> return (String 255)
   121     , try (string "string") >> optionMaybe (brackets pas $ integer pas) >>= return . String . fromMaybe 255
   124     , try (string "string") >> optionMaybe (brackets pas $ integer pas) >>= return . String . fromMaybe 255