author | sheepluva |
Tue, 18 Feb 2014 06:02:22 +0100 | |
changeset 10145 | 67b255f839db |
parent 10131 | 4b4a043111f4 |
child 10245 | 3ccc054c3c3e |
permissions | -rw-r--r-- |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
1 |
module PascalParser ( |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
2 |
pascalUnit |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
3 |
) |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
4 |
where |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
5 |
|
6412 | 6 |
import Text.Parsec |
6272 | 7 |
import Text.Parsec.Token |
6412 | 8 |
import Text.Parsec.Expr |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
9 |
import Control.Monad |
6399 | 10 |
import Data.Maybe |
7067
f98ec3aecf4e
A solution to char vs string problem: mark single-letter strings with _S macro
unc0rr
parents:
7066
diff
changeset
|
11 |
import Data.Char |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
12 |
|
6412 | 13 |
import PascalBasics |
6467 | 14 |
import PascalUnitSyntaxTree |
7315 | 15 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
16 |
knownTypes :: [String] |
6891
ab9843957664
Improve rendering of function types, ranges, and more
unc0rr
parents:
6875
diff
changeset
|
17 |
knownTypes = ["shortstring", "ansistring", "char", "byte"] |
6357 | 18 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
19 |
pascalUnit :: Parsec String u PascalUnit |
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
|
20 |
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
|
21 |
comments |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
22 |
u <- choice [program, unit, systemUnit, redoUnit] |
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
|
23 |
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
|
24 |
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
|
25 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
26 |
iD :: Parsec String u Identifier |
6275 | 27 |
iD = do |
9166 | 28 |
i <- identifier pas |
6275 | 29 |
comments |
9166 | 30 |
when (i == "not") $ unexpected "'not' used as an identifier" |
31 |
return $ Identifier i BTUnknown |
|
7315 | 32 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
33 |
unit :: Parsec String u PascalUnit |
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 |
unit = do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
35 |
string' "unit" >> comments |
6275 | 36 |
name <- iD |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
37 |
void $ 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
|
38 |
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
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
return $ Unit name int impl Nothing Nothing |
6275 | 43 |
|
7315 | 44 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
45 |
reference :: Parsec String u Reference |
6275 | 46 |
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
|
47 |
where |
6275 | 48 |
term = comments >> choice [ |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
49 |
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
|
50 |
, try $ typeCast >>= postfixes |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
51 |
, char' '@' >> liftM Address reference >>= postfixes |
8442 | 52 |
, liftM SimpleReference iD >>= postfixes |
6275 | 53 |
] <?> "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
|
54 |
|
7315 | 55 |
table = [ |
6275 | 56 |
] |
7315 | 57 |
|
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
|
58 |
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
|
59 |
postfix = choice [ |
7d7703b26bda
Prefix followed by prefix issue solved. Also some slight improvements.
unc0rr
parents:
6357
diff
changeset
|
60 |
parens pas (option [] parameters) >>= return . FunCall |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
61 |
, char' '^' >> return Dereference |
6386
7d7703b26bda
Prefix followed by prefix issue solved. Also some slight improvements.
unc0rr
parents:
6357
diff
changeset
|
62 |
, (brackets pas) (commaSep1 pas $ expression) >>= return . ArrayElement |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
63 |
, (char' '.' >> notFollowedBy (char' '.')) >> liftM (flip RecordField) reference |
6386
7d7703b26bda
Prefix followed by prefix issue solved. Also some slight improvements.
unc0rr
parents:
6357
diff
changeset
|
64 |
] |
6316 | 65 |
|
6450 | 66 |
typeCast = do |
67 |
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
|
68 |
e <- parens pas expression |
6450 | 69 |
comments |
6618 | 70 |
return $ TypeCast (Identifier t BTUnknown) e |
7315 | 71 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
72 |
varsDecl1, varsDecl :: Bool -> Parsec String u [TypeVarDeclaration] |
7315 | 73 |
varsDecl1 = varsParser sepEndBy1 |
6290 | 74 |
varsDecl = varsParser sepEndBy |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
75 |
|
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
76 |
varsParser :: |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
77 |
(Parsec String u TypeVarDeclaration |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
78 |
-> Parsec String u String |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
79 |
-> Parsec |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
80 |
String u [TypeVarDeclaration]) |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
81 |
-> Bool |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
82 |
-> Parsec |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
83 |
String u [TypeVarDeclaration] |
6277 | 84 |
varsParser m endsWithSemi = do |
6290 | 85 |
vs <- m (aVarDecl endsWithSemi) (semi pas) |
86 |
return vs |
|
87 |
||
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
88 |
aVarDecl :: Bool -> Parsec String u TypeVarDeclaration |
6290 | 89 |
aVarDecl endsWithSemi = do |
7317 | 90 |
isVar <- liftM (== Just "var") $ |
91 |
if not endsWithSemi then |
|
92 |
optionMaybe $ choice [ |
|
93 |
try $ string "var" |
|
94 |
, try $ string "const" |
|
95 |
, try $ string "out" |
|
96 |
] |
|
97 |
else |
|
98 |
return Nothing |
|
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
|
99 |
comments |
6290 | 100 |
ids <- do |
101 |
i <- (commaSep1 pas) $ (try iD <?> "variable declaration") |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
102 |
char' ':' |
6290 | 103 |
return i |
104 |
comments |
|
105 |
t <- typeDecl <?> "variable type declaration" |
|
106 |
comments |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
107 |
initialization <- option Nothing $ do |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
108 |
char' '=' |
6275 | 109 |
comments |
6355 | 110 |
e <- initExpression |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
111 |
comments |
6290 | 112 |
return (Just e) |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
113 |
return $ VarDeclaration isVar False (ids, t) initialization |
6275 | 114 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
115 |
constsDecl :: Parsec String u [TypeVarDeclaration] |
6275 | 116 |
constsDecl = do |
6317
83b93a2d2741
Improve parsing of complex references like "a^[b[c], d]"
unc0rr
parents:
6316
diff
changeset
|
117 |
vs <- many1 (try (aConstDecl >>= \i -> semi pas >> return i) >>= \i -> comments >> return i) |
6275 | 118 |
comments |
6277 | 119 |
return vs |
6275 | 120 |
where |
121 |
aConstDecl = do |
|
122 |
comments |
|
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
123 |
i <- iD |
6444 | 124 |
t <- optionMaybe $ do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
125 |
char' ':' |
6275 | 126 |
comments |
127 |
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
|
128 |
comments |
6444 | 129 |
return t |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
130 |
char' '=' |
6275 | 131 |
comments |
6355 | 132 |
e <- initExpression |
6275 | 133 |
comments |
7317 | 134 |
return $ VarDeclaration False (isNothing t) ([i], fromMaybe (DeriveType e) t) (Just e) |
7315 | 135 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
136 |
typeDecl :: Parsec String u TypeDecl |
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
|
137 |
typeDecl = choice [ |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
138 |
char' '^' >> typeDecl >>= return . PointerTo |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
139 |
, try (string' "shortstring") >> return String |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
140 |
, try (string' "string") >> optionMaybe (brackets pas $ integer pas) >> return String |
10120 | 141 |
, try (string' "ansistring") >> optionMaybe (brackets pas $ integer pas) >> return AString |
6290 | 142 |
, arrayDecl |
6277 | 143 |
, 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
|
144 |
, 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
|
145 |
, functionType |
6355 | 146 |
, sequenceDecl >>= return . Sequence |
6489 | 147 |
, 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
|
148 |
, 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
|
149 |
] <?> "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
|
150 |
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
|
151 |
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
|
152 |
try $ do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
153 |
optional $ (try $ string' "packed") >> comments |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
154 |
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
|
155 |
comments |
6426 | 156 |
r <- option [] $ do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
157 |
char' '[' |
6426 | 158 |
r <- commaSep pas rangeDecl |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
159 |
char' ']' |
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
|
160 |
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
|
161 |
return r |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
162 |
string' "of" |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
163 |
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
|
164 |
t <- typeDecl |
6426 | 165 |
if null r then |
166 |
return $ ArrayDecl Nothing t |
|
167 |
else |
|
8442 | 168 |
return $ foldr (\a b -> ArrayDecl (Just a) b) (ArrayDecl (Just $ head r) t) (tail r) |
6277 | 169 |
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
|
170 |
try $ do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
171 |
optional $ (try $ string' "packed") >> comments |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
172 |
string' "record" |
6277 | 173 |
comments |
174 |
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
|
175 |
union <- optionMaybe $ do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
176 |
string' "case" |
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
|
177 |
comments |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
178 |
void $ 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
|
179 |
comments |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
180 |
string' "of" |
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
|
181 |
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
|
182 |
many unionCase |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
183 |
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
|
184 |
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
|
185 |
setDecl = do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
186 |
try $ string' "set" >> void space |
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
|
187 |
comments |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
188 |
string' "of" |
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
|
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 |
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
|
191 |
unionCase = do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
192 |
void $ try $ commaSep pas $ (void $ iD) <|> (void $ integer pas) |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
193 |
char' ':' |
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
|
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 |
u <- parens pas $ varsDecl True |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
196 |
char' ';' |
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
|
197 |
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
|
198 |
return u |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
199 |
sequenceDecl = (parens pas) $ (commaSep pas) (iD >>= \i -> optional (spaces >> char' '=' >> spaces >> integer pas) >> return i) |
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
|
200 |
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
|
201 |
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
|
202 |
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
|
203 |
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
|
204 |
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
|
205 |
ret <- if (fp == "function") then do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
206 |
char' ':' |
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
|
207 |
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
|
208 |
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
|
209 |
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
|
210 |
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
|
211 |
else |
6826 | 212 |
return VoidType |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
213 |
optional $ try $ char' ';' >> comments >> string' "cdecl" |
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
|
214 |
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
|
215 |
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
|
216 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
217 |
typesDecl :: Parsec String u [TypeVarDeclaration] |
6277 | 218 |
typesDecl = many (aTypeDecl >>= \t -> comments >> return t) |
219 |
where |
|
220 |
aTypeDecl = do |
|
221 |
i <- try $ do |
|
222 |
i <- iD <?> "type declaration" |
|
223 |
comments |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
224 |
char' '=' |
6277 | 225 |
return i |
226 |
comments |
|
227 |
t <- typeDecl |
|
228 |
comments |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
229 |
void $ semi pas |
6277 | 230 |
comments |
231 |
return $ TypeDeclaration i t |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
232 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
233 |
rangeDecl :: Parsec String u 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
|
234 |
rangeDecl = choice [ |
6277 | 235 |
try $ rangeft |
236 |
, 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
|
237 |
] <?> "range declaration" |
6277 | 238 |
where |
239 |
rangeft = do |
|
6388 | 240 |
e1 <- initExpression |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
241 |
string' ".." |
6388 | 242 |
e2 <- initExpression |
7315 | 243 |
return $ RangeFromTo e1 e2 |
244 |
||
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
245 |
typeVarDeclaration :: Bool -> Parsec String u [TypeVarDeclaration] |
6277 | 246 |
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
|
247 |
varSection, |
6275 | 248 |
constSection, |
6277 | 249 |
typeSection, |
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
250 |
funcDecl, |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
251 |
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
|
252 |
] |
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
|
253 |
where |
8020 | 254 |
|
255 |
fixInit v = concat $ map (\x -> case x of |
|
256 |
VarDeclaration a b (ids, t) c -> |
|
257 |
let typeId = (Identifier ((\(Identifier i _) -> i) (head ids) ++ "_tt") BTUnknown) in |
|
258 |
let res = [TypeDeclaration typeId t, VarDeclaration a b (ids, (SimpleType typeId)) c] in |
|
259 |
case t of |
|
260 |
RecordType _ _ -> res -- create a separated type declaration |
|
261 |
ArrayDecl _ _ -> res |
|
262 |
_ -> [x] |
|
263 |
_ -> error ("checkInit:\n" ++ (show v))) v |
|
264 |
||
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
|
265 |
varSection = do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
266 |
try $ string' "var" |
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
|
267 |
comments |
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
268 |
v <- varsDecl1 True <?> "variable declaration" |
6272 | 269 |
comments |
8020 | 270 |
return $ fixInit v |
6275 | 271 |
|
272 |
constSection = do |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
273 |
try $ string' "const" |
6275 | 274 |
comments |
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
275 |
c <- constsDecl <?> "const declaration" |
6275 | 276 |
comments |
8020 | 277 |
return $ fixInit c |
6277 | 278 |
|
279 |
typeSection = do |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
280 |
try $ string' "type" |
6277 | 281 |
comments |
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
282 |
t <- typesDecl <?> "type declaration" |
6277 | 283 |
comments |
284 |
return t |
|
7315 | 285 |
|
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
286 |
operatorDecl = do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
287 |
try $ string' "operator" |
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
288 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
289 |
i <- manyTill anyChar space |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
290 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
291 |
vs <- parens pas $ varsDecl False |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
292 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
293 |
rid <- iD |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
294 |
comments |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
295 |
char' ':' |
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
296 |
comments |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
297 |
ret <- typeDecl |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
298 |
comments |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
299 |
-- return ret |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
300 |
-- ^^^^^^^^^^ wth was this??? |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
301 |
char' ';' |
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
302 |
comments |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
303 |
forward <- liftM isJust $ optionMaybe (try (string' "forward;") >> comments) |
7513 | 304 |
inline <- liftM (any (== "inline;")) $ many functionDecorator |
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
305 |
b <- if isImpl && (not forward) then |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
306 |
liftM Just functionBody |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
307 |
else |
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
308 |
return Nothing |
7513 | 309 |
return $ [OperatorDeclaration i rid inline ret vs b] |
6443
23364a5fcc86
- Help parser by dropping that insane formatting syntax in str function
unc0rr
parents:
6426
diff
changeset
|
310 |
|
7315 | 311 |
|
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
|
312 |
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
|
313 |
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
|
314 |
comments |
6275 | 315 |
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
|
316 |
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
|
317 |
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
|
318 |
ret <- if (fp == "function") then do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
319 |
char' ':' |
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
|
320 |
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
|
321 |
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
|
322 |
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
|
323 |
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
|
324 |
else |
6836 | 325 |
return VoidType |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
326 |
char' ';' |
6399 | 327 |
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
|
328 |
forward <- liftM isJust $ optionMaybe (try (string "forward;") >> comments) |
8020 | 329 |
decorators <- many functionDecorator |
330 |
let inline = any (== "inline;") decorators |
|
331 |
overload = any (== "overload;") decorators |
|
10129
cd2a64a1f4aa
- Pas2C: make use of 'external' function decorator
unc0rr
parents:
10120
diff
changeset
|
332 |
external = any (== "external;") decorators |
cd2a64a1f4aa
- Pas2C: make use of 'external' function decorator
unc0rr
parents:
10120
diff
changeset
|
333 |
-- TODO: don't mangle external functions names (and remove fpcrtl.h defines hacks) |
cd2a64a1f4aa
- Pas2C: make use of 'external' function decorator
unc0rr
parents:
10120
diff
changeset
|
334 |
b <- if isImpl && (not forward) && (not external) 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
|
335 |
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
|
336 |
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
|
337 |
return Nothing |
10129
cd2a64a1f4aa
- Pas2C: make use of 'external' function decorator
unc0rr
parents:
10120
diff
changeset
|
338 |
return $ [FunctionDeclaration i inline overload external ret vs b] |
7315 | 339 |
|
7513 | 340 |
functionDecorator = do |
341 |
d <- choice [ |
|
342 |
try $ string "inline;" |
|
343 |
, try $ caseInsensitiveString "cdecl;" |
|
344 |
, try $ string "overload;" |
|
345 |
, try $ string "export;" |
|
346 |
, try $ string "varargs;" |
|
10129
cd2a64a1f4aa
- Pas2C: make use of 'external' function decorator
unc0rr
parents:
10120
diff
changeset
|
347 |
, try (string' "external") >> comments >> iD >> comments >> |
cd2a64a1f4aa
- Pas2C: make use of 'external' function decorator
unc0rr
parents:
10120
diff
changeset
|
348 |
optional (string' "name" >> comments >> stringLiteral pas) >> string' ";" >> return "external;" |
7513 | 349 |
] |
350 |
comments |
|
351 |
return d |
|
7315 | 352 |
|
353 |
||
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
354 |
program :: Parsec String u PascalUnit |
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
|
355 |
program = do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
356 |
string' "program" |
6275 | 357 |
comments |
358 |
name <- iD |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
359 |
(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
|
360 |
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
|
361 |
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
|
362 |
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
|
363 |
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
|
364 |
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
|
365 |
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
|
366 |
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
|
367 |
comments |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
368 |
char' '.' |
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
|
369 |
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
|
370 |
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
|
371 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
372 |
interface :: Parsec String u Interface |
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
|
373 |
interface = do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
374 |
string' "interface" |
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
|
375 |
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
|
376 |
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
|
377 |
comments |
6277 | 378 |
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
|
379 |
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
|
380 |
return $ Interface u (TypesAndVars tv) |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
381 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
382 |
implementation :: Parsec String u Implementation |
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
|
383 |
implementation = do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
384 |
string' "implementation" |
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
|
385 |
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
|
386 |
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
|
387 |
comments |
6277 | 388 |
tv <- typeVarDeclaration True |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
389 |
string' "end." |
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
|
390 |
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
|
391 |
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
|
392 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
393 |
expression :: Parsec String u Expression |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
394 |
expression = do |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
395 |
buildExpressionParser table term <?> "expression" |
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
|
396 |
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
|
397 |
term = comments >> choice [ |
6618 | 398 |
builtInFunction expression >>= \(n, e) -> return $ BuiltInFunCall e (SimpleReference (Identifier n BTUnknown)) |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
399 |
, try (parens pas $ expression >>= \e -> notFollowedBy (comments >> char' '.') >> return e) |
6450 | 400 |
, brackets pas (commaSep pas iD) >>= return . SetExpression |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
401 |
, try $ integer pas >>= \i -> notFollowedBy (char' '.') >> (return . NumberLiteral . show) i |
6452 | 402 |
, float pas >>= return . FloatLiteral . show |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
403 |
, try $ integer pas >>= return . NumberLiteral . show |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
404 |
, try (string' "_S" >> stringLiteral pas) >>= return . StringLiteral |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
405 |
, try (string' "_P" >> stringLiteral pas) >>= return . PCharLiteral |
7067
f98ec3aecf4e
A solution to char vs string problem: mark single-letter strings with _S macro
unc0rr
parents:
7066
diff
changeset
|
406 |
, stringLiteral pas >>= return . strOrChar |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
407 |
, try (string' "#$") >> many hexDigit >>= \c -> comments >> return (HexCharCode c) |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
408 |
, char' '#' >> many digit >>= \c -> comments >> return (CharCode c) |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
409 |
, char' '$' >> many hexDigit >>= \h -> comments >> return (HexNumber h) |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
410 |
--, char' '-' >> expression >>= return . PrefixOp "-" |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
411 |
, char' '-' >> reference >>= return . PrefixOp "-" . Reference |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
412 |
, (try $ string' "not" >> notFollowedBy comments) >> unexpected "'not'" |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
413 |
, try $ string' "nil" >> return Null |
6275 | 414 |
, 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
|
415 |
] <?> "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
|
416 |
|
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
417 |
table = [ |
8020 | 418 |
[ Prefix (reservedOp pas "not">> return (PrefixOp "not")) |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
419 |
, Prefix (try (char' '-') >> return (PrefixOp "-"))] |
8020 | 420 |
, |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
421 |
[ Infix (char' '*' >> return (BinOp "*")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
422 |
, Infix (char' '/' >> return (BinOp "/")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
423 |
, Infix (try (string' "div") >> return (BinOp "div")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
424 |
, Infix (try (string' "mod") >> return (BinOp "mod")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
425 |
, Infix (try (string' "in") >> return (BinOp "in")) AssocNone |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
426 |
, Infix (try $ string' "and" >> return (BinOp "and")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
427 |
, Infix (try $ string' "shl" >> return (BinOp "shl")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
428 |
, Infix (try $ string' "shr" >> return (BinOp "shr")) AssocLeft |
6275 | 429 |
] |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
430 |
, [ Infix (char' '+' >> return (BinOp "+")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
431 |
, Infix (char' '-' >> return (BinOp "-")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
432 |
, Infix (try $ string' "or" >> return (BinOp "or")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
433 |
, Infix (try $ string' "xor" >> return (BinOp "xor")) AssocLeft |
6275 | 434 |
] |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
435 |
, [ Infix (try (string' "<>") >> return (BinOp "<>")) AssocNone |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
436 |
, Infix (try (string' "<=") >> return (BinOp "<=")) AssocNone |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
437 |
, Infix (try (string' ">=") >> return (BinOp ">=")) AssocNone |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
438 |
, Infix (char' '<' >> return (BinOp "<")) AssocNone |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
439 |
, Infix (char' '>' >> return (BinOp ">")) AssocNone |
6275 | 440 |
] |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
441 |
{-, [ Infix (try $ string' "shl" >> return (BinOp "shl")) AssocNone |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
442 |
, Infix (try $ string' "shr" >> return (BinOp "shr")) AssocNone |
7043
7c080e5ac8d0
Some work to make more units compile after conversion to c
unc0rr
parents:
6897
diff
changeset
|
443 |
] |
8442 | 444 |
, [ |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
445 |
Infix (try $ string' "or" >> return (BinOp "or")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
446 |
, Infix (try $ string' "xor" >> return (BinOp "xor")) AssocLeft |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
447 |
]-} |
7069 | 448 |
, [ |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
449 |
Infix (char' '=' >> return (BinOp "=")) AssocNone |
7069 | 450 |
] |
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
|
451 |
] |
7067
f98ec3aecf4e
A solution to char vs string problem: mark single-letter strings with _S macro
unc0rr
parents:
7066
diff
changeset
|
452 |
strOrChar [a] = CharCode . show . ord $ a |
7315 | 453 |
strOrChar a = StringLiteral a |
454 |
||
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
455 |
phrasesBlock :: Parsec String u 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
|
456 |
phrasesBlock = do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
457 |
try $ string' "begin" |
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
|
458 |
comments |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
459 |
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
|
460 |
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
|
461 |
return $ Phrases p |
7315 | 462 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
463 |
phrase :: Parsec String u 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
|
464 |
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
|
465 |
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
|
466 |
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
|
467 |
, 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
|
468 |
, whileCycle |
6275 | 469 |
, 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
|
470 |
, switchCase |
6275 | 471 |
, withBlock |
472 |
, forCycle |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
473 |
, (try $ reference >>= \r -> string' ":=" >> return r) >>= \r -> comments >> expression >>= return . Assignment r |
6895 | 474 |
, builtInFunction expression >>= \(n, e) -> return $ BuiltInFunctionCall e (SimpleReference (Identifier n BTUnknown)) |
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
|
475 |
, procCall |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
476 |
, 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
|
477 |
] |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
478 |
optional $ 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
|
479 |
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
|
480 |
return o |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
481 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
482 |
ifBlock :: Parsec String u 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
|
483 |
ifBlock = do |
7642
91fce82f9c6f
fix parsing of 'if': identifiers can also contain underscores
sheepluva
parents:
7641
diff
changeset
|
484 |
try $ string "if" >> notFollowedBy (alphaNum <|> 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
|
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 |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
488 |
string' "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
|
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 |
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
|
491 |
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
|
492 |
o2 <- optionMaybe $ do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
493 |
try $ string' "else" >> void 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
|
494 |
comments |
6450 | 495 |
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
|
496 |
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
|
497 |
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
|
498 |
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
|
499 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
500 |
whileCycle :: Parsec String u 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
|
501 |
whileCycle = do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
502 |
try $ string' "while" |
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 |
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
|
505 |
comments |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
506 |
string' "do" |
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
|
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 |
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
|
509 |
return $ WhileCycle e o |
4353
671d66ba3af6
Dumb parser of pascal, and a program which lists unit dependencies
unC0Rr
parents:
diff
changeset
|
510 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
511 |
withBlock :: Parsec String u Phrase |
6275 | 512 |
withBlock = do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
513 |
try $ string' "with" >> void space |
6275 | 514 |
comments |
6387 | 515 |
rs <- (commaSep1 pas) reference |
6275 | 516 |
comments |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
517 |
string' "do" |
6275 | 518 |
comments |
519 |
o <- phrase |
|
6387 | 520 |
return $ foldr WithBlock o rs |
7315 | 521 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
522 |
repeatCycle :: Parsec String u Phrase |
6275 | 523 |
repeatCycle = do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
524 |
try $ string' "repeat" >> void space |
6275 | 525 |
comments |
526 |
o <- many phrase |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
527 |
string' "until" |
6275 | 528 |
comments |
529 |
e <- expression |
|
530 |
comments |
|
531 |
return $ RepeatCycle e o |
|
532 |
||
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
533 |
forCycle :: Parsec String u Phrase |
6275 | 534 |
forCycle = do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
535 |
try $ string' "for" >> void space |
6275 | 536 |
comments |
537 |
i <- iD |
|
538 |
comments |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
539 |
string' ":=" |
6275 | 540 |
comments |
541 |
e1 <- expression |
|
542 |
comments |
|
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
543 |
up <- liftM (== Just "to") $ |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
544 |
optionMaybe $ choice [ |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
545 |
try $ string "to" |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
546 |
, try $ string "downto" |
8442 | 547 |
] |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
548 |
--choice [string' "to", string' "downto"] |
6275 | 549 |
comments |
550 |
e2 <- expression |
|
551 |
comments |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
552 |
string' "do" |
6275 | 553 |
comments |
554 |
p <- phrase |
|
555 |
comments |
|
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
556 |
return $ ForCycle i e1 e2 p up |
7315 | 557 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
558 |
switchCase :: Parsec String u 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
|
559 |
switchCase = do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
560 |
try $ string' "case" |
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
|
561 |
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
|
562 |
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
|
563 |
comments |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
564 |
string' "of" |
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
|
565 |
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
|
566 |
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
|
567 |
o2 <- optionMaybe $ do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
568 |
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
|
569 |
comments |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
570 |
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
|
571 |
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
|
572 |
return o |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
573 |
string' "end" |
6399 | 574 |
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
|
575 |
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
|
576 |
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
|
577 |
aCase = do |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
578 |
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
|
579 |
comments |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
580 |
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
|
581 |
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
|
582 |
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
|
583 |
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
|
584 |
return (e, p) |
7315 | 585 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
586 |
procCall :: Parsec String u 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
|
587 |
procCall = do |
6450 | 588 |
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
|
589 |
p <- option [] $ (parens pas) parameters |
6450 | 590 |
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
|
591 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
592 |
parameters :: Parsec String u [Expression] |
6275 | 593 |
parameters = (commaSep pas) expression <?> "parameters" |
7315 | 594 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
595 |
functionBody :: Parsec String u (TypesAndVars, 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
|
596 |
functionBody = do |
6399 | 597 |
tv <- typeVarDeclaration True |
598 |
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
|
599 |
p <- phrasesBlock |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
600 |
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
|
601 |
comments |
6399 | 602 |
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
|
603 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
604 |
uses :: Parsec String u Uses |
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
|
605 |
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
|
606 |
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
|
607 |
u = do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
608 |
string' "uses" |
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
|
609 |
comments |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
610 |
ulist <- (iD >>= \i -> comments >> return i) `sepBy1` (char' ',' >> comments) |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
611 |
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
|
612 |
comments |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
613 |
return ulist |
6355 | 614 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
615 |
initExpression :: Parsec String u InitExpression |
6355 | 616 |
initExpression = buildExpressionParser table term <?> "initialization expression" |
617 |
where |
|
618 |
term = comments >> choice [ |
|
8442 | 619 |
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
|
620 |
, try $ brackets pas (commaSep pas $ initExpression) >>= return . InitSet |
9954 | 621 |
, try $ parens pas (commaSep pas $ initExpression) >>= \ia -> when ((notRecord $ head ia) && (null $ tail ia)) mzero >> return (InitArray ia) |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
622 |
, try $ parens pas (sepEndBy recField (char' ';' >> comments)) >>= return . InitRecord |
7690
6ef121a80cb0
Treat init expression in parens as just expression instead of array initializer when there's only one entry in expressions list
unc0rr
parents:
7642
diff
changeset
|
623 |
, parens pas initExpression |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
624 |
, try $ integer pas >>= \i -> notFollowedBy (char' '.') >> (return . InitNumber . show) i |
6355 | 625 |
, try $ float pas >>= return . InitFloat . show |
6388 | 626 |
, try $ integer pas >>= return . InitNumber . show |
6355 | 627 |
, stringLiteral pas >>= return . InitString |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
628 |
, char' '#' >> many digit >>= \c -> comments >> return (InitChar c) |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
629 |
, char' '$' >> many hexDigit >>= \h -> comments >> return (InitHexNumber h) |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
630 |
, char' '@' >> initExpression >>= \c -> comments >> return (InitAddress c) |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
631 |
, try $ string' "nil" >> return InitNull |
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10129
diff
changeset
|
632 |
, try itypeCast |
6355 | 633 |
, iD >>= return . InitReference |
634 |
] |
|
7315 | 635 |
|
9954 | 636 |
notRecord (InitRecord _) = False |
637 |
notRecord _ = True |
|
638 |
||
6355 | 639 |
recField = do |
640 |
i <- iD |
|
641 |
spaces |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
642 |
char' ':' |
6355 | 643 |
spaces |
644 |
e <- initExpression |
|
645 |
spaces |
|
646 |
return (i ,e) |
|
647 |
||
7315 | 648 |
table = [ |
7066
12cc2bd84b0b
Make pas2c even more happier with uGears.c, allow assigning arrays in some cases
unc0rr
parents:
7043
diff
changeset
|
649 |
[ |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
650 |
Prefix (char' '-' >> return (InitPrefixOp "-")) |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
651 |
,Prefix (try (string' "not") >> return (InitPrefixOp "not")) |
7066
12cc2bd84b0b
Make pas2c even more happier with uGears.c, allow assigning arrays in some cases
unc0rr
parents:
7043
diff
changeset
|
652 |
] |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
653 |
, [ Infix (char' '*' >> return (InitBinOp "*")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
654 |
, Infix (char' '/' >> return (InitBinOp "/")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
655 |
, Infix (try (string' "div") >> return (InitBinOp "div")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
656 |
, Infix (try (string' "mod") >> return (InitBinOp "mod")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
657 |
, Infix (try $ string' "and" >> return (InitBinOp "and")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
658 |
, Infix (try $ string' "shl" >> return (InitBinOp "shl")) AssocNone |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
659 |
, Infix (try $ string' "shr" >> return (InitBinOp "shr")) AssocNone |
6355 | 660 |
] |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
661 |
, [ Infix (char' '+' >> return (InitBinOp "+")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
662 |
, Infix (char' '-' >> return (InitBinOp "-")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
663 |
, Infix (try $ string' "or" >> return (InitBinOp "or")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
664 |
, Infix (try $ string' "xor" >> return (InitBinOp "xor")) AssocLeft |
6355 | 665 |
] |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
666 |
, [ Infix (try (string' "<>") >> return (InitBinOp "<>")) AssocNone |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
667 |
, Infix (try (string' "<=") >> return (InitBinOp "<=")) AssocNone |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
668 |
, Infix (try (string' ">=") >> return (InitBinOp ">=")) AssocNone |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
669 |
, Infix (char' '<' >> return (InitBinOp "<")) AssocNone |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
670 |
, Infix (char' '>' >> return (InitBinOp ">")) AssocNone |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
671 |
, Infix (char' '=' >> return (InitBinOp "=")) AssocNone |
6355 | 672 |
] |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
673 |
{--, [ Infix (try $ string' "and" >> return (InitBinOp "and")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
674 |
, Infix (try $ string' "or" >> return (InitBinOp "or")) AssocLeft |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
675 |
, Infix (try $ string' "xor" >> return (InitBinOp "xor")) AssocLeft |
6355 | 676 |
] |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
677 |
, [ Infix (try $ string' "shl" >> return (InitBinOp "shl")) AssocNone |
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
678 |
, Infix (try $ string' "shr" >> return (InitBinOp "shr")) AssocNone |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
679 |
]--} |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
680 |
--, [Prefix (try (string' "not") >> return (InitPrefixOp "not"))] |
6355 | 681 |
] |
6388 | 682 |
|
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
683 |
itypeCast = do |
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10129
diff
changeset
|
684 |
--t <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) knownTypes |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10129
diff
changeset
|
685 |
t <- iD |
6453
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
686 |
i <- parens pas initExpression |
11c578d30bd3
Countless imporvements to the parser and countless help to the parser in sources.
unc0rr
parents:
6452
diff
changeset
|
687 |
comments |
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10129
diff
changeset
|
688 |
return $ InitTypeCast t i |
7315 | 689 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
690 |
builtInFunction :: Parsec String u a -> Parsec String u (String, [a]) |
6388 | 691 |
builtInFunction e = do |
692 |
name <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) builtin |
|
693 |
spaces |
|
6897 | 694 |
exprs <- option [] $ parens pas $ option [] $ commaSep1 pas $ e |
6388 | 695 |
spaces |
696 |
return (name, exprs) |
|
6512 | 697 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
698 |
systemUnit :: Parsec String u PascalUnit |
6512 | 699 |
systemUnit = do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
700 |
string' "system;" |
6512 | 701 |
comments |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
702 |
string' "type" |
6512 | 703 |
comments |
704 |
t <- typesDecl |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
705 |
string' "var" |
6512 | 706 |
v <- varsDecl True |
707 |
return $ System (t ++ v) |
|
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
708 |
|
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
709 |
redoUnit :: Parsec String u PascalUnit |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
710 |
redoUnit = do |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
711 |
string' "redo;" |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
712 |
comments |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
713 |
string' "type" |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
714 |
comments |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
715 |
t <- typesDecl |
10113
b26c2772e754
Fix tons and tons of pas2c warnings (but still not all of them)
unc0rr
parents:
10111
diff
changeset
|
716 |
string' "var" |
7429
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
717 |
v <- varsDecl True |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
718 |
return $ Redo (t ++ v) |
fcf13e40d6b6
Changes to pas2c - unreviewed apart from cursory glance and compile test.
xymeng
parents:
7317
diff
changeset
|
719 |