tools/PascalParser.hs
changeset 8442 535a00ca0d35
parent 7762 d2fd8040534f
equal deleted inserted replaced
8441:a00b0fa0dbd7 8442:535a00ca0d35
    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
   399            , Infix (char '>' >> return (BinOp ">")) AssocNone
   399            , Infix (char '>' >> return (BinOp ">")) AssocNone
   400           ]
   400           ]
   401         {-, [  Infix (try $ string "shl" >> return (BinOp "shl")) AssocNone
   401         {-, [  Infix (try $ string "shl" >> return (BinOp "shl")) AssocNone
   402              , Infix (try $ string "shr" >> return (BinOp "shr")) AssocNone
   402              , Infix (try $ string "shr" >> return (BinOp "shr")) AssocNone
   403           ]
   403           ]
   404         , [ 
   404         , [
   405              Infix (try $ string "or" >> return (BinOp "or")) AssocLeft
   405              Infix (try $ string "or" >> return (BinOp "or")) AssocLeft
   406            , Infix (try $ string "xor" >> return (BinOp "xor")) AssocLeft
   406            , Infix (try $ string "xor" >> return (BinOp "xor")) AssocLeft
   407           ]-}
   407           ]-}
   408         , [
   408         , [
   409              Infix (char '=' >> return (BinOp "=")) AssocNone
   409              Infix (char '=' >> return (BinOp "=")) AssocNone
   495     comments
   495     comments
   496     up <- liftM (== Just "to") $
   496     up <- liftM (== Just "to") $
   497             optionMaybe $ choice [
   497             optionMaybe $ choice [
   498                 try $ string "to"
   498                 try $ string "to"
   499                 , try $ string "downto"
   499                 , try $ string "downto"
   500                 ]   
   500                 ]
   501     --choice [string "to", string "downto"]
   501     --choice [string "to", string "downto"]
   502     comments
   502     comments
   503     e2 <- expression
   503     e2 <- expression
   504     comments
   504     comments
   505     string "do"
   505     string "do"
   561             return u
   561             return u
   562 
   562 
   563 initExpression = buildExpressionParser table term <?> "initialization expression"
   563 initExpression = buildExpressionParser table term <?> "initialization expression"
   564     where
   564     where
   565     term = comments >> choice [
   565     term = comments >> choice [
   566         liftM (uncurry BuiltInFunction) $ builtInFunction initExpression 
   566         liftM (uncurry BuiltInFunction) $ builtInFunction initExpression
   567         , try $ brackets pas (commaSep pas $ initExpression) >>= return . InitSet
   567         , try $ brackets pas (commaSep pas $ initExpression) >>= return . InitSet
   568         , try $ parens pas (commaSep pas $ initExpression) >>= \ia -> when (null $ tail ia) mzero >> return (InitArray ia)
   568         , try $ parens pas (commaSep pas $ initExpression) >>= \ia -> when (null $ tail ia) mzero >> return (InitArray ia)
   569         , try $ parens pas (sepEndBy recField (char ';' >> comments)) >>= return . InitRecord
   569         , try $ parens pas (sepEndBy recField (char ';' >> comments)) >>= return . InitRecord
   570         , parens pas initExpression
   570         , parens pas initExpression
   571         , try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . InitNumber . show) i
   571         , try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . InitNumber . show) i