author | koda |
Sat, 28 Jan 2012 23:10:39 +0100 | |
changeset 6609 | 5861b2cc991f |
parent 6512 | 0df7f6697939 |
child 6618 | 2d3232069c4b |
permissions | -rw-r--r-- |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
1 |
module PascalParser where |
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
2 |
|
6412 | 3 |
import Text.Parsec |
6272 | 4 |
import Text.Parsec.Char |
5 |
import Text.Parsec.Token |
|
6 |
import Text.Parsec.Language |
|
6412 | 7 |
import Text.Parsec.Expr |
6272 | 8 |
import Text.Parsec.Prim |
9 |
import Text.Parsec.Combinator |
|
10 |
import Text.Parsec.String |
|
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
11 |
import Control.Monad |
6399 | 12 |
import Data.Maybe |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
13 |
|
6412 | 14 |
import PascalBasics |
6467 | 15 |
import PascalUnitSyntaxTree |
6450 | 16 |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
17 |
knownTypes = ["shortstring", "char", "byte"] |
6357 | 18 |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
19 |
pascalUnit = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
20 |
comments |
6512 | 21 |
u <- choice [program, unit, systemUnit] |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
22 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
23 |
return u |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
24 |
|
6275 | 25 |
iD = do |
6489 | 26 |
i <- liftM (flip Identifier Unknown) (identifier pas) |
6275 | 27 |
comments |
28 |
return i |
|
29 |
||
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
30 |
unit = do |
6275 | 31 |
string "unit" >> comments |
32 |
name <- iD |
|
33 |
semi pas |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
34 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
35 |
int <- interface |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
36 |
impl <- implementation |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
37 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
38 |
return $ Unit name int impl Nothing Nothing |
6275 | 39 |
|
40 |
||
41 |
reference = buildExpressionParser table term <?> "reference" |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
42 |
where |
6275 | 43 |
term = comments >> choice [ |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
44 |
parens pas (liftM RefExpression expression >>= postfixes) >>= postfixes |
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
45 |
, try $ typeCast >>= postfixes |
6450 | 46 |
, char '@' >> liftM Address reference >>= postfixes |
6386
7d7703b26bda
Prefix followed by prefix issue solved. Also some slight improvements.
unc0rr
parents:
6357
diff
changeset
|
47 |
, liftM SimpleReference iD >>= postfixes |
6275 | 48 |
] <?> "simple reference" |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
49 |
|
6275 | 50 |
table = [ |
51 |
] |
|
6386
7d7703b26bda
Prefix followed by prefix issue solved. Also some slight improvements.
unc0rr
parents:
6357
diff
changeset
|
52 |
|
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
53 |
postfixes r = many postfix >>= return . foldl (flip ($)) r |
6386
7d7703b26bda
Prefix followed by prefix issue solved. Also some slight improvements.
unc0rr
parents:
6357
diff
changeset
|
54 |
postfix = choice [ |
7d7703b26bda
Prefix followed by prefix issue solved. Also some slight improvements.
unc0rr
parents:
6357
diff
changeset
|
55 |
parens pas (option [] parameters) >>= return . FunCall |
7d7703b26bda
Prefix followed by prefix issue solved. Also some slight improvements.
unc0rr
parents:
6357
diff
changeset
|
56 |
, char '^' >> return Dereference |
7d7703b26bda
Prefix followed by prefix issue solved. Also some slight improvements.
unc0rr
parents:
6357
diff
changeset
|
57 |
, (brackets pas) (commaSep1 pas $ expression) >>= return . ArrayElement |
6467 | 58 |
, (char '.' >> notFollowedBy (char '.')) >> liftM (flip RecordField) reference |
6386
7d7703b26bda
Prefix followed by prefix issue solved. Also some slight improvements.
unc0rr
parents:
6357
diff
changeset
|
59 |
] |
6316 | 60 |
|
6450 | 61 |
typeCast = do |
62 |
t <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) knownTypes |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
63 |
e <- parens pas expression |
6450 | 64 |
comments |
6489 | 65 |
return $ TypeCast (Identifier t Unknown) e |
6450 | 66 |
|
6275 | 67 |
|
6290 | 68 |
varsDecl1 = varsParser sepEndBy1 |
69 |
varsDecl = varsParser sepEndBy |
|
6277 | 70 |
varsParser m endsWithSemi = do |
6290 | 71 |
vs <- m (aVarDecl endsWithSemi) (semi pas) |
72 |
return vs |
|
73 |
||
74 |
aVarDecl endsWithSemi = do |
|
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
75 |
unless endsWithSemi $ |
6290 | 76 |
optional $ choice [ |
77 |
try $ string "var" |
|
78 |
, try $ string "const" |
|
79 |
, try $ string "out" |
|
80 |
] |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
81 |
comments |
6290 | 82 |
ids <- do |
83 |
i <- (commaSep1 pas) $ (try iD <?> "variable declaration") |
|
84 |
char ':' |
|
85 |
return i |
|
86 |
comments |
|
87 |
t <- typeDecl <?> "variable type declaration" |
|
88 |
comments |
|
89 |
init <- option Nothing $ do |
|
90 |
char '=' |
|
6275 | 91 |
comments |
6355 | 92 |
e <- initExpression |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
93 |
comments |
6290 | 94 |
return (Just e) |
95 |
return $ VarDeclaration False (ids, t) init |
|
6275 | 96 |
|
97 |
||
98 |
constsDecl = do |
|
6317
83b93a2d2741
Improve parsing of complex references like "a^[b[c], d]"
unc0rr
parents:
6316
diff
changeset
|
99 |
vs <- many1 (try (aConstDecl >>= \i -> semi pas >> return i) >>= \i -> comments >> return i) |
6275 | 100 |
comments |
6277 | 101 |
return vs |
6275 | 102 |
where |
103 |
aConstDecl = do |
|
104 |
comments |
|
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
105 |
i <- iD |
6444 | 106 |
t <- optionMaybe $ do |
6275 | 107 |
char ':' |
108 |
comments |
|
109 |
t <- typeDecl |
|
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
110 |
comments |
6444 | 111 |
return t |
6275 | 112 |
char '=' |
113 |
comments |
|
6355 | 114 |
e <- initExpression |
6275 | 115 |
comments |
6444 | 116 |
return $ VarDeclaration False ([i], fromMaybe UnknownType t) (Just e) |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
117 |
|
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
118 |
typeDecl = choice [ |
6290 | 119 |
char '^' >> typeDecl >>= return . PointerTo |
6399 | 120 |
, try (string "shortstring") >> return (String 255) |
121 |
, try (string "string") >> optionMaybe (brackets pas $ integer pas) >>= return . String . fromMaybe 255 |
|
6290 | 122 |
, arrayDecl |
6277 | 123 |
, recordDecl |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
124 |
, setDecl |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
125 |
, functionType |
6355 | 126 |
, sequenceDecl >>= return . Sequence |
6489 | 127 |
, try iD >>= return . SimpleType |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
128 |
, rangeDecl >>= return . RangeType |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
129 |
] <?> "type declaration" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
130 |
where |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
131 |
arrayDecl = do |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
132 |
try $ do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
133 |
optional $ (try $ string "packed") >> comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
134 |
string "array" |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
135 |
comments |
6426 | 136 |
r <- option [] $ do |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
137 |
char '[' |
6426 | 138 |
r <- commaSep pas rangeDecl |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
139 |
char ']' |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
140 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
141 |
return r |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
142 |
string "of" |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
143 |
comments |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
144 |
t <- typeDecl |
6426 | 145 |
if null r then |
146 |
return $ ArrayDecl Nothing t |
|
147 |
else |
|
148 |
return $ foldr (\a b -> ArrayDecl (Just a) b) (ArrayDecl (Just $ head r) t) (tail r) |
|
6277 | 149 |
recordDecl = do |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
150 |
try $ do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
151 |
optional $ (try $ string "packed") >> comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
152 |
string "record" |
6277 | 153 |
comments |
154 |
vs <- varsDecl True |
|
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
155 |
union <- optionMaybe $ do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
156 |
string "case" |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
157 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
158 |
iD |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
159 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
160 |
string "of" |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
161 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
162 |
many unionCase |
6277 | 163 |
string "end" |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
164 |
return $ RecordType vs union |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
165 |
setDecl = do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
166 |
try $ string "set" >> space |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
167 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
168 |
string "of" |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
169 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
170 |
liftM Set typeDecl |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
171 |
unionCase = do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
172 |
try $ commaSep pas $ (iD >> return ()) <|> (integer pas >> return ()) |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
173 |
char ':' |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
174 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
175 |
u <- parens pas $ varsDecl True |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
176 |
char ';' |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
177 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
178 |
return u |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
179 |
sequenceDecl = (parens pas) $ (commaSep pas) (iD >>= \i -> optional (spaces >> char '=' >> spaces >> integer pas) >> return i) |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
180 |
functionType = do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
181 |
fp <- try (string "function") <|> try (string "procedure") |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
182 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
183 |
vs <- option [] $ parens pas $ varsDecl False |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
184 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
185 |
ret <- if (fp == "function") then do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
186 |
char ':' |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
187 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
188 |
ret <- typeDecl |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
189 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
190 |
return ret |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
191 |
else |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
192 |
return UnknownType |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
193 |
optional $ try $ char ';' >> comments >> string "cdecl" |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
194 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
195 |
return $ FunctionType ret vs |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
196 |
|
6277 | 197 |
typesDecl = many (aTypeDecl >>= \t -> comments >> return t) |
198 |
where |
|
199 |
aTypeDecl = do |
|
200 |
i <- try $ do |
|
201 |
i <- iD <?> "type declaration" |
|
202 |
comments |
|
203 |
char '=' |
|
204 |
return i |
|
205 |
comments |
|
206 |
t <- typeDecl |
|
207 |
comments |
|
208 |
semi pas |
|
209 |
comments |
|
210 |
return $ TypeDeclaration i t |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
211 |
|
6275 | 212 |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
213 |
rangeDecl = choice [ |
6277 | 214 |
try $ rangeft |
215 |
, iD >>= return . Range |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
216 |
] <?> "range declaration" |
6277 | 217 |
where |
218 |
rangeft = do |
|
6388 | 219 |
e1 <- initExpression |
6277 | 220 |
string ".." |
6388 | 221 |
e2 <- initExpression |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
222 |
return $ RangeFromTo e1 e2 |
6275 | 223 |
|
6277 | 224 |
typeVarDeclaration isImpl = (liftM concat . many . choice) [ |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
225 |
varSection, |
6275 | 226 |
constSection, |
6277 | 227 |
typeSection, |
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
228 |
funcDecl, |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
229 |
operatorDecl |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
230 |
] |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
231 |
where |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
232 |
varSection = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
233 |
try $ string "var" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
234 |
comments |
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
235 |
v <- varsDecl1 True <?> "variable declaration" |
6272 | 236 |
comments |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
237 |
return v |
6275 | 238 |
|
239 |
constSection = do |
|
240 |
try $ string "const" |
|
241 |
comments |
|
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
242 |
c <- constsDecl <?> "const declaration" |
6275 | 243 |
comments |
244 |
return c |
|
6277 | 245 |
|
246 |
typeSection = do |
|
247 |
try $ string "type" |
|
248 |
comments |
|
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
249 |
t <- typesDecl <?> "type declaration" |
6277 | 250 |
comments |
251 |
return t |
|
6275 | 252 |
|
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
253 |
operatorDecl = do |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
254 |
try $ string "operator" |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
255 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
256 |
i <- manyTill anyChar space |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
257 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
258 |
vs <- parens pas $ varsDecl False |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
259 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
260 |
rid <- iD |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
261 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
262 |
char ':' |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
263 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
264 |
ret <- typeDecl |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
265 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
266 |
return ret |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
267 |
char ';' |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
268 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
269 |
forward <- liftM isJust $ optionMaybe (try (string "forward;") >> comments) |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
270 |
many functionDecorator |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
271 |
b <- if isImpl && (not forward) then |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
272 |
liftM Just functionBody |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
273 |
else |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
274 |
return Nothing |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
275 |
return $ [OperatorDeclaration i rid ret vs b] |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
276 |
|
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
277 |
|
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
278 |
funcDecl = do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
279 |
fp <- try (string "function") <|> try (string "procedure") |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
280 |
comments |
6275 | 281 |
i <- iD |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
282 |
vs <- option [] $ parens pas $ varsDecl False |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
283 |
comments |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
284 |
ret <- if (fp == "function") then do |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
285 |
char ':' |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
286 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
287 |
ret <- typeDecl |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
288 |
comments |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
289 |
return ret |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
290 |
else |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
291 |
return UnknownType |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
292 |
char ';' |
6399 | 293 |
comments |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
294 |
forward <- liftM isJust $ optionMaybe (try (string "forward;") >> comments) |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
295 |
many functionDecorator |
6417
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
296 |
b <- if isImpl && (not forward) then |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
297 |
liftM Just functionBody |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
298 |
else |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
299 |
return Nothing |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
300 |
return $ [FunctionDeclaration i ret vs b] |
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
301 |
|
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
302 |
functionDecorator = choice [ |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
303 |
try $ string "inline;" |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
304 |
, try $ caseInsensitiveString "cdecl;" |
6444 | 305 |
, try $ string "overload;" |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
306 |
, try $ string "export;" |
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
307 |
, try $ string "varargs;" |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
308 |
, try (string "external") >> comments >> iD >> optional (string "name" >> comments >> stringLiteral pas)>> string ";" |
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
309 |
] >> comments |
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
310 |
|
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
311 |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
312 |
program = do |
6275 | 313 |
string "program" |
314 |
comments |
|
315 |
name <- iD |
|
316 |
(char ';') |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
317 |
comments |
6417
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
318 |
comments |
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
319 |
u <- uses |
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
320 |
comments |
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
321 |
tv <- typeVarDeclaration True |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
322 |
comments |
6417
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
323 |
p <- phrase |
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
324 |
comments |
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
325 |
char '.' |
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
326 |
comments |
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
327 |
return $ Program name (Implementation u (TypesAndVars tv)) p |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
328 |
|
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
329 |
interface = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
330 |
string "interface" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
331 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
332 |
u <- uses |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
333 |
comments |
6277 | 334 |
tv <- typeVarDeclaration False |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
335 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
336 |
return $ Interface u (TypesAndVars tv) |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
337 |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
338 |
implementation = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
339 |
string "implementation" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
340 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
341 |
u <- uses |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
342 |
comments |
6277 | 343 |
tv <- typeVarDeclaration True |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
344 |
string "end." |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
345 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
346 |
return $ Implementation u (TypesAndVars tv) |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
347 |
|
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
348 |
expression = buildExpressionParser table term <?> "expression" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
349 |
where |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
350 |
term = comments >> choice [ |
6489 | 351 |
builtInFunction expression >>= \(n, e) -> return $ BuiltInFunCall e (SimpleReference (Identifier n Unknown)) |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
352 |
, try (parens pas $ expression >>= \e -> notFollowedBy (comments >> char '.') >> return e) |
6450 | 353 |
, brackets pas (commaSep pas iD) >>= return . SetExpression |
6412 | 354 |
, try $ natural pas >>= \i -> notFollowedBy (char '.') >> (return . NumberLiteral . show) i |
6452 | 355 |
, float pas >>= return . FloatLiteral . show |
356 |
, natural pas >>= return . NumberLiteral . show |
|
6275 | 357 |
, stringLiteral pas >>= return . StringLiteral |
6444 | 358 |
, try (string "#$") >> many hexDigit >>= \c -> comments >> return (HexCharCode c) |
6417
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
359 |
, char '#' >> many digit >>= \c -> comments >> return (CharCode c) |
eae5900fd8a4
Improve parser a bit, preparation to parsing whole program at once and compiling it into single C file
unc0rr
parents:
6414
diff
changeset
|
360 |
, char '$' >> many hexDigit >>= \h -> comments >> return (HexNumber h) |
6412 | 361 |
, char '-' >> expression >>= return . PrefixOp "-" |
6290 | 362 |
, try $ string "nil" >> return Null |
6467 | 363 |
, try $ string "not" >> expression >>= return . PrefixOp "not" |
6275 | 364 |
, reference >>= return . Reference |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
365 |
] <?> "simple expression" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
366 |
|
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
367 |
table = [ |
6290 | 368 |
[ Infix (char '*' >> return (BinOp "*")) AssocLeft |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
369 |
, Infix (char '/' >> return (BinOp "/")) AssocLeft |
6275 | 370 |
, Infix (try (string "div") >> return (BinOp "div")) AssocLeft |
371 |
, Infix (try (string "mod") >> return (BinOp "mod")) AssocLeft |
|
6450 | 372 |
, Infix (try (string "in") >> return (BinOp "in")) AssocNone |
6275 | 373 |
] |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
374 |
, [ Infix (char '+' >> return (BinOp "+")) AssocLeft |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
375 |
, Infix (char '-' >> return (BinOp "-")) AssocLeft |
6275 | 376 |
] |
377 |
, [ Infix (try (string "<>") >> return (BinOp "<>")) AssocNone |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
378 |
, Infix (try (string "<=") >> return (BinOp "<=")) AssocNone |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
379 |
, Infix (try (string ">=") >> return (BinOp ">=")) AssocNone |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
380 |
, Infix (char '<' >> return (BinOp "<")) AssocNone |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
381 |
, Infix (char '>' >> return (BinOp ">")) AssocNone |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
382 |
, Infix (char '=' >> return (BinOp "=")) AssocNone |
6275 | 383 |
] |
384 |
, [ Infix (try $ string "and" >> return (BinOp "and")) AssocLeft |
|
385 |
, Infix (try $ string "or" >> return (BinOp "or")) AssocLeft |
|
386 |
, Infix (try $ string "xor" >> return (BinOp "xor")) AssocLeft |
|
387 |
] |
|
6355 | 388 |
, [ Infix (try $ string "shl" >> return (BinOp "shl")) AssocNone |
389 |
, Infix (try $ string "shr" >> return (BinOp "shr")) AssocNone |
|
6307 | 390 |
] |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
391 |
] |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
392 |
|
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
393 |
phrasesBlock = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
394 |
try $ string "begin" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
395 |
comments |
6444 | 396 |
p <- manyTill phrase (try $ string "end" >> notFollowedBy alphaNum) |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
397 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
398 |
return $ Phrases p |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
399 |
|
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
400 |
phrase = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
401 |
o <- choice [ |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
402 |
phrasesBlock |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
403 |
, ifBlock |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
404 |
, whileCycle |
6275 | 405 |
, repeatCycle |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
406 |
, switchCase |
6275 | 407 |
, withBlock |
408 |
, forCycle |
|
409 |
, (try $ reference >>= \r -> string ":=" >> return r) >>= \r -> expression >>= return . Assignment r |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
410 |
, procCall |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
411 |
, char ';' >> comments >> return NOP |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
412 |
] |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
413 |
optional $ char ';' |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
414 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
415 |
return o |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
416 |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
417 |
ifBlock = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
418 |
try $ string "if" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
419 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
420 |
e <- expression |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
421 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
422 |
string "then" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
423 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
424 |
o1 <- phrase |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
425 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
426 |
o2 <- optionMaybe $ do |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
427 |
try $ string "else" >> space |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
428 |
comments |
6450 | 429 |
o <- option NOP phrase |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
430 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
431 |
return o |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
432 |
return $ IfThenElse e o1 o2 |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
433 |
|
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
434 |
whileCycle = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
435 |
try $ string "while" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
436 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
437 |
e <- expression |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
438 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
439 |
string "do" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
440 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
441 |
o <- phrase |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
442 |
return $ WhileCycle e o |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
443 |
|
6275 | 444 |
withBlock = do |
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
445 |
try $ string "with" >> space |
6275 | 446 |
comments |
6387 | 447 |
rs <- (commaSep1 pas) reference |
6275 | 448 |
comments |
449 |
string "do" |
|
450 |
comments |
|
451 |
o <- phrase |
|
6387 | 452 |
return $ foldr WithBlock o rs |
6275 | 453 |
|
454 |
repeatCycle = do |
|
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
455 |
try $ string "repeat" >> space |
6275 | 456 |
comments |
457 |
o <- many phrase |
|
458 |
string "until" |
|
459 |
comments |
|
460 |
e <- expression |
|
461 |
comments |
|
462 |
return $ RepeatCycle e o |
|
463 |
||
464 |
forCycle = do |
|
6425
1ef4192aa80d
- Parse unions, sets, function type, packed arrays and some more imporvements to the parser. Now it parses uVariable, uConsts and even SDLh.pas
unc0rr
parents:
6417
diff
changeset
|
465 |
try $ string "for" >> space |
6275 | 466 |
comments |
467 |
i <- iD |
|
468 |
comments |
|
469 |
string ":=" |
|
470 |
comments |
|
471 |
e1 <- expression |
|
472 |
comments |
|
473 |
choice [string "to", string "downto"] |
|
474 |
comments |
|
475 |
e2 <- expression |
|
476 |
comments |
|
477 |
string "do" |
|
478 |
comments |
|
479 |
p <- phrase |
|
480 |
comments |
|
481 |
return $ ForCycle i e1 e2 p |
|
482 |
||
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
483 |
switchCase = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
484 |
try $ string "case" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
485 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
486 |
e <- expression |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
487 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
488 |
string "of" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
489 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
490 |
cs <- many1 aCase |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
491 |
o2 <- optionMaybe $ do |
6450 | 492 |
try $ string "else" >> notFollowedBy alphaNum |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
493 |
comments |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
494 |
o <- many phrase |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
495 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
496 |
return o |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
497 |
string "end" |
6399 | 498 |
comments |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
499 |
return $ SwitchCase e cs o2 |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
500 |
where |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
501 |
aCase = do |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
502 |
e <- (commaSep pas) $ (liftM InitRange rangeDecl <|> initExpression) |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
503 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
504 |
char ':' |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
505 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
506 |
p <- phrase |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
507 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
508 |
return (e, p) |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
509 |
|
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
510 |
procCall = do |
6450 | 511 |
r <- reference |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
512 |
p <- option [] $ (parens pas) parameters |
6450 | 513 |
return $ ProcCall r p |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
514 |
|
6275 | 515 |
parameters = (commaSep pas) expression <?> "parameters" |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
516 |
|
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
517 |
functionBody = do |
6399 | 518 |
tv <- typeVarDeclaration True |
519 |
comments |
|
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
520 |
p <- phrasesBlock |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
521 |
char ';' |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
522 |
comments |
6399 | 523 |
return (TypesAndVars tv, p) |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
524 |
|
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
525 |
uses = liftM Uses (option [] u) |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
526 |
where |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
527 |
u = do |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
528 |
string "uses" |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
529 |
comments |
6275 | 530 |
u <- (iD >>= \i -> comments >> return i) `sepBy1` (char ',' >> comments) |
6270
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
531 |
char ';' |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
532 |
comments |
0a99f73dd8dd
Improve pascal parser, now it is able to successfully parse uGame.pas (though it eats all comments). Many things are still missing. Well, it's just a matter of time to implement the rest. All basic work is already done anyway.
unc0rr
parents:
4353
diff
changeset
|
533 |
return u |
6355 | 534 |
|
535 |
initExpression = buildExpressionParser table term <?> "initialization expression" |
|
536 |
where |
|
537 |
term = comments >> choice [ |
|
6388 | 538 |
liftM (uncurry BuiltInFunction) $ builtInFunction initExpression |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
539 |
, try $ brackets pas (commaSep pas $ initExpression) >>= return . InitSet |
6388 | 540 |
, try $ parens pas (commaSep pas $ initExpression) >>= return . InitArray |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
541 |
, parens pas (sepEndBy recField (char ';' >> comments)) >>= return . InitRecord |
6355 | 542 |
, try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . InitNumber . show) i |
543 |
, try $ float pas >>= return . InitFloat . show |
|
6388 | 544 |
, try $ integer pas >>= return . InitNumber . show |
6355 | 545 |
, stringLiteral pas >>= return . InitString |
6444 | 546 |
, char '#' >> many digit >>= \c -> comments >> return (InitChar c) |
547 |
, char '$' >> many hexDigit >>= \h -> comments >> return (InitHexNumber h) |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
548 |
, char '@' >> initExpression >>= \c -> comments >> return (InitAddress c) |
6355 | 549 |
, try $ string "nil" >> return InitNull |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
550 |
, itypeCast |
6355 | 551 |
, iD >>= return . InitReference |
552 |
] |
|
553 |
||
554 |
recField = do |
|
555 |
i <- iD |
|
556 |
spaces |
|
557 |
char ':' |
|
558 |
spaces |
|
559 |
e <- initExpression |
|
560 |
spaces |
|
561 |
return (i ,e) |
|
562 |
||
563 |
table = [ |
|
564 |
[ Infix (char '*' >> return (InitBinOp "*")) AssocLeft |
|
565 |
, Infix (char '/' >> return (InitBinOp "/")) AssocLeft |
|
566 |
, Infix (try (string "div") >> return (InitBinOp "div")) AssocLeft |
|
567 |
, Infix (try (string "mod") >> return (InitBinOp "mod")) AssocLeft |
|
568 |
] |
|
569 |
, [ Infix (char '+' >> return (InitBinOp "+")) AssocLeft |
|
570 |
, Infix (char '-' >> return (InitBinOp "-")) AssocLeft |
|
571 |
, Prefix (char '-' >> return (InitPrefixOp "-")) |
|
572 |
] |
|
573 |
, [ Infix (try (string "<>") >> return (InitBinOp "<>")) AssocNone |
|
574 |
, Infix (try (string "<=") >> return (InitBinOp "<=")) AssocNone |
|
575 |
, Infix (try (string ">=") >> return (InitBinOp ">=")) AssocNone |
|
576 |
, Infix (char '<' >> return (InitBinOp "<")) AssocNone |
|
577 |
, Infix (char '>' >> return (InitBinOp ">")) AssocNone |
|
578 |
, Infix (char '=' >> return (InitBinOp "=")) AssocNone |
|
579 |
] |
|
580 |
, [ Infix (try $ string "and" >> return (InitBinOp "and")) AssocLeft |
|
581 |
, Infix (try $ string "or" >> return (InitBinOp "or")) AssocLeft |
|
582 |
, Infix (try $ string "xor" >> return (InitBinOp "xor")) AssocLeft |
|
583 |
] |
|
584 |
, [ Infix (try $ string "shl" >> return (InitBinOp "and")) AssocNone |
|
585 |
, Infix (try $ string "shr" >> return (InitBinOp "or")) AssocNone |
|
586 |
] |
|
587 |
, [Prefix (try (string "not") >> return (InitPrefixOp "not"))] |
|
588 |
] |
|
6388 | 589 |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
590 |
itypeCast = do |
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
591 |
t <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) knownTypes |
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
592 |
i <- parens pas initExpression |
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
593 |
comments |
6489 | 594 |
return $ InitTypeCast (Identifier t Unknown) i |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
595 |
|
6388 | 596 |
builtInFunction e = do |
597 |
name <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) builtin |
|
598 |
spaces |
|
6397 | 599 |
exprs <- parens pas $ commaSep1 pas $ e |
6388 | 600 |
spaces |
601 |
return (name, exprs) |
|
6512 | 602 |
|
603 |
systemUnit = do |
|
604 |
string "system;" |
|
605 |
comments |
|
606 |
string "type" |
|
607 |
comments |
|
608 |
t <- typesDecl |
|
609 |
string "var" |
|
610 |
v <- varsDecl True |
|
611 |
return $ System (t ++ v) |