Mercurial > projects > dil
annotate trunk/src/Parser.d @ 237:805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
author | aziz |
---|---|
date | Fri, 27 Jul 2007 16:03:00 +0000 |
parents | e961d1b957c3 |
children | f3c6c15961bb |
rev | line source |
---|---|
0 | 1 /++ |
2 Author: Aziz Köksal | |
3 License: GPL2 | |
4 +/ | |
65 | 5 module Parser; |
69
24db7c5522d5
- Added module Information for compiler messages like warnings, info and errors to the user.
aziz
parents:
68
diff
changeset
|
6 import Lexer; |
71 | 7 import Token; |
8 import Messages; | |
9 import Information; | |
102 | 10 import Declarations; |
11 import Statements; | |
70 | 12 import Expressions; |
94 | 13 import Types; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
14 import std.stdio; |
65 | 15 |
71 | 16 private alias TOK T; |
17 | |
65 | 18 class Parser |
19 { | |
71 | 20 Lexer lx; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
21 Token* token; |
71 | 22 |
23 Information[] errors; | |
24 | |
25 this(char[] srcText, string fileName) | |
26 { | |
27 lx = new Lexer(srcText, fileName); | |
216 | 28 token = &lx.token; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
29 } |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
30 |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
31 char* prev; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
32 |
206 | 33 void start() |
34 { | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
35 prev = lx.text.ptr; |
206 | 36 nT(); |
37 } | |
38 | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
39 void nT() |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
40 { |
132 | 41 do |
42 { | |
43 lx.nextToken(); | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
44 if (!trying) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
45 { |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
46 writef("\33[32m%s\33[0m", token.type); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
47 try |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
48 writef("%s", prev[0 .. token.end - prev]); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
49 catch |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
50 {writef("\33[30mø\33[0m");} |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
51 prev = token.end; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
52 } |
132 | 53 } while (token.type == T.Comment) // Skip comments |
71 | 54 } |
70 | 55 |
102 | 56 void skipToOnePast(TOK tok) |
57 { | |
58 for (; token.type != tok && token.type != T.EOF; nT()) | |
59 {} | |
60 nT(); | |
61 } | |
105 | 62 |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
63 int trying; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
64 int errorCount; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
65 |
214 | 66 ReturnType try_(ReturnType)(lazy ReturnType parseMethod, out bool success) |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
67 { |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
68 writef("\33[31mtry_\33[0m"); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
69 ++trying; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
70 // auto len = errors.length; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
71 auto oldCount = errorCount; |
105 | 72 auto lexerState = lx.getState(); |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
73 auto result = parseMethod(); |
105 | 74 // If the length of the array changed we know an error occurred. |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
75 if (errorCount != oldCount) |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
76 { |
105 | 77 lexerState.restore(); // Restore state of the Lexer object. |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
78 // errors = errors[0..len]; // Remove errors that were added when parseMethod() was called. |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
79 errorCount = oldCount; |
214 | 80 success = false; |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
81 } |
214 | 82 else |
83 success = true; | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
84 --trying; |
214 | 85 writef("\33[34m%s\33[0m", success); |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
86 return result; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
87 } |
105 | 88 |
102 | 89 /++++++++++++++++++++++++++++++ |
90 + Declaration parsing methods + | |
91 ++++++++++++++++++++++++++++++/ | |
92 | |
93 Declaration[] parseModule() | |
94 { | |
95 Declaration[] decls; | |
96 | |
97 if (token.type == T.Module) | |
98 { | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
99 ModuleName moduleName; |
102 | 100 do |
101 { | |
102 nT(); | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
103 moduleName ~= requireIdentifier(); |
102 | 104 } while (token.type == T.Dot) |
105 require(T.Semicolon); | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
106 decls ~= new ModuleDeclaration(moduleName); |
102 | 107 } |
110 | 108 decls ~= parseDeclarationDefinitions(); |
102 | 109 return decls; |
110 } | |
111 | |
110 | 112 Declaration[] parseDeclarationDefinitions() |
102 | 113 { |
114 Declaration[] decls; | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
115 while (token.type != T.EOF) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
116 decls ~= parseDeclarationDefinition(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
117 return decls; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
118 } |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
119 |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
120 /* |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
121 DeclDefsBlock: |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
122 { } |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
123 { DeclDefs } |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
124 */ |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
125 Declaration[] parseDeclarationDefinitionsBlock() |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
126 { |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
127 Declaration[] decls; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
128 require(T.LBrace); |
122 | 129 while (token.type != T.RBrace && token.type != T.EOF) |
161 | 130 decls ~= parseDeclarationDefinition(); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
131 require(T.RBrace); |
102 | 132 return decls; |
133 } | |
134 | |
110 | 135 Declaration parseDeclarationDefinition() |
102 | 136 { |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
137 Declaration decl; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
138 switch (token.type) |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
139 { |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
140 case T.Extern, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
141 T.Align, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
142 T.Pragma, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
143 T.Private, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
144 T.Package, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
145 T.Protected, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
146 T.Public, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
147 T.Export, |
203
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
148 T.Deprecated, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
149 T.Override, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
150 T.Abstract, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
151 T.Synchronized, |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
152 //T.Static, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
153 T.Final, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
154 T.Const, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
155 T.Auto, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
156 T.Scope: |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
157 case_AttributeSpecifier: |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
158 decl = parseAttributeSpecifier(); |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
159 break; |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
160 case T.Alias: |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
161 nT(); |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
162 decl = new AliasDeclaration(parseDeclaration()); |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
163 break; |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
164 case T.Typedef: |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
165 nT(); |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
166 decl = new TypedefDeclaration(parseDeclaration()); |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
167 break; |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
168 case T.Static: |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
169 Token next; |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
170 lx.peek(next); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
171 |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
172 switch (next.type) |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
173 { |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
174 case T.Import: |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
175 goto case T.Import; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
176 case T.This: |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
177 decl = parseStaticConstructorDeclaration(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
178 break; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
179 case T.Tilde: |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
180 decl = parseStaticDestructorDeclaration(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
181 break; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
182 case T.If: |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
183 decl = parseStaticIfDeclaration(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
184 break; |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
185 case T.Assert: |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
186 decl = parseStaticAssertDeclaration(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
187 break; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
188 default: |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
189 goto case_AttributeSpecifier; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
190 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
191 break; |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
192 case T.Import: |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
193 decl = parseImportDeclaration(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
194 break; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
195 case T.Enum: |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
196 decl = parseEnumDeclaration(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
197 break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
198 case T.Class: |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
199 decl = parseClassDeclaration(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
200 break; |
112 | 201 case T.Interface: |
202 decl = parseInterfaceDeclaration(); | |
203 break; | |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
204 case T.Struct, T.Union: |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
205 decl = parseAggregateDeclaration(); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
206 break; |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
207 case T.This: |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
208 decl = parseConstructorDeclaration(); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
209 break; |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
210 case T.Tilde: |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
211 decl = parseDestructorDeclaration(); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
212 break; |
120 | 213 case T.Invariant: |
214 decl = parseInvariantDeclaration(); | |
215 break; | |
121 | 216 case T.Unittest: |
217 decl = parseUnittestDeclaration(); | |
218 break; | |
122 | 219 case T.Debug: |
220 decl = parseDebugDeclaration(); | |
140 | 221 break; |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
222 case T.Version: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
223 decl = parseVersionDeclaration(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
224 break; |
140 | 225 case T.Template: |
226 decl = parseTemplateDeclaration(); | |
227 break; | |
141 | 228 case T.New: |
229 decl = parseNewDeclaration(); | |
230 break; | |
231 case T.Delete: | |
232 decl = parseDeleteDeclaration(); | |
233 break; | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
234 case T.Mixin: |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
235 decl = parseMixinDeclaration(); |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
236 break; |
129 | 237 case T.Semicolon: |
238 nT(); | |
239 decl = new EmptyDeclaration(); | |
240 break; | |
192 | 241 // Declaration |
242 case T.Identifier, T.Dot, T.Typeof: | |
243 // BasicType | |
244 case T.Char, T.Wchar, T.Dchar, T.Bool, | |
245 T.Byte, T.Ubyte, T.Short, T.Ushort, | |
246 T.Int, T.Uint, T.Long, T.Ulong, | |
247 T.Float, T.Double, T.Real, | |
248 T.Ifloat, T.Idouble, T.Ireal, | |
249 T.Cfloat, T.Cdouble, T.Creal, T.Void: | |
250 decl = parseDeclaration(); | |
251 break; | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
252 /+case T.Module: |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
253 // TODO: Error: module is optional and can appear only once at the top of the source file. |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
254 break;+/ |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
255 default: |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
256 // TODO: issue error msg. |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
257 error(MID.ExpectedButFound, "Declaration", token.srcText); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
258 decl = new IllegalDeclaration(token.type); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
259 nT(); |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
260 } |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
261 // writef("§%s§", decl.classinfo.name); |
129 | 262 return decl; |
102 | 263 } |
264 | |
122 | 265 /* |
266 DeclarationsBlock: | |
267 : DeclDefs | |
268 { } | |
269 { DeclDefs } | |
270 DeclDef | |
271 */ | |
272 Declaration[] parseDeclarationsBlock() | |
273 { | |
274 Declaration[] decls; | |
275 switch (token.type) | |
276 { | |
277 case T.LBrace: | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
278 decls = parseDeclarationDefinitionsBlock(); |
122 | 279 break; |
280 case T.Colon: | |
281 nT(); | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
282 while (token.type != T.RBrace && token.type != T.EOF) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
283 decls ~= parseDeclarationDefinition(); |
122 | 284 break; |
285 default: | |
286 decls ~= parseDeclarationDefinition(); | |
287 } | |
288 return decls; | |
289 } | |
290 | |
192 | 291 Declaration parseDeclaration() |
292 { | |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
293 Type type; |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
294 string ident; |
192 | 295 |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
296 // Check for AutoDeclaration |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
297 if (token.type == T.Identifier) |
192 | 298 { |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
299 Token next; |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
300 lx.peek(next); |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
301 if (/+next.type == T.Comma || +/next.type == T.Assign) |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
302 { |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
303 ident = token.identifier; |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
304 nT(); |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
305 } |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
306 else |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
307 goto LnonAutoDeclaration; |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
308 } |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
309 else |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
310 { |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
311 LnonAutoDeclaration: |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
312 type = parseType(); |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
313 ident = requireIdentifier(); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
314 // writefln("trying=%s,errorCount=%d", trying, errorCount); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
315 // writefln("ident=%s", ident); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
316 // Type FunctionName ( ParameterList ) FunctionBody |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
317 if (token.type == T.LParen) |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
318 { |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
319 // writef("°Function°"); |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
320 // It's a function declaration |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
321 TemplateParameter[] tparams; |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
322 if (tokenAfterParenIs(T.LParen)) |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
323 { |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
324 // ( TemplateParameterList ) ( ParameterList ) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
325 tparams = parseTemplateParameterList(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
326 } |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
327 |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
328 auto params = parseParameterList(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
329 // ReturnType FunctionName ( ParameterList ) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
330 type = new FunctionType(type, params, tparams); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
331 // type = parseDeclaratorSuffix(type); |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
332 auto funcBody = parseFunctionBody(new FunctionBody); |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
333 return new FunctionDeclaration(ident, type, null, funcBody); |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
334 } |
230
8f1790d16753
- Fix: added missing call to parseDeclaratorSuffx() in parseDeclaration.
aziz
parents:
229
diff
changeset
|
335 type = parseDeclaratorSuffix(type); |
192 | 336 } |
337 | |
338 // It's a variable declaration. | |
194 | 339 string[] idents = [ident]; |
340 Expression[] values; | |
199
a95fee6e4b7e
- Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents:
198
diff
changeset
|
341 goto LenterLoop; // We've already parsed an identifier. Jump to if statement and check for initializer. |
194 | 342 while (token.type == T.Comma) |
343 { | |
222
4f31e4671e06
- Fix: nT() wasn't called in while loop to skip T.Comma.
aziz
parents:
220
diff
changeset
|
344 nT(); |
194 | 345 idents ~= requireIdentifier(); |
346 LenterLoop: | |
347 if (token.type == T.Assign) | |
348 { | |
349 nT(); | |
350 values ~= parseInitializer(); | |
351 } | |
199
a95fee6e4b7e
- Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents:
198
diff
changeset
|
352 else |
a95fee6e4b7e
- Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents:
198
diff
changeset
|
353 values ~= null; |
194 | 354 } |
355 require(T.Semicolon); | |
356 return new VariableDeclaration(idents, values); | |
357 } | |
192 | 358 |
194 | 359 Expression parseInitializer() |
360 { | |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
361 if (token.type == T.Void) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
362 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
363 Token next; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
364 lx.peek(next); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
365 if (next.type == T.Comma || next.type == T.Semicolon) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
366 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
367 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
368 return new VoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
369 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
370 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
371 return parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
372 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
373 |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
374 Expression parseNonVoidInitializer() |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
375 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
376 Expression init; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
377 switch (token.type) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
378 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
379 case T.LBracket: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
380 // ArrayInitializer: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
381 // [ ] |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
382 // [ ArrayMemberInitializations ] |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
383 Expression[] keys; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
384 Expression[] values; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
385 |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
386 nT(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
387 while (token.type != T.RBracket) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
388 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
389 auto e = parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
390 if (token.type == T.Colon) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
391 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
392 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
393 keys ~= e; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
394 values ~= parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
395 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
396 else |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
397 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
398 keys ~= null; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
399 values ~= e; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
400 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
401 |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
402 if (token.type != T.Comma) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
403 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
404 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
405 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
406 require(T.RBracket); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
407 init = new ArrayInitializer(keys, values); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
408 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
409 case T.LBrace: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
410 // StructInitializer: |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
411 // { } |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
412 // { StructMemberInitializers } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
413 Expression parseStructInitializer() |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
414 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
415 string[] idents; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
416 Expression[] values; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
417 |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
418 nT(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
419 while (token.type != T.RBrace) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
420 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
421 if (token.type == T.Identifier) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
422 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
423 Token next; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
424 lx.peek(next); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
425 // Peek for colon to see if this is a member identifier. |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
426 if (next.type == T.Colon) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
427 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
428 idents ~= token.identifier(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
429 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
430 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
431 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
432 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
433 // NonVoidInitializer |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
434 values ~= parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
435 |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
436 if (token.type != T.Comma) |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
437 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
438 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
439 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
440 require(T.RBrace); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
441 return new StructInitializer(idents, values); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
442 } |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
443 |
214 | 444 bool success; |
445 auto si = try_(parseStructInitializer(), success); | |
446 if (success) | |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
447 { |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
448 init = si; |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
449 break; |
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
450 } |
216 | 451 assert(token.type == T.LBrace); |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
452 //goto default; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
453 default: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
454 init = parseAssignExpression(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
455 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
456 return init; |
192 | 457 } |
458 | |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
459 FunctionBody parseFunctionBody(FunctionBody func) |
192 | 460 { |
461 while (1) | |
462 { | |
463 switch (token.type) | |
464 { | |
465 case T.LBrace: | |
466 require(T.LBrace); | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
467 func.funcBody = parseStatements(); |
192 | 468 require(T.RBrace); |
469 break; | |
470 case T.Semicolon: | |
471 nT(); | |
472 break; | |
473 case T.In: | |
474 //if (func.inBody) | |
475 // TODO: issue error msg. | |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
476 nT(); |
192 | 477 require(T.LBrace); |
478 func.inBody = parseStatements(); | |
479 require(T.RBrace); | |
480 continue; | |
481 case T.Out: | |
482 //if (func.outBody) | |
483 // TODO: issue error msg. | |
484 nT(); | |
485 if (token.type == T.LParen) | |
486 { | |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
487 nT(); |
192 | 488 func.outIdent = requireIdentifier(); |
489 require(T.RParen); | |
490 } | |
491 require(T.LBrace); | |
492 func.outBody = parseStatements(); | |
493 require(T.RBrace); | |
494 continue; | |
495 case T.Body: | |
496 nT(); | |
497 goto case T.LBrace; | |
498 default: | |
499 // TODO: issue error msg. | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
500 error(MID.ExpectedButFound, "FunctionBody", token.srcText); |
192 | 501 } |
502 break; // exit while loop | |
503 } | |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
504 return func; |
192 | 505 } |
506 | |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
507 Declaration parseAttributeSpecifier() |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
508 { |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
509 Declaration decl; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
510 |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
511 switch (token.type) |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
512 { |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
513 case T.Extern: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
514 nT(); |
159 | 515 Linkage linkage; |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
516 if (token.type == T.LParen) |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
517 { |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
518 nT(); |
159 | 519 auto ident = requireIdentifier(); |
520 switch (ident) | |
521 { | |
522 case "C": | |
523 if (token.type == T.PlusPlus) | |
524 { | |
525 nT(); | |
526 linkage = Linkage.Cpp; | |
527 break; | |
528 } | |
529 linkage = Linkage.C; | |
530 break; | |
531 case "D": | |
532 linkage = Linkage.D; | |
533 break; | |
534 case "Windows": | |
535 linkage = Linkage.Windows; | |
536 break; | |
537 case "Pascal": | |
538 linkage = Linkage.Pascal; | |
539 break; | |
540 default: | |
541 // TODO: issue error msg. Unrecognized LinkageType. | |
542 } | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
543 require(T.RParen); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
544 } |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
545 decl = new ExternDeclaration(linkage, parseDeclarationsBlock()); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
546 break; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
547 case T.Align: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
548 nT(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
549 int size = -1; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
550 if (token.type == T.LParen) |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
551 { |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
552 nT(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
553 if (token.type == T.Int32) |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
554 { |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
555 size = token.int_; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
556 nT(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
557 } |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
558 else |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
559 expected(T.Int32); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
560 require(T.RParen); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
561 } |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
562 decl = new AlignDeclaration(size, parseDeclarationsBlock()); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
563 break; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
564 case T.Pragma: |
147 | 565 // Pragma: |
566 // pragma ( Identifier ) | |
567 // pragma ( Identifier , ExpressionList ) | |
568 // ExpressionList: | |
569 // AssignExpression | |
570 // AssignExpression , ExpressionList | |
571 nT(); | |
572 string ident; | |
573 Expression[] args; | |
574 Declaration[] decls; | |
575 | |
576 require(T.LParen); | |
577 ident = requireIdentifier(); | |
578 | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
579 // TODO: pragma(msg,) shouldn't be allowed |
147 | 580 if (token.type == T.Comma) |
581 args = parseArguments(T.RParen); | |
582 else | |
583 require(T.RParen); | |
584 | |
585 if (token.type == T.Semicolon) | |
586 nT(); | |
587 else | |
588 decls = parseDeclarationsBlock(); | |
589 | |
590 decl = new PragmaDeclaration(ident, args, decls); | |
591 break; | |
149 | 592 // Protection attributes |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
593 case T.Private: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
594 case T.Package: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
595 case T.Protected: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
596 case T.Public: |
148 | 597 case T.Export: |
149 | 598 // StorageClass attributes |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
599 case T.Override: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
600 case T.Deprecated: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
601 case T.Abstract: |
203
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
602 case T.Synchronized: |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
603 case T.Static: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
604 case T.Final: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
605 case T.Const: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
606 case T.Auto: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
607 case T.Scope: |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
608 nT(); |
149 | 609 decl = new AttributeDeclaration(token.type, parseDeclarationsBlock()); |
610 break; | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
611 default: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
612 assert(0); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
613 } |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
614 return decl; |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
615 } |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
616 |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
617 Declaration parseImportDeclaration() |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
618 { |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
619 assert(token.type == T.Import || token.type == T.Static); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
620 |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
621 Declaration decl; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
622 bool isStatic; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
623 |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
624 if (token.type == T.Static) |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
625 { |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
626 isStatic = true; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
627 nT(); |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
628 } |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
629 |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
630 ModuleName[] moduleNames; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
631 string[] moduleAliases; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
632 string[] bindNames; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
633 string[] bindAliases; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
634 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
635 nT(); // Skip import keyword. |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
636 do |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
637 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
638 ModuleName moduleName; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
639 string moduleAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
640 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
641 moduleAlias = requireIdentifier(); |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
642 |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
643 // AliasName = ModuleName |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
644 if (token.type == T.Assign) |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
645 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
646 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
647 moduleName ~= requireIdentifier(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
648 } |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
649 else // import Identifier [^=] |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
650 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
651 moduleName ~= moduleAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
652 moduleAlias = null; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
653 } |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
654 |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
655 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
656 // parse Identifier(.Identifier)* |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
657 while (token.type == T.Dot) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
658 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
659 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
660 moduleName ~= requireIdentifier(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
661 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
662 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
663 // Push identifiers. |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
664 moduleNames ~= moduleName; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
665 moduleAliases ~= moduleAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
666 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
667 // parse : BindAlias = BindName(, BindAlias = BindName)*; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
668 // : BindName(, BindName)*; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
669 if (token.type == T.Colon) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
670 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
671 string bindName, bindAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
672 do |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
673 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
674 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
675 bindAlias = requireIdentifier(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
676 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
677 if (token.type == T.Assign) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
678 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
679 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
680 bindName = requireIdentifier(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
681 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
682 else |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
683 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
684 bindName = bindAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
685 bindAlias = null; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
686 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
687 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
688 // Push identifiers. |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
689 bindNames ~= bindName; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
690 bindAliases ~= bindAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
691 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
692 } while (token.type == T.Comma) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
693 break; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
694 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
695 } while (token.type == T.Comma) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
696 require(T.Semicolon); |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
697 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
698 return new ImportDeclaration(moduleNames, moduleAliases, bindNames, bindAliases); |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
699 } |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
700 |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
701 Declaration parseEnumDeclaration() |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
702 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
703 assert(token.type == T.Enum); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
704 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
705 string enumName; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
706 Type baseType; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
707 string[] members; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
708 Expression[] values; |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
709 bool hasBody; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
710 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
711 nT(); // Skip enum keyword. |
231 | 712 |
713 if (token.type == T.Identifier) | |
714 { | |
715 enumName = token.identifier; | |
716 nT(); | |
717 } | |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
718 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
719 if (token.type == T.Colon) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
720 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
721 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
722 baseType = parseBasicType(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
723 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
724 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
725 if (token.type == T.Semicolon) |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
726 { |
231 | 727 if (enumName.length == 0) |
728 expected(T.Identifier); | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
729 nT(); |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
730 } |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
731 else if (token.type == T.LBrace) |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
732 { |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
733 hasBody = true; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
734 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
735 do |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
736 { |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
737 members ~= requireIdentifier(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
738 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
739 if (token.type == T.Assign) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
740 { |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
741 nT(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
742 values ~= parseAssignExpression(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
743 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
744 else |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
745 values ~= null; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
746 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
747 if (token.type == T.Comma) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
748 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
749 else if (token.type != T.RBrace) |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
750 { |
124 | 751 expected(T.RBrace); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
752 break; |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
753 } |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
754 } while (token.type != T.RBrace) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
755 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
756 } |
231 | 757 else |
758 error(MID.ExpectedButFound, "enum declaration", token.srcText); | |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
759 |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
760 return new EnumDeclaration(enumName, baseType, members, values, hasBody); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
761 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
762 |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
763 Declaration parseClassDeclaration() |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
764 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
765 assert(token.type == T.Class); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
766 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
767 string className; |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
768 TemplateParameter[] tparams; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
769 BaseClass[] bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
770 Declaration[] decls; |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
771 bool hasBody; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
772 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
773 nT(); // Skip class keyword. |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
774 className = requireIdentifier(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
775 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
776 if (token.type == T.LParen) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
777 { |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
778 tparams = parseTemplateParameterList(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
779 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
780 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
781 if (token.type == T.Colon) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
782 bases = parseBaseClasses(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
783 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
784 if (token.type == T.Semicolon) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
785 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
786 //if (bases.length != 0) |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
787 // TODO: Error: bases classes are not allowed in forward declarations. |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
788 nT(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
789 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
790 else if (token.type == T.LBrace) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
791 { |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
792 hasBody = true; |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
793 // TODO: think about setting a member status variable to a flag InClassBody... this way we can check for DeclDefs that are illegal in class bodies in the parsing phase. |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
794 decls = parseDeclarationDefinitionsBlock(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
795 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
796 else |
124 | 797 expected(T.LBrace); // TODO: better error msg |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
798 |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
799 return new ClassDeclaration(className, tparams, bases, decls, hasBody); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
800 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
801 |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
802 BaseClass[] parseBaseClasses(bool colonLeadsOff = true) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
803 { |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
804 if (colonLeadsOff) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
805 { |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
806 assert(token.type == T.Colon); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
807 nT(); // Skip colon |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
808 } |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
809 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
810 BaseClass[] bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
811 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
812 while (1) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
813 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
814 Protection prot = Protection.Public; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
815 switch (token.type) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
816 { |
204 | 817 case T.Identifier, T.Dot, T.Typeof: goto LparseBasicType; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
818 case T.Private: prot = Protection.Private; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
819 case T.Protected: prot = Protection.Protected; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
820 case T.Package: prot = Protection.Package; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
821 case T.Public: /*prot = Protection.Public;*/ break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
822 default: |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
823 // TODO: issue error msg |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
824 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
825 } |
158
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
826 nT(); // Skip protection attribute. |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
827 LparseBasicType: |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
828 auto type = parseBasicType(); |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
829 //if (type.tid != TID.DotList) |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
830 // TODO: issue error msg. base classes can only be one or more identifiers or template instances separated by dots. |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
831 bases ~= new BaseClass(prot, type); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
832 if (token.type != T.Comma) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
833 break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
834 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
835 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
836 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
837 |
112 | 838 Declaration parseInterfaceDeclaration() |
839 { | |
840 assert(token.type == T.Interface); | |
841 | |
842 string name; | |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
843 TemplateParameter[] tparams; |
112 | 844 BaseClass[] bases; |
845 Declaration[] decls; | |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
846 bool hasBody; |
112 | 847 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
848 nT(); // Skip interface keyword. |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
849 name = requireIdentifier(); |
112 | 850 |
851 if (token.type == T.LParen) | |
852 { | |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
853 tparams = parseTemplateParameterList(); |
112 | 854 } |
855 | |
856 if (token.type == T.Colon) | |
857 bases = parseBaseClasses(); | |
858 | |
859 if (token.type == T.Semicolon) | |
860 { | |
861 //if (bases.length != 0) | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
862 // TODO: error: base classes are not allowed in forward declarations. |
112 | 863 nT(); |
864 } | |
865 else if (token.type == T.LBrace) | |
866 { | |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
867 hasBody = true; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
868 decls = parseDeclarationDefinitionsBlock(); |
112 | 869 } |
870 else | |
124 | 871 expected(T.LBrace); // TODO: better error msg |
112 | 872 |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
873 // TODO: error if decls.length == 0 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
874 |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
875 return new InterfaceDeclaration(name, tparams, bases, decls, hasBody); |
112 | 876 } |
877 | |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
878 Declaration parseAggregateDeclaration() |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
879 { |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
880 assert(token.type == T.Struct || token.type == T.Union); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
881 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
882 TOK tok = token.type; |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
883 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
884 string name; |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
885 TemplateParameter[] tparams; |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
886 Declaration[] decls; |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
887 bool hasBody; |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
888 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
889 nT(); // Skip struct or union keyword. |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
890 // name is optional. |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
891 if (token.type == T.Identifier) |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
892 { |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
893 name = token.identifier; |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
894 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
895 if (token.type == T.LParen) |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
896 { |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
897 tparams = parseTemplateParameterList(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
898 } |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
899 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
900 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
901 if (token.type == T.Semicolon) |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
902 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
903 //if (name.length == 0) |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
904 // TODO: error: forward declarations must have a name. |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
905 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
906 } |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
907 else if (token.type == T.LBrace) |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
908 { |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
909 hasBody = true; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
910 decls = parseDeclarationDefinitionsBlock(); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
911 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
912 else |
124 | 913 expected(T.LBrace); // TODO: better error msg |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
914 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
915 // TODO: error if decls.length == 0 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
916 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
917 if (tok == T.Struct) |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
918 return new StructDeclaration(name, tparams, decls, hasBody); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
919 else |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
920 return new UnionDeclaration(name, tparams, decls, hasBody); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
921 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
922 |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
923 Declaration parseConstructorDeclaration() |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
924 { |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
925 assert(token.type == T.This); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
926 nT(); // Skip 'this' keyword. |
143 | 927 auto parameters = parseParameterList(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
928 auto funcBody = parseFunctionBody(new FunctionBody); |
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
929 return new ConstructorDeclaration(parameters, funcBody); |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
930 } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
931 |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
932 Declaration parseDestructorDeclaration() |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
933 { |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
934 assert(token.type == T.Tilde); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
935 nT(); // Skip ~ |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
936 require(T.This); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
937 require(T.LParen); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
938 require(T.RParen); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
939 auto funcBody = parseFunctionBody(new FunctionBody); |
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
940 return new DestructorDeclaration(funcBody); |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
941 } |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
942 |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
943 Declaration parseStaticConstructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
944 { |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
945 assert(token.type == T.Static); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
946 nT(); // Skip static keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
947 nT(); // Skip 'this' keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
948 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
949 require(T.RParen); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
950 auto funcBody = parseFunctionBody(new FunctionBody); |
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
951 return new StaticConstructorDeclaration(funcBody); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
952 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
953 |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
954 Declaration parseStaticDestructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
955 { |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
956 assert(token.type == T.Static); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
957 nT(); // Skip static keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
958 nT(); // Skip ~ |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
959 require(T.This); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
960 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
961 require(T.RParen); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
962 auto funcBody = parseFunctionBody(new FunctionBody); |
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
963 return new StaticDestructorDeclaration(funcBody); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
964 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
965 |
120 | 966 Declaration parseInvariantDeclaration() |
967 { | |
968 assert(token.type == T.Invariant); | |
969 nT(); // Skip invariant keyword. | |
970 // Optional () for getting ready porting to D 2.0 | |
971 if (token.type == T.LParen) | |
122 | 972 requireNext(T.RParen); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
973 auto funcBody = parseFunctionBody(new FunctionBody); |
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
974 return new InvariantDeclaration(funcBody); |
120 | 975 } |
976 | |
121 | 977 Declaration parseUnittestDeclaration() |
978 { | |
979 assert(token.type == T.Unittest); | |
980 | |
122 | 981 nT(); // Skip unittest keyword. |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
982 auto funcBody = parseFunctionBody(new FunctionBody); |
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
983 return new UnittestDeclaration(funcBody); |
121 | 984 } |
985 | |
122 | 986 Declaration parseDebugDeclaration() |
987 { | |
988 assert(token.type == T.Debug); | |
989 | |
990 nT(); // Skip debug keyword. | |
991 | |
992 int levelSpec = -1; // debug = Integer ; | |
993 string identSpec; // debug = Identifier ; | |
994 int levelCond = -1; // debug ( Integer ) | |
995 string identCond; // debug ( Identifier ) | |
996 Declaration[] decls, elseDecls; | |
997 | |
123 | 998 void parseIdentOrInt(ref string ident, ref int level) |
122 | 999 { |
1000 nT(); | |
1001 if (token.type == T.Int32) | |
123 | 1002 level = token.int_; |
122 | 1003 else if (token.type == T.Identifier) |
123 | 1004 ident = token.identifier; |
122 | 1005 else |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1006 { |
124 | 1007 expected(T.Identifier); // TODO: better error msg |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1008 return; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1009 } |
122 | 1010 nT(); |
123 | 1011 } |
1012 | |
1013 if (token.type == T.Assign) | |
1014 { | |
1015 parseIdentOrInt(identSpec, levelSpec); | |
122 | 1016 require(T.Semicolon); |
1017 } | |
1018 else | |
1019 { | |
123 | 1020 // Condition: |
1021 // Integer | |
1022 // Identifier | |
1023 // ( Condition ) | |
122 | 1024 if (token.type == T.LParen) |
1025 { | |
123 | 1026 parseIdentOrInt(identCond, levelCond); |
122 | 1027 require(T.RParen); |
1028 } | |
1029 | |
123 | 1030 // debug DeclarationsBlock |
1031 // debug ( Condition ) DeclarationsBlock | |
1032 decls = parseDeclarationsBlock(); | |
1033 | |
1034 // else DeclarationsBlock | |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1035 // debug without condition and else body makes no sense |
123 | 1036 if (token.type == T.Else && (levelCond != -1 || identCond.length != 0)) |
122 | 1037 { |
123 | 1038 nT(); |
1039 //if (token.type == T.Colon) | |
1040 // TODO: avoid "else:"? | |
1041 elseDecls = parseDeclarationsBlock(); | |
1042 } | |
1043 // else | |
1044 // TODO: issue error msg | |
1045 } | |
1046 | |
1047 return new DebugDeclaration(levelSpec, identSpec, levelCond, identCond, decls, elseDecls); | |
1048 } | |
1049 | |
1050 Declaration parseVersionDeclaration() | |
1051 { | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
1052 assert(token.type == T.Version); |
123 | 1053 |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
1054 nT(); // Skip version keyword. |
123 | 1055 |
1056 int levelSpec = -1; // version = Integer ; | |
1057 string identSpec; // version = Identifier ; | |
1058 int levelCond = -1; // version ( Integer ) | |
1059 string identCond; // version ( Identifier ) | |
1060 Declaration[] decls, elseDecls; | |
122 | 1061 |
123 | 1062 void parseIdentOrInt(ref string ident, ref int level) |
1063 { | |
1064 if (token.type == T.Int32) | |
1065 level = token.int_; | |
1066 else if (token.type == T.Identifier) | |
1067 ident = token.identifier; | |
1068 else | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1069 { |
124 | 1070 expected(T.Identifier); // TODO: better error msg |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1071 return; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1072 } |
123 | 1073 nT(); |
1074 } | |
1075 | |
1076 if (token.type == T.Assign) | |
1077 { | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1078 nT(); |
123 | 1079 parseIdentOrInt(identSpec, levelSpec); |
1080 require(T.Semicolon); | |
1081 } | |
1082 else | |
1083 { | |
1084 // Condition: | |
1085 // Integer | |
1086 // Identifier | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
1087 |
123 | 1088 // ( Condition ) |
1089 require(T.LParen); | |
1090 parseIdentOrInt(identCond, levelCond); | |
1091 require(T.RParen); | |
1092 | |
1093 // version ( Condition ) DeclarationsBlock | |
1094 decls = parseDeclarationsBlock(); | |
1095 | |
1096 // else DeclarationsBlock | |
1097 if (token.type == T.Else) | |
1098 { | |
1099 nT(); | |
1100 //if (token.type == T.Colon) | |
1101 // TODO: avoid "else:"? | |
1102 elseDecls = parseDeclarationsBlock(); | |
122 | 1103 } |
1104 } | |
1105 | |
123 | 1106 return new VersionDeclaration(levelSpec, identSpec, levelCond, identCond, decls, elseDecls); |
122 | 1107 } |
1108 | |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1109 Declaration parseStaticIfDeclaration() |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1110 { |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1111 assert(token.type == T.Static); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1112 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1113 nT(); // Skip static keyword. |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1114 nT(); // Skip if keyword. |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1115 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1116 Expression condition; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1117 Declaration[] ifDecls, elseDecls; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1118 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1119 require(T.LParen); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1120 condition = parseAssignExpression(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1121 require(T.RParen); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1122 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1123 if (token.type != T.Colon) |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1124 ifDecls = parseDeclarationsBlock(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1125 else |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1126 expected(T.LBrace); // TODO: better error msg |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1127 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1128 if (token.type == T.Else) |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1129 { |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1130 nT(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1131 if (token.type != T.Colon) |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1132 elseDecls = parseDeclarationsBlock(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1133 else |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1134 expected(T.LBrace); // TODO: better error msg |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1135 } |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1136 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1137 return new StaticIfDeclaration(condition, ifDecls, elseDecls); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1138 } |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1139 |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1140 Declaration parseStaticAssertDeclaration() |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1141 { |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1142 assert(token.type == T.Static); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1143 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1144 nT(); // Skip static keyword. |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1145 nT(); // Skip assert keyword. |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1146 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1147 Expression condition, message; |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1148 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1149 require(T.LParen); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1150 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1151 condition = parseAssignExpression(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1152 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1153 if (token.type == T.Comma) |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1154 { |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1155 nT(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1156 message = parseAssignExpression(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1157 } |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1158 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1159 require(T.RParen); |
128 | 1160 require(T.Semicolon); |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1161 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1162 return new StaticAssertDeclaration(condition, message); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1163 } |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1164 |
140 | 1165 Declaration parseTemplateDeclaration() |
1166 { | |
1167 assert(token.type == T.Template); | |
1168 nT(); // Skip template keyword. | |
1169 auto templateName = requireIdentifier(); | |
143 | 1170 auto templateParams = parseTemplateParameterList(); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1171 auto decls = parseDeclarationDefinitionsBlock(); |
140 | 1172 return new TemplateDeclaration(templateName, templateParams, decls); |
1173 } | |
1174 | |
141 | 1175 Declaration parseNewDeclaration() |
1176 { | |
1177 assert(token.type == T.New); | |
1178 nT(); // Skip new keyword. | |
143 | 1179 auto parameters = parseParameterList(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1180 auto funcBody = parseFunctionBody(new FunctionBody); |
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1181 return new NewDeclaration(parameters, funcBody); |
141 | 1182 } |
1183 | |
1184 Declaration parseDeleteDeclaration() | |
1185 { | |
1186 assert(token.type == T.Delete); | |
1187 nT(); // Skip delete keyword. | |
143 | 1188 auto parameters = parseParameterList(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1189 // TODO: only one parameter of type void* allowed. Check in parsing or semantic phase? |
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1190 auto funcBody = parseFunctionBody(new FunctionBody); |
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1191 return new DeleteDeclaration(parameters, funcBody); |
141 | 1192 } |
1193 | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1194 /+ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1195 DotListExpression: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1196 . DotListItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1197 DotListItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1198 Typeof |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1199 Typeof . DotListItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1200 DotListItems: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1201 DotListItem |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1202 DotListItem . DotListItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1203 DotListItem: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1204 Identifier |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1205 TemplateInstance |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1206 NewExpression |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1207 TemplateInstance: |
233 | 1208 Identifier !( TemplateArguments ) |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1209 +/ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1210 DotListExpression parseDotListExpression() |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1211 { |
233 | 1212 assert(token.type == T.Identifier || token.type == T.Dot || token.type == T.Typeof); |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1213 Expression[] identList; |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1214 if (token.type == T.Dot) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1215 { |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1216 nT(); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1217 identList ~= new IdentifierExpression("."); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1218 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1219 else if (token.type == T.Typeof) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1220 { |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1221 requireNext(T.LParen); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1222 auto type = new TypeofType(parseExpression()); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1223 require(T.RParen); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1224 identList ~= new TypeofExpression(type); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1225 if (token.type != T.Dot) |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1226 goto Lreturn; |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1227 nT(); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1228 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1229 |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1230 while (1) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1231 { |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1232 string ident = requireIdentifier(); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1233 Token next; |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1234 lx.peek(next); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1235 if (token.type == T.Not && next.type == T.LParen) // Identifier !( TemplateArguments ) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1236 { |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1237 nT(); // Skip !. |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1238 identList ~= new TemplateInstanceExpression(ident, parseTemplateArguments()); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1239 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1240 else // Identifier |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1241 identList ~= new IdentifierExpression(ident); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1242 |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1243 LnewExpressionLoop: |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1244 if (token.type != T.Dot) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1245 break; |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1246 nT(); // Skip dot. |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1247 |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1248 if (token.type == T.New) |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1249 { |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1250 identList ~= parseNewExpression(); |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1251 goto LnewExpressionLoop; |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1252 } |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1253 } |
233 | 1254 |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1255 Lreturn: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1256 return new DotListExpression(identList); |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1257 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
1258 |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1259 /+ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1260 DotListType: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1261 . TypeItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1262 TypeItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1263 Typeof |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1264 Typeof . TypeItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1265 TypeItems: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1266 TypeItem |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1267 TypeItem . TypeItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1268 TypeItem: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1269 Identifier |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1270 TemplateInstance |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1271 TemplateInstance: |
233 | 1272 Identifier !( TemplateArguments ) |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1273 +/ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1274 DotListType parseDotListType() |
153 | 1275 { |
1276 Type[] identList; | |
1277 if (token.type == T.Dot) | |
1278 { | |
1279 nT(); | |
1280 identList ~= new IdentifierType("."); | |
1281 } | |
1282 else if (token.type == T.Typeof) | |
1283 { | |
1284 requireNext(T.LParen); | |
1285 identList ~= new TypeofType(parseExpression()); | |
1286 require(T.RParen); | |
1287 if (token.type != T.Dot) | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1288 goto Lreturn; |
153 | 1289 nT(); |
1290 } | |
1291 | |
1292 while (1) | |
1293 { | |
1294 string ident = requireIdentifier(); | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1295 // NB.: Currently Types can't be followed by "!=" so we don't need to peek for "(" when parsing TemplateInstances. |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1296 /+Token next; |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1297 lx.peek(next);+/ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1298 if (token.type == T.Not/+ && next.type == T.LParen+/) // Identifier !( TemplateArguments ) |
153 | 1299 { |
1300 nT(); // Skip !. | |
1301 identList ~= new TemplateInstanceType(ident, parseTemplateArguments()); | |
1302 } | |
1303 else // Identifier | |
1304 identList ~= new IdentifierType(ident); | |
1305 | |
1306 if (token.type != T.Dot) | |
1307 break; | |
1308 nT(); | |
1309 } | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1310 Lreturn: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1311 return new DotListType(identList); |
153 | 1312 } |
1313 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1314 /* |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1315 TemplateMixin: |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1316 mixin ( AssignExpression ) ; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1317 mixin TemplateIdentifier ; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1318 mixin TemplateIdentifier MixinIdentifier ; |
233 | 1319 mixin TemplateIdentifier !( TemplateArguments ) ; |
1320 mixin TemplateIdentifier !( TemplateArguments ) MixinIdentifier ; | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1321 */ |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1322 Declaration parseMixinDeclaration() |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1323 { |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1324 assert(token.type == T.Mixin); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1325 nT(); // Skip mixin keyword. |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1326 |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1327 if (token.type == T.LParen) |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1328 { |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1329 // TODO: What about mixin(...).ident;? |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1330 nT(); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1331 auto e = parseAssignExpression(); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1332 require(T.RParen); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1333 require(T.Semicolon); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1334 return new MixinDeclaration(e); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1335 } |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1336 |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1337 Expression[] templateIdent; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1338 string mixinIdent; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1339 |
159 | 1340 // This code is similar to parseDotListType(). |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1341 if (token.type == T.Dot) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1342 { |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1343 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1344 templateIdent ~= new IdentifierExpression("."); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1345 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1346 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1347 while (1) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1348 { |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1349 string ident = requireIdentifier(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1350 if (token.type == T.Not) // Identifier !( TemplateArguments ) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1351 { |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1352 // No need to peek for T.LParen. This must be a template instance. |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1353 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1354 templateIdent ~= new TemplateInstanceExpression(ident, parseTemplateArguments()); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1355 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1356 else // Identifier |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1357 templateIdent ~= new IdentifierExpression(ident); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1358 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1359 if (token.type != T.Dot) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1360 break; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1361 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1362 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1363 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1364 if (token.type == T.Identifier) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1365 { |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1366 mixinIdent = token.identifier; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1367 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1368 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1369 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1370 require(T.Semicolon); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1371 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1372 return new MixinDeclaration(templateIdent, mixinIdent); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1373 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1374 |
102 | 1375 /+++++++++++++++++++++++++++++ |
161 | 1376 + Statement parsing methods + |
1377 +++++++++++++++++++++++++++++/ | |
1378 | |
1379 Statements parseStatements() | |
1380 { | |
162 | 1381 auto statements = new Statements(); |
161 | 1382 while (token.type != T.RBrace && token.type != T.EOF) |
1383 statements ~= parseStatement(); | |
1384 return statements; | |
1385 } | |
1386 | |
1387 Statement parseStatement() | |
1388 { | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1389 // writefln("°parseStatement:(%d)token='%s'°", lx.loc, token.srcText); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1390 |
161 | 1391 Statement s; |
188 | 1392 Declaration d; |
161 | 1393 switch (token.type) |
1394 { | |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1395 case T.Extern, |
201 | 1396 T.Align: |
1397 d = parseAttributeSpecifier(); | |
1398 goto case_DeclarationStatement; | |
1399 /+ Not applicable for statements. | |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1400 // T.Deprecated, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1401 // T.Private, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1402 // T.Package, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1403 // T.Protected, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1404 // T.Public, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1405 // T.Export, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1406 // T.Override, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1407 // T.Abstract, |
201 | 1408 +/ |
1409 //T.Pragma, | |
1410 //T.Static, | |
1411 case T.Final, | |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1412 T.Const, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1413 T.Auto/+, |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1414 T.Scope+/: |
201 | 1415 case_parseAttribute: |
1416 s = parseAttributeStatement(); | |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1417 break; |
161 | 1418 case T.Identifier: |
1419 Token next; | |
1420 lx.peek(next); | |
1421 if (next.type == T.Colon) | |
1422 { | |
1423 string ident = token.identifier; | |
1424 nT(); // Skip Identifier | |
1425 nT(); // Skip : | |
234 | 1426 s = new LabeledStatement(ident, parseNoScopeOrEmptyStatement()); |
161 | 1427 break; |
1428 } | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1429 goto case T.Dot; |
201 | 1430 case T.Dot, T.Typeof: |
214 | 1431 bool success; |
1432 d = try_(parseDeclaration(), success); | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1433 // writefln("parseDeclaration()=", failed?"failed":"success"); |
214 | 1434 if (success) |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1435 goto case_DeclarationStatement; // Declaration |
201 | 1436 else |
1437 goto default; // Expression | |
1438 // BasicType | |
1439 case T.Char, T.Wchar, T.Dchar, T.Bool, | |
1440 T.Byte, T.Ubyte, T.Short, T.Ushort, | |
1441 T.Int, T.Uint, T.Long, T.Ulong, | |
1442 T.Float, T.Double, T.Real, | |
1443 T.Ifloat, T.Idouble, T.Ireal, | |
1444 T.Cfloat, T.Cdouble, T.Creal, T.Void: | |
1445 case_parseDeclaration: | |
1446 d = parseDeclaration(); | |
1447 goto case_DeclarationStatement; | |
162 | 1448 case T.If: |
1449 s = parseIfStatement(); | |
1450 break; | |
164 | 1451 case T.While: |
1452 s = parseWhileStatement(); | |
1453 break; | |
165 | 1454 case T.Do: |
1455 s = parseDoWhileStatement(); | |
1456 break; | |
216 | 1457 case T.For: |
1458 s = parseForStatement(); | |
1459 break; | |
169 | 1460 case T.Foreach, T.Foreach_reverse: |
1461 s = parseForeachStatement(); | |
1462 break; | |
170 | 1463 case T.Switch: |
1464 s = parseSwitchStatement(); | |
1465 break; | |
171 | 1466 case T.Case: |
1467 s = parseCaseStatement(); | |
1468 break; | |
172 | 1469 case T.Default: |
1470 s = parseDefaultStatement(); | |
1471 break; | |
173 | 1472 case T.Continue: |
1473 s = parseContinueStatement(); | |
1474 break; | |
174 | 1475 case T.Break: |
1476 s = parseBreakStatement(); | |
1477 break; | |
175 | 1478 case T.Return: |
1479 s = parseReturnStatement(); | |
1480 break; | |
176 | 1481 case T.Goto: |
1482 s = parseGotoStatement(); | |
1483 break; | |
177 | 1484 case T.With: |
1485 s = parseWithStatement(); | |
1486 break; | |
178 | 1487 case T.Synchronized: |
1488 s = parseSynchronizedStatement(); | |
1489 break; | |
179 | 1490 case T.Try: |
1491 s = parseTryStatement(); | |
1492 break; | |
180 | 1493 case T.Throw: |
1494 s = parseThrowStatement(); | |
1495 break; | |
181 | 1496 case T.Scope: |
1497 Token next; | |
1498 lx.peek(next); | |
1499 if (next.type != T.LParen) | |
201 | 1500 goto case_parseAttribute; |
181 | 1501 s = parseScopeGuardStatement(); |
1502 break; | |
182 | 1503 case T.Volatile: |
1504 s = parseVolatileStatement(); | |
1505 break; | |
183 | 1506 case T.Asm: |
1507 s = parseAsmStatement(); | |
1508 break; | |
184 | 1509 case T.Pragma: |
1510 s = parsePragmaStatement(); | |
1511 break; | |
185 | 1512 case T.Mixin: |
1513 s = new MixinStatement(parseMixinDeclaration()); | |
1514 break; | |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1515 case T.Static: |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1516 Token next; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1517 lx.peek(next); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1518 switch (next.type) |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1519 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1520 case T.If: |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1521 s = parseStaticIfStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1522 break; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1523 case T.Assert: |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1524 s = parseStaticAssertStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1525 break; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1526 default: |
201 | 1527 goto case_parseAttribute; |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1528 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1529 assert(0); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1530 case T.Debug: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1531 s = parseDebugStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1532 break; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1533 case T.Version: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1534 s = parseVersionStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1535 break; |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1536 // DeclDef |
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1537 case T.Alias, T.Typedef: |
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1538 d = parseDeclarationDefinition(); |
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1539 goto case_DeclarationStatement; |
188 | 1540 case T.Enum: |
1541 d = parseEnumDeclaration(); | |
1542 goto case_DeclarationStatement; | |
1543 case T.Class: | |
1544 d = parseClassDeclaration(); | |
1545 goto case_DeclarationStatement; | |
1546 case T.Interface: | |
1547 d = parseInterfaceDeclaration(); | |
1548 goto case_DeclarationStatement; | |
1549 case T.Struct, T.Union: | |
1550 d = parseAggregateDeclaration(); | |
1551 goto case_DeclarationStatement; | |
1552 case_DeclarationStatement: | |
1553 s = new DeclarationStatement(d); | |
1554 break; | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1555 case T.LBrace: |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1556 s = parseScopeStatement(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1557 break; |
216 | 1558 case T.Semicolon: |
231 | 1559 nT(); |
216 | 1560 s = new EmptyStatement(); |
1561 break; | |
161 | 1562 default: |
214 | 1563 bool success; |
1564 auto expression = try_(parseExpression(), success); | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1565 // writefln("parseExpression()=", failed?"failed":"success"); |
214 | 1566 if (success) |
187 | 1567 { |
1568 require(T.Semicolon); | |
1569 s = new ExpressionStatement(expression); | |
1570 } | |
1571 else | |
1572 { | |
216 | 1573 error(MID.ExpectedButFound, "Statement", token.srcText); |
206 | 1574 s = new IllegalStatement(token.type); |
1575 nT(); | |
187 | 1576 } |
161 | 1577 } |
205 | 1578 assert(s !is null); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1579 // writef("§%s§", s.classinfo.name); |
161 | 1580 return s; |
1581 } | |
1582 | |
162 | 1583 /+ |
1584 ScopeStatement: | |
219 | 1585 NoScopeStatement |
162 | 1586 +/ |
164 | 1587 Statement parseScopeStatement() |
162 | 1588 { |
219 | 1589 return new ScopeStatement(parseNoScopeStatement()); |
162 | 1590 } |
1591 | |
166 | 1592 /+ |
1593 NoScopeStatement: | |
1594 NonEmptyStatement | |
1595 BlockStatement | |
1596 BlockStatement: | |
1597 { } | |
1598 { StatementList } | |
1599 +/ | |
1600 Statement parseNoScopeStatement() | |
1601 { | |
1602 Statement s; | |
1603 if (token.type == T.LBrace) | |
1604 { | |
1605 nT(); | |
1606 auto ss = new Statements(); | |
1607 while (token.type != T.RBrace && token.type != T.EOF) | |
1608 ss ~= parseStatement(); | |
1609 require(T.RBrace); | |
1610 s = ss; | |
1611 } | |
219 | 1612 else if (token.type == T.Semicolon) |
1613 { | |
1614 error(MID.ExpectedButFound, "non-empty statement", ";"); | |
1615 s = new EmptyStatement(); | |
1616 nT(); | |
1617 } | |
166 | 1618 else |
1619 s = parseStatement(); | |
1620 return s; | |
1621 } | |
1622 | |
234 | 1623 /+ |
1624 NoScopeOrEmptyStatement: | |
1625 ; | |
1626 NoScopeStatement | |
1627 +/ | |
1628 Statement parseNoScopeOrEmptyStatement() | |
1629 { | |
1630 if (token.type == T.Semicolon) | |
1631 nT(); | |
1632 else | |
1633 return parseNoScopeStatement(); | |
1634 return null; | |
1635 } | |
1636 | |
201 | 1637 Statement parseAttributeStatement() |
1638 { | |
1639 switch (token.type) | |
1640 { | |
1641 case T.Static, | |
1642 T.Final, | |
1643 T.Const, | |
1644 T.Auto, | |
1645 T.Scope: | |
1646 TOK tok = token.type; | |
1647 nT(); | |
1648 return new AttributeStatement(tok, parseStatement()); | |
1649 default: | |
1650 } | |
1651 assert(0); | |
1652 } | |
1653 | |
162 | 1654 Statement parseIfStatement() |
1655 { | |
1656 assert(token.type == T.If); | |
1657 nT(); | |
1658 | |
1659 Type type; | |
1660 string ident; | |
1661 Expression condition; | |
1662 Statement ifBody, elseBody; | |
1663 | |
1664 require(T.LParen); | |
1665 // auto Identifier = Expression | |
1666 if (token.type == T.Auto) | |
1667 { | |
1668 nT(); | |
1669 ident = requireIdentifier(); | |
1670 require(T.Assign); | |
1671 } | |
1672 else | |
1673 { | |
1674 // Declarator = Expression | |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1675 Type parseDeclaratorAssign() |
162 | 1676 { |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1677 auto type = parseDeclarator(ident); |
162 | 1678 require(T.Assign); |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1679 return type; |
162 | 1680 } |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1681 bool success; |
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1682 type = try_(parseDeclaratorAssign(), success); |
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1683 if (!success) |
163
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1684 { |
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1685 type = null; |
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1686 ident = null; |
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1687 } |
162 | 1688 } |
1689 condition = parseExpression(); | |
1690 require(T.RParen); | |
164 | 1691 ifBody = parseScopeStatement(); |
162 | 1692 if (token.type == T.Else) |
1693 { | |
1694 nT(); | |
164 | 1695 elseBody = parseScopeStatement(); |
162 | 1696 } |
1697 return new IfStatement(type, ident, condition, ifBody, elseBody); | |
1698 } | |
1699 | |
164 | 1700 Statement parseWhileStatement() |
1701 { | |
1702 assert(token.type == T.While); | |
1703 nT(); | |
166 | 1704 require(T.LParen); |
164 | 1705 auto condition = parseExpression(); |
166 | 1706 require(T.RParen); |
164 | 1707 return new WhileStatement(condition, parseScopeStatement()); |
1708 } | |
1709 | |
165 | 1710 Statement parseDoWhileStatement() |
1711 { | |
1712 assert(token.type == T.Do); | |
1713 nT(); | |
1714 auto doBody = parseScopeStatement(); | |
1715 require(T.While); | |
166 | 1716 require(T.LParen); |
165 | 1717 auto condition = parseExpression(); |
166 | 1718 require(T.RParen); |
1719 return new DoWhileStatement(condition, doBody); | |
1720 } | |
1721 | |
1722 Statement parseForStatement() | |
1723 { | |
1724 assert(token.type == T.For); | |
1725 nT(); | |
165 | 1726 require(T.LParen); |
166 | 1727 |
1728 Statement init, forBody; | |
1729 Expression condition, increment; | |
1730 | |
1731 if (token.type != T.Semicolon) | |
1732 init = parseNoScopeStatement(); | |
230
8f1790d16753
- Fix: added missing call to parseDeclaratorSuffx() in parseDeclaration.
aziz
parents:
229
diff
changeset
|
1733 else |
8f1790d16753
- Fix: added missing call to parseDeclaratorSuffx() in parseDeclaration.
aziz
parents:
229
diff
changeset
|
1734 nT(); // Skip ; |
166 | 1735 if (token.type != T.Semicolon) |
1736 condition = parseExpression(); | |
168 | 1737 require(T.Semicolon); |
166 | 1738 if (token.type != T.RParen) |
1739 increment = parseExpression(); | |
168 | 1740 require(T.RParen); |
167 | 1741 forBody = parseScopeStatement(); |
166 | 1742 return new ForStatement(init, condition, increment, forBody); |
165 | 1743 } |
1744 | |
169 | 1745 Statement parseForeachStatement() |
1746 { | |
1747 assert(token.type == T.Foreach || token.type == T.Foreach_reverse); | |
1748 TOK tok = token.type; | |
1749 nT(); | |
1750 | |
1751 Parameters params; | |
1752 Expression aggregate; | |
1753 | |
1754 require(T.LParen); | |
1755 while (1) | |
1756 { | |
1757 StorageClass stc; | |
1758 Type type; | |
1759 string ident; | |
1760 | |
1761 switch (token.type) | |
1762 { | |
236
e961d1b957c3
- Fix in parseForeachStatement(): added T.Inout to case T.Ref; removed break statement.
aziz
parents:
235
diff
changeset
|
1763 case T.Ref, T.Inout: |
169 | 1764 nT(); |
1765 stc = StorageClass.Ref; | |
236
e961d1b957c3
- Fix in parseForeachStatement(): added T.Inout to case T.Ref; removed break statement.
aziz
parents:
235
diff
changeset
|
1766 // fall through |
169 | 1767 case T.Identifier: |
1768 Token next; | |
1769 lx.peek(next); | |
1770 if (next.type == T.Comma || next.type == T.Semicolon || next.type == T.RParen) | |
1771 { | |
1772 ident = token.identifier; | |
1773 nT(); | |
1774 break; | |
1775 } | |
1776 // fall through | |
1777 default: | |
1778 type = parseDeclarator(ident); | |
1779 } | |
1780 | |
1781 params ~= new Parameter(stc, type, ident, null); | |
1782 | |
1783 if (token.type != T.Comma) | |
1784 break; | |
1785 nT(); | |
1786 } | |
1787 require(T.Semicolon); | |
1788 aggregate = parseExpression(); | |
1789 require(T.RParen); | |
1790 auto forBody = parseScopeStatement(); | |
1791 return new ForeachStatement(tok, params, aggregate, forBody); | |
1792 } | |
1793 | |
170 | 1794 Statement parseSwitchStatement() |
1795 { | |
1796 assert(token.type == T.Switch); | |
1797 nT(); | |
1798 | |
1799 require(T.LParen); | |
1800 auto condition = parseExpression(); | |
1801 require(T.RParen); | |
1802 auto switchBody = parseScopeStatement(); | |
1803 return new SwitchStatement(condition, switchBody); | |
1804 } | |
1805 | |
220 | 1806 Statement parseCaseDefaultBody() |
1807 { | |
1808 // This function is similar to parseNoScopeStatement() | |
224 | 1809 auto s = new Statements(); |
1810 while (token.type != T.Case && | |
1811 token.type != T.Default && | |
1812 token.type != T.RBrace && | |
1813 token.type != T.EOF) | |
1814 s ~= parseStatement(); | |
220 | 1815 return new ScopeStatement(s); |
1816 } | |
1817 | |
171 | 1818 Statement parseCaseStatement() |
1819 { | |
1820 assert(token.type == T.Case); | |
1821 // T.Case skipped in do-while. | |
1822 Expression[] values; | |
1823 do | |
1824 { | |
1825 nT(); | |
1826 values ~= parseAssignExpression(); | |
1827 } while (token.type == T.Comma) | |
1828 require(T.Colon); | |
1829 | |
220 | 1830 auto caseBody = parseCaseDefaultBody(); |
171 | 1831 return new CaseStatement(values, caseBody); |
1832 } | |
1833 | |
172 | 1834 Statement parseDefaultStatement() |
1835 { | |
1836 assert(token.type == T.Default); | |
1837 nT(); | |
1838 require(T.Colon); | |
220 | 1839 return new DefaultStatement(parseCaseDefaultBody()); |
172 | 1840 } |
1841 | |
173 | 1842 Statement parseContinueStatement() |
1843 { | |
1844 assert(token.type == T.Continue); | |
1845 nT(); | |
1846 string ident; | |
1847 if (token.type == T.Identifier) | |
1848 { | |
1849 ident = token.identifier; | |
1850 nT(); | |
1851 } | |
1852 require(T.Semicolon); | |
1853 return new ContinueStatement(ident); | |
1854 } | |
1855 | |
174 | 1856 Statement parseBreakStatement() |
1857 { | |
1858 assert(token.type == T.Break); | |
1859 nT(); | |
1860 string ident; | |
1861 if (token.type == T.Identifier) | |
1862 { | |
1863 ident = token.identifier; | |
1864 nT(); | |
1865 } | |
1866 require(T.Semicolon); | |
1867 return new BreakStatement(ident); | |
1868 } | |
1869 | |
175 | 1870 Statement parseReturnStatement() |
1871 { | |
1872 assert(token.type == T.Return); | |
1873 nT(); | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1874 Expression expr; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1875 if (token.type != T.Semicolon) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1876 expr = parseExpression(); |
175 | 1877 require(T.Semicolon); |
1878 return new ReturnStatement(expr); | |
1879 } | |
1880 | |
176 | 1881 Statement parseGotoStatement() |
1882 { | |
1883 assert(token.type == T.Goto); | |
1884 nT(); | |
1885 string ident; | |
1886 Expression caseExpr; | |
1887 switch (token.type) | |
1888 { | |
1889 case T.Case: | |
1890 nT(); | |
1891 if (token.type == T.Semicolon) | |
1892 break; | |
1893 caseExpr = parseExpression(); | |
1894 break; | |
1895 case T.Default: | |
1896 nT(); | |
1897 break; | |
1898 default: | |
1899 ident = requireIdentifier(); | |
1900 } | |
1901 require(T.Semicolon); | |
1902 return new GotoStatement(ident, caseExpr); | |
1903 } | |
1904 | |
177 | 1905 Statement parseWithStatement() |
1906 { | |
1907 assert(token.type == T.With); | |
1908 nT(); | |
1909 require(T.LParen); | |
1910 auto expr = parseExpression(); | |
1911 require(T.RParen); | |
1912 return new WithStatement(expr, parseScopeStatement()); | |
1913 } | |
1914 | |
178 | 1915 Statement parseSynchronizedStatement() |
1916 { | |
1917 assert(token.type == T.Synchronized); | |
1918 nT(); | |
1919 Expression expr; | |
1920 | |
1921 if (token.type == T.LParen) | |
1922 { | |
1923 nT(); | |
1924 expr = parseExpression(); | |
1925 require(T.RParen); | |
1926 } | |
1927 return new SynchronizedStatement(expr, parseScopeStatement()); | |
1928 } | |
1929 | |
179 | 1930 Statement parseTryStatement() |
1931 { | |
1932 assert(token.type == T.Try); | |
1933 nT(); | |
1934 | |
1935 auto tryBody = parseScopeStatement(); | |
1936 CatchBody[] catchBodies; | |
1937 FinallyBody finBody; | |
1938 | |
1939 while (token.type == T.Catch) | |
1940 { | |
1941 nT(); | |
1942 Parameter param; | |
1943 if (token.type == T.LParen) | |
1944 { | |
229 | 1945 nT(); |
179 | 1946 string ident; |
1947 auto type = parseDeclarator(ident); | |
1948 param = new Parameter(StorageClass.None, type, ident, null); | |
1949 require(T.RParen); | |
1950 } | |
1951 catchBodies ~= new CatchBody(param, parseNoScopeStatement()); | |
1952 if (param is null) | |
1953 break; // This is a LastCatch | |
1954 } | |
1955 | |
1956 if (token.type == T.Finally) | |
1957 { | |
1958 nT(); | |
1959 finBody = new FinallyBody(parseNoScopeStatement()); | |
1960 } | |
1961 | |
1962 if (catchBodies.length == 0 || finBody is null) | |
1963 { | |
1964 // TODO: issue error msg. | |
1965 } | |
1966 | |
1967 return new TryStatement(tryBody, catchBodies, finBody); | |
1968 } | |
1969 | |
180 | 1970 Statement parseThrowStatement() |
1971 { | |
1972 assert(token.type == T.Throw); | |
1973 nT(); | |
1974 auto expr = parseExpression(); | |
1975 require(T.Semicolon); | |
1976 return new ThrowStatement(expr); | |
1977 } | |
1978 | |
181 | 1979 Statement parseScopeGuardStatement() |
1980 { | |
1981 assert(token.type == T.Scope); | |
1982 nT(); | |
1983 assert(token.type == T.LParen); | |
1984 nT(); | |
1985 | |
1986 string condition = requireIdentifier(); | |
1987 if (condition.length) | |
1988 switch (condition) | |
1989 { | |
1990 case "exit": | |
1991 case "success": | |
1992 case "failure": | |
1993 break; | |
1994 default: | |
1995 // TODO: issue error msg. | |
1996 } | |
1997 require(T.RParen); | |
1998 Statement scopeBody; | |
1999 if (token.type == T.LBrace) | |
2000 scopeBody = parseScopeStatement(); | |
2001 else | |
2002 scopeBody = parseNoScopeStatement(); | |
2003 return new ScopeGuardStatement(condition, scopeBody); | |
2004 } | |
2005 | |
182 | 2006 Statement parseVolatileStatement() |
2007 { | |
2008 assert(token.type == T.Volatile); | |
2009 nT(); | |
2010 Statement volatileBody; | |
2011 if (token.type == T.Semicolon) | |
2012 nT(); | |
2013 else if (token.type == T.LBrace) | |
2014 volatileBody = parseScopeStatement(); | |
2015 else | |
219 | 2016 volatileBody = parseStatement(); |
182 | 2017 return new VolatileStatement(volatileBody); |
2018 } | |
2019 | |
184 | 2020 Statement parsePragmaStatement() |
2021 { | |
2022 assert(token.type == T.Pragma); | |
2023 nT(); | |
2024 | |
2025 string ident; | |
2026 Expression[] args; | |
2027 Statement pragmaBody; | |
2028 | |
2029 require(T.LParen); | |
2030 ident = requireIdentifier(); | |
2031 | |
2032 if (token.type == T.Comma) | |
2033 args = parseArguments(T.RParen); | |
2034 else | |
2035 require(T.RParen); | |
2036 | |
234 | 2037 pragmaBody = parseNoScopeOrEmptyStatement(); |
184 | 2038 |
2039 return new PragmaStatement(ident, args, pragmaBody); | |
2040 } | |
2041 | |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2042 Statement parseStaticIfStatement() |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2043 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2044 assert(token.type == T.Static); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2045 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2046 assert(token.type == T.If); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2047 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2048 Expression condition; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2049 Statement ifBody, elseBody; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2050 |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2051 require(T.LParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2052 condition = parseExpression(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2053 require(T.RParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2054 ifBody = parseNoScopeStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2055 if (token.type == T.Else) |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2056 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2057 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2058 elseBody = parseNoScopeStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2059 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2060 return new StaticIfStatement(condition, ifBody, elseBody); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2061 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2062 |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2063 Statement parseStaticAssertStatement() |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2064 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2065 assert(token.type == T.Static); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2066 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2067 assert(token.type == T.Assert); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2068 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2069 Expression condition, message; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2070 require(T.LParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2071 condition = parseAssignExpression(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2072 if (token.type == T.Comma) |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2073 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2074 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2075 message = parseAssignExpression(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2076 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2077 require(T.RParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2078 require(T.Semicolon); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2079 return new StaticAssertStatement(condition, message); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2080 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2081 |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2082 Statement parseDebugStatement() |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2083 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2084 assert(token.type == T.Debug); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2085 nT(); // Skip debug keyword. |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2086 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2087 // int levelSpec = -1; // debug = Integer ; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2088 // string identSpec; // debug = Identifier ; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2089 int levelCond = -1; // debug ( Integer ) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2090 string identCond; // debug ( Identifier ) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2091 Statement debugBody, elseBody; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2092 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2093 void parseIdentOrInt(ref string ident, ref int level) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2094 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2095 nT(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2096 if (token.type == T.Int32) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2097 level = token.int_; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2098 else if (token.type == T.Identifier) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2099 ident = token.identifier; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2100 else |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2101 expected(T.Identifier); // TODO: better error msg |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2102 nT(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2103 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2104 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2105 // if (token.type == T.Assign) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2106 // { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2107 // parseIdentOrInt(identSpec, levelSpec); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2108 // require(T.Semicolon); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2109 // } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2110 // else |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2111 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2112 // Condition: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2113 // Integer |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2114 // Identifier |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2115 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2116 // ( Condition ) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2117 if (token.type == T.LParen) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2118 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2119 parseIdentOrInt(identCond, levelCond); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2120 require(T.RParen); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2121 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2122 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2123 // debug Statement |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2124 // debug ( Condition ) Statement |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2125 debugBody = parseNoScopeStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2126 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2127 // else Statement |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2128 if (token.type == T.Else) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2129 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2130 // debug without condition and else body makes no sense |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2131 //if (levelCond == -1 && identCond.length == 0) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2132 // TODO: issue error msg |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2133 nT(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2134 elseBody = parseNoScopeStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2135 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2136 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2137 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2138 return new DebugStatement(/+levelSpec, identSpec,+/ levelCond, identCond, debugBody, elseBody); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2139 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2140 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2141 Statement parseVersionStatement() |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2142 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2143 assert(token.type == T.Version); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2144 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2145 nT(); // Skip version keyword. |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2146 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2147 // int levelSpec = -1; // version = Integer ; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2148 // string identSpec; // version = Identifier ; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2149 int levelCond = -1; // version ( Integer ) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2150 string identCond; // version ( Identifier ) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2151 Statement versionBody, elseBody; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2152 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2153 void parseIdentOrInt(ref string ident, ref int level) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2154 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2155 if (token.type == T.Int32) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2156 level = token.int_; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2157 else if (token.type == T.Identifier) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2158 ident = token.identifier; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2159 else |
219 | 2160 { |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2161 expected(T.Identifier); // TODO: better error msg |
219 | 2162 return; |
2163 } | |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2164 nT(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2165 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2166 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2167 // if (token.type == T.Assign) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2168 // { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2169 // parseIdentOrInt(identSpec, levelSpec); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2170 // require(T.Semicolon); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2171 // } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2172 // else |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2173 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2174 // Condition: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2175 // Integer |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2176 // Identifier |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2177 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2178 // ( Condition ) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2179 require(T.LParen); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2180 parseIdentOrInt(identCond, levelCond); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2181 require(T.RParen); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2182 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2183 // version ( Condition ) Statement |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2184 versionBody = parseNoScopeStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2185 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2186 // else Statement |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2187 if (token.type == T.Else) |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2188 { |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2189 nT(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2190 elseBody = parseNoScopeStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2191 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2192 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2193 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2194 return new VersionStatement(/+levelSpec, identSpec,+/ levelCond, identCond, versionBody, elseBody); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2195 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2196 |
161 | 2197 /+++++++++++++++++++++++++++++ |
183 | 2198 + Assembler parsing methods + |
2199 +++++++++++++++++++++++++++++/ | |
2200 | |
2201 Statement parseAsmStatement() | |
2202 { | |
2203 assert(token.type == T.Asm); | |
2204 // TODO: implement asm statements parser. | |
2205 return null; | |
2206 } | |
2207 | |
2208 /+++++++++++++++++++++++++++++ | |
102 | 2209 + Expression parsing methods + |
2210 +++++++++++++++++++++++++++++/ | |
2211 | |
72 | 2212 Expression parseExpression() |
2213 { | |
2214 auto e = parseAssignExpression(); | |
122 | 2215 while (token.type == T.Comma) |
235 | 2216 { |
2217 nT(); | |
81 | 2218 e = new CommaExpression(e, parseAssignExpression()); |
235 | 2219 } |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2220 // if (!trying) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2221 // writef("§%s§", e.classinfo.name); |
72 | 2222 return e; |
2223 } | |
2224 | |
71 | 2225 Expression parseAssignExpression() |
2226 { | |
2227 auto e = parseCondExpression(); | |
72 | 2228 while (1) |
71 | 2229 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2230 switch (token.type) |
72 | 2231 { |
2232 case T.Assign: | |
2233 nT(); e = new AssignExpression(e, parseAssignExpression()); | |
2234 break; | |
2235 case T.LShiftAssign: | |
2236 nT(); e = new LShiftAssignExpression(e, parseAssignExpression()); | |
2237 break; | |
2238 case T.RShiftAssign: | |
2239 nT(); e = new RShiftAssignExpression(e, parseAssignExpression()); | |
2240 break; | |
2241 case T.URShiftAssign: | |
2242 nT(); e = new URShiftAssignExpression(e, parseAssignExpression()); | |
2243 break; | |
2244 case T.OrAssign: | |
2245 nT(); e = new OrAssignExpression(e, parseAssignExpression()); | |
2246 break; | |
2247 case T.AndAssign: | |
2248 nT(); e = new AndAssignExpression(e, parseAssignExpression()); | |
2249 break; | |
2250 case T.PlusAssign: | |
2251 nT(); e = new PlusAssignExpression(e, parseAssignExpression()); | |
2252 break; | |
2253 case T.MinusAssign: | |
2254 nT(); e = new MinusAssignExpression(e, parseAssignExpression()); | |
2255 break; | |
2256 case T.DivAssign: | |
2257 nT(); e = new DivAssignExpression(e, parseAssignExpression()); | |
2258 break; | |
2259 case T.MulAssign: | |
2260 nT(); e = new MulAssignExpression(e, parseAssignExpression()); | |
2261 break; | |
2262 case T.ModAssign: | |
2263 nT(); e = new ModAssignExpression(e, parseAssignExpression()); | |
2264 break; | |
2265 case T.XorAssign: | |
2266 nT(); e = new XorAssignExpression(e, parseAssignExpression()); | |
2267 break; | |
2268 case T.CatAssign: | |
2269 nT(); e = new CatAssignExpression(e, parseAssignExpression()); | |
2270 break; | |
2271 default: | |
218 | 2272 return e; |
72 | 2273 } |
71 | 2274 } |
2275 return e; | |
2276 } | |
72 | 2277 |
71 | 2278 Expression parseCondExpression() |
2279 { | |
72 | 2280 auto e = parseOrOrExpression(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2281 if (token.type == T.Question) |
72 | 2282 { |
2283 nT(); | |
2284 auto iftrue = parseExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2285 require(T.Colon); |
72 | 2286 auto iffalse = parseCondExpression(); |
2287 e = new CondExpression(e, iftrue, iffalse); | |
2288 } | |
2289 return e; | |
2290 } | |
2291 | |
2292 Expression parseOrOrExpression() | |
2293 { | |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2294 alias parseAndAndExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2295 auto e = parseNext(); |
223 | 2296 while (token.type == T.OrLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2297 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2298 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2299 e = new OrOrExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2300 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2301 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2302 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2303 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2304 Expression parseAndAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2305 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2306 alias parseOrExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2307 auto e = parseNext(); |
223 | 2308 while (token.type == T.AndLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2309 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2310 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2311 e = new AndAndExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2312 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2313 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2314 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2315 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2316 Expression parseOrExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2317 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2318 alias parseXorExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2319 auto e = parseNext(); |
223 | 2320 while (token.type == T.OrBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2321 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2322 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2323 e = new OrExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2324 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2325 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2326 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2327 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2328 Expression parseXorExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2329 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2330 alias parseAndExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2331 auto e = parseNext(); |
223 | 2332 while (token.type == T.Xor) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2333 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2334 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2335 e = new XorExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2336 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2337 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2338 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2339 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2340 Expression parseAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2341 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2342 alias parseCmpExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2343 auto e = parseNext(); |
223 | 2344 while (token.type == T.AndBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2345 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2346 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2347 e = new AndExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2348 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2349 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2350 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2351 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2352 Expression parseCmpExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2353 { |
74 | 2354 auto e = parseShiftExpression(); |
2355 | |
217 | 2356 TOK operator = token.type; |
74 | 2357 switch (operator) |
2358 { | |
2359 case T.Equal, T.NotEqual: | |
2360 nT(); | |
2361 e = new EqualExpression(e, parseShiftExpression(), operator); | |
2362 break; | |
2363 case T.Not: | |
2364 Token t; | |
2365 lx.peek(t); | |
2366 if (t.type != T.Is) | |
2367 break; | |
2368 nT(); | |
2369 operator = T.NotIdentity; | |
2370 goto LNotIdentity; | |
225 | 2371 case T.Is: |
74 | 2372 operator = T.Identity; |
2373 LNotIdentity: | |
2374 nT(); | |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2375 e = new IdentityExpression(e, parseShiftExpression(), operator); |
74 | 2376 break; |
2377 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater, | |
2378 T.Unordered, T.UorE, T.UorG, T.UorGorE, | |
2379 T.UorL, T.UorLorE, T.LorEorG, T.LorG: | |
2380 nT(); | |
2381 e = new RelExpression(e, parseShiftExpression(), operator); | |
2382 break; | |
2383 case T.In: | |
2384 nT(); | |
2385 e = new InExpression(e, parseShiftExpression(), operator); | |
2386 break; | |
2387 default: | |
2388 } | |
2389 return e; | |
2390 } | |
2391 | |
2392 Expression parseShiftExpression() | |
2393 { | |
75 | 2394 auto e = parseAddExpression(); |
2395 while (1) | |
2396 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2397 switch (token.type) |
75 | 2398 { |
2399 case T.LShift: nT(); e = new LShiftExpression(e, parseAddExpression()); break; | |
2400 case T.RShift: nT(); e = new RShiftExpression(e, parseAddExpression()); break; | |
2401 case T.URShift: nT(); e = new URShiftExpression(e, parseAddExpression()); break; | |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2402 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2403 return e; |
75 | 2404 } |
2405 } | |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2406 assert(0); |
75 | 2407 } |
2408 | |
2409 Expression parseAddExpression() | |
2410 { | |
76 | 2411 auto e = parseMulExpression(); |
2412 while (1) | |
2413 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2414 switch (token.type) |
76 | 2415 { |
2416 case T.Plus: nT(); e = new PlusExpression(e, parseMulExpression()); break; | |
2417 case T.Minus: nT(); e = new MinusExpression(e, parseMulExpression()); break; | |
2418 case T.Tilde: nT(); e = new CatExpression(e, parseMulExpression()); break; | |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2419 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2420 return e; |
76 | 2421 } |
2422 } | |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2423 assert(0); |
76 | 2424 } |
2425 | |
2426 Expression parseMulExpression() | |
2427 { | |
77 | 2428 auto e = parseUnaryExpression(); |
2429 while (1) | |
2430 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2431 switch (token.type) |
77 | 2432 { |
2433 case T.Mul: nT(); e = new MulExpression(e, parseUnaryExpression()); break; | |
2434 case T.Div: nT(); e = new DivExpression(e, parseUnaryExpression()); break; | |
2435 case T.Mod: nT(); e = new ModExpression(e, parseUnaryExpression()); break; | |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2436 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2437 return e; |
77 | 2438 } |
2439 } | |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2440 assert(0); |
71 | 2441 } |
2442 | |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2443 Expression parseUnaryExpression() |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2444 { |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2445 Expression e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2446 switch (token.type) |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2447 { |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2448 case T.AndBinary: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2449 nT(); e = new AddressExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2450 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2451 case T.PlusPlus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2452 nT(); e = new PreIncrExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2453 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2454 case T.MinusMinus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2455 nT(); e = new PreDecrExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2456 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2457 case T.Mul: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2458 nT(); e = new DerefExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2459 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2460 case T.Minus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2461 case T.Plus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2462 nT(); e = new SignExpression(parseUnaryExpression(), token.type); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2463 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2464 case T.Not: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2465 nT(); e = new NotExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2466 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2467 case T.Tilde: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2468 nT(); e = new CompExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2469 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2470 case T.New: |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2471 e = parseNewExpression(); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2472 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2473 case T.Delete: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2474 nT(); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2475 e = new DeleteExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2476 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2477 case T.Cast: |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
2478 requireNext(T.LParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
2479 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
2480 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
2481 e = new CastExpression(parseUnaryExpression(), type); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2482 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2483 case T.LParen: |
102 | 2484 // ( Type ) . Identifier |
225 | 2485 Type parseType_() |
2486 { | |
2487 nT(); | |
2488 auto type = parseType(); | |
2489 require(T.RParen); | |
233 | 2490 require(T.Dot); |
225 | 2491 return type; |
2492 } | |
2493 bool success; | |
2494 auto type = try_(parseType_(), success); | |
2495 if (success) | |
2496 { | |
2497 string ident = requireIdentifier(); | |
2498 e = new TypeDotIdExpression(type, ident); | |
2499 break; | |
2500 } | |
2501 goto default; | |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2502 default: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2503 e = parsePostExpression(parsePrimaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2504 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2505 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2506 assert(e !is null); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2507 return e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2508 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2509 |
90
a02950cb7036
- Fixed order of parsing unary, post and primary expressions.
aziz
parents:
89
diff
changeset
|
2510 Expression parsePostExpression(Expression e) |
77 | 2511 { |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2512 while (1) |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2513 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2514 switch (token.type) |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2515 { |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2516 /* |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2517 // Commented out because parseDotListExpression() handles this. |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2518 case T.Dot: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2519 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2520 if (token.type == T.Identifier) |
92 | 2521 { |
153 | 2522 string ident = token.identifier; |
2523 nT(); | |
2524 Token next; | |
2525 lx.peek(next); | |
2526 if (token.type == T.Not && next.type == T.LParen) // Identifier !( TemplateArguments ) | |
2527 { | |
2528 nT(); // Skip !. | |
2529 e = new DotTemplateInstanceExpression(e, ident, parseTemplateArguments()); | |
2530 } | |
2531 else | |
2532 { | |
2533 e = new DotIdExpression(e, ident); | |
2534 nT(); | |
2535 } | |
92 | 2536 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2537 else if (token.type == T.New) |
81 | 2538 e = parseNewExpression(e); |
92 | 2539 else |
124 | 2540 expected(T.Identifier); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
2541 continue; |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2542 */ |
160
c21192e8be2b
- Parsing PostDotListExpression in parsePostExpression().
aziz
parents:
159
diff
changeset
|
2543 case T.Dot: |
c21192e8be2b
- Parsing PostDotListExpression in parsePostExpression().
aziz
parents:
159
diff
changeset
|
2544 e = new PostDotListExpression(e, parseDotListExpression()); |
227
cd0acc9dadc1
- Fix in parsePostExpression(): break should be continue.
aziz
parents:
226
diff
changeset
|
2545 continue; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2546 case T.PlusPlus: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2547 e = new PostIncrExpression(e); |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2548 break; |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2549 case T.MinusMinus: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2550 e = new PostDecrExpression(e); |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2551 break; |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2552 case T.LParen: |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2553 e = new CallExpression(e, parseArguments(T.RParen)); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
2554 continue; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2555 case T.LBracket: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2556 // parse Slice- and IndexExpression |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2557 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2558 if (token.type == T.RBracket) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2559 { |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2560 e = new SliceExpression(e, null, null); |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2561 break; |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2562 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2563 |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2564 Expression[] es = [parseAssignExpression()]; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2565 |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2566 if (token.type == T.Slice) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2567 { |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2568 nT(); |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2569 e = new SliceExpression(e, es[0], parseAssignExpression()); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2570 require(T.RBracket); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
2571 continue; |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2572 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2573 else if (token.type == T.Comma) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2574 { |
143 | 2575 es ~= parseArguments(T.RBracket); |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2576 } |
85 | 2577 else |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2578 require(T.RBracket); |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2579 |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2580 e = new IndexExpression(e, es); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
2581 continue; |
92 | 2582 default: |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
2583 return e; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2584 } |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
2585 nT(); |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2586 } |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
2587 assert(0); |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2588 } |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2589 |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
2590 Expression parsePrimaryExpression() |
78
f043759fb59a
- Added code to parseUnaryExpression(); not fully implemented.
aziz
parents:
77
diff
changeset
|
2591 { |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2592 Expression e; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2593 switch (token.type) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2594 { |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2595 /* |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2596 // Commented out because parseDotListExpression() handles this. |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2597 case T.Identifier: |
153 | 2598 string ident = token.identifier; |
89 | 2599 nT(); |
153 | 2600 Token next; |
2601 lx.peek(next); | |
2602 if (token.type == T.Not && next.type == T.LParen) // Identifier !( TemplateArguments ) | |
2603 { | |
2604 nT(); // Skip !. | |
2605 e = new TemplateInstanceExpression(ident, parseTemplateArguments()); | |
2606 } | |
2607 else | |
2608 e = new IdentifierExpression(ident); | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2609 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2610 case T.Dot: |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
2611 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
2612 e = new IdentifierExpression("."); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2613 break; |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2614 */ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2615 case T.Identifier, T.Dot, T.Typeof: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2616 e = parseDotListExpression(); |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2617 break; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2618 case T.This: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2619 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2620 e = new ThisExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2621 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2622 case T.Super: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2623 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2624 e = new SuperExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2625 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2626 case T.Null: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2627 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2628 e = new NullExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2629 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2630 case T.True, T.False: |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2631 e = new BoolExpression(token.type == T.True ? true : false); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2632 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2633 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2634 case T.Dollar: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2635 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2636 e = new DollarExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2637 break; |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
2638 case T.Int32, T.Int64, T.Uint32, T.Uint64: |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2639 e = new IntNumberExpression(token.type, token.ulong_); |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
2640 nT(); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
2641 break; |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
2642 case T.Float32, T.Float64, T.Float80, |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
2643 T.Imaginary32, T.Imaginary64, T.Imaginary80: |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2644 e = new RealNumberExpression(token.type, token.real_); |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
2645 nT(); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2646 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2647 case T.CharLiteral, T.WCharLiteral, T.DCharLiteral: |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2648 e = new CharLiteralExpression(token.type); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2649 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2650 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2651 case T.String: |
216 | 2652 // TODO: The Lexer doesn't allocate the tokens on the heap yet. So Token* will not work here. |
157
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
2653 Token*[] stringLiterals; |
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
2654 do |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2655 { |
157
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
2656 stringLiterals ~= token; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2657 nT(); |
157
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
2658 } while (token.type == T.String) |
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
2659 e = new StringLiteralsExpression(stringLiterals); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2660 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2661 case T.LBracket: |
85 | 2662 Expression[] values; |
2663 | |
2664 nT(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2665 if (token.type != T.RBracket) |
85 | 2666 { |
2667 e = parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2668 if (token.type == T.Colon) |
85 | 2669 goto LparseAssocArray; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2670 else if (token.type == T.Comma) |
143 | 2671 values = [e] ~ parseArguments(T.RBracket); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2672 else |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2673 require(T.RBracket); |
85 | 2674 } |
2675 | |
2676 e = new ArrayLiteralExpression(values); | |
2677 break; | |
2678 | |
2679 LparseAssocArray: | |
2680 Expression[] keys; | |
2681 | |
2682 keys ~= e; | |
2683 nT(); // Skip colon. | |
2684 values ~= parseAssignExpression(); | |
2685 | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2686 if (token.type != T.RBracket) |
88 | 2687 { |
2688 require(T.Comma); | |
85 | 2689 while (1) |
2690 { | |
2691 keys ~= parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2692 if (token.type != T.Colon) |
85 | 2693 { |
124 | 2694 expected(T.Colon); |
85 | 2695 values ~= null; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2696 if (token.type == T.RBracket) |
85 | 2697 break; |
2698 else | |
2699 continue; | |
2700 } | |
2701 nT(); | |
2702 values ~= parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2703 if (token.type == T.RBracket) |
85 | 2704 break; |
88 | 2705 require(T.Comma); |
85 | 2706 } |
88 | 2707 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2708 assert(token.type == T.RBracket); |
85 | 2709 nT(); |
2710 e = new AssocArrayLiteralExpression(keys, values); | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2711 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2712 case T.LBrace: |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
2713 // DelegateLiteral := { Statements } |
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
2714 auto funcType = new FunctionType(null, Parameters.init); |
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
2715 auto funcBody = parseFunctionBody(new FunctionBody); |
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
2716 e = new FunctionLiteralExpression(funcType, funcBody); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2717 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2718 case T.Function, T.Delegate: |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
2719 // FunctionLiteral := (function|delegate) Type? '(' ArgumentList ')' '{' Statements '}' |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2720 TOK funcTok = token.type; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2721 nT(); // Skip function|delegate token. |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2722 Type returnType; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2723 Parameters parameters; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2724 if (token.type != T.LBrace) |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2725 { |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2726 if (token.type != T.LParen) // Optional return type |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2727 returnType = parseType(); |
143 | 2728 parameters = parseParameterList(); |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2729 } |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
2730 auto funcType = new FunctionType(returnType, parameters); |
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
2731 auto funcBody = parseFunctionBody(new FunctionBody); |
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
2732 e = new FunctionLiteralExpression(funcType, funcBody, funcTok); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2733 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2734 case T.Assert: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2735 Expression msg; |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2736 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2737 e = parseAssignExpression(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2738 if (token.type == T.Comma) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2739 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2740 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2741 msg = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2742 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2743 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2744 e = new AssertExpression(e, msg); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2745 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2746 case T.Mixin: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2747 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2748 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2749 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2750 e = new MixinExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2751 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2752 case T.Import: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2753 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2754 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2755 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2756 e = new ImportExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2757 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2758 case T.Typeid: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2759 requireNext(T.LParen); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
2760 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
2761 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
2762 e = new TypeidExpression(type); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2763 break; |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2764 /* |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2765 // Commented out because parseDotListExpression() handles this. |
101 | 2766 case T.Typeof: |
2767 requireNext(T.LParen); | |
2768 auto type = new TypeofType(parseExpression()); | |
2769 require(T.RParen); | |
2770 if (token.type == T.Dot) | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2771 { // typeof ( Expression ) . Identifier |
101 | 2772 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2773 string ident = requireIdentifier; |
101 | 2774 e = new TypeDotIdExpression(type, ident); |
2775 } | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2776 else // typeof ( Expression ) |
101 | 2777 e = new TypeofExpression(type); |
2778 break; | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2779 */ |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2780 case T.Is: |
100 | 2781 requireNext(T.LParen); |
2782 | |
2783 Type type; | |
2784 SpecializationType specType; | |
2785 string ident; // optional Identifier | |
2786 | |
2787 type = parseDeclarator(ident, true); | |
2788 | |
2789 switch (token.type) | |
2790 { | |
2791 case T.Colon, T.Equal: | |
2792 TOK specTok = token.type; | |
2793 nT(); | |
2794 switch (token.type) | |
2795 { | |
2796 case T.Typedef, | |
2797 T.Struct, | |
2798 T.Union, | |
2799 T.Class, | |
2800 T.Interface, | |
2801 T.Enum, | |
2802 T.Function, | |
2803 T.Delegate, | |
2804 T.Super, | |
2805 T.Return: | |
102 | 2806 nT(); |
100 | 2807 specType = new SpecializationType(specTok, token.type); |
2808 break; | |
2809 default: | |
2810 specType = new SpecializationType(specTok, parseType()); | |
2811 } | |
2812 default: | |
2813 } | |
102 | 2814 require(T.RParen); |
100 | 2815 e = new IsExpression(type, ident, specType); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2816 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2817 case T.LParen: |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
2818 if (tokenAfterParenIs(T.LBrace)) |
130 | 2819 { |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
2820 auto parameters = parseParameterList(); |
143 | 2821 // ( ParameterList ) FunctionBody |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
2822 auto funcType = new FunctionType(null, parameters); |
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
2823 auto funcBody = parseFunctionBody(new FunctionBody); |
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
2824 e = new FunctionLiteralExpression(funcType, funcBody); |
130 | 2825 } |
2826 else | |
2827 { | |
131 | 2828 // ( Expression ) |
130 | 2829 nT(); |
2830 e = parseExpression(); | |
2831 require(T.RParen); | |
2832 } | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2833 break; |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2834 // BasicType . Identifier |
192 | 2835 case T.Char, T.Wchar, T.Dchar, T.Bool, |
94 | 2836 T.Byte, T.Ubyte, T.Short, T.Ushort, |
2837 T.Int, T.Uint, T.Long, T.Ulong, | |
2838 T.Float, T.Double, T.Real, | |
2839 T.Ifloat, T.Idouble, T.Ireal, | |
192 | 2840 T.Cfloat, T.Cdouble, T.Creal, T.Void: |
94 | 2841 auto type = new Type(token.type); |
2842 requireNext(T.Dot); | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2843 auto ident = requireIdentifier(); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2844 |
94 | 2845 e = new TypeDotIdExpression(type, ident); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2846 break; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2847 default: |
136
96468715ea79
- Returning EmptyExpression in parsePrimaryExpression() when no token matched.
aziz
parents:
135
diff
changeset
|
2848 // TODO: issue error msg. |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2849 error(MID.ExpectedButFound, "Expression", token.srcText); |
136
96468715ea79
- Returning EmptyExpression in parsePrimaryExpression() when no token matched.
aziz
parents:
135
diff
changeset
|
2850 e = new EmptyExpression(); |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2851 } |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2852 return e; |
77 | 2853 } |
2854 | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2855 Expression parseNewExpression(/*Expression e*/) |
81 | 2856 { |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2857 assert(token.type == T.New); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2858 nT(); // Skip new keyword. |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2859 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2860 Expression[] newArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2861 Expression[] ctorArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2862 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2863 if (token.type == T.LParen) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2864 newArguments = parseArguments(T.RParen); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2865 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2866 // NewAnonClassExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2867 // new (ArgumentList)opt class (ArgumentList)opt SuperClassopt InterfaceClassesopt ClassBody |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2868 if (token.type == T.Class) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2869 { |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2870 nT(); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2871 if (token.type == T.LParen) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2872 ctorArguments = parseArguments(T.RParen); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2873 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2874 BaseClass[] bases = token.type != T.LBrace ? parseBaseClasses(false) : null ; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2875 |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2876 auto decls = parseDeclarationDefinitionsBlock(); |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2877 return new NewAnonClassExpression(/*e, */newArguments, bases, ctorArguments, decls); |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2878 } |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2879 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2880 // NewExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2881 // NewArguments Type [ AssignExpression ] |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2882 // NewArguments Type ( ArgumentList ) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2883 // NewArguments Type |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2884 auto type = parseType(); |
156
53c667aabbf2
- parseNewExpression(): constructor arguments should only be parsed when the Type is a DotListType and when '(' is found.
aziz
parents:
155
diff
changeset
|
2885 if (type.tid == TID.DotList && token.type == T.LParen) |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2886 { |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2887 ctorArguments = parseArguments(T.RParen); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2888 } |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2889 return new NewExpression(/*e, */newArguments, type, ctorArguments); |
81 | 2890 } |
2891 | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2892 Type parseType() |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2893 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
2894 return parseBasicType2(parseBasicType()); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2895 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2896 |
94 | 2897 Type parseBasicType() |
2898 { | |
2899 Type t; | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2900 // IdentifierType tident; |
94 | 2901 |
2902 switch (token.type) | |
2903 { | |
192 | 2904 case T.Char, T.Wchar, T.Dchar, T.Bool, |
94 | 2905 T.Byte, T.Ubyte, T.Short, T.Ushort, |
2906 T.Int, T.Uint, T.Long, T.Ulong, | |
2907 T.Float, T.Double, T.Real, | |
2908 T.Ifloat, T.Idouble, T.Ireal, | |
192 | 2909 T.Cfloat, T.Cdouble, T.Creal, T.Void: |
94 | 2910 t = new Type(token.type); |
2911 nT(); | |
2912 break; | |
153 | 2913 /+ |
94 | 2914 case T.Identifier, T.Dot: |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
2915 tident = new IdentifierType([token.identifier]); |
94 | 2916 nT(); |
102 | 2917 // TODO: parse template instance |
94 | 2918 // if (token.type == T.Not) |
2919 // parse template instance | |
2920 Lident: | |
2921 while (token.type == T.Dot) | |
2922 { | |
2923 nT(); | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2924 tident ~= requireIdentifier(); |
102 | 2925 // TODO: parse template instance |
94 | 2926 // if (token.type == T.Not) |
2927 // parse template instance | |
2928 } | |
2929 t = tident; | |
2930 break; | |
2931 case T.Typeof: | |
2932 requireNext(T.LParen); | |
2933 tident = new TypeofType(parseExpression()); | |
2934 require(T.RParen); | |
2935 goto Lident; | |
153 | 2936 +/ |
2937 case T.Identifier, T.Typeof, T.Dot: | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2938 t = parseDotListType(); |
153 | 2939 break; |
94 | 2940 default: |
136
96468715ea79
- Returning EmptyExpression in parsePrimaryExpression() when no token matched.
aziz
parents:
135
diff
changeset
|
2941 // TODO: issue error msg. |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2942 error(MID.ExpectedButFound, "BasicType", token.srcText); |
134
a31aa0d6dd5e
- Added class UndefinedType. Returning it in parseBasicType() when no token matched the basic type list.
aziz
parents:
133
diff
changeset
|
2943 t = new UndefinedType(); |
94 | 2944 } |
2945 return t; | |
2946 } | |
2947 | |
95 | 2948 Type parseBasicType2(Type t) |
2949 { | |
2950 while (1) | |
2951 { | |
2952 switch (token.type) | |
2953 { | |
2954 case T.Mul: | |
2955 t = new PointerType(t); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2956 nT(); |
95 | 2957 break; |
2958 case T.LBracket: | |
106 | 2959 t = parseArrayType(t); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2960 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2961 case T.Function, T.Delegate: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2962 TOK tok = token.type; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2963 nT(); |
143 | 2964 auto parameters = parseParameterList(); |
135 | 2965 t = new FunctionType(t, parameters); |
2966 if (tok == T.Function) | |
2967 t = new PointerType(t); | |
2968 else | |
2969 t = new DelegateType(t); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2970 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2971 default: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2972 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2973 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2974 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2975 assert(0); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2976 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2977 |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
2978 bool tokenAfterParenIs(TOK tok) |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
2979 { |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
2980 // We count nested parentheses tokens because template types may appear inside parameter lists; e.g. (int x, Foo!(int) y). |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
2981 assert(token.type == T.LParen); |
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
2982 Token next; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
2983 uint level = 1; |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
2984 while (1) |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
2985 { |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
2986 lx.peek(next); |
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
2987 switch (next.type) |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
2988 { |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
2989 case T.RParen: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
2990 if (--level == 0) |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2991 { // Closing parentheses found. |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
2992 lx.peek(next); |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
2993 break; |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
2994 } |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
2995 continue; |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
2996 case T.LParen: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
2997 ++level; |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
2998 continue; |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
2999 case T.EOF: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3000 break; |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3001 default: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3002 continue; |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3003 } |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3004 break; |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3005 } |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3006 |
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3007 return next.type == tok; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3008 } |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3009 |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3010 Type parseDeclaratorSuffix(Type t) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3011 { |
192 | 3012 switch (token.type) |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3013 { |
192 | 3014 case T.LBracket: |
3015 // Type Identifier ArrayType | |
3016 // ArrayType := [] or [Type] or [Expression..Expression] | |
3017 do | |
106 | 3018 t = parseArrayType(t); |
192 | 3019 while (token.type == T.LBracket) |
3020 break; | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3021 /+ // parsed in parseDeclaration() |
192 | 3022 case T.LParen: |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3023 TemplateParameter[] tparams; |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3024 if (tokenAfterParenIs(T.LParen)) |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3025 { |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3026 // ( TemplateParameterList ) ( ParameterList ) |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3027 tparams = parseTemplateParameterList(); |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3028 } |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3029 |
192 | 3030 auto params = parseParameterList(); |
3031 // ReturnType FunctionName ( ParameterList ) | |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3032 t = new FunctionType(t, params, tparams); |
192 | 3033 break; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3034 +/ |
192 | 3035 default: |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3036 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3037 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3038 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3039 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3040 |
106 | 3041 Type parseArrayType(Type t) |
3042 { | |
3043 assert(token.type == T.LBracket); | |
3044 nT(); | |
3045 if (token.type == T.RBracket) | |
3046 { | |
3047 t = new ArrayType(t); | |
3048 nT(); | |
3049 } | |
3050 else | |
3051 { | |
214 | 3052 bool success; |
3053 auto assocType = try_(parseType(), success); | |
3054 if (success) | |
106 | 3055 t = new ArrayType(t, assocType); |
3056 else | |
3057 { | |
3058 Expression e = parseExpression(), e2; | |
3059 if (token.type == T.Slice) | |
3060 { | |
3061 nT(); | |
3062 e2 = parseExpression(); | |
3063 } | |
3064 t = new ArrayType(t, e, e2); | |
3065 } | |
3066 require(T.RBracket); | |
3067 } | |
3068 return t; | |
3069 } | |
3070 | |
100 | 3071 Type parseDeclarator(ref string ident, bool identOptional = false) |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3072 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
3073 auto t = parseType(); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3074 |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3075 if (token.type == T.Identifier) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3076 { |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
3077 ident = token.identifier; |
95 | 3078 nT(); |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
3079 t = parseDeclaratorSuffix(t); |
95 | 3080 } |
100 | 3081 else if (!identOptional) |
124 | 3082 expected(T.Identifier); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3083 |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
3084 return t; |
95 | 3085 } |
3086 | |
143 | 3087 Expression[] parseArguments(TOK terminator) |
138 | 3088 { |
155 | 3089 assert(token.type == T.LParen || token.type == T.LBracket || token.type == T.Comma); |
3090 assert(terminator == T.RParen || terminator == T.RBracket); | |
139 | 3091 Expression[] args; |
138 | 3092 |
3093 nT(); | |
3094 if (token.type == terminator) | |
3095 { | |
3096 nT(); | |
3097 return null; | |
3098 } | |
3099 | |
139 | 3100 goto LenterLoop; |
3101 do | |
138 | 3102 { |
139 | 3103 nT(); |
3104 LenterLoop: | |
3105 args ~= parseAssignExpression(); | |
3106 } while (token.type == T.Comma) | |
3107 | |
3108 require(terminator); | |
3109 return args; | |
138 | 3110 } |
3111 | |
143 | 3112 Parameters parseParameterList() |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3113 out(params) |
96 | 3114 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3115 if (params.length > 1) |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3116 foreach (param; params.items[0..$-1]) |
96 | 3117 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3118 if (param.isVariadic()) |
96 | 3119 assert(0, "variadic arguments can only appear at the end of the parameter list."); |
3120 } | |
3121 } | |
3122 body | |
95 | 3123 { |
3124 require(T.LParen); | |
3125 | |
3126 if (token.type == T.RParen) | |
3127 { | |
3128 nT(); | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3129 return Parameters.init; |
95 | 3130 } |
3131 | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3132 Parameters params; |
95 | 3133 StorageClass stc; |
3134 | |
3135 while (1) | |
3136 { | |
3137 stc = StorageClass.In; | |
3138 switch (token.type) | |
3139 { | |
3140 case T.In: stc = StorageClass.In; nT(); goto default; | |
3141 case T.Out: stc = StorageClass.Out; nT(); goto default; | |
229 | 3142 case T.Inout: |
95 | 3143 case T.Ref: stc = StorageClass.Ref; nT(); goto default; |
3144 case T.Lazy: stc = StorageClass.Lazy; nT(); goto default; | |
3145 case T.Ellipses: | |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
3146 nT(); |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3147 params ~= new Parameter(StorageClass.Variadic, null, null, null); |
95 | 3148 break; |
3149 default: | |
3150 string ident; | |
130 | 3151 auto type = parseDeclarator(ident, true); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3152 |
95 | 3153 Expression assignExpr; |
3154 if (token.type == T.Assign) | |
3155 { | |
3156 nT(); | |
3157 assignExpr = parseAssignExpression(); | |
3158 } | |
3159 | |
3160 if (token.type == T.Ellipses) | |
3161 { | |
3162 stc |= StorageClass.Variadic; | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3163 params ~= new Parameter(stc, type, ident, assignExpr); |
95 | 3164 nT(); |
3165 break; | |
3166 } | |
3167 | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3168 params ~= new Parameter(stc, type, ident, assignExpr); |
95 | 3169 if (token.type == T.Comma) |
3170 { | |
3171 nT(); | |
3172 continue; | |
3173 } | |
3174 break; | |
3175 } | |
3176 break; | |
3177 } | |
3178 require(T.RParen); | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3179 return params; |
95 | 3180 } |
3181 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
3182 TemplateArguments parseTemplateArguments() |
139 | 3183 { |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
3184 TemplateArguments args; |
139 | 3185 |
3186 require(T.LParen); | |
3187 if (token.type == T.RParen) | |
3188 { | |
3189 nT(); | |
3190 return null; | |
3191 } | |
3192 | |
3193 goto LenterLoop; | |
3194 do | |
3195 { | |
3196 nT(); // Skip comma. | |
3197 LenterLoop: | |
3198 | |
214 | 3199 bool success; |
3200 auto typeArgument = try_(parseType(), success); | |
139 | 3201 |
214 | 3202 if (success) |
139 | 3203 { |
3204 // TemplateArgument: | |
3205 // Type | |
3206 // Symbol | |
3207 args ~= typeArgument; | |
3208 } | |
3209 else | |
3210 { | |
3211 // TemplateArgument: | |
3212 // AssignExpression | |
3213 args ~= parseAssignExpression(); | |
3214 } | |
3215 } while (token.type == T.Comma) | |
3216 | |
3217 require(T.RParen); | |
3218 return args; | |
3219 } | |
3220 | |
143 | 3221 TemplateParameter[] parseTemplateParameterList() |
137 | 3222 { |
3223 require(T.LParen); | |
3224 if (token.type == T.RParen) | |
3225 return null; | |
3226 | |
3227 TemplateParameter[] tparams; | |
3228 while (1) | |
3229 { | |
3230 TP tp; | |
3231 string ident; | |
3232 Type valueType; | |
3233 Type specType, defType; | |
3234 Expression specValue, defValue; | |
3235 | |
3236 switch (token.type) | |
3237 { | |
3238 case T.Alias: | |
3239 // TemplateAliasParameter: | |
3240 // alias Identifier | |
3241 tp = TP.Alias; | |
3242 nT(); // Skip alias keyword. | |
3243 ident = requireIdentifier(); | |
3244 // : SpecializationType | |
3245 if (token.type == T.Colon) | |
3246 { | |
3247 nT(); | |
3248 specType = parseType(); | |
3249 } | |
3250 // = DefaultType | |
3251 if (token.type == T.Assign) | |
3252 { | |
3253 nT(); | |
3254 defType = parseType(); | |
3255 } | |
3256 break; | |
3257 case T.Identifier: | |
3258 ident = token.identifier; | |
3259 Token peeked; | |
3260 lx.peek(peeked); | |
3261 switch (peeked.type) | |
3262 { | |
3263 case T.Ellipses: | |
3264 // TemplateTupleParameter: | |
3265 // Identifier ... | |
3266 tp = TP.Tuple; | |
3267 nT(); // Skip Identifier. | |
3268 nT(); // Skip Ellipses. | |
3269 // if (token.type == T.Comma) | |
3270 // error(); // TODO: issue error msg for variadic param not being last. | |
3271 break; | |
3272 case T.Comma, T.RParen, T.Colon, T.Assign: | |
3273 // TemplateTypeParameter: | |
3274 // Identifier | |
3275 tp = TP.Type; | |
3276 nT(); // Skip Identifier. | |
3277 // : SpecializationType | |
3278 if (token.type == T.Colon) | |
3279 { | |
3280 nT(); | |
3281 specType = parseType(); | |
3282 } | |
3283 // = DefaultType | |
3284 if (token.type == T.Assign) | |
3285 { | |
3286 nT(); | |
3287 defType = parseType(); | |
3288 } | |
3289 break; | |
3290 default: | |
3291 // TemplateValueParameter: | |
3292 // Declarator | |
3293 ident = null; | |
3294 goto LTemplateValueParameter; | |
3295 } | |
3296 break; | |
3297 default: | |
3298 LTemplateValueParameter: | |
3299 // TemplateValueParameter: | |
3300 // Declarator | |
3301 tp = TP.Value; | |
3302 valueType = parseDeclarator(ident); | |
3303 // : SpecializationValue | |
3304 if (token.type == T.Colon) | |
3305 { | |
3306 nT(); | |
3307 specValue = parseCondExpression(); | |
3308 } | |
3309 // = DefaultValue | |
3310 if (token.type == T.Assign) | |
3311 { | |
3312 nT(); | |
3313 defValue = parseCondExpression(); | |
3314 } | |
3315 } | |
3316 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
3317 tparams ~= new TemplateParameter(tp, valueType, ident, specType, defType, specValue, defValue); |
137 | 3318 |
3319 if (token.type != T.Comma) | |
3320 break; | |
3321 nT(); | |
3322 } | |
3323 require(T.RParen); | |
3324 return tparams; | |
3325 } | |
3326 | |
124 | 3327 void expected(TOK tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3328 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
3329 if (token.type != tok) |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3330 error(MID.ExpectedButFound, Token.Token.toString(tok), token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3331 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3332 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3333 void require(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3334 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
3335 if (token.type == tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3336 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3337 else |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3338 error(MID.ExpectedButFound, Token.Token.toString(tok), token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3339 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3340 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3341 void requireNext(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3342 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3343 nT(); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3344 require(tok); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3345 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3346 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
3347 string requireIdentifier() |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
3348 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
3349 string identifier; |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
3350 if (token.type == T.Identifier) |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
3351 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
3352 identifier = token.identifier; |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
3353 nT(); |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
3354 } |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
3355 else |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
3356 error(MID.ExpectedButFound, "Identifier", token.srcText); |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
3357 return identifier; |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
3358 } |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
3359 |
71 | 3360 void error(MID id, ...) |
3361 { | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3362 if (trying) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3363 { |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3364 ++errorCount; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3365 return; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3366 } |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3367 |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3368 // if (errors.length == 10) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3369 // return; |
94 | 3370 errors ~= new Information(InfoType.Parser, id, lx.loc, arguments(_arguments, _argptr)); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3371 // writefln("(%d)P: ", lx.loc, errors[$-1].getMsg); |
71 | 3372 } |
65 | 3373 } |