Mercurial > projects > dil
annotate trunk/src/Parser.d @ 181:abfd51142477
- Implemented parseScopeGuardStatement().
author | aziz |
---|---|
date | Sat, 14 Jul 2007 14:10:01 +0000 |
parents | d5a67aa578a8 |
children | 673b355ba0e9 |
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; |
65 | 14 |
71 | 15 private alias TOK T; |
16 | |
65 | 17 class Parser |
18 { | |
71 | 19 Lexer lx; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
20 Token* token; |
71 | 21 |
22 Information[] errors; | |
23 | |
24 this(char[] srcText, string fileName) | |
25 { | |
26 lx = new Lexer(srcText, fileName); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
27 } |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
28 |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
29 void nT() |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
30 { |
132 | 31 do |
32 { | |
33 lx.nextToken(); | |
34 token = &lx.token; | |
35 } while (token.type == T.Comment) // Skip comments | |
71 | 36 } |
70 | 37 |
102 | 38 void skipToOnePast(TOK tok) |
39 { | |
40 for (; token.type != tok && token.type != T.EOF; nT()) | |
41 {} | |
42 nT(); | |
43 } | |
105 | 44 |
106 | 45 ReturnType try_(ReturnType)(lazy ReturnType parseMethod, out bool failed) |
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
|
46 { |
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
|
47 auto len = errors.length; |
105 | 48 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
|
49 auto result = parseMethod(); |
105 | 50 // If the length of the array changed we know an error occurred. |
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
|
51 if (errors.length != len) |
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
|
52 { |
105 | 53 lexerState.restore(); // Restore state of the Lexer object. |
54 errors = errors[0..len]; // Remove errors that were added when parseMethod() was called. | |
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
|
55 failed = 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
|
56 } |
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
|
57 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
|
58 } |
105 | 59 |
102 | 60 /++++++++++++++++++++++++++++++ |
61 + Declaration parsing methods + | |
62 ++++++++++++++++++++++++++++++/ | |
63 | |
64 Declaration[] parseModule() | |
65 { | |
66 Declaration[] decls; | |
67 | |
68 if (token.type == T.Module) | |
69 { | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
70 ModuleName moduleName; |
102 | 71 do |
72 { | |
73 nT(); | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
74 moduleName ~= requireIdentifier(); |
102 | 75 } while (token.type == T.Dot) |
76 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
|
77 decls ~= new ModuleDeclaration(moduleName); |
102 | 78 } |
110 | 79 decls ~= parseDeclarationDefinitions(); |
102 | 80 return decls; |
81 } | |
82 | |
110 | 83 Declaration[] parseDeclarationDefinitions() |
102 | 84 { |
85 Declaration[] decls; | |
122 | 86 while (token.type != T.RBrace && token.type != T.EOF) |
161 | 87 decls ~= parseDeclarationDefinition(); |
102 | 88 return decls; |
89 } | |
90 | |
110 | 91 Declaration parseDeclarationDefinition() |
102 | 92 { |
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
|
93 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
|
94 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
|
95 { |
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
|
96 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
|
97 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
|
98 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
|
99 T.Deprecated, |
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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 T.Export, |
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
|
105 //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
|
106 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
|
107 T.Override, |
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
|
108 T.Abstract, |
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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 break; |
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
|
115 case 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
|
116 Token t; |
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
|
117 lx.peek(t); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
118 |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
119 switch (t.type) |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
120 { |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
121 case T.Import: |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
122 goto case T.Import; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
123 case T.This: |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
124 decl = parseStaticConstructorDeclaration(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
125 break; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
126 case T.Tilde: |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
127 decl = parseStaticDestructorDeclaration(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
128 break; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
129 case T.If: |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
130 decl = parseStaticIfDeclaration(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
131 break; |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
132 case T.Assert: |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
133 decl = parseStaticAssertDeclaration(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
134 break; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
135 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
|
136 goto case_AttributeSpecifier; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
137 } |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
138 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
|
139 case T.Import: |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
140 decl = parseImportDeclaration(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
141 break; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
142 case T.Enum: |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
143 decl = parseEnumDeclaration(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
144 break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
145 case T.Class: |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
146 decl = parseClassDeclaration(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
147 break; |
112 | 148 case T.Interface: |
149 decl = parseInterfaceDeclaration(); | |
150 break; | |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
151 case T.Struct, T.Union: |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
152 decl = parseAggregateDeclaration(); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
153 break; |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
154 case T.This: |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
155 decl = parseConstructorDeclaration(); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
156 break; |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
157 case T.Tilde: |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
158 decl = parseDestructorDeclaration(); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
159 break; |
120 | 160 case T.Invariant: |
161 decl = parseInvariantDeclaration(); | |
162 break; | |
121 | 163 case T.Unittest: |
164 decl = parseUnittestDeclaration(); | |
165 break; | |
122 | 166 case T.Debug: |
167 decl = parseDebugDeclaration(); | |
140 | 168 break; |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
169 case T.Version: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
170 decl = parseVersionDeclaration(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
171 break; |
140 | 172 case T.Template: |
173 decl = parseTemplateDeclaration(); | |
174 break; | |
141 | 175 case T.New: |
176 decl = parseNewDeclaration(); | |
177 break; | |
178 case T.Delete: | |
179 decl = parseDeleteDeclaration(); | |
180 break; | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
181 case T.Mixin: |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
182 decl = parseMixinDeclaration(); |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
183 break; |
129 | 184 case T.Semicolon: |
185 nT(); | |
186 decl = new EmptyDeclaration(); | |
187 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
|
188 case T.Module: |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
189 // TODO: Error: module is optional and can appear only once at the top of the source file. |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
190 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
|
191 default: |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
192 // TODO: issue error msg. |
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
|
193 } |
129 | 194 return decl; |
102 | 195 } |
196 | |
122 | 197 /* |
198 DeclarationsBlock: | |
199 : DeclDefs | |
200 { } | |
201 { DeclDefs } | |
202 DeclDef | |
203 */ | |
204 Declaration[] parseDeclarationsBlock() | |
205 { | |
206 Declaration[] decls; | |
207 switch (token.type) | |
208 { | |
209 case T.LBrace: | |
210 nT(); | |
211 if (token.type == T.RBrace) | |
212 nT(); | |
213 else | |
214 { | |
215 decls = parseDeclarationDefinitions(); | |
216 require(T.RBrace); | |
217 } | |
218 break; | |
219 case T.Colon: | |
220 nT(); | |
221 decls = parseDeclarationDefinitions(); | |
123 | 222 assert(token.type == T.RBrace || token.type == T.EOF); |
122 | 223 break; |
224 default: | |
225 decls ~= parseDeclarationDefinition(); | |
226 } | |
227 return decls; | |
228 } | |
229 | |
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
|
230 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
|
231 { |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
232 Declaration decl; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
233 |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
234 switch (token.type) |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
235 { |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
236 case T.Extern: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
237 nT(); |
159 | 238 Linkage linkage; |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
239 if (token.type == T.LParen) |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
240 { |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
241 nT(); |
159 | 242 auto ident = requireIdentifier(); |
243 switch (ident) | |
244 { | |
245 case "C": | |
246 if (token.type == T.PlusPlus) | |
247 { | |
248 nT(); | |
249 linkage = Linkage.Cpp; | |
250 break; | |
251 } | |
252 linkage = Linkage.C; | |
253 break; | |
254 case "D": | |
255 linkage = Linkage.D; | |
256 break; | |
257 case "Windows": | |
258 linkage = Linkage.Windows; | |
259 break; | |
260 case "Pascal": | |
261 linkage = Linkage.Pascal; | |
262 break; | |
263 default: | |
264 // TODO: issue error msg. Unrecognized LinkageType. | |
265 } | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
266 require(T.RParen); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
267 } |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
268 decl = new ExternDeclaration(linkage, parseDeclarationsBlock()); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
269 break; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
270 case T.Align: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
271 nT(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
272 int size = -1; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
273 if (token.type == T.LParen) |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
274 { |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
275 nT(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
276 if (token.type == T.Int32) |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
277 { |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
278 size = token.int_; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
279 nT(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
280 } |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
281 else |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
282 expected(T.Int32); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
283 require(T.RParen); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
284 } |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
285 decl = new AlignDeclaration(size, parseDeclarationsBlock()); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
286 break; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
287 case T.Pragma: |
147 | 288 // Pragma: |
289 // pragma ( Identifier ) | |
290 // pragma ( Identifier , ExpressionList ) | |
291 // ExpressionList: | |
292 // AssignExpression | |
293 // AssignExpression , ExpressionList | |
294 nT(); | |
295 string ident; | |
296 Expression[] args; | |
297 Declaration[] decls; | |
298 | |
299 require(T.LParen); | |
300 ident = requireIdentifier(); | |
301 | |
302 if (token.type == T.Comma) | |
303 args = parseArguments(T.RParen); | |
304 else | |
305 require(T.RParen); | |
306 | |
307 if (token.type == T.Semicolon) | |
308 nT(); | |
309 else | |
310 decls = parseDeclarationsBlock(); | |
311 | |
312 decl = new PragmaDeclaration(ident, args, decls); | |
313 break; | |
149 | 314 // Protection attributes |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
315 case T.Private: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
316 case T.Package: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
317 case T.Protected: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
318 case T.Public: |
148 | 319 case T.Export: |
149 | 320 // StorageClass attributes |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
321 case T.Override: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
322 case T.Deprecated: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
323 case T.Abstract: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
324 case T.Static: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
325 case T.Final: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
326 case T.Const: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
327 case T.Auto: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
328 case T.Scope: |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
329 nT(); |
149 | 330 decl = new AttributeDeclaration(token.type, parseDeclarationsBlock()); |
331 break; | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
332 default: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
333 assert(0); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
334 } |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
335 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
|
336 } |
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
|
337 |
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
|
338 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
|
339 { |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
340 assert(token.type == T.Import || token.type == T.Static); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
341 |
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
|
342 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
|
343 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
|
344 |
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
|
345 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
|
346 { |
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
|
347 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
|
348 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
|
349 } |
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
|
350 |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
351 ModuleName[] moduleNames; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
352 string[] moduleAliases; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
353 string[] bindNames; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
354 string[] bindAliases; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
355 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
356 nT(); // Skip import keyword. |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
357 do |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
358 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
359 ModuleName moduleName; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
360 string moduleAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
361 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
362 moduleAlias = requireIdentifier(); |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
363 |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
364 // AliasName = ModuleName |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
365 if (token.type == T.Assign) |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
366 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
367 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
368 moduleName ~= requireIdentifier(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
369 } |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
370 else // import Identifier [^=] |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
371 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
372 moduleName ~= moduleAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
373 moduleAlias = null; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
374 } |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
375 |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
376 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
377 // parse Identifier(.Identifier)* |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
378 while (token.type == T.Dot) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
379 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
380 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
381 moduleName ~= requireIdentifier(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
382 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
383 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
384 // Push identifiers. |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
385 moduleNames ~= moduleName; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
386 moduleAliases ~= moduleAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
387 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
388 // parse : BindAlias = BindName(, BindAlias = BindName)*; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
389 // : BindName(, BindName)*; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
390 if (token.type == T.Colon) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
391 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
392 string bindName, bindAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
393 do |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
394 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
395 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
396 bindAlias = requireIdentifier(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
397 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
398 if (token.type == T.Assign) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
399 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
400 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
401 bindName = requireIdentifier(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
402 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
403 else |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
404 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
405 bindName = bindAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
406 bindAlias = null; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
407 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
408 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
409 // Push identifiers. |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
410 bindNames ~= bindName; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
411 bindAliases ~= bindAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
412 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
413 } while (token.type == T.Comma) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
414 break; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
415 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
416 } while (token.type == T.Comma) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
417 require(T.Semicolon); |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
418 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
419 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
|
420 } |
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
|
421 |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
422 Declaration parseEnumDeclaration() |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
423 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
424 assert(token.type == T.Enum); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
425 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
426 string enumName; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
427 Type baseType; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
428 string[] members; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
429 Expression[] values; |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
430 bool hasBody; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
431 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
432 nT(); // Skip enum keyword. |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
433 enumName = requireIdentifier(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
434 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
435 if (token.type == T.Colon) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
436 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
437 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
438 baseType = parseBasicType(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
439 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
440 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
441 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
|
442 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
443 //if (ident.length == 0) |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
444 // TODO: issue error msg |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
445 nT(); |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
446 } |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
447 else if (token.type == T.LBrace) |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
448 { |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
449 hasBody = true; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
450 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
451 do |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
452 { |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
453 members ~= requireIdentifier(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
454 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
455 if (token.type == T.Assign) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
456 { |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
457 nT(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
458 values ~= parseAssignExpression(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
459 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
460 else |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
461 values ~= null; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
462 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
463 if (token.type == T.Comma) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
464 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
465 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
|
466 { |
124 | 467 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
|
468 break; |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
469 } |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
470 } while (token.type != T.RBrace) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
471 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
472 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
473 |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
474 return new EnumDeclaration(enumName, baseType, members, values, hasBody); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
475 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
476 |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
477 Declaration parseClassDeclaration() |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
478 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
479 assert(token.type == T.Class); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
480 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
481 string className; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
482 BaseClass[] bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
483 Declaration[] decls; |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
484 bool hasBody; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
485 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
486 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
|
487 className = requireIdentifier(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
488 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
489 if (token.type == T.LParen) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
490 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
491 // TODO: parse template parameters |
140 | 492 // parseTemplateParameters(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
493 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
494 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
495 if (token.type == T.Colon) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
496 bases = parseBaseClasses(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
497 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
498 if (token.type == T.Semicolon) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
499 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
500 //if (bases.length != 0) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
501 // error: bases classes are not allowed in forward declarations. |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
502 nT(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
503 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
504 else if (token.type == T.LBrace) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
505 { |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
506 hasBody = true; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
507 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
508 // 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. |
110 | 509 decls = parseDeclarationDefinitions(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
510 require(T.RBrace); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
511 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
512 else |
124 | 513 expected(T.LBrace); // TODO: better error msg |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
514 |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
515 // TODO: error if decls.length == 0 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
516 |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
517 return new ClassDeclaration(className, bases, decls, hasBody); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
518 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
519 |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
520 BaseClass[] parseBaseClasses(bool colonLeadsOff = true) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
521 { |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
522 if (colonLeadsOff) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
523 { |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
524 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
|
525 nT(); // Skip colon |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
526 } |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
527 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
528 BaseClass[] bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
529 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
530 while (1) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
531 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
532 Protection prot = Protection.Public; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
533 switch (token.type) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
534 { |
158
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
535 // TODO: What about class Foo : typeof(new Bar)? |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
536 case T.Identifier, T.Dot/+, Typeof+/: goto LparseBasicType; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
537 case T.Private: prot = Protection.Private; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
538 case T.Protected: prot = Protection.Protected; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
539 case T.Package: prot = Protection.Package; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
540 case T.Public: /*prot = Protection.Public;*/ break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
541 default: |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
542 // TODO: issue error msg |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
543 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
544 } |
158
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
545 nT(); // Skip protection attribute. |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
546 LparseBasicType: |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
547 auto type = parseBasicType(); |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
548 //if (type.tid != TID.DotList) |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
549 // 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
|
550 bases ~= new BaseClass(prot, type); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
551 if (token.type != T.Comma) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
552 break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
553 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
554 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
555 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
556 |
112 | 557 Declaration parseInterfaceDeclaration() |
558 { | |
559 assert(token.type == T.Interface); | |
560 | |
561 string name; | |
562 BaseClass[] bases; | |
563 Declaration[] decls; | |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
564 bool hasBody; |
112 | 565 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
566 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
|
567 name = requireIdentifier(); |
112 | 568 |
569 if (token.type == T.LParen) | |
570 { | |
571 // TODO: parse template parameters | |
572 } | |
573 | |
574 if (token.type == T.Colon) | |
575 bases = parseBaseClasses(); | |
576 | |
577 if (token.type == T.Semicolon) | |
578 { | |
579 //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
|
580 // TODO: error: base classes are not allowed in forward declarations. |
112 | 581 nT(); |
582 } | |
583 else if (token.type == T.LBrace) | |
584 { | |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
585 hasBody = true; |
112 | 586 nT(); |
587 decls = parseDeclarationDefinitions(); | |
588 require(T.RBrace); | |
589 } | |
590 else | |
124 | 591 expected(T.LBrace); // TODO: better error msg |
112 | 592 |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
593 // TODO: error if decls.length == 0 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
594 |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
595 return new InterfaceDeclaration(name, bases, decls, hasBody); |
112 | 596 } |
597 | |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
598 Declaration parseAggregateDeclaration() |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
599 { |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
600 assert(token.type == T.Struct || token.type == T.Union); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
601 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
602 TOK tok = token.type; |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
603 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
604 string name; |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
605 Declaration[] decls; |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
606 bool hasBody; |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
607 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
608 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
|
609 // name is optional. |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
610 if (token.type == T.Identifier) |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
611 { |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
612 name = token.identifier; |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
613 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
614 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
|
615 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
616 // TODO: parse template parameters |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
617 } |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
618 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
619 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
620 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
|
621 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
622 //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
|
623 // TODO: error: forward declarations must have a name. |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
624 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
625 } |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
626 else if (token.type == T.LBrace) |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
627 { |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
628 hasBody = true; |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
629 nT(); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
630 decls = parseDeclarationDefinitions(); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
631 require(T.RBrace); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
632 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
633 else |
124 | 634 expected(T.LBrace); // TODO: better error msg |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
635 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
636 // TODO: error if decls.length == 0 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
637 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
638 if (tok == T.Struct) |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
639 return new StructDeclaration(name, decls, hasBody); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
640 else |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
641 return new UnionDeclaration(name, decls, hasBody); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
642 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
643 |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
644 Declaration parseConstructorDeclaration() |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
645 { |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
646 assert(token.type == T.This); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
647 nT(); // Skip 'this' keyword. |
143 | 648 auto parameters = parseParameterList(); |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
649 require(T.LBrace); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
650 auto statements = parseStatements(); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
651 require(T.RBrace); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
652 return new ConstructorDeclaration(parameters, statements); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
653 } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
654 |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
655 Declaration parseDestructorDeclaration() |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
656 { |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
657 assert(token.type == T.Tilde); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
658 nT(); // Skip ~ |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
659 require(T.This); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
660 require(T.LParen); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
661 require(T.RParen); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
662 require(T.LBrace); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
663 auto statements = parseStatements(); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
664 require(T.RBrace); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
665 return new DestructorDeclaration(statements); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
666 } |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
667 |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
668 Declaration parseStaticConstructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
669 { |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
670 assert(token.type == T.Static); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
671 nT(); // Skip static keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
672 nT(); // Skip 'this' keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
673 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
674 require(T.RParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
675 require(T.LBrace); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
676 auto statements = parseStatements(); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
677 require(T.RBrace); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
678 return new StaticConstructorDeclaration(statements); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
679 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
680 |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
681 Declaration parseStaticDestructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
682 { |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
683 assert(token.type == T.Static); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
684 nT(); // Skip static keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
685 nT(); // Skip ~ |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
686 require(T.This); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
687 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
688 require(T.RParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
689 require(T.LBrace); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
690 auto statements = parseStatements(); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
691 require(T.RBrace); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
692 return new StaticDestructorDeclaration(statements); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
693 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
694 |
120 | 695 Declaration parseInvariantDeclaration() |
696 { | |
697 assert(token.type == T.Invariant); | |
698 nT(); // Skip invariant keyword. | |
699 // Optional () for getting ready porting to D 2.0 | |
700 if (token.type == T.LParen) | |
122 | 701 requireNext(T.RParen); |
120 | 702 require(T.LBrace); |
703 auto statements = parseStatements(); | |
704 require(T.RBrace); | |
705 return new InvariantDeclaration(statements); | |
706 } | |
707 | |
121 | 708 Declaration parseUnittestDeclaration() |
709 { | |
710 assert(token.type == T.Unittest); | |
711 | |
122 | 712 nT(); // Skip unittest keyword. |
121 | 713 require(T.LBrace); |
714 auto statements = parseStatements(); | |
715 require(T.RBrace); | |
716 return new UnittestDeclaration(statements); | |
717 } | |
718 | |
122 | 719 Declaration parseDebugDeclaration() |
720 { | |
721 assert(token.type == T.Debug); | |
722 | |
723 nT(); // Skip debug keyword. | |
724 | |
725 int levelSpec = -1; // debug = Integer ; | |
726 string identSpec; // debug = Identifier ; | |
727 int levelCond = -1; // debug ( Integer ) | |
728 string identCond; // debug ( Identifier ) | |
729 Declaration[] decls, elseDecls; | |
730 | |
123 | 731 void parseIdentOrInt(ref string ident, ref int level) |
122 | 732 { |
733 nT(); | |
734 if (token.type == T.Int32) | |
123 | 735 level = token.int_; |
122 | 736 else if (token.type == T.Identifier) |
123 | 737 ident = token.identifier; |
122 | 738 else |
124 | 739 expected(T.Identifier); // TODO: better error msg |
122 | 740 nT(); |
123 | 741 } |
742 | |
743 if (token.type == T.Assign) | |
744 { | |
745 parseIdentOrInt(identSpec, levelSpec); | |
122 | 746 require(T.Semicolon); |
747 } | |
748 else | |
749 { | |
123 | 750 // Condition: |
751 // Integer | |
752 // Identifier | |
753 // ( Condition ) | |
122 | 754 if (token.type == T.LParen) |
755 { | |
123 | 756 parseIdentOrInt(identCond, levelCond); |
122 | 757 require(T.RParen); |
758 } | |
759 | |
123 | 760 // debug DeclarationsBlock |
761 // debug ( Condition ) DeclarationsBlock | |
762 decls = parseDeclarationsBlock(); | |
763 | |
764 // else DeclarationsBlock | |
765 // debug without condition and else statement makes no sense | |
766 if (token.type == T.Else && (levelCond != -1 || identCond.length != 0)) | |
122 | 767 { |
123 | 768 nT(); |
769 //if (token.type == T.Colon) | |
770 // TODO: avoid "else:"? | |
771 elseDecls = parseDeclarationsBlock(); | |
772 } | |
773 // else | |
774 // TODO: issue error msg | |
775 } | |
776 | |
777 return new DebugDeclaration(levelSpec, identSpec, levelCond, identCond, decls, elseDecls); | |
778 } | |
779 | |
780 Declaration parseVersionDeclaration() | |
781 { | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
782 assert(token.type == T.Version); |
123 | 783 |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
784 nT(); // Skip version keyword. |
123 | 785 |
786 int levelSpec = -1; // version = Integer ; | |
787 string identSpec; // version = Identifier ; | |
788 int levelCond = -1; // version ( Integer ) | |
789 string identCond; // version ( Identifier ) | |
790 Declaration[] decls, elseDecls; | |
122 | 791 |
123 | 792 void parseIdentOrInt(ref string ident, ref int level) |
793 { | |
794 nT(); | |
795 if (token.type == T.Int32) | |
796 level = token.int_; | |
797 else if (token.type == T.Identifier) | |
798 ident = token.identifier; | |
799 else | |
124 | 800 expected(T.Identifier); // TODO: better error msg |
123 | 801 nT(); |
802 } | |
803 | |
804 if (token.type == T.Assign) | |
805 { | |
806 parseIdentOrInt(identSpec, levelSpec); | |
807 require(T.Semicolon); | |
808 } | |
809 else | |
810 { | |
811 // Condition: | |
812 // Integer | |
813 // Identifier | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
814 |
123 | 815 // ( Condition ) |
816 require(T.LParen); | |
817 parseIdentOrInt(identCond, levelCond); | |
818 require(T.RParen); | |
819 | |
820 // version ( Condition ) DeclarationsBlock | |
821 decls = parseDeclarationsBlock(); | |
822 | |
823 // else DeclarationsBlock | |
824 if (token.type == T.Else) | |
825 { | |
826 nT(); | |
827 //if (token.type == T.Colon) | |
828 // TODO: avoid "else:"? | |
829 elseDecls = parseDeclarationsBlock(); | |
122 | 830 } |
831 } | |
832 | |
123 | 833 return new VersionDeclaration(levelSpec, identSpec, levelCond, identCond, decls, elseDecls); |
122 | 834 } |
835 | |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
836 Declaration parseStaticIfDeclaration() |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
837 { |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
838 assert(token.type == T.Static); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
839 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
840 nT(); // Skip static keyword. |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
841 nT(); // Skip if keyword. |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
842 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
843 Expression condition; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
844 Declaration[] ifDecls, elseDecls; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
845 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
846 require(T.LParen); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
847 condition = parseAssignExpression(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
848 require(T.RParen); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
849 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
850 if (token.type != T.Colon) |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
851 ifDecls = parseDeclarationsBlock(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
852 else |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
853 expected(T.LBrace); // TODO: better error msg |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
854 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
855 if (token.type == T.Else) |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
856 { |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
857 nT(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
858 if (token.type != T.Colon) |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
859 elseDecls = parseDeclarationsBlock(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
860 else |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
861 expected(T.LBrace); // TODO: better error msg |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
862 } |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
863 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
864 return new StaticIfDeclaration(condition, ifDecls, elseDecls); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
865 } |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
866 |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
867 Declaration parseStaticAssertDeclaration() |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
868 { |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
869 assert(token.type == T.Static); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
870 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
871 nT(); // Skip static keyword. |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
872 nT(); // Skip assert keyword. |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
873 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
874 Expression condition, message; |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
875 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
876 require(T.LParen); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
877 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
878 condition = parseAssignExpression(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
879 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
880 if (token.type == T.Comma) |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
881 { |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
882 nT(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
883 message = parseAssignExpression(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
884 } |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
885 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
886 require(T.RParen); |
128 | 887 require(T.Semicolon); |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
888 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
889 return new StaticAssertDeclaration(condition, message); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
890 } |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
891 |
140 | 892 Declaration parseTemplateDeclaration() |
893 { | |
894 assert(token.type == T.Template); | |
895 nT(); // Skip template keyword. | |
896 auto templateName = requireIdentifier(); | |
143 | 897 auto templateParams = parseTemplateParameterList(); |
140 | 898 require(T.LBrace); |
899 auto decls = parseDeclarationDefinitions(); | |
900 require(T.RBrace); | |
901 return new TemplateDeclaration(templateName, templateParams, decls); | |
902 } | |
903 | |
141 | 904 Declaration parseNewDeclaration() |
905 { | |
906 assert(token.type == T.New); | |
907 nT(); // Skip new keyword. | |
143 | 908 auto parameters = parseParameterList(); |
141 | 909 require(T.LBrace); |
910 auto decls = parseDeclarationDefinitions(); | |
911 require(T.RBrace); | |
912 return new NewDeclaration(parameters, decls); | |
913 } | |
914 | |
915 Declaration parseDeleteDeclaration() | |
916 { | |
917 assert(token.type == T.Delete); | |
918 nT(); // Skip delete keyword. | |
143 | 919 auto parameters = parseParameterList(); |
141 | 920 // TODO: only one parameter of type void* allowed. |
921 require(T.LBrace); | |
922 auto decls = parseDeclarationDefinitions(); | |
923 require(T.RBrace); | |
924 return new DeleteDeclaration(parameters, decls); | |
925 } | |
926 | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
927 /+ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
928 DotListExpression: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
929 . DotListItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
930 DotListItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
931 Typeof |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
932 Typeof . DotListItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
933 DotListItems: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
934 DotListItem |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
935 DotListItem . DotListItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
936 DotListItem: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
937 Identifier |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
938 TemplateInstance |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
939 NewExpression |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
940 TemplateInstance: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
941 Identifier !( TemplateArgumentList ) |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
942 +/ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
943 DotListExpression parseDotListExpression() |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
944 { |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
945 Expression[] identList; |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
946 if (token.type == T.Dot) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
947 { |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
948 nT(); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
949 identList ~= new IdentifierExpression("."); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
950 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
951 else if (token.type == T.Typeof) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
952 { |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
953 requireNext(T.LParen); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
954 auto type = new TypeofType(parseExpression()); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
955 require(T.RParen); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
956 identList ~= new TypeofExpression(type); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
957 if (token.type != T.Dot) |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
958 goto Lreturn; |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
959 nT(); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
960 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
961 |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
962 while (1) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
963 { |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
964 string ident = requireIdentifier(); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
965 Token next; |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
966 lx.peek(next); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
967 if (token.type == T.Not && next.type == T.LParen) // Identifier !( TemplateArguments ) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
968 { |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
969 nT(); // Skip !. |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
970 identList ~= new TemplateInstanceExpression(ident, parseTemplateArguments()); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
971 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
972 else // Identifier |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
973 identList ~= new IdentifierExpression(ident); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
974 |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
975 LnewExpressionLoop: |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
976 if (token.type != T.Dot) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
977 break; |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
978 nT(); // Skip dot. |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
979 |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
980 if (token.type == T.New) |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
981 { |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
982 identList ~= parseNewExpression(); |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
983 goto LnewExpressionLoop; |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
984 } |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
985 } |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
986 Lreturn: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
987 return new DotListExpression(identList); |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
988 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
989 |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
990 /+ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
991 DotListType: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
992 . TypeItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
993 TypeItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
994 Typeof |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
995 Typeof . TypeItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
996 TypeItems: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
997 TypeItem |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
998 TypeItem . TypeItems |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
999 TypeItem: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1000 Identifier |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1001 TemplateInstance |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1002 TemplateInstance: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1003 Identifier !( TemplateArgumentList ) |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1004 +/ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1005 DotListType parseDotListType() |
153 | 1006 { |
1007 Type[] identList; | |
1008 if (token.type == T.Dot) | |
1009 { | |
1010 nT(); | |
1011 identList ~= new IdentifierType("."); | |
1012 } | |
1013 else if (token.type == T.Typeof) | |
1014 { | |
1015 requireNext(T.LParen); | |
1016 identList ~= new TypeofType(parseExpression()); | |
1017 require(T.RParen); | |
1018 if (token.type != T.Dot) | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1019 goto Lreturn; |
153 | 1020 nT(); |
1021 } | |
1022 | |
1023 while (1) | |
1024 { | |
1025 string ident = requireIdentifier(); | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1026 // 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
|
1027 /+Token next; |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1028 lx.peek(next);+/ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1029 if (token.type == T.Not/+ && next.type == T.LParen+/) // Identifier !( TemplateArguments ) |
153 | 1030 { |
1031 nT(); // Skip !. | |
1032 identList ~= new TemplateInstanceType(ident, parseTemplateArguments()); | |
1033 } | |
1034 else // Identifier | |
1035 identList ~= new IdentifierType(ident); | |
1036 | |
1037 if (token.type != T.Dot) | |
1038 break; | |
1039 nT(); | |
1040 } | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1041 Lreturn: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1042 return new DotListType(identList); |
153 | 1043 } |
1044 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1045 /* |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1046 TemplateMixin: |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1047 mixin ( AssignExpression ) ; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1048 mixin TemplateIdentifier ; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1049 mixin TemplateIdentifier MixinIdentifier ; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1050 mixin TemplateIdentifier !( TemplateArgumentList ) ; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1051 mixin TemplateIdentifier !( TemplateArgumentList ) MixinIdentifier ; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1052 */ |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1053 Declaration parseMixinDeclaration() |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1054 { |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1055 assert(token.type == T.Mixin); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1056 nT(); // Skip mixin keyword. |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1057 |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1058 if (token.type == T.LParen) |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1059 { |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1060 // TODO: What about mixin(...).ident;? |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1061 nT(); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1062 auto e = parseAssignExpression(); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1063 require(T.RParen); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1064 require(T.Semicolon); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1065 return new MixinDeclaration(e); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1066 } |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1067 |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1068 Expression[] templateIdent; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1069 string mixinIdent; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1070 |
159 | 1071 // This code is similar to parseDotListType(). |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1072 if (token.type == T.Dot) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1073 { |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1074 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1075 templateIdent ~= new IdentifierExpression("."); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1076 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1077 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1078 while (1) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1079 { |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1080 string ident = requireIdentifier(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1081 if (token.type == T.Not) // Identifier !( TemplateArguments ) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1082 { |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1083 // 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
|
1084 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1085 templateIdent ~= new TemplateInstanceExpression(ident, parseTemplateArguments()); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1086 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1087 else // Identifier |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1088 templateIdent ~= new IdentifierExpression(ident); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1089 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1090 if (token.type != T.Dot) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1091 break; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1092 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1093 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1094 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1095 if (token.type == T.Identifier) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1096 { |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1097 mixinIdent = token.identifier; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1098 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1099 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1100 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1101 require(T.Semicolon); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1102 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1103 return new MixinDeclaration(templateIdent, mixinIdent); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1104 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1105 |
102 | 1106 /+++++++++++++++++++++++++++++ |
161 | 1107 + Statement parsing methods + |
1108 +++++++++++++++++++++++++++++/ | |
1109 | |
1110 Statements parseStatements() | |
1111 { | |
162 | 1112 auto statements = new Statements(); |
161 | 1113 while (token.type != T.RBrace && token.type != T.EOF) |
1114 statements ~= parseStatement(); | |
1115 return statements; | |
1116 } | |
1117 | |
1118 Statement parseStatement() | |
1119 { | |
1120 Statement s; | |
1121 switch (token.type) | |
1122 { | |
1123 case T.Identifier: | |
1124 Token next; | |
1125 lx.peek(next); | |
1126 if (next.type == T.Colon) | |
1127 { | |
1128 string ident = token.identifier; | |
1129 nT(); // Skip Identifier | |
1130 nT(); // Skip : | |
1131 s = parseStatements(); | |
1132 s = new LabeledStatement(ident, s); | |
1133 break; | |
1134 } | |
1135 goto case_Declaration; | |
1136 case_Declaration: | |
1137 // TODO: parse Declaration | |
1138 break; | |
162 | 1139 case T.If: |
1140 s = parseIfStatement(); | |
1141 break; | |
164 | 1142 case T.While: |
1143 s = parseWhileStatement(); | |
1144 break; | |
165 | 1145 case T.Do: |
1146 s = parseDoWhileStatement(); | |
1147 break; | |
169 | 1148 case T.Foreach, T.Foreach_reverse: |
1149 s = parseForeachStatement(); | |
1150 break; | |
170 | 1151 case T.Switch: |
1152 s = parseSwitchStatement(); | |
1153 break; | |
171 | 1154 case T.Case: |
1155 s = parseCaseStatement(); | |
1156 break; | |
172 | 1157 case T.Default: |
1158 s = parseDefaultStatement(); | |
1159 break; | |
173 | 1160 case T.Continue: |
1161 s = parseContinueStatement(); | |
1162 break; | |
174 | 1163 case T.Break: |
1164 s = parseBreakStatement(); | |
1165 break; | |
175 | 1166 case T.Return: |
1167 s = parseReturnStatement(); | |
1168 break; | |
176 | 1169 case T.Goto: |
1170 s = parseGotoStatement(); | |
1171 break; | |
177 | 1172 case T.With: |
1173 s = parseWithStatement(); | |
1174 break; | |
178 | 1175 case T.Synchronized: |
1176 s = parseSynchronizedStatement(); | |
1177 break; | |
179 | 1178 case T.Try: |
1179 s = parseTryStatement(); | |
1180 break; | |
180 | 1181 case T.Throw: |
1182 s = parseThrowStatement(); | |
1183 break; | |
181 | 1184 case T.Scope: |
1185 Token next; | |
1186 lx.peek(next); | |
1187 if (next.type != T.LParen) | |
1188 goto case_Declaration; | |
1189 s = parseScopeGuardStatement(); | |
1190 break; | |
161 | 1191 default: |
164 | 1192 // TODO: issue error msg and return IllegalStatement. |
161 | 1193 } |
1194 return s; | |
1195 } | |
1196 | |
162 | 1197 /+ |
1198 ScopeStatement: | |
1199 NonEmptyStatement | |
1200 BlockStatement | |
1201 BlockStatement: | |
1202 { } | |
1203 { StatementList } | |
1204 +/ | |
164 | 1205 Statement parseScopeStatement() |
162 | 1206 { |
1207 Statement s; | |
1208 if (token.type == T.LBrace) | |
1209 { | |
1210 nT(); | |
1211 auto ss = new Statements(); | |
1212 while (token.type != T.RBrace && token.type != T.EOF) | |
1213 ss ~= parseStatement(); | |
1214 require(T.RBrace); | |
1215 s = ss; | |
1216 } | |
1217 else | |
1218 s = parseStatement(); | |
1219 return new ScopeStatement(s); | |
1220 } | |
1221 | |
166 | 1222 /+ |
1223 NoScopeStatement: | |
1224 NonEmptyStatement | |
1225 BlockStatement | |
1226 BlockStatement: | |
1227 { } | |
1228 { StatementList } | |
1229 +/ | |
1230 Statement parseNoScopeStatement() | |
1231 { | |
1232 Statement s; | |
1233 if (token.type == T.LBrace) | |
1234 { | |
1235 nT(); | |
1236 auto ss = new Statements(); | |
1237 while (token.type != T.RBrace && token.type != T.EOF) | |
1238 ss ~= parseStatement(); | |
1239 require(T.RBrace); | |
1240 s = ss; | |
1241 } | |
1242 else | |
1243 s = parseStatement(); | |
1244 return s; | |
1245 } | |
1246 | |
162 | 1247 Statement parseIfStatement() |
1248 { | |
1249 assert(token.type == T.If); | |
1250 nT(); | |
1251 | |
1252 Type type; | |
1253 string ident; | |
1254 Expression condition; | |
1255 Statement ifBody, elseBody; | |
1256 | |
1257 require(T.LParen); | |
1258 // auto Identifier = Expression | |
1259 if (token.type == T.Auto) | |
1260 { | |
1261 nT(); | |
1262 ident = requireIdentifier(); | |
1263 require(T.Assign); | |
1264 } | |
1265 else | |
1266 { | |
1267 // Declarator = Expression | |
1268 bool failed; | |
1269 type = try_(parseDeclarator(ident), failed); | |
1270 if (!failed) | |
1271 { | |
1272 require(T.Assign); | |
1273 } | |
163
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1274 else |
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1275 { |
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1276 type = null; |
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1277 ident = null; |
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1278 } |
162 | 1279 } |
1280 condition = parseExpression(); | |
1281 require(T.RParen); | |
164 | 1282 ifBody = parseScopeStatement(); |
162 | 1283 if (token.type == T.Else) |
1284 { | |
1285 nT(); | |
164 | 1286 elseBody = parseScopeStatement(); |
162 | 1287 } |
1288 return new IfStatement(type, ident, condition, ifBody, elseBody); | |
1289 } | |
1290 | |
164 | 1291 Statement parseWhileStatement() |
1292 { | |
1293 assert(token.type == T.While); | |
1294 nT(); | |
166 | 1295 require(T.LParen); |
164 | 1296 auto condition = parseExpression(); |
166 | 1297 require(T.RParen); |
164 | 1298 return new WhileStatement(condition, parseScopeStatement()); |
1299 } | |
1300 | |
165 | 1301 Statement parseDoWhileStatement() |
1302 { | |
1303 assert(token.type == T.Do); | |
1304 nT(); | |
1305 auto doBody = parseScopeStatement(); | |
1306 require(T.While); | |
166 | 1307 require(T.LParen); |
165 | 1308 auto condition = parseExpression(); |
166 | 1309 require(T.RParen); |
1310 return new DoWhileStatement(condition, doBody); | |
1311 } | |
1312 | |
1313 Statement parseForStatement() | |
1314 { | |
1315 assert(token.type == T.For); | |
1316 nT(); | |
165 | 1317 require(T.LParen); |
166 | 1318 |
1319 Statement init, forBody; | |
1320 Expression condition, increment; | |
1321 | |
1322 if (token.type != T.Semicolon) | |
1323 init = parseNoScopeStatement(); | |
168 | 1324 require(T.Semicolon); |
166 | 1325 if (token.type != T.Semicolon) |
1326 condition = parseExpression(); | |
168 | 1327 require(T.Semicolon); |
166 | 1328 if (token.type != T.RParen) |
1329 increment = parseExpression(); | |
168 | 1330 require(T.RParen); |
167 | 1331 forBody = parseScopeStatement(); |
166 | 1332 return new ForStatement(init, condition, increment, forBody); |
165 | 1333 } |
1334 | |
169 | 1335 Statement parseForeachStatement() |
1336 { | |
1337 assert(token.type == T.Foreach || token.type == T.Foreach_reverse); | |
1338 TOK tok = token.type; | |
1339 nT(); | |
1340 | |
1341 Parameters params; | |
1342 Expression aggregate; | |
1343 | |
1344 require(T.LParen); | |
1345 while (1) | |
1346 { | |
1347 StorageClass stc; | |
1348 Type type; | |
1349 string ident; | |
1350 | |
1351 switch (token.type) | |
1352 { | |
1353 case T.Ref: | |
1354 nT(); | |
1355 stc = StorageClass.Ref; | |
1356 break; | |
1357 case T.Identifier: | |
1358 Token next; | |
1359 lx.peek(next); | |
1360 if (next.type == T.Comma || next.type == T.Semicolon || next.type == T.RParen) | |
1361 { | |
1362 ident = token.identifier; | |
1363 nT(); | |
1364 break; | |
1365 } | |
1366 // fall through | |
1367 default: | |
1368 type = parseDeclarator(ident); | |
1369 } | |
1370 | |
1371 params ~= new Parameter(stc, type, ident, null); | |
1372 | |
1373 if (token.type != T.Comma) | |
1374 break; | |
1375 nT(); | |
1376 } | |
1377 require(T.Semicolon); | |
1378 aggregate = parseExpression(); | |
1379 require(T.RParen); | |
1380 auto forBody = parseScopeStatement(); | |
1381 return new ForeachStatement(tok, params, aggregate, forBody); | |
1382 } | |
1383 | |
170 | 1384 Statement parseSwitchStatement() |
1385 { | |
1386 assert(token.type == T.Switch); | |
1387 nT(); | |
1388 | |
1389 require(T.LParen); | |
1390 auto condition = parseExpression(); | |
1391 require(T.RParen); | |
1392 auto switchBody = parseScopeStatement(); | |
1393 return new SwitchStatement(condition, switchBody); | |
1394 } | |
1395 | |
171 | 1396 Statement parseCaseStatement() |
1397 { | |
1398 assert(token.type == T.Case); | |
1399 // T.Case skipped in do-while. | |
1400 Expression[] values; | |
1401 do | |
1402 { | |
1403 nT(); | |
1404 values ~= parseAssignExpression(); | |
1405 } while (token.type == T.Comma) | |
1406 require(T.Colon); | |
1407 | |
1408 auto caseBody = parseScopeStatement(); | |
1409 return new CaseStatement(values, caseBody); | |
1410 } | |
1411 | |
172 | 1412 Statement parseDefaultStatement() |
1413 { | |
1414 assert(token.type == T.Default); | |
1415 nT(); | |
1416 require(T.Colon); | |
1417 return new DefaultStatement(parseScopeStatement()); | |
1418 } | |
1419 | |
173 | 1420 Statement parseContinueStatement() |
1421 { | |
1422 assert(token.type == T.Continue); | |
1423 nT(); | |
1424 string ident; | |
1425 if (token.type == T.Identifier) | |
1426 { | |
1427 ident = token.identifier; | |
1428 nT(); | |
1429 } | |
1430 require(T.Semicolon); | |
1431 return new ContinueStatement(ident); | |
1432 } | |
1433 | |
174 | 1434 Statement parseBreakStatement() |
1435 { | |
1436 assert(token.type == T.Break); | |
1437 nT(); | |
1438 string ident; | |
1439 if (token.type == T.Identifier) | |
1440 { | |
1441 ident = token.identifier; | |
1442 nT(); | |
1443 } | |
1444 require(T.Semicolon); | |
1445 return new BreakStatement(ident); | |
1446 } | |
1447 | |
175 | 1448 Statement parseReturnStatement() |
1449 { | |
1450 assert(token.type == T.Return); | |
1451 nT(); | |
1452 auto expr = parseExpression(); | |
1453 require(T.Semicolon); | |
1454 return new ReturnStatement(expr); | |
1455 } | |
1456 | |
176 | 1457 Statement parseGotoStatement() |
1458 { | |
1459 assert(token.type == T.Goto); | |
1460 nT(); | |
1461 string ident; | |
1462 Expression caseExpr; | |
1463 switch (token.type) | |
1464 { | |
1465 case T.Case: | |
1466 nT(); | |
1467 if (token.type == T.Semicolon) | |
1468 break; | |
1469 caseExpr = parseExpression(); | |
1470 break; | |
1471 case T.Default: | |
1472 nT(); | |
1473 break; | |
1474 default: | |
1475 ident = requireIdentifier(); | |
1476 nT(); | |
1477 } | |
1478 require(T.Semicolon); | |
1479 return new GotoStatement(ident, caseExpr); | |
1480 } | |
1481 | |
177 | 1482 Statement parseWithStatement() |
1483 { | |
1484 assert(token.type == T.With); | |
1485 nT(); | |
1486 require(T.LParen); | |
1487 auto expr = parseExpression(); | |
1488 require(T.RParen); | |
1489 return new WithStatement(expr, parseScopeStatement()); | |
1490 } | |
1491 | |
178 | 1492 Statement parseSynchronizedStatement() |
1493 { | |
1494 assert(token.type == T.Synchronized); | |
1495 nT(); | |
1496 Expression expr; | |
1497 | |
1498 if (token.type == T.LParen) | |
1499 { | |
1500 nT(); | |
1501 expr = parseExpression(); | |
1502 require(T.RParen); | |
1503 } | |
1504 return new SynchronizedStatement(expr, parseScopeStatement()); | |
1505 } | |
1506 | |
179 | 1507 Statement parseTryStatement() |
1508 { | |
1509 assert(token.type == T.Try); | |
1510 nT(); | |
1511 | |
1512 auto tryBody = parseScopeStatement(); | |
1513 CatchBody[] catchBodies; | |
1514 FinallyBody finBody; | |
1515 | |
1516 while (token.type == T.Catch) | |
1517 { | |
1518 nT(); | |
1519 Parameter param; | |
1520 if (token.type == T.LParen) | |
1521 { | |
1522 string ident; | |
1523 auto type = parseDeclarator(ident); | |
1524 param = new Parameter(StorageClass.None, type, ident, null); | |
1525 require(T.RParen); | |
1526 } | |
1527 catchBodies ~= new CatchBody(param, parseNoScopeStatement()); | |
1528 if (param is null) | |
1529 break; // This is a LastCatch | |
1530 } | |
1531 | |
1532 if (token.type == T.Finally) | |
1533 { | |
1534 nT(); | |
1535 finBody = new FinallyBody(parseNoScopeStatement()); | |
1536 } | |
1537 | |
1538 if (catchBodies.length == 0 || finBody is null) | |
1539 { | |
1540 // TODO: issue error msg. | |
1541 } | |
1542 | |
1543 return new TryStatement(tryBody, catchBodies, finBody); | |
1544 } | |
1545 | |
180 | 1546 Statement parseThrowStatement() |
1547 { | |
1548 assert(token.type == T.Throw); | |
1549 nT(); | |
1550 auto expr = parseExpression(); | |
1551 require(T.Semicolon); | |
1552 return new ThrowStatement(expr); | |
1553 } | |
1554 | |
181 | 1555 Statement parseScopeGuardStatement() |
1556 { | |
1557 assert(token.type == T.Scope); | |
1558 nT(); | |
1559 assert(token.type == T.LParen); | |
1560 nT(); | |
1561 | |
1562 string condition = requireIdentifier(); | |
1563 if (condition.length) | |
1564 switch (condition) | |
1565 { | |
1566 case "exit": | |
1567 case "success": | |
1568 case "failure": | |
1569 break; | |
1570 default: | |
1571 // TODO: issue error msg. | |
1572 } | |
1573 require(T.RParen); | |
1574 Statement scopeBody; | |
1575 if (token.type == T.LBrace) | |
1576 scopeBody = parseScopeStatement(); | |
1577 else | |
1578 scopeBody = parseNoScopeStatement(); | |
1579 return new ScopeGuardStatement(condition, scopeBody); | |
1580 } | |
1581 | |
161 | 1582 /+++++++++++++++++++++++++++++ |
102 | 1583 + Expression parsing methods + |
1584 +++++++++++++++++++++++++++++/ | |
1585 | |
72 | 1586 Expression parseExpression() |
1587 { | |
1588 auto e = parseAssignExpression(); | |
122 | 1589 while (token.type == T.Comma) |
81 | 1590 e = new CommaExpression(e, parseAssignExpression()); |
72 | 1591 return e; |
1592 } | |
1593 | |
71 | 1594 Expression parseAssignExpression() |
1595 { | |
1596 auto e = parseCondExpression(); | |
72 | 1597 while (1) |
71 | 1598 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1599 switch (token.type) |
72 | 1600 { |
1601 case T.Assign: | |
1602 nT(); e = new AssignExpression(e, parseAssignExpression()); | |
1603 break; | |
1604 case T.LShiftAssign: | |
1605 nT(); e = new LShiftAssignExpression(e, parseAssignExpression()); | |
1606 break; | |
1607 case T.RShiftAssign: | |
1608 nT(); e = new RShiftAssignExpression(e, parseAssignExpression()); | |
1609 break; | |
1610 case T.URShiftAssign: | |
1611 nT(); e = new URShiftAssignExpression(e, parseAssignExpression()); | |
1612 break; | |
1613 case T.OrAssign: | |
1614 nT(); e = new OrAssignExpression(e, parseAssignExpression()); | |
1615 break; | |
1616 case T.AndAssign: | |
1617 nT(); e = new AndAssignExpression(e, parseAssignExpression()); | |
1618 break; | |
1619 case T.PlusAssign: | |
1620 nT(); e = new PlusAssignExpression(e, parseAssignExpression()); | |
1621 break; | |
1622 case T.MinusAssign: | |
1623 nT(); e = new MinusAssignExpression(e, parseAssignExpression()); | |
1624 break; | |
1625 case T.DivAssign: | |
1626 nT(); e = new DivAssignExpression(e, parseAssignExpression()); | |
1627 break; | |
1628 case T.MulAssign: | |
1629 nT(); e = new MulAssignExpression(e, parseAssignExpression()); | |
1630 break; | |
1631 case T.ModAssign: | |
1632 nT(); e = new ModAssignExpression(e, parseAssignExpression()); | |
1633 break; | |
1634 case T.XorAssign: | |
1635 nT(); e = new XorAssignExpression(e, parseAssignExpression()); | |
1636 break; | |
1637 case T.CatAssign: | |
1638 nT(); e = new CatAssignExpression(e, parseAssignExpression()); | |
1639 break; | |
1640 default: | |
1641 break; | |
1642 } | |
71 | 1643 break; |
1644 } | |
1645 return e; | |
1646 } | |
72 | 1647 |
71 | 1648 Expression parseCondExpression() |
1649 { | |
72 | 1650 auto e = parseOrOrExpression(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1651 if (token.type == T.Question) |
72 | 1652 { |
1653 nT(); | |
1654 auto iftrue = parseExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1655 require(T.Colon); |
72 | 1656 auto iffalse = parseCondExpression(); |
1657 e = new CondExpression(e, iftrue, iffalse); | |
1658 } | |
1659 return e; | |
1660 } | |
1661 | |
1662 Expression parseOrOrExpression() | |
1663 { | |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1664 alias parseAndAndExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1665 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1666 if (token.type == T.OrLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1667 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1668 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1669 e = new OrOrExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1670 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1671 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1672 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1673 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1674 Expression parseAndAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1675 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1676 alias parseOrExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1677 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1678 if (token.type == T.AndLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1679 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1680 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1681 e = new AndAndExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1682 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1683 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1684 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1685 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1686 Expression parseOrExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1687 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1688 alias parseXorExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1689 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1690 if (token.type == T.OrBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1691 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1692 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1693 e = new OrExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1694 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1695 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1696 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1697 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1698 Expression parseXorExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1699 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1700 alias parseAndExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1701 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1702 if (token.type == T.Xor) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1703 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1704 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1705 e = new XorExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1706 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1707 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1708 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1709 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1710 Expression parseAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1711 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1712 alias parseCmpExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1713 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1714 if (token.type == T.AndBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1715 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1716 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1717 e = new AndExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1718 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1719 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1720 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1721 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1722 Expression parseCmpExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1723 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1724 TOK operator = token.type; |
74 | 1725 |
1726 auto e = parseShiftExpression(); | |
1727 | |
1728 switch (operator) | |
1729 { | |
1730 case T.Equal, T.NotEqual: | |
1731 nT(); | |
1732 e = new EqualExpression(e, parseShiftExpression(), operator); | |
1733 break; | |
1734 case T.Not: | |
1735 Token t; | |
1736 lx.peek(t); | |
1737 if (t.type != T.Is) | |
1738 break; | |
1739 nT(); | |
1740 operator = T.NotIdentity; | |
1741 goto LNotIdentity; | |
1742 case T.Identity: | |
1743 operator = T.Identity; | |
1744 LNotIdentity: | |
1745 nT(); | |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1746 e = new IdentityExpression(e, parseShiftExpression(), operator); |
74 | 1747 break; |
1748 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater, | |
1749 T.Unordered, T.UorE, T.UorG, T.UorGorE, | |
1750 T.UorL, T.UorLorE, T.LorEorG, T.LorG: | |
1751 nT(); | |
1752 e = new RelExpression(e, parseShiftExpression(), operator); | |
1753 break; | |
1754 case T.In: | |
1755 nT(); | |
1756 e = new InExpression(e, parseShiftExpression(), operator); | |
1757 break; | |
1758 default: | |
1759 } | |
1760 return e; | |
1761 } | |
1762 | |
1763 Expression parseShiftExpression() | |
1764 { | |
75 | 1765 auto e = parseAddExpression(); |
1766 while (1) | |
1767 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1768 switch (token.type) |
75 | 1769 { |
1770 case T.LShift: nT(); e = new LShiftExpression(e, parseAddExpression()); break; | |
1771 case T.RShift: nT(); e = new RShiftExpression(e, parseAddExpression()); break; | |
1772 case T.URShift: nT(); e = new URShiftExpression(e, parseAddExpression()); break; | |
1773 default: break; | |
1774 } | |
1775 break; | |
1776 } | |
1777 return e; | |
1778 } | |
1779 | |
1780 Expression parseAddExpression() | |
1781 { | |
76 | 1782 auto e = parseMulExpression(); |
1783 while (1) | |
1784 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1785 switch (token.type) |
76 | 1786 { |
1787 case T.Plus: nT(); e = new PlusExpression(e, parseMulExpression()); break; | |
1788 case T.Minus: nT(); e = new MinusExpression(e, parseMulExpression()); break; | |
1789 case T.Tilde: nT(); e = new CatExpression(e, parseMulExpression()); break; | |
1790 default: break; | |
1791 } | |
1792 break; | |
1793 } | |
1794 return new Expression(); | |
1795 } | |
1796 | |
1797 Expression parseMulExpression() | |
1798 { | |
77 | 1799 auto e = parseUnaryExpression(); |
1800 while (1) | |
1801 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1802 switch (token.type) |
77 | 1803 { |
1804 case T.Mul: nT(); e = new MulExpression(e, parseUnaryExpression()); break; | |
1805 case T.Div: nT(); e = new DivExpression(e, parseUnaryExpression()); break; | |
1806 case T.Mod: nT(); e = new ModExpression(e, parseUnaryExpression()); break; | |
1807 default: break; | |
1808 } | |
1809 break; | |
1810 } | |
74 | 1811 return new Expression(); |
71 | 1812 } |
1813 | |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1814 Expression parseUnaryExpression() |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1815 { |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1816 Expression e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1817 switch (token.type) |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1818 { |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1819 case T.AndBinary: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1820 nT(); e = new AddressExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1821 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1822 case T.PlusPlus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1823 nT(); e = new PreIncrExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1824 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1825 case T.MinusMinus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1826 nT(); e = new PreDecrExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1827 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1828 case T.Mul: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1829 nT(); e = new DerefExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1830 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1831 case T.Minus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1832 case T.Plus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1833 nT(); e = new SignExpression(parseUnaryExpression(), token.type); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1834 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1835 case T.Not: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1836 nT(); e = new NotExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1837 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1838 case T.Tilde: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1839 nT(); e = new CompExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1840 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1841 case T.New: |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1842 e = parseNewExpression(); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1843 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1844 case T.Delete: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1845 nT(); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1846 e = new DeleteExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1847 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1848 case T.Cast: |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1849 requireNext(T.LParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1850 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1851 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1852 e = new CastExpression(parseUnaryExpression(), type); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1853 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1854 case T.LParen: |
102 | 1855 // ( Type ) . Identifier |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1856 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1857 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1858 require(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
|
1859 string ident = requireIdentifier(); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1860 e = new TypeDotIdExpression(type, ident); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1861 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1862 default: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1863 e = parsePostExpression(parsePrimaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1864 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1865 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1866 assert(e !is null); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1867 return e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1868 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1869 |
90
a02950cb7036
- Fixed order of parsing unary, post and primary expressions.
aziz
parents:
89
diff
changeset
|
1870 Expression parsePostExpression(Expression e) |
77 | 1871 { |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1872 while (1) |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1873 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1874 switch (token.type) |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1875 { |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1876 /* |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1877 // Commented out because parseDotListExpression() handles this. |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1878 case T.Dot: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1879 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1880 if (token.type == T.Identifier) |
92 | 1881 { |
153 | 1882 string ident = token.identifier; |
1883 nT(); | |
1884 Token next; | |
1885 lx.peek(next); | |
1886 if (token.type == T.Not && next.type == T.LParen) // Identifier !( TemplateArguments ) | |
1887 { | |
1888 nT(); // Skip !. | |
1889 e = new DotTemplateInstanceExpression(e, ident, parseTemplateArguments()); | |
1890 } | |
1891 else | |
1892 { | |
1893 e = new DotIdExpression(e, ident); | |
1894 nT(); | |
1895 } | |
92 | 1896 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1897 else if (token.type == T.New) |
81 | 1898 e = parseNewExpression(e); |
92 | 1899 else |
124 | 1900 expected(T.Identifier); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1901 continue; |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1902 */ |
160
c21192e8be2b
- Parsing PostDotListExpression in parsePostExpression().
aziz
parents:
159
diff
changeset
|
1903 case T.Dot: |
c21192e8be2b
- Parsing PostDotListExpression in parsePostExpression().
aziz
parents:
159
diff
changeset
|
1904 e = new PostDotListExpression(e, parseDotListExpression()); |
c21192e8be2b
- Parsing PostDotListExpression in parsePostExpression().
aziz
parents:
159
diff
changeset
|
1905 break; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1906 case T.PlusPlus: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1907 e = new PostIncrExpression(e); |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1908 break; |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1909 case T.MinusMinus: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1910 e = new PostDecrExpression(e); |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1911 break; |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1912 case T.LParen: |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1913 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
|
1914 continue; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1915 case T.LBracket: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1916 // parse Slice- and IndexExpression |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1917 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1918 if (token.type == T.RBracket) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1919 { |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1920 e = new SliceExpression(e, null, null); |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1921 break; |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1922 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1923 |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1924 Expression[] es = [parseAssignExpression()]; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1925 |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1926 if (token.type == T.Slice) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1927 { |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1928 nT(); |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1929 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
|
1930 require(T.RBracket); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1931 continue; |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1932 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1933 else if (token.type == T.Comma) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1934 { |
143 | 1935 es ~= parseArguments(T.RBracket); |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1936 } |
85 | 1937 else |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1938 require(T.RBracket); |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1939 |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1940 e = new IndexExpression(e, es); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1941 continue; |
92 | 1942 default: |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1943 return e; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1944 } |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1945 nT(); |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1946 } |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1947 assert(0); |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1948 } |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1949 |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1950 Expression parsePrimaryExpression() |
78
f043759fb59a
- Added code to parseUnaryExpression(); not fully implemented.
aziz
parents:
77
diff
changeset
|
1951 { |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1952 Expression e; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1953 switch (token.type) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1954 { |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1955 /* |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1956 // Commented out because parseDotListExpression() handles this. |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1957 case T.Identifier: |
153 | 1958 string ident = token.identifier; |
89 | 1959 nT(); |
153 | 1960 Token next; |
1961 lx.peek(next); | |
1962 if (token.type == T.Not && next.type == T.LParen) // Identifier !( TemplateArguments ) | |
1963 { | |
1964 nT(); // Skip !. | |
1965 e = new TemplateInstanceExpression(ident, parseTemplateArguments()); | |
1966 } | |
1967 else | |
1968 e = new IdentifierExpression(ident); | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1969 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1970 case T.Dot: |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1971 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1972 e = new IdentifierExpression("."); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1973 break; |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1974 */ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1975 case T.Identifier, T.Dot, T.Typeof: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1976 e = parseDotListExpression(); |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1977 break; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1978 case T.This: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1979 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1980 e = new ThisExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1981 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1982 case T.Super: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1983 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1984 e = new SuperExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1985 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1986 case T.Null: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1987 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1988 e = new NullExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1989 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1990 case T.True, T.False: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1991 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1992 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
|
1993 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1994 case T.Dollar: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1995 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1996 e = new DollarExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1997 break; |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1998 case T.Int32, T.Int64, T.Uint32, T.Uint64: |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1999 nT(); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
2000 e = new IntNumberExpression(token.type, token.ulong_); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
2001 break; |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
2002 case T.Float32, T.Float64, T.Float80, |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
2003 T.Imaginary32, T.Imaginary64, T.Imaginary80: |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
2004 nT(); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
2005 e = new RealNumberExpression(token.type, token.real_); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2006 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2007 case T.CharLiteral, T.WCharLiteral, T.DCharLiteral: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2008 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2009 e = new CharLiteralExpression(token.type); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2010 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2011 case T.String: |
157
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
2012 Token*[] stringLiterals; |
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
2013 do |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2014 { |
157
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
2015 stringLiterals ~= token; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2016 nT(); |
157
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
2017 } while (token.type == T.String) |
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
2018 e = new StringLiteralsExpression(stringLiterals); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2019 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2020 case T.LBracket: |
85 | 2021 Expression[] values; |
2022 | |
2023 nT(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2024 if (token.type != T.RBracket) |
85 | 2025 { |
2026 e = parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2027 if (token.type == T.Colon) |
85 | 2028 goto LparseAssocArray; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2029 else if (token.type == T.Comma) |
143 | 2030 values = [e] ~ parseArguments(T.RBracket); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2031 else |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2032 require(T.RBracket); |
85 | 2033 } |
2034 | |
2035 e = new ArrayLiteralExpression(values); | |
2036 break; | |
2037 | |
2038 LparseAssocArray: | |
2039 Expression[] keys; | |
2040 | |
2041 keys ~= e; | |
2042 nT(); // Skip colon. | |
2043 values ~= parseAssignExpression(); | |
2044 | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2045 if (token.type != T.RBracket) |
88 | 2046 { |
2047 require(T.Comma); | |
85 | 2048 while (1) |
2049 { | |
2050 keys ~= parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2051 if (token.type != T.Colon) |
85 | 2052 { |
124 | 2053 expected(T.Colon); |
85 | 2054 values ~= null; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2055 if (token.type == T.RBracket) |
85 | 2056 break; |
2057 else | |
2058 continue; | |
2059 } | |
2060 nT(); | |
2061 values ~= parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2062 if (token.type == T.RBracket) |
85 | 2063 break; |
88 | 2064 require(T.Comma); |
85 | 2065 } |
88 | 2066 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2067 assert(token.type == T.RBracket); |
85 | 2068 nT(); |
2069 e = new AssocArrayLiteralExpression(keys, values); | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2070 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2071 case T.LBrace: |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2072 // DelegateLiteral := { DeclDefs } |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2073 require(T.LBrace); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2074 auto decls = parseDeclarationDefinitions(); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2075 require(T.RBrace); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2076 auto func = new FunctionType(null, Parameters.init); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2077 e = new FunctionLiteralExpression(func, decls); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2078 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2079 case T.Function, T.Delegate: |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2080 // FunctionLiteral := (function|delegate) Type? '(' ArgumentList ')' '{' DeclDefs '}' |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2081 TOK funcTok = token.type; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2082 nT(); // Skip function|delegate token. |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2083 Type returnType; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2084 Parameters parameters; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2085 if (token.type != T.LBrace) |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2086 { |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2087 if (token.type != T.LParen) // Optional return type |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2088 returnType = parseType(); |
143 | 2089 parameters = parseParameterList(); |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2090 } |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2091 require(T.LBrace); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2092 auto decls = parseDeclarationDefinitions(); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2093 require(T.RBrace); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2094 auto func = new FunctionType(returnType, parameters); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
2095 e = new FunctionLiteralExpression(func, decls, funcTok); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2096 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2097 case T.Assert: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2098 Expression msg; |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2099 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2100 e = parseAssignExpression(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2101 if (token.type == T.Comma) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2102 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2103 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2104 msg = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2105 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2106 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2107 e = new AssertExpression(e, msg); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2108 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2109 case T.Mixin: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2110 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2111 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2112 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2113 e = new MixinExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2114 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2115 case T.Import: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2116 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2117 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2118 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2119 e = new ImportExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2120 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2121 case T.Typeid: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2122 requireNext(T.LParen); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
2123 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
2124 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
2125 e = new TypeidExpression(type); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2126 break; |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2127 /* |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2128 // Commented out because parseDotListExpression() handles this. |
101 | 2129 case T.Typeof: |
2130 requireNext(T.LParen); | |
2131 auto type = new TypeofType(parseExpression()); | |
2132 require(T.RParen); | |
2133 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
|
2134 { // typeof ( Expression ) . Identifier |
101 | 2135 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2136 string ident = requireIdentifier; |
101 | 2137 e = new TypeDotIdExpression(type, ident); |
2138 } | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2139 else // typeof ( Expression ) |
101 | 2140 e = new TypeofExpression(type); |
2141 break; | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2142 */ |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2143 case T.Is: |
100 | 2144 requireNext(T.LParen); |
2145 | |
2146 Type type; | |
2147 SpecializationType specType; | |
2148 string ident; // optional Identifier | |
2149 | |
2150 type = parseDeclarator(ident, true); | |
2151 | |
2152 switch (token.type) | |
2153 { | |
2154 case T.Colon, T.Equal: | |
2155 TOK specTok = token.type; | |
2156 nT(); | |
2157 switch (token.type) | |
2158 { | |
2159 case T.Typedef, | |
2160 T.Struct, | |
2161 T.Union, | |
2162 T.Class, | |
2163 T.Interface, | |
2164 T.Enum, | |
2165 T.Function, | |
2166 T.Delegate, | |
2167 T.Super, | |
2168 T.Return: | |
102 | 2169 nT(); |
100 | 2170 specType = new SpecializationType(specTok, token.type); |
2171 break; | |
2172 default: | |
2173 specType = new SpecializationType(specTok, parseType()); | |
2174 } | |
2175 default: | |
2176 } | |
102 | 2177 require(T.RParen); |
100 | 2178 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
|
2179 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2180 case T.LParen: |
130 | 2181 Token t; |
2182 bool failed; | |
143 | 2183 auto parameters = try_(parseParameterList(), failed); |
130 | 2184 if (!failed) |
2185 { | |
143 | 2186 // ( ParameterList ) FunctionBody |
130 | 2187 require(T.LBrace); |
2188 auto decls = parseDeclarationDefinitions(); | |
2189 require(T.RBrace); | |
2190 auto func = new FunctionType(null, parameters); | |
2191 e = new FunctionLiteralExpression(func, decls); | |
2192 } | |
2193 else | |
2194 { | |
131 | 2195 // ( Expression ) |
130 | 2196 nT(); |
2197 e = parseExpression(); | |
2198 require(T.RParen); | |
2199 } | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2200 break; |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2201 // BasicType . Identifier |
94 | 2202 case T.Void, T.Char, T.Wchar, T.Dchar, T.Bool, |
2203 T.Byte, T.Ubyte, T.Short, T.Ushort, | |
2204 T.Int, T.Uint, T.Long, T.Ulong, | |
2205 T.Float, T.Double, T.Real, | |
2206 T.Ifloat, T.Idouble, T.Ireal, | |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2207 T.Cfloat, T.Cdouble, T.Creal: |
94 | 2208 auto type = new Type(token.type); |
2209 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
|
2210 auto ident = requireIdentifier(); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2211 |
94 | 2212 e = new TypeDotIdExpression(type, ident); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2213 break; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2214 default: |
136
96468715ea79
- Returning EmptyExpression in parsePrimaryExpression() when no token matched.
aziz
parents:
135
diff
changeset
|
2215 // TODO: issue error msg. |
96468715ea79
- Returning EmptyExpression in parsePrimaryExpression() when no token matched.
aziz
parents:
135
diff
changeset
|
2216 e = new EmptyExpression(); |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2217 } |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2218 return e; |
77 | 2219 } |
2220 | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2221 Expression parseNewExpression(/*Expression e*/) |
81 | 2222 { |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2223 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
|
2224 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
|
2225 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2226 Expression[] newArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2227 Expression[] ctorArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2228 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2229 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
|
2230 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
|
2231 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2232 // NewAnonClassExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2233 // 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
|
2234 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
|
2235 { |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2236 nT(); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2237 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
|
2238 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
|
2239 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2240 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
|
2241 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2242 require(T.LBrace); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2243 auto decls = parseDeclarationDefinitions(); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2244 require(T.RBrace); |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2245 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
|
2246 } |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2247 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2248 // NewExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2249 // NewArguments Type [ AssignExpression ] |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2250 // NewArguments Type ( ArgumentList ) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2251 // NewArguments Type |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2252 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
|
2253 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
|
2254 { |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2255 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
|
2256 } |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2257 return new NewExpression(/*e, */newArguments, type, ctorArguments); |
81 | 2258 } |
2259 | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2260 Type parseType() |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2261 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
2262 return parseBasicType2(parseBasicType()); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2263 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2264 |
94 | 2265 Type parseBasicType() |
2266 { | |
2267 Type t; | |
2268 IdentifierType tident; | |
2269 | |
2270 switch (token.type) | |
2271 { | |
2272 case T.Void, T.Char, T.Wchar, T.Dchar, T.Bool, | |
2273 T.Byte, T.Ubyte, T.Short, T.Ushort, | |
2274 T.Int, T.Uint, T.Long, T.Ulong, | |
2275 T.Float, T.Double, T.Real, | |
2276 T.Ifloat, T.Idouble, T.Ireal, | |
2277 T.Cfloat, T.Cdouble, T.Creal: | |
2278 t = new Type(token.type); | |
2279 nT(); | |
2280 break; | |
153 | 2281 /+ |
94 | 2282 case T.Identifier, T.Dot: |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
2283 tident = new IdentifierType([token.identifier]); |
94 | 2284 nT(); |
102 | 2285 // TODO: parse template instance |
94 | 2286 // if (token.type == T.Not) |
2287 // parse template instance | |
2288 Lident: | |
2289 while (token.type == T.Dot) | |
2290 { | |
2291 nT(); | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2292 tident ~= requireIdentifier(); |
102 | 2293 // TODO: parse template instance |
94 | 2294 // if (token.type == T.Not) |
2295 // parse template instance | |
2296 } | |
2297 t = tident; | |
2298 break; | |
2299 case T.Typeof: | |
2300 requireNext(T.LParen); | |
2301 tident = new TypeofType(parseExpression()); | |
2302 require(T.RParen); | |
2303 goto Lident; | |
153 | 2304 +/ |
2305 case T.Identifier, T.Typeof, T.Dot: | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2306 t = parseDotListType(); |
153 | 2307 break; |
94 | 2308 default: |
136
96468715ea79
- Returning EmptyExpression in parsePrimaryExpression() when no token matched.
aziz
parents:
135
diff
changeset
|
2309 // TODO: issue error msg. |
134
a31aa0d6dd5e
- Added class UndefinedType. Returning it in parseBasicType() when no token matched the basic type list.
aziz
parents:
133
diff
changeset
|
2310 t = new UndefinedType(); |
94 | 2311 } |
2312 return t; | |
2313 } | |
2314 | |
95 | 2315 Type parseBasicType2(Type t) |
2316 { | |
2317 while (1) | |
2318 { | |
2319 switch (token.type) | |
2320 { | |
2321 case T.Mul: | |
2322 t = new PointerType(t); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2323 nT(); |
95 | 2324 break; |
2325 case T.LBracket: | |
106 | 2326 t = parseArrayType(t); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2327 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2328 case T.Function, T.Delegate: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2329 TOK tok = token.type; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2330 nT(); |
143 | 2331 auto parameters = parseParameterList(); |
135 | 2332 t = new FunctionType(t, parameters); |
2333 if (tok == T.Function) | |
2334 t = new PointerType(t); | |
2335 else | |
2336 t = new DelegateType(t); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2337 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2338 default: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2339 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2340 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2341 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2342 assert(0); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2343 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2344 |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2345 Type parseDeclaratorSuffix(Type t) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2346 { |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2347 while (1) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2348 { |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2349 switch (token.type) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2350 { |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2351 case T.LBracket: |
131 | 2352 // Type Identifier ArrayType |
2353 // ArrayType := [] or [Type] or [Expression..Expression] | |
106 | 2354 t = parseArrayType(t); |
95 | 2355 continue; |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2356 case T.LParen: |
143 | 2357 auto params = parseParameterList(); |
131 | 2358 // TODO: handle ( TemplateParameterList ) ( ParameterList ) |
2359 // ReturnType FunctionName ( ParameterList ) | |
2360 t = new FunctionType(t, params); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2361 break; |
100 | 2362 default: |
2363 break; | |
95 | 2364 } |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2365 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2366 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2367 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2368 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2369 |
106 | 2370 Type parseArrayType(Type t) |
2371 { | |
2372 assert(token.type == T.LBracket); | |
2373 nT(); | |
2374 if (token.type == T.RBracket) | |
2375 { | |
2376 t = new ArrayType(t); | |
2377 nT(); | |
2378 } | |
2379 else | |
2380 { | |
2381 bool failed; | |
2382 auto assocType = try_(parseType(), failed); | |
2383 if (!failed) | |
2384 t = new ArrayType(t, assocType); | |
2385 else | |
2386 { | |
2387 Expression e = parseExpression(), e2; | |
2388 if (token.type == T.Slice) | |
2389 { | |
2390 nT(); | |
2391 e2 = parseExpression(); | |
2392 } | |
2393 t = new ArrayType(t, e, e2); | |
2394 } | |
2395 require(T.RBracket); | |
2396 } | |
2397 return t; | |
2398 } | |
2399 | |
100 | 2400 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
|
2401 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
2402 auto t = parseType(); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2403 |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2404 if (token.type == T.Identifier) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2405 { |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
2406 ident = token.identifier; |
95 | 2407 nT(); |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
2408 t = parseDeclaratorSuffix(t); |
95 | 2409 } |
100 | 2410 else if (!identOptional) |
124 | 2411 expected(T.Identifier); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2412 |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
2413 return t; |
95 | 2414 } |
2415 | |
143 | 2416 Expression[] parseArguments(TOK terminator) |
138 | 2417 { |
155 | 2418 assert(token.type == T.LParen || token.type == T.LBracket || token.type == T.Comma); |
2419 assert(terminator == T.RParen || terminator == T.RBracket); | |
139 | 2420 Expression[] args; |
138 | 2421 |
2422 nT(); | |
2423 if (token.type == terminator) | |
2424 { | |
2425 nT(); | |
2426 return null; | |
2427 } | |
2428 | |
139 | 2429 goto LenterLoop; |
2430 do | |
138 | 2431 { |
139 | 2432 nT(); |
2433 LenterLoop: | |
2434 args ~= parseAssignExpression(); | |
2435 } while (token.type == T.Comma) | |
2436 | |
2437 require(terminator); | |
2438 return args; | |
138 | 2439 } |
2440 | |
143 | 2441 Parameters parseParameterList() |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2442 out(params) |
96 | 2443 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2444 if (params.length > 1) |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2445 foreach (param; params.items[0..$-1]) |
96 | 2446 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2447 if (param.isVariadic()) |
96 | 2448 assert(0, "variadic arguments can only appear at the end of the parameter list."); |
2449 } | |
2450 } | |
2451 body | |
95 | 2452 { |
2453 require(T.LParen); | |
2454 | |
2455 if (token.type == T.RParen) | |
2456 { | |
2457 nT(); | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2458 return Parameters.init; |
95 | 2459 } |
2460 | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2461 Parameters params; |
95 | 2462 StorageClass stc; |
2463 | |
2464 while (1) | |
2465 { | |
2466 stc = StorageClass.In; | |
2467 switch (token.type) | |
2468 { | |
2469 case T.In: stc = StorageClass.In; nT(); goto default; | |
2470 case T.Out: stc = StorageClass.Out; nT(); goto default; | |
2471 case T.Ref: stc = StorageClass.Ref; nT(); goto default; | |
2472 case T.Lazy: stc = StorageClass.Lazy; nT(); goto default; | |
2473 case T.Ellipses: | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2474 params ~= new Parameter(StorageClass.Variadic, null, null, null); |
95 | 2475 break; |
2476 default: | |
2477 string ident; | |
130 | 2478 auto type = parseDeclarator(ident, true); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
2479 |
95 | 2480 Expression assignExpr; |
2481 if (token.type == T.Assign) | |
2482 { | |
2483 nT(); | |
2484 assignExpr = parseAssignExpression(); | |
2485 } | |
2486 | |
2487 if (token.type == T.Ellipses) | |
2488 { | |
2489 stc |= StorageClass.Variadic; | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2490 params ~= new Parameter(stc, type, ident, assignExpr); |
95 | 2491 nT(); |
2492 break; | |
2493 } | |
2494 | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2495 params ~= new Parameter(stc, type, ident, assignExpr); |
95 | 2496 if (token.type == T.Comma) |
2497 { | |
2498 nT(); | |
2499 continue; | |
2500 } | |
2501 break; | |
2502 } | |
2503 break; | |
2504 } | |
2505 require(T.RParen); | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2506 return params; |
95 | 2507 } |
2508 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
2509 TemplateArguments parseTemplateArguments() |
139 | 2510 { |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
2511 TemplateArguments args; |
139 | 2512 |
2513 require(T.LParen); | |
2514 if (token.type == T.RParen) | |
2515 { | |
2516 nT(); | |
2517 return null; | |
2518 } | |
2519 | |
2520 goto LenterLoop; | |
2521 do | |
2522 { | |
2523 nT(); // Skip comma. | |
2524 LenterLoop: | |
2525 | |
2526 bool failed; | |
2527 auto typeArgument = try_(parseType(), failed); | |
2528 | |
2529 if (!failed) | |
2530 { | |
2531 // TemplateArgument: | |
2532 // Type | |
2533 // Symbol | |
2534 args ~= typeArgument; | |
2535 } | |
2536 else | |
2537 { | |
2538 // TemplateArgument: | |
2539 // AssignExpression | |
2540 args ~= parseAssignExpression(); | |
2541 } | |
2542 } while (token.type == T.Comma) | |
2543 | |
2544 require(T.RParen); | |
2545 return args; | |
2546 } | |
2547 | |
143 | 2548 TemplateParameter[] parseTemplateParameterList() |
137 | 2549 { |
2550 require(T.LParen); | |
2551 if (token.type == T.RParen) | |
2552 return null; | |
2553 | |
2554 TemplateParameter[] tparams; | |
2555 while (1) | |
2556 { | |
2557 TP tp; | |
2558 string ident; | |
2559 Type valueType; | |
2560 Type specType, defType; | |
2561 Expression specValue, defValue; | |
2562 | |
2563 switch (token.type) | |
2564 { | |
2565 case T.Alias: | |
2566 // TemplateAliasParameter: | |
2567 // alias Identifier | |
2568 tp = TP.Alias; | |
2569 nT(); // Skip alias keyword. | |
2570 ident = requireIdentifier(); | |
2571 // : SpecializationType | |
2572 if (token.type == T.Colon) | |
2573 { | |
2574 nT(); | |
2575 specType = parseType(); | |
2576 } | |
2577 // = DefaultType | |
2578 if (token.type == T.Assign) | |
2579 { | |
2580 nT(); | |
2581 defType = parseType(); | |
2582 } | |
2583 break; | |
2584 case T.Identifier: | |
2585 ident = token.identifier; | |
2586 Token peeked; | |
2587 lx.peek(peeked); | |
2588 switch (peeked.type) | |
2589 { | |
2590 case T.Ellipses: | |
2591 // TemplateTupleParameter: | |
2592 // Identifier ... | |
2593 tp = TP.Tuple; | |
2594 nT(); // Skip Identifier. | |
2595 nT(); // Skip Ellipses. | |
2596 // if (token.type == T.Comma) | |
2597 // error(); // TODO: issue error msg for variadic param not being last. | |
2598 break; | |
2599 case T.Comma, T.RParen, T.Colon, T.Assign: | |
2600 // TemplateTypeParameter: | |
2601 // Identifier | |
2602 tp = TP.Type; | |
2603 nT(); // Skip Identifier. | |
2604 // : SpecializationType | |
2605 if (token.type == T.Colon) | |
2606 { | |
2607 nT(); | |
2608 specType = parseType(); | |
2609 } | |
2610 // = DefaultType | |
2611 if (token.type == T.Assign) | |
2612 { | |
2613 nT(); | |
2614 defType = parseType(); | |
2615 } | |
2616 break; | |
2617 default: | |
2618 // TemplateValueParameter: | |
2619 // Declarator | |
2620 ident = null; | |
2621 goto LTemplateValueParameter; | |
2622 } | |
2623 break; | |
2624 default: | |
2625 LTemplateValueParameter: | |
2626 // TemplateValueParameter: | |
2627 // Declarator | |
2628 tp = TP.Value; | |
2629 valueType = parseDeclarator(ident); | |
2630 // : SpecializationValue | |
2631 if (token.type == T.Colon) | |
2632 { | |
2633 nT(); | |
2634 specValue = parseCondExpression(); | |
2635 } | |
2636 // = DefaultValue | |
2637 if (token.type == T.Assign) | |
2638 { | |
2639 nT(); | |
2640 defValue = parseCondExpression(); | |
2641 } | |
2642 } | |
2643 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
2644 tparams ~= new TemplateParameter(tp, valueType, ident, specType, defType, specValue, defValue); |
137 | 2645 |
2646 if (token.type != T.Comma) | |
2647 break; | |
2648 nT(); | |
2649 } | |
2650 require(T.RParen); | |
2651 return tparams; | |
2652 } | |
2653 | |
124 | 2654 void expected(TOK tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2655 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2656 if (token.type != tok) |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2657 error(MID.ExpectedButFound, tok, token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2658 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2659 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2660 void require(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2661 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2662 if (token.type == tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2663 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2664 else |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2665 error(MID.ExpectedButFound, tok, token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2666 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2667 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2668 void requireNext(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2669 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2670 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2671 if (token.type == tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2672 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2673 else |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2674 error(MID.ExpectedButFound, tok, token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2675 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2676 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2677 string requireIdentifier() |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2678 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2679 string identifier; |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2680 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
|
2681 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2682 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
|
2683 nT(); |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2684 } |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2685 else |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2686 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
|
2687 return identifier; |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2688 } |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2689 |
71 | 2690 void error(MID id, ...) |
2691 { | |
94 | 2692 errors ~= new Information(InfoType.Parser, id, lx.loc, arguments(_arguments, _argptr)); |
71 | 2693 } |
65 | 2694 } |