tools/pas2c/PascalParser.hs
changeset 10924 ed1b6914cac5
parent 10747 07ade56c3b4a
child 11366 f1b5f1dc61a3
equal deleted inserted replaced
10921:05e6f3b02612 10924:ed1b6914cac5
    46     comments
    46     comments
    47     return $ Unit name int impl Nothing Nothing
    47     return $ Unit name int impl Nothing Nothing
    48 
    48 
    49 
    49 
    50 reference :: Parsec String u Reference
    50 reference :: Parsec String u Reference
    51 reference = buildExpressionParser table term <?> "reference"
    51 reference = term <?> "reference"
    52     where
    52     where
    53     term = comments >> choice [
    53     term = comments >> choice [
    54         parens pas (liftM RefExpression expression >>= postfixes) >>= postfixes
    54         parens pas (liftM RefExpression expression >>= postfixes) >>= postfixes
    55         , try $ typeCast >>= postfixes
    55         , try $ typeCast >>= postfixes
    56         , char' '@' >> liftM Address reference >>= postfixes
    56         , char' '@' >> liftM Address reference >>= postfixes
    57         , liftM SimpleReference iD >>= postfixes
    57         , liftM SimpleReference iD >>= postfixes
    58         ] <?> "simple reference"
    58         ] <?> "simple reference"
    59 
       
    60     table = [
       
    61         ]
       
    62 
    59 
    63     postfixes r = many postfix >>= return . foldl (flip ($)) r
    60     postfixes r = many postfix >>= return . foldl (flip ($)) r
    64     postfix = choice [
    61     postfix = choice [
    65             parens pas (option [] parameters) >>= return . FunCall
    62             parens pas (option [] parameters) >>= return . FunCall
    66           , char' '^' >> return Dereference
    63           , char' '^' >> return Dereference
   399 expression = do
   396 expression = do
   400     buildExpressionParser table term <?> "expression"
   397     buildExpressionParser table term <?> "expression"
   401     where
   398     where
   402     term = comments >> choice [
   399     term = comments >> choice [
   403         builtInFunction expression >>= \(n, e) -> return $ BuiltInFunCall e (SimpleReference (Identifier n BTUnknown))
   400         builtInFunction expression >>= \(n, e) -> return $ BuiltInFunCall e (SimpleReference (Identifier n BTUnknown))
   404         , try (parens pas $ expression >>= \e -> notFollowedBy (comments >> char' '.') >> return e)
   401         , try (parens pas expression >>= \e -> notFollowedBy (comments >> char' '.') >> return e)
   405         , brackets pas (commaSep pas iD) >>= return . SetExpression
   402         , brackets pas (commaSep pas iD) >>= return . SetExpression
   406         , try $ integer pas >>= \i -> notFollowedBy (char' '.') >> (return . NumberLiteral . show) i
   403         , try $ integer pas >>= \i -> notFollowedBy (char' '.') >> (return . NumberLiteral . show) i
   407         , float pas >>= return . FloatLiteral . show
   404         , float pas >>= return . FloatLiteral . show
   408         , try $ integer pas >>= return . NumberLiteral . show
   405         , try $ integer pas >>= return . NumberLiteral . show
   409         , try (string' "_S" >> stringLiteral pas) >>= return . StringLiteral
   406         , try (string' "_S" >> stringLiteral pas) >>= return . StringLiteral