tools/PascalParser.hs
changeset 6489 e1f0058cfedd
parent 6467 090269e528df
child 6512 0df7f6697939
equal deleted inserted replaced
6488:c356ddebab84 6489:e1f0058cfedd
    21     u <- choice [program, unit]
    21     u <- choice [program, unit]
    22     comments
    22     comments
    23     return u
    23     return u
    24 
    24 
    25 iD = do
    25 iD = do
    26     i <- liftM Identifier (identifier pas)
    26     i <- liftM (flip Identifier Unknown) (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) e
    65         return $ TypeCast (Identifier t Unknown) 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
   122     , arrayDecl
   122     , arrayDecl
   123     , recordDecl
   123     , recordDecl
   124     , setDecl
   124     , setDecl
   125     , functionType
   125     , functionType
   126     , sequenceDecl >>= return . Sequence
   126     , sequenceDecl >>= return . Sequence
   127     , try (identifier pas) >>= return . SimpleType . Identifier
   127     , try iD >>= return . SimpleType
   128     , rangeDecl >>= return . RangeType
   128     , rangeDecl >>= return . RangeType
   129     ] <?> "type declaration"
   129     ] <?> "type declaration"
   130     where
   130     where
   131     arrayDecl = do
   131     arrayDecl = do
   132         try $ do
   132         try $ 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))
   351         builtInFunction expression >>= \(n, e) -> return $ BuiltInFunCall e (SimpleReference (Identifier n Unknown))
   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) i
   594         return $ InitTypeCast (Identifier t Unknown) 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