tools/PascalParser.hs
changeset 6386 7d7703b26bda
parent 6357 52cb4807a78c
child 6387 3dcb839b5904
equal deleted inserted replaced
6385:e6d30db1e3b0 6386:7d7703b26bda
   101             , "implementation", "and", "or", "xor", "shl"
   101             , "implementation", "and", "or", "xor", "shl"
   102             , "shr", "while", "do", "repeat", "until", "case", "of"
   102             , "shr", "while", "do", "repeat", "until", "case", "of"
   103             , "type", "var", "const", "out", "array", "packed"
   103             , "type", "var", "const", "out", "array", "packed"
   104             , "procedure", "function", "with", "for", "to"
   104             , "procedure", "function", "with", "for", "to"
   105             , "downto", "div", "mod", "record", "set", "nil"
   105             , "downto", "div", "mod", "record", "set", "nil"
   106             , "string", "shortstring", "succ", "pred", "low"
   106             , "string", "shortstring"--, "succ", "pred", "low"
   107             , "high"
   107             --, "high"
   108             ]
   108             ]
   109     , reservedOpNames= [] 
   109     , reservedOpNames= [] 
   110     , caseSensitive  = False   
   110     , caseSensitive  = False   
   111     }
   111     }
   112     
   112     
   160 
   160 
   161     
   161     
   162 reference = buildExpressionParser table term <?> "reference"
   162 reference = buildExpressionParser table term <?> "reference"
   163     where
   163     where
   164     term = comments >> choice [
   164     term = comments >> choice [
   165         parens pas reference 
   165         parens pas (reference >>= postfixes) >>= postfixes
   166         , char '@' >> reference >>= return . Address
   166         , char '@' >> reference >>= postfixes >>= return . Address
   167         , iD >>= return . SimpleReference
   167         , liftM SimpleReference iD >>= postfixes 
   168         ] <?> "simple reference"
   168         ] <?> "simple reference"
   169 
   169 
   170     table = [ 
   170     table = [ 
   171             [Postfix $ (parens pas) (option [] parameters) >>= return . FunCall]
   171             [Infix (try (char '.' >> notFollowedBy (char '.')) >> return RecordField) AssocLeft]
   172           , [Postfix (char '^' >> return Dereference)]
       
   173           , [Postfix $ (brackets pas) (commaSep1 pas $ expression) >>= return . ArrayElement]
       
   174           , [Infix (try (char '.' >> notFollowedBy (char '.')) >> return RecordField) AssocLeft]
       
   175         ]
   172         ]
       
   173     
       
   174     postfixes r = many postfix >>= return . foldl fp r
       
   175     postfix = choice [
       
   176             parens pas (option [] parameters) >>= return . FunCall
       
   177           , char '^' >> return Dereference
       
   178           , (brackets pas) (commaSep1 pas $ expression) >>= return . ArrayElement
       
   179         ]
       
   180     fp r f = f r
   176 
   181 
   177     
   182     
   178 varsDecl1 = varsParser sepEndBy1    
   183 varsDecl1 = varsParser sepEndBy1    
   179 varsDecl = varsParser sepEndBy
   184 varsDecl = varsParser sepEndBy
   180 varsParser m endsWithSemi = do
   185 varsParser m endsWithSemi = do
   475     return $ WhileCycle e o
   480     return $ WhileCycle e o
   476 
   481 
   477 withBlock = do
   482 withBlock = do
   478     try $ string "with"
   483     try $ string "with"
   479     comments
   484     comments
   480     r <- reference
   485     (r:rs) <- (commaSep1 pas) reference
   481     comments
   486     comments
   482     string "do"
   487     string "do"
   483     comments
   488     comments
   484     o <- phrase
   489     o <- phrase
   485     return $ WithBlock r o
   490     return $ WithBlock r (foldl (\ph r -> WithBlock r ph) o rs)
   486     
   491     
   487 repeatCycle = do
   492 repeatCycle = do
   488     try $ string "repeat"
   493     try $ string "repeat"
   489     comments
   494     comments
   490     o <- many phrase
   495     o <- many phrase