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