8 import Text.Parsec.Prim |
8 import Text.Parsec.Prim |
9 import Text.Parsec.Combinator |
9 import Text.Parsec.Combinator |
10 import Text.Parsec.String |
10 import Text.Parsec.String |
11 import Control.Monad |
11 import Control.Monad |
12 import Data.Maybe |
12 import Data.Maybe |
|
13 import Data.Char |
13 |
14 |
14 import PascalBasics |
15 import PascalBasics |
15 import PascalUnitSyntaxTree |
16 import PascalUnitSyntaxTree |
16 |
17 |
17 knownTypes = ["shortstring", "ansistring", "char", "byte"] |
18 knownTypes = ["shortstring", "ansistring", "char", "byte"] |
353 , try (parens pas $ expression >>= \e -> notFollowedBy (comments >> char '.') >> return e) |
354 , try (parens pas $ expression >>= \e -> notFollowedBy (comments >> char '.') >> return e) |
354 , brackets pas (commaSep pas iD) >>= return . SetExpression |
355 , brackets pas (commaSep pas iD) >>= return . SetExpression |
355 , try $ natural pas >>= \i -> notFollowedBy (char '.') >> (return . NumberLiteral . show) i |
356 , try $ natural pas >>= \i -> notFollowedBy (char '.') >> (return . NumberLiteral . show) i |
356 , float pas >>= return . FloatLiteral . show |
357 , float pas >>= return . FloatLiteral . show |
357 , natural pas >>= return . NumberLiteral . show |
358 , natural pas >>= return . NumberLiteral . show |
358 , stringLiteral pas >>= return . StringLiteral |
359 , try (string "_S" >> stringLiteral pas) >>= return . StringLiteral |
|
360 , stringLiteral pas >>= return . strOrChar |
359 , try (string "#$") >> many hexDigit >>= \c -> comments >> return (HexCharCode c) |
361 , try (string "#$") >> many hexDigit >>= \c -> comments >> return (HexCharCode c) |
360 , char '#' >> many digit >>= \c -> comments >> return (CharCode c) |
362 , char '#' >> many digit >>= \c -> comments >> return (CharCode c) |
361 , char '$' >> many hexDigit >>= \h -> comments >> return (HexNumber h) |
363 , char '$' >> many hexDigit >>= \h -> comments >> return (HexNumber h) |
362 , char '-' >> expression >>= return . PrefixOp "-" |
364 , char '-' >> expression >>= return . PrefixOp "-" |
363 , try $ string "nil" >> return Null |
365 , try $ string "nil" >> return Null |
388 , [ Infix (try $ string "and" >> return (BinOp "and")) AssocLeft |
390 , [ Infix (try $ string "and" >> return (BinOp "and")) AssocLeft |
389 , Infix (try $ string "or" >> return (BinOp "or")) AssocLeft |
391 , Infix (try $ string "or" >> return (BinOp "or")) AssocLeft |
390 , Infix (try $ string "xor" >> return (BinOp "xor")) AssocLeft |
392 , Infix (try $ string "xor" >> return (BinOp "xor")) AssocLeft |
391 ] |
393 ] |
392 ] |
394 ] |
|
395 strOrChar [a] = CharCode . show . ord $ a |
|
396 strOrChar a = StringLiteral a |
393 |
397 |
394 phrasesBlock = do |
398 phrasesBlock = do |
395 try $ string "begin" |
399 try $ string "begin" |
396 comments |
400 comments |
397 p <- manyTill phrase (try $ string "end" >> notFollowedBy alphaNum) |
401 p <- manyTill phrase (try $ string "end" >> notFollowedBy alphaNum) |