--- a/tools/PascalParser.hs Thu Nov 24 16:33:36 2011 +0100
+++ b/tools/PascalParser.hs Thu Nov 24 20:59:13 2011 +0300
@@ -14,7 +14,7 @@
import PascalBasics
data PascalUnit =
- Program Identifier Implementation
+ Program Identifier Implementation Phrase
| Unit Identifier Interface Implementation (Maybe Initialize) (Maybe Finalize)
deriving Show
data Interface = Interface Uses TypesAndVars
@@ -27,7 +27,7 @@
deriving Show
data TypeVarDeclaration = TypeDeclaration Identifier TypeDecl
| VarDeclaration Bool ([Identifier], TypeDecl) (Maybe InitExpression)
- | FunctionDeclaration Identifier TypeDecl (Maybe (TypesAndVars,Phrase))
+ | FunctionDeclaration Identifier TypeDecl (Maybe (TypesAndVars, Phrase))
deriving Show
data TypeDecl = SimpleType Identifier
| RangeType Range
@@ -54,7 +54,7 @@
| ForCycle Identifier Expression Expression Phrase
| WithBlock Reference Phrase
| Phrases [Phrase]
- | SwitchCase Expression [(Expression, Phrase)] (Maybe Phrase)
+ | SwitchCase Expression [([Expression], Phrase)] (Maybe Phrase)
| Assignment Reference Expression
deriving Show
data Expression = Expression String
@@ -278,11 +278,12 @@
comments
char ';'
comments
- b <- if isImpl then
+ forward <- liftM isJust $ optionMaybe ((try $ string "forward;") >> comments)
+ b <- if isImpl && (not forward) then
liftM Just functionBody
else
return Nothing
- comments
+-- comments
return $ [FunctionDeclaration i UnknownType b]
funcDecl = do
@@ -297,7 +298,8 @@
comments
char ';'
comments
- b <- if isImpl then
+ forward <- liftM isJust $ optionMaybe ((try $ string "forward;") >> comments)
+ b <- if isImpl && (not forward) then
liftM Just functionBody
else
return Nothing
@@ -309,9 +311,16 @@
name <- iD
(char ';')
comments
- impl <- implementation
+ comments
+ u <- uses
+ comments
+ tv <- typeVarDeclaration True
comments
- return $ Program name impl
+ p <- phrase
+ comments
+ char '.'
+ comments
+ return $ Program name (Implementation u (TypesAndVars tv)) p
interface = do
string "interface"
@@ -341,8 +350,8 @@
, try $ float pas >>= return . FloatLiteral . show
, try $ natural pas >>= return . NumberLiteral . show
, stringLiteral pas >>= return . StringLiteral
- , char '#' >> many digit >>= return . CharCode
- , char '$' >> many hexDigit >>= return . HexNumber
+ , char '#' >> many digit >>= \c -> comments >> return (CharCode c)
+ , char '$' >> many hexDigit >>= \h -> comments >> return (HexNumber h)
, char '-' >> expression >>= return . PrefixOp "-"
, try $ string "nil" >> return Null
, reference >>= return . Reference
@@ -482,7 +491,7 @@
return $ SwitchCase e cs o2
where
aCase = do
- e <- expression
+ e <- (commaSep pas) expression
comments
char ':'
comments
@@ -574,3 +583,4 @@
exprs <- parens pas $ commaSep1 pas $ e
spaces
return (name, exprs)
+
\ No newline at end of file