tools/pas2c/PascalParser.hs
branchwebgl
changeset 8444 75db7bb8dce8
parent 8442 535a00ca0d35
parent 8020 00b1facf2805
child 9166 3774ac58e65e
equal deleted inserted replaced
8340:46a9fde631f4 8444:75db7bb8dce8
    43     where
    43     where
    44     term = comments >> choice [
    44     term = comments >> choice [
    45         parens pas (liftM RefExpression expression >>= postfixes) >>= postfixes
    45         parens pas (liftM RefExpression expression >>= postfixes) >>= postfixes
    46         , try $ typeCast >>= postfixes
    46         , try $ typeCast >>= postfixes
    47         , char '@' >> liftM Address reference >>= postfixes
    47         , char '@' >> liftM Address reference >>= postfixes
    48         , liftM SimpleReference iD >>= postfixes 
    48         , liftM SimpleReference iD >>= postfixes
    49         ] <?> "simple reference"
    49         ] <?> "simple reference"
    50 
    50 
    51     table = [
    51     table = [
    52         ]
    52         ]
    53 
    53 
   147         comments
   147         comments
   148         t <- typeDecl
   148         t <- typeDecl
   149         if null r then
   149         if null r then
   150             return $ ArrayDecl Nothing t
   150             return $ ArrayDecl Nothing t
   151             else
   151             else
   152             return $ foldr (\a b -> ArrayDecl (Just a) b) (ArrayDecl (Just $ head r) t) (tail r) 
   152             return $ foldr (\a b -> ArrayDecl (Just a) b) (ArrayDecl (Just $ head r) t) (tail r)
   153     recordDecl = do
   153     recordDecl = do
   154         try $ do
   154         try $ do
   155             optional $ (try $ string "packed") >> comments
   155             optional $ (try $ string "packed") >> comments
   156             string "record"
   156             string "record"
   157         comments
   157         comments
   412            , Infix (char '>' >> return (BinOp ">")) AssocNone
   412            , Infix (char '>' >> return (BinOp ">")) AssocNone
   413           ]
   413           ]
   414         {-, [  Infix (try $ string "shl" >> return (BinOp "shl")) AssocNone
   414         {-, [  Infix (try $ string "shl" >> return (BinOp "shl")) AssocNone
   415              , Infix (try $ string "shr" >> return (BinOp "shr")) AssocNone
   415              , Infix (try $ string "shr" >> return (BinOp "shr")) AssocNone
   416           ]
   416           ]
   417         , [ 
   417         , [
   418              Infix (try $ string "or" >> return (BinOp "or")) AssocLeft
   418              Infix (try $ string "or" >> return (BinOp "or")) AssocLeft
   419            , Infix (try $ string "xor" >> return (BinOp "xor")) AssocLeft
   419            , Infix (try $ string "xor" >> return (BinOp "xor")) AssocLeft
   420           ]-}
   420           ]-}
   421         , [
   421         , [
   422              Infix (char '=' >> return (BinOp "=")) AssocNone
   422              Infix (char '=' >> return (BinOp "=")) AssocNone
   508     comments
   508     comments
   509     up <- liftM (== Just "to") $
   509     up <- liftM (== Just "to") $
   510             optionMaybe $ choice [
   510             optionMaybe $ choice [
   511                 try $ string "to"
   511                 try $ string "to"
   512                 , try $ string "downto"
   512                 , try $ string "downto"
   513                 ]   
   513                 ]
   514     --choice [string "to", string "downto"]
   514     --choice [string "to", string "downto"]
   515     comments
   515     comments
   516     e2 <- expression
   516     e2 <- expression
   517     comments
   517     comments
   518     string "do"
   518     string "do"
   574             return u
   574             return u
   575 
   575 
   576 initExpression = buildExpressionParser table term <?> "initialization expression"
   576 initExpression = buildExpressionParser table term <?> "initialization expression"
   577     where
   577     where
   578     term = comments >> choice [
   578     term = comments >> choice [
   579         liftM (uncurry BuiltInFunction) $ builtInFunction initExpression 
   579         liftM (uncurry BuiltInFunction) $ builtInFunction initExpression
   580         , try $ brackets pas (commaSep pas $ initExpression) >>= return . InitSet
   580         , try $ brackets pas (commaSep pas $ initExpression) >>= return . InitSet
   581         , try $ parens pas (commaSep pas $ initExpression) >>= \ia -> when (null $ tail ia) mzero >> return (InitArray ia)
   581         , try $ parens pas (commaSep pas $ initExpression) >>= \ia -> when (null $ tail ia) mzero >> return (InitArray ia)
   582         , try $ parens pas (sepEndBy recField (char ';' >> comments)) >>= return . InitRecord
   582         , try $ parens pas (sepEndBy recField (char ';' >> comments)) >>= return . InitRecord
   583         , parens pas initExpression
   583         , parens pas initExpression
   584         , try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . InitNumber . show) i
   584         , try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . InitNumber . show) i