tools/PascalParser.hs
changeset 6618 2d3232069c4b
parent 6512 0df7f6697939
child 6626 a447993f2ad7
equal deleted inserted replaced
6617:c61a4f68e6e9 6618:2d3232069c4b
    21     u <- choice [program, unit, systemUnit]
    21     u <- choice [program, unit, systemUnit]
    22     comments
    22     comments
    23     return u
    23     return u
    24 
    24 
    25 iD = do
    25 iD = do
    26     i <- liftM (flip Identifier Unknown) (identifier pas)
    26     i <- liftM (flip Identifier BTUnknown) (identifier pas)
    27     comments
    27     comments
    28     return i
    28     return i
    29         
    29         
    30 unit = do
    30 unit = do
    31     string "unit" >> comments
    31     string "unit" >> comments
    60 
    60 
    61     typeCast = do
    61     typeCast = do
    62         t <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) knownTypes
    62         t <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) knownTypes
    63         e <- parens pas expression
    63         e <- parens pas expression
    64         comments
    64         comments
    65         return $ TypeCast (Identifier t Unknown) e
    65         return $ TypeCast (Identifier t BTUnknown) e
    66         
    66         
    67     
    67     
    68 varsDecl1 = varsParser sepEndBy1    
    68 varsDecl1 = varsParser sepEndBy1    
    69 varsDecl = varsParser sepEndBy
    69 varsDecl = varsParser sepEndBy
    70 varsParser m endsWithSemi = do
    70 varsParser m endsWithSemi = do
   346     return $ Implementation u (TypesAndVars tv)
   346     return $ Implementation u (TypesAndVars tv)
   347 
   347 
   348 expression = buildExpressionParser table term <?> "expression"
   348 expression = buildExpressionParser table term <?> "expression"
   349     where
   349     where
   350     term = comments >> choice [
   350     term = comments >> choice [
   351         builtInFunction expression >>= \(n, e) -> return $ BuiltInFunCall e (SimpleReference (Identifier n Unknown))
   351         builtInFunction expression >>= \(n, e) -> return $ BuiltInFunCall e (SimpleReference (Identifier n BTUnknown))
   352         , try (parens pas $ expression >>= \e -> notFollowedBy (comments >> char '.') >> return e)
   352         , try (parens pas $ expression >>= \e -> notFollowedBy (comments >> char '.') >> return e)
   353         , brackets pas (commaSep pas iD) >>= return . SetExpression
   353         , brackets pas (commaSep pas iD) >>= return . SetExpression
   354         , try $ natural pas >>= \i -> notFollowedBy (char '.') >> (return . NumberLiteral . show) i
   354         , try $ natural pas >>= \i -> notFollowedBy (char '.') >> (return . NumberLiteral . show) i
   355         , float pas >>= return . FloatLiteral . show
   355         , float pas >>= return . FloatLiteral . show
   356         , natural pas >>= return . NumberLiteral . show
   356         , natural pas >>= return . NumberLiteral . show
   589 
   589 
   590     itypeCast = do
   590     itypeCast = do
   591         t <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) knownTypes
   591         t <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) knownTypes
   592         i <- parens pas initExpression
   592         i <- parens pas initExpression
   593         comments
   593         comments
   594         return $ InitTypeCast (Identifier t Unknown) i
   594         return $ InitTypeCast (Identifier t BTUnknown) i
   595         
   595         
   596 builtInFunction e = do
   596 builtInFunction e = do
   597     name <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) builtin
   597     name <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) builtin
   598     spaces
   598     spaces
   599     exprs <- parens pas $ commaSep1 pas $ e
   599     exprs <- parens pas $ commaSep1 pas $ e
   607     comments
   607     comments
   608     t <- typesDecl
   608     t <- typesDecl
   609     string "var"
   609     string "var"
   610     v <- varsDecl True
   610     v <- varsDecl True
   611     return $ System (t ++ v)
   611     return $ System (t ++ v)
       
   612