Mercurial > projects > dil
annotate trunk/src/Parser.d @ 175:522df6f0f230
- Implemented parseReturnStatement().
author | aziz |
---|---|
date | Sat, 14 Jul 2007 10:44:05 +0000 |
parents | e51c9ee66ea0 |
children | 3071522c0cf0 |
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; | |
161 | 1169 default: |
164 | 1170 // TODO: issue error msg and return IllegalStatement. |
161 | 1171 } |
1172 return s; | |
1173 } | |
1174 | |
162 | 1175 /+ |
1176 ScopeStatement: | |
1177 NonEmptyStatement | |
1178 BlockStatement | |
1179 BlockStatement: | |
1180 { } | |
1181 { StatementList } | |
1182 +/ | |
164 | 1183 Statement parseScopeStatement() |
162 | 1184 { |
1185 Statement s; | |
1186 if (token.type == T.LBrace) | |
1187 { | |
1188 nT(); | |
1189 auto ss = new Statements(); | |
1190 while (token.type != T.RBrace && token.type != T.EOF) | |
1191 ss ~= parseStatement(); | |
1192 require(T.RBrace); | |
1193 s = ss; | |
1194 } | |
1195 else | |
1196 s = parseStatement(); | |
1197 return new ScopeStatement(s); | |
1198 } | |
1199 | |
166 | 1200 /+ |
1201 NoScopeStatement: | |
1202 NonEmptyStatement | |
1203 BlockStatement | |
1204 BlockStatement: | |
1205 { } | |
1206 { StatementList } | |
1207 +/ | |
1208 Statement parseNoScopeStatement() | |
1209 { | |
1210 Statement s; | |
1211 if (token.type == T.LBrace) | |
1212 { | |
1213 nT(); | |
1214 auto ss = new Statements(); | |
1215 while (token.type != T.RBrace && token.type != T.EOF) | |
1216 ss ~= parseStatement(); | |
1217 require(T.RBrace); | |
1218 s = ss; | |
1219 } | |
1220 else | |
1221 s = parseStatement(); | |
1222 return s; | |
1223 } | |
1224 | |
162 | 1225 Statement parseIfStatement() |
1226 { | |
1227 assert(token.type == T.If); | |
1228 nT(); | |
1229 | |
1230 Type type; | |
1231 string ident; | |
1232 Expression condition; | |
1233 Statement ifBody, elseBody; | |
1234 | |
1235 require(T.LParen); | |
1236 // auto Identifier = Expression | |
1237 if (token.type == T.Auto) | |
1238 { | |
1239 nT(); | |
1240 ident = requireIdentifier(); | |
1241 require(T.Assign); | |
1242 } | |
1243 else | |
1244 { | |
1245 // Declarator = Expression | |
1246 bool failed; | |
1247 type = try_(parseDeclarator(ident), failed); | |
1248 if (!failed) | |
1249 { | |
1250 require(T.Assign); | |
1251 } | |
163
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1252 else |
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1253 { |
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1254 type = null; |
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1255 ident = null; |
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1256 } |
162 | 1257 } |
1258 condition = parseExpression(); | |
1259 require(T.RParen); | |
164 | 1260 ifBody = parseScopeStatement(); |
162 | 1261 if (token.type == T.Else) |
1262 { | |
1263 nT(); | |
164 | 1264 elseBody = parseScopeStatement(); |
162 | 1265 } |
1266 return new IfStatement(type, ident, condition, ifBody, elseBody); | |
1267 } | |
1268 | |
164 | 1269 Statement parseWhileStatement() |
1270 { | |
1271 assert(token.type == T.While); | |
1272 nT(); | |
166 | 1273 require(T.LParen); |
164 | 1274 auto condition = parseExpression(); |
166 | 1275 require(T.RParen); |
164 | 1276 return new WhileStatement(condition, parseScopeStatement()); |
1277 } | |
1278 | |
165 | 1279 Statement parseDoWhileStatement() |
1280 { | |
1281 assert(token.type == T.Do); | |
1282 nT(); | |
1283 auto doBody = parseScopeStatement(); | |
1284 require(T.While); | |
166 | 1285 require(T.LParen); |
165 | 1286 auto condition = parseExpression(); |
166 | 1287 require(T.RParen); |
1288 return new DoWhileStatement(condition, doBody); | |
1289 } | |
1290 | |
1291 Statement parseForStatement() | |
1292 { | |
1293 assert(token.type == T.For); | |
1294 nT(); | |
165 | 1295 require(T.LParen); |
166 | 1296 |
1297 Statement init, forBody; | |
1298 Expression condition, increment; | |
1299 | |
1300 if (token.type != T.Semicolon) | |
1301 init = parseNoScopeStatement(); | |
168 | 1302 require(T.Semicolon); |
166 | 1303 if (token.type != T.Semicolon) |
1304 condition = parseExpression(); | |
168 | 1305 require(T.Semicolon); |
166 | 1306 if (token.type != T.RParen) |
1307 increment = parseExpression(); | |
168 | 1308 require(T.RParen); |
167 | 1309 forBody = parseScopeStatement(); |
166 | 1310 return new ForStatement(init, condition, increment, forBody); |
165 | 1311 } |
1312 | |
169 | 1313 Statement parseForeachStatement() |
1314 { | |
1315 assert(token.type == T.Foreach || token.type == T.Foreach_reverse); | |
1316 TOK tok = token.type; | |
1317 nT(); | |
1318 | |
1319 Parameters params; | |
1320 Expression aggregate; | |
1321 | |
1322 require(T.LParen); | |
1323 while (1) | |
1324 { | |
1325 StorageClass stc; | |
1326 Type type; | |
1327 string ident; | |
1328 | |
1329 switch (token.type) | |
1330 { | |
1331 case T.Ref: | |
1332 nT(); | |
1333 stc = StorageClass.Ref; | |
1334 break; | |
1335 case T.Identifier: | |
1336 Token next; | |
1337 lx.peek(next); | |
1338 if (next.type == T.Comma || next.type == T.Semicolon || next.type == T.RParen) | |
1339 { | |
1340 ident = token.identifier; | |
1341 nT(); | |
1342 break; | |
1343 } | |
1344 // fall through | |
1345 default: | |
1346 type = parseDeclarator(ident); | |
1347 } | |
1348 | |
1349 params ~= new Parameter(stc, type, ident, null); | |
1350 | |
1351 if (token.type != T.Comma) | |
1352 break; | |
1353 nT(); | |
1354 } | |
1355 require(T.Semicolon); | |
1356 aggregate = parseExpression(); | |
1357 require(T.RParen); | |
1358 auto forBody = parseScopeStatement(); | |
1359 return new ForeachStatement(tok, params, aggregate, forBody); | |
1360 } | |
1361 | |
170 | 1362 Statement parseSwitchStatement() |
1363 { | |
1364 assert(token.type == T.Switch); | |
1365 nT(); | |
1366 | |
1367 require(T.LParen); | |
1368 auto condition = parseExpression(); | |
1369 require(T.RParen); | |
1370 auto switchBody = parseScopeStatement(); | |
1371 return new SwitchStatement(condition, switchBody); | |
1372 } | |
1373 | |
171 | 1374 Statement parseCaseStatement() |
1375 { | |
1376 assert(token.type == T.Case); | |
1377 // T.Case skipped in do-while. | |
1378 Expression[] values; | |
1379 do | |
1380 { | |
1381 nT(); | |
1382 values ~= parseAssignExpression(); | |
1383 } while (token.type == T.Comma) | |
1384 require(T.Colon); | |
1385 | |
1386 auto caseBody = parseScopeStatement(); | |
1387 return new CaseStatement(values, caseBody); | |
1388 } | |
1389 | |
172 | 1390 Statement parseDefaultStatement() |
1391 { | |
1392 assert(token.type == T.Default); | |
1393 nT(); | |
1394 require(T.Colon); | |
1395 return new DefaultStatement(parseScopeStatement()); | |
1396 } | |
1397 | |
173 | 1398 Statement parseContinueStatement() |
1399 { | |
1400 assert(token.type == T.Continue); | |
1401 nT(); | |
1402 string ident; | |
1403 if (token.type == T.Identifier) | |
1404 { | |
1405 ident = token.identifier; | |
1406 nT(); | |
1407 } | |
1408 require(T.Semicolon); | |
1409 return new ContinueStatement(ident); | |
1410 } | |
1411 | |
174 | 1412 Statement parseBreakStatement() |
1413 { | |
1414 assert(token.type == T.Break); | |
1415 nT(); | |
1416 string ident; | |
1417 if (token.type == T.Identifier) | |
1418 { | |
1419 ident = token.identifier; | |
1420 nT(); | |
1421 } | |
1422 require(T.Semicolon); | |
1423 return new BreakStatement(ident); | |
1424 } | |
1425 | |
175 | 1426 Statement parseReturnStatement() |
1427 { | |
1428 assert(token.type == T.Return); | |
1429 nT(); | |
1430 auto expr = parseExpression(); | |
1431 require(T.Semicolon); | |
1432 return new ReturnStatement(expr); | |
1433 } | |
1434 | |
161 | 1435 /+++++++++++++++++++++++++++++ |
102 | 1436 + Expression parsing methods + |
1437 +++++++++++++++++++++++++++++/ | |
1438 | |
72 | 1439 Expression parseExpression() |
1440 { | |
1441 auto e = parseAssignExpression(); | |
122 | 1442 while (token.type == T.Comma) |
81 | 1443 e = new CommaExpression(e, parseAssignExpression()); |
72 | 1444 return e; |
1445 } | |
1446 | |
71 | 1447 Expression parseAssignExpression() |
1448 { | |
1449 auto e = parseCondExpression(); | |
72 | 1450 while (1) |
71 | 1451 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1452 switch (token.type) |
72 | 1453 { |
1454 case T.Assign: | |
1455 nT(); e = new AssignExpression(e, parseAssignExpression()); | |
1456 break; | |
1457 case T.LShiftAssign: | |
1458 nT(); e = new LShiftAssignExpression(e, parseAssignExpression()); | |
1459 break; | |
1460 case T.RShiftAssign: | |
1461 nT(); e = new RShiftAssignExpression(e, parseAssignExpression()); | |
1462 break; | |
1463 case T.URShiftAssign: | |
1464 nT(); e = new URShiftAssignExpression(e, parseAssignExpression()); | |
1465 break; | |
1466 case T.OrAssign: | |
1467 nT(); e = new OrAssignExpression(e, parseAssignExpression()); | |
1468 break; | |
1469 case T.AndAssign: | |
1470 nT(); e = new AndAssignExpression(e, parseAssignExpression()); | |
1471 break; | |
1472 case T.PlusAssign: | |
1473 nT(); e = new PlusAssignExpression(e, parseAssignExpression()); | |
1474 break; | |
1475 case T.MinusAssign: | |
1476 nT(); e = new MinusAssignExpression(e, parseAssignExpression()); | |
1477 break; | |
1478 case T.DivAssign: | |
1479 nT(); e = new DivAssignExpression(e, parseAssignExpression()); | |
1480 break; | |
1481 case T.MulAssign: | |
1482 nT(); e = new MulAssignExpression(e, parseAssignExpression()); | |
1483 break; | |
1484 case T.ModAssign: | |
1485 nT(); e = new ModAssignExpression(e, parseAssignExpression()); | |
1486 break; | |
1487 case T.XorAssign: | |
1488 nT(); e = new XorAssignExpression(e, parseAssignExpression()); | |
1489 break; | |
1490 case T.CatAssign: | |
1491 nT(); e = new CatAssignExpression(e, parseAssignExpression()); | |
1492 break; | |
1493 default: | |
1494 break; | |
1495 } | |
71 | 1496 break; |
1497 } | |
1498 return e; | |
1499 } | |
72 | 1500 |
71 | 1501 Expression parseCondExpression() |
1502 { | |
72 | 1503 auto e = parseOrOrExpression(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1504 if (token.type == T.Question) |
72 | 1505 { |
1506 nT(); | |
1507 auto iftrue = parseExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1508 require(T.Colon); |
72 | 1509 auto iffalse = parseCondExpression(); |
1510 e = new CondExpression(e, iftrue, iffalse); | |
1511 } | |
1512 return e; | |
1513 } | |
1514 | |
1515 Expression parseOrOrExpression() | |
1516 { | |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1517 alias parseAndAndExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1518 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1519 if (token.type == T.OrLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1520 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1521 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1522 e = new OrOrExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1523 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1524 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1525 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1526 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1527 Expression parseAndAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1528 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1529 alias parseOrExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1530 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1531 if (token.type == T.AndLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1532 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1533 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1534 e = new AndAndExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1535 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1536 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1537 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1538 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1539 Expression parseOrExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1540 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1541 alias parseXorExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1542 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1543 if (token.type == T.OrBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1544 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1545 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1546 e = new OrExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1547 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1548 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1549 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1550 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1551 Expression parseXorExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1552 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1553 alias parseAndExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1554 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1555 if (token.type == T.Xor) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1556 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1557 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1558 e = new XorExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1559 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1560 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1561 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1562 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1563 Expression parseAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1564 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1565 alias parseCmpExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1566 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1567 if (token.type == T.AndBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1568 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1569 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1570 e = new AndExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1571 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1572 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1573 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1574 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1575 Expression parseCmpExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1576 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1577 TOK operator = token.type; |
74 | 1578 |
1579 auto e = parseShiftExpression(); | |
1580 | |
1581 switch (operator) | |
1582 { | |
1583 case T.Equal, T.NotEqual: | |
1584 nT(); | |
1585 e = new EqualExpression(e, parseShiftExpression(), operator); | |
1586 break; | |
1587 case T.Not: | |
1588 Token t; | |
1589 lx.peek(t); | |
1590 if (t.type != T.Is) | |
1591 break; | |
1592 nT(); | |
1593 operator = T.NotIdentity; | |
1594 goto LNotIdentity; | |
1595 case T.Identity: | |
1596 operator = T.Identity; | |
1597 LNotIdentity: | |
1598 nT(); | |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1599 e = new IdentityExpression(e, parseShiftExpression(), operator); |
74 | 1600 break; |
1601 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater, | |
1602 T.Unordered, T.UorE, T.UorG, T.UorGorE, | |
1603 T.UorL, T.UorLorE, T.LorEorG, T.LorG: | |
1604 nT(); | |
1605 e = new RelExpression(e, parseShiftExpression(), operator); | |
1606 break; | |
1607 case T.In: | |
1608 nT(); | |
1609 e = new InExpression(e, parseShiftExpression(), operator); | |
1610 break; | |
1611 default: | |
1612 } | |
1613 return e; | |
1614 } | |
1615 | |
1616 Expression parseShiftExpression() | |
1617 { | |
75 | 1618 auto e = parseAddExpression(); |
1619 while (1) | |
1620 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1621 switch (token.type) |
75 | 1622 { |
1623 case T.LShift: nT(); e = new LShiftExpression(e, parseAddExpression()); break; | |
1624 case T.RShift: nT(); e = new RShiftExpression(e, parseAddExpression()); break; | |
1625 case T.URShift: nT(); e = new URShiftExpression(e, parseAddExpression()); break; | |
1626 default: break; | |
1627 } | |
1628 break; | |
1629 } | |
1630 return e; | |
1631 } | |
1632 | |
1633 Expression parseAddExpression() | |
1634 { | |
76 | 1635 auto e = parseMulExpression(); |
1636 while (1) | |
1637 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1638 switch (token.type) |
76 | 1639 { |
1640 case T.Plus: nT(); e = new PlusExpression(e, parseMulExpression()); break; | |
1641 case T.Minus: nT(); e = new MinusExpression(e, parseMulExpression()); break; | |
1642 case T.Tilde: nT(); e = new CatExpression(e, parseMulExpression()); break; | |
1643 default: break; | |
1644 } | |
1645 break; | |
1646 } | |
1647 return new Expression(); | |
1648 } | |
1649 | |
1650 Expression parseMulExpression() | |
1651 { | |
77 | 1652 auto e = parseUnaryExpression(); |
1653 while (1) | |
1654 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1655 switch (token.type) |
77 | 1656 { |
1657 case T.Mul: nT(); e = new MulExpression(e, parseUnaryExpression()); break; | |
1658 case T.Div: nT(); e = new DivExpression(e, parseUnaryExpression()); break; | |
1659 case T.Mod: nT(); e = new ModExpression(e, parseUnaryExpression()); break; | |
1660 default: break; | |
1661 } | |
1662 break; | |
1663 } | |
74 | 1664 return new Expression(); |
71 | 1665 } |
1666 | |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1667 Expression parseUnaryExpression() |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1668 { |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1669 Expression e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1670 switch (token.type) |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1671 { |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1672 case T.AndBinary: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1673 nT(); e = new AddressExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1674 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1675 case T.PlusPlus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1676 nT(); e = new PreIncrExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1677 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1678 case T.MinusMinus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1679 nT(); e = new PreDecrExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1680 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1681 case T.Mul: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1682 nT(); e = new DerefExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1683 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1684 case T.Minus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1685 case T.Plus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1686 nT(); e = new SignExpression(parseUnaryExpression(), token.type); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1687 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1688 case T.Not: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1689 nT(); e = new NotExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1690 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1691 case T.Tilde: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1692 nT(); e = new CompExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1693 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1694 case T.New: |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1695 e = parseNewExpression(); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1696 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1697 case T.Delete: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1698 nT(); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1699 e = new DeleteExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1700 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1701 case T.Cast: |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1702 requireNext(T.LParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1703 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1704 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1705 e = new CastExpression(parseUnaryExpression(), type); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1706 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1707 case T.LParen: |
102 | 1708 // ( Type ) . Identifier |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1709 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1710 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1711 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
|
1712 string ident = requireIdentifier(); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1713 e = new TypeDotIdExpression(type, ident); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1714 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1715 default: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1716 e = parsePostExpression(parsePrimaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1717 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1718 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1719 assert(e !is null); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1720 return e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1721 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1722 |
90
a02950cb7036
- Fixed order of parsing unary, post and primary expressions.
aziz
parents:
89
diff
changeset
|
1723 Expression parsePostExpression(Expression e) |
77 | 1724 { |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1725 while (1) |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1726 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1727 switch (token.type) |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1728 { |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1729 /* |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1730 // Commented out because parseDotListExpression() handles this. |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1731 case T.Dot: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1732 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1733 if (token.type == T.Identifier) |
92 | 1734 { |
153 | 1735 string ident = token.identifier; |
1736 nT(); | |
1737 Token next; | |
1738 lx.peek(next); | |
1739 if (token.type == T.Not && next.type == T.LParen) // Identifier !( TemplateArguments ) | |
1740 { | |
1741 nT(); // Skip !. | |
1742 e = new DotTemplateInstanceExpression(e, ident, parseTemplateArguments()); | |
1743 } | |
1744 else | |
1745 { | |
1746 e = new DotIdExpression(e, ident); | |
1747 nT(); | |
1748 } | |
92 | 1749 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1750 else if (token.type == T.New) |
81 | 1751 e = parseNewExpression(e); |
92 | 1752 else |
124 | 1753 expected(T.Identifier); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1754 continue; |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1755 */ |
160
c21192e8be2b
- Parsing PostDotListExpression in parsePostExpression().
aziz
parents:
159
diff
changeset
|
1756 case T.Dot: |
c21192e8be2b
- Parsing PostDotListExpression in parsePostExpression().
aziz
parents:
159
diff
changeset
|
1757 e = new PostDotListExpression(e, parseDotListExpression()); |
c21192e8be2b
- Parsing PostDotListExpression in parsePostExpression().
aziz
parents:
159
diff
changeset
|
1758 break; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1759 case T.PlusPlus: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1760 e = new PostIncrExpression(e); |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1761 break; |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1762 case T.MinusMinus: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1763 e = new PostDecrExpression(e); |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1764 break; |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1765 case T.LParen: |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1766 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
|
1767 continue; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1768 case T.LBracket: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1769 // parse Slice- and IndexExpression |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1770 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1771 if (token.type == T.RBracket) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1772 { |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1773 e = new SliceExpression(e, null, null); |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1774 break; |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1775 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1776 |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1777 Expression[] es = [parseAssignExpression()]; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1778 |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1779 if (token.type == T.Slice) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1780 { |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1781 nT(); |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1782 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
|
1783 require(T.RBracket); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1784 continue; |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1785 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1786 else if (token.type == T.Comma) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1787 { |
143 | 1788 es ~= parseArguments(T.RBracket); |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1789 } |
85 | 1790 else |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1791 require(T.RBracket); |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1792 |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1793 e = new IndexExpression(e, es); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1794 continue; |
92 | 1795 default: |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1796 return e; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1797 } |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1798 nT(); |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1799 } |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1800 assert(0); |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1801 } |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1802 |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1803 Expression parsePrimaryExpression() |
78
f043759fb59a
- Added code to parseUnaryExpression(); not fully implemented.
aziz
parents:
77
diff
changeset
|
1804 { |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1805 Expression e; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1806 switch (token.type) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1807 { |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1808 /* |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1809 // Commented out because parseDotListExpression() handles this. |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1810 case T.Identifier: |
153 | 1811 string ident = token.identifier; |
89 | 1812 nT(); |
153 | 1813 Token next; |
1814 lx.peek(next); | |
1815 if (token.type == T.Not && next.type == T.LParen) // Identifier !( TemplateArguments ) | |
1816 { | |
1817 nT(); // Skip !. | |
1818 e = new TemplateInstanceExpression(ident, parseTemplateArguments()); | |
1819 } | |
1820 else | |
1821 e = new IdentifierExpression(ident); | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1822 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1823 case T.Dot: |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1824 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1825 e = new IdentifierExpression("."); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1826 break; |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1827 */ |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1828 case T.Identifier, T.Dot, T.Typeof: |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1829 e = parseDotListExpression(); |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1830 break; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1831 case T.This: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1832 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1833 e = new ThisExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1834 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1835 case T.Super: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1836 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1837 e = new SuperExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1838 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1839 case T.Null: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1840 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1841 e = new NullExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1842 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1843 case T.True, T.False: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1844 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1845 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
|
1846 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1847 case T.Dollar: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1848 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1849 e = new DollarExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1850 break; |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1851 case T.Int32, T.Int64, T.Uint32, T.Uint64: |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1852 nT(); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1853 e = new IntNumberExpression(token.type, token.ulong_); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1854 break; |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1855 case T.Float32, T.Float64, T.Float80, |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1856 T.Imaginary32, T.Imaginary64, T.Imaginary80: |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1857 nT(); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1858 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
|
1859 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1860 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
|
1861 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1862 e = new CharLiteralExpression(token.type); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1863 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1864 case T.String: |
157
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
1865 Token*[] stringLiterals; |
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
1866 do |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1867 { |
157
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
1868 stringLiterals ~= token; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1869 nT(); |
157
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
1870 } while (token.type == T.String) |
fdbd47d72614
- Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents:
156
diff
changeset
|
1871 e = new StringLiteralsExpression(stringLiterals); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1872 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1873 case T.LBracket: |
85 | 1874 Expression[] values; |
1875 | |
1876 nT(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1877 if (token.type != T.RBracket) |
85 | 1878 { |
1879 e = parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1880 if (token.type == T.Colon) |
85 | 1881 goto LparseAssocArray; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1882 else if (token.type == T.Comma) |
143 | 1883 values = [e] ~ parseArguments(T.RBracket); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1884 else |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1885 require(T.RBracket); |
85 | 1886 } |
1887 | |
1888 e = new ArrayLiteralExpression(values); | |
1889 break; | |
1890 | |
1891 LparseAssocArray: | |
1892 Expression[] keys; | |
1893 | |
1894 keys ~= e; | |
1895 nT(); // Skip colon. | |
1896 values ~= parseAssignExpression(); | |
1897 | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1898 if (token.type != T.RBracket) |
88 | 1899 { |
1900 require(T.Comma); | |
85 | 1901 while (1) |
1902 { | |
1903 keys ~= parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1904 if (token.type != T.Colon) |
85 | 1905 { |
124 | 1906 expected(T.Colon); |
85 | 1907 values ~= null; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1908 if (token.type == T.RBracket) |
85 | 1909 break; |
1910 else | |
1911 continue; | |
1912 } | |
1913 nT(); | |
1914 values ~= parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1915 if (token.type == T.RBracket) |
85 | 1916 break; |
88 | 1917 require(T.Comma); |
85 | 1918 } |
88 | 1919 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1920 assert(token.type == T.RBracket); |
85 | 1921 nT(); |
1922 e = new AssocArrayLiteralExpression(keys, values); | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1923 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1924 case T.LBrace: |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1925 // DelegateLiteral := { DeclDefs } |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1926 require(T.LBrace); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1927 auto decls = parseDeclarationDefinitions(); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1928 require(T.RBrace); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1929 auto func = new FunctionType(null, Parameters.init); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1930 e = new FunctionLiteralExpression(func, decls); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1931 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1932 case T.Function, T.Delegate: |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1933 // FunctionLiteral := (function|delegate) Type? '(' ArgumentList ')' '{' DeclDefs '}' |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1934 TOK funcTok = token.type; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1935 nT(); // Skip function|delegate token. |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1936 Type returnType; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1937 Parameters parameters; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1938 if (token.type != T.LBrace) |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1939 { |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1940 if (token.type != T.LParen) // Optional return type |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1941 returnType = parseType(); |
143 | 1942 parameters = parseParameterList(); |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1943 } |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1944 require(T.LBrace); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1945 auto decls = parseDeclarationDefinitions(); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1946 require(T.RBrace); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1947 auto func = new FunctionType(returnType, parameters); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1948 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
|
1949 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1950 case T.Assert: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1951 Expression msg; |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1952 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1953 e = parseAssignExpression(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1954 if (token.type == T.Comma) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1955 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1956 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1957 msg = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1958 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1959 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1960 e = new AssertExpression(e, msg); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1961 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1962 case T.Mixin: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1963 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1964 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1965 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1966 e = new MixinExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1967 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1968 case T.Import: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1969 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1970 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1971 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1972 e = new ImportExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1973 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1974 case T.Typeid: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1975 requireNext(T.LParen); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1976 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1977 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1978 e = new TypeidExpression(type); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1979 break; |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1980 /* |
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1981 // Commented out because parseDotListExpression() handles this. |
101 | 1982 case T.Typeof: |
1983 requireNext(T.LParen); | |
1984 auto type = new TypeofType(parseExpression()); | |
1985 require(T.RParen); | |
1986 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
|
1987 { // typeof ( Expression ) . Identifier |
101 | 1988 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1989 string ident = requireIdentifier; |
101 | 1990 e = new TypeDotIdExpression(type, ident); |
1991 } | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1992 else // typeof ( Expression ) |
101 | 1993 e = new TypeofExpression(type); |
1994 break; | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
1995 */ |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1996 case T.Is: |
100 | 1997 requireNext(T.LParen); |
1998 | |
1999 Type type; | |
2000 SpecializationType specType; | |
2001 string ident; // optional Identifier | |
2002 | |
2003 type = parseDeclarator(ident, true); | |
2004 | |
2005 switch (token.type) | |
2006 { | |
2007 case T.Colon, T.Equal: | |
2008 TOK specTok = token.type; | |
2009 nT(); | |
2010 switch (token.type) | |
2011 { | |
2012 case T.Typedef, | |
2013 T.Struct, | |
2014 T.Union, | |
2015 T.Class, | |
2016 T.Interface, | |
2017 T.Enum, | |
2018 T.Function, | |
2019 T.Delegate, | |
2020 T.Super, | |
2021 T.Return: | |
102 | 2022 nT(); |
100 | 2023 specType = new SpecializationType(specTok, token.type); |
2024 break; | |
2025 default: | |
2026 specType = new SpecializationType(specTok, parseType()); | |
2027 } | |
2028 default: | |
2029 } | |
102 | 2030 require(T.RParen); |
100 | 2031 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
|
2032 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2033 case T.LParen: |
130 | 2034 Token t; |
2035 bool failed; | |
143 | 2036 auto parameters = try_(parseParameterList(), failed); |
130 | 2037 if (!failed) |
2038 { | |
143 | 2039 // ( ParameterList ) FunctionBody |
130 | 2040 require(T.LBrace); |
2041 auto decls = parseDeclarationDefinitions(); | |
2042 require(T.RBrace); | |
2043 auto func = new FunctionType(null, parameters); | |
2044 e = new FunctionLiteralExpression(func, decls); | |
2045 } | |
2046 else | |
2047 { | |
131 | 2048 // ( Expression ) |
130 | 2049 nT(); |
2050 e = parseExpression(); | |
2051 require(T.RParen); | |
2052 } | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2053 break; |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2054 // BasicType . Identifier |
94 | 2055 case T.Void, T.Char, T.Wchar, T.Dchar, T.Bool, |
2056 T.Byte, T.Ubyte, T.Short, T.Ushort, | |
2057 T.Int, T.Uint, T.Long, T.Ulong, | |
2058 T.Float, T.Double, T.Real, | |
2059 T.Ifloat, T.Idouble, T.Ireal, | |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2060 T.Cfloat, T.Cdouble, T.Creal: |
94 | 2061 auto type = new Type(token.type); |
2062 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
|
2063 auto ident = requireIdentifier(); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2064 |
94 | 2065 e = new TypeDotIdExpression(type, ident); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2066 break; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
2067 default: |
136
96468715ea79
- Returning EmptyExpression in parsePrimaryExpression() when no token matched.
aziz
parents:
135
diff
changeset
|
2068 // TODO: issue error msg. |
96468715ea79
- Returning EmptyExpression in parsePrimaryExpression() when no token matched.
aziz
parents:
135
diff
changeset
|
2069 e = new EmptyExpression(); |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2070 } |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
2071 return e; |
77 | 2072 } |
2073 | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2074 Expression parseNewExpression(/*Expression e*/) |
81 | 2075 { |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2076 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
|
2077 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
|
2078 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2079 Expression[] newArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2080 Expression[] ctorArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2081 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2082 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
|
2083 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
|
2084 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2085 // NewAnonClassExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2086 // 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
|
2087 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
|
2088 { |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2089 nT(); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2090 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
|
2091 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
|
2092 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2093 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
|
2094 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2095 require(T.LBrace); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2096 auto decls = parseDeclarationDefinitions(); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2097 require(T.RBrace); |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2098 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
|
2099 } |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2100 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2101 // NewExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2102 // NewArguments Type [ AssignExpression ] |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2103 // NewArguments Type ( ArgumentList ) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2104 // NewArguments Type |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2105 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
|
2106 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
|
2107 { |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
2108 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
|
2109 } |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2110 return new NewExpression(/*e, */newArguments, type, ctorArguments); |
81 | 2111 } |
2112 | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2113 Type parseType() |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2114 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
2115 return parseBasicType2(parseBasicType()); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2116 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2117 |
94 | 2118 Type parseBasicType() |
2119 { | |
2120 Type t; | |
2121 IdentifierType tident; | |
2122 | |
2123 switch (token.type) | |
2124 { | |
2125 case T.Void, T.Char, T.Wchar, T.Dchar, T.Bool, | |
2126 T.Byte, T.Ubyte, T.Short, T.Ushort, | |
2127 T.Int, T.Uint, T.Long, T.Ulong, | |
2128 T.Float, T.Double, T.Real, | |
2129 T.Ifloat, T.Idouble, T.Ireal, | |
2130 T.Cfloat, T.Cdouble, T.Creal: | |
2131 t = new Type(token.type); | |
2132 nT(); | |
2133 break; | |
153 | 2134 /+ |
94 | 2135 case T.Identifier, T.Dot: |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
2136 tident = new IdentifierType([token.identifier]); |
94 | 2137 nT(); |
102 | 2138 // TODO: parse template instance |
94 | 2139 // if (token.type == T.Not) |
2140 // parse template instance | |
2141 Lident: | |
2142 while (token.type == T.Dot) | |
2143 { | |
2144 nT(); | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2145 tident ~= requireIdentifier(); |
102 | 2146 // TODO: parse template instance |
94 | 2147 // if (token.type == T.Not) |
2148 // parse template instance | |
2149 } | |
2150 t = tident; | |
2151 break; | |
2152 case T.Typeof: | |
2153 requireNext(T.LParen); | |
2154 tident = new TypeofType(parseExpression()); | |
2155 require(T.RParen); | |
2156 goto Lident; | |
153 | 2157 +/ |
2158 case T.Identifier, T.Typeof, T.Dot: | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
2159 t = parseDotListType(); |
153 | 2160 break; |
94 | 2161 default: |
136
96468715ea79
- Returning EmptyExpression in parsePrimaryExpression() when no token matched.
aziz
parents:
135
diff
changeset
|
2162 // 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
|
2163 t = new UndefinedType(); |
94 | 2164 } |
2165 return t; | |
2166 } | |
2167 | |
95 | 2168 Type parseBasicType2(Type t) |
2169 { | |
2170 while (1) | |
2171 { | |
2172 switch (token.type) | |
2173 { | |
2174 case T.Mul: | |
2175 t = new PointerType(t); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2176 nT(); |
95 | 2177 break; |
2178 case T.LBracket: | |
106 | 2179 t = parseArrayType(t); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2180 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2181 case T.Function, T.Delegate: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2182 TOK tok = token.type; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2183 nT(); |
143 | 2184 auto parameters = parseParameterList(); |
135 | 2185 t = new FunctionType(t, parameters); |
2186 if (tok == T.Function) | |
2187 t = new PointerType(t); | |
2188 else | |
2189 t = new DelegateType(t); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2190 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2191 default: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2192 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2193 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2194 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2195 assert(0); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2196 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2197 |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2198 Type parseDeclaratorSuffix(Type t) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2199 { |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2200 while (1) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2201 { |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2202 switch (token.type) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2203 { |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2204 case T.LBracket: |
131 | 2205 // Type Identifier ArrayType |
2206 // ArrayType := [] or [Type] or [Expression..Expression] | |
106 | 2207 t = parseArrayType(t); |
95 | 2208 continue; |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2209 case T.LParen: |
143 | 2210 auto params = parseParameterList(); |
131 | 2211 // TODO: handle ( TemplateParameterList ) ( ParameterList ) |
2212 // ReturnType FunctionName ( ParameterList ) | |
2213 t = new FunctionType(t, params); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2214 break; |
100 | 2215 default: |
2216 break; | |
95 | 2217 } |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2218 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2219 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2220 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2221 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2222 |
106 | 2223 Type parseArrayType(Type t) |
2224 { | |
2225 assert(token.type == T.LBracket); | |
2226 nT(); | |
2227 if (token.type == T.RBracket) | |
2228 { | |
2229 t = new ArrayType(t); | |
2230 nT(); | |
2231 } | |
2232 else | |
2233 { | |
2234 bool failed; | |
2235 auto assocType = try_(parseType(), failed); | |
2236 if (!failed) | |
2237 t = new ArrayType(t, assocType); | |
2238 else | |
2239 { | |
2240 Expression e = parseExpression(), e2; | |
2241 if (token.type == T.Slice) | |
2242 { | |
2243 nT(); | |
2244 e2 = parseExpression(); | |
2245 } | |
2246 t = new ArrayType(t, e, e2); | |
2247 } | |
2248 require(T.RBracket); | |
2249 } | |
2250 return t; | |
2251 } | |
2252 | |
100 | 2253 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
|
2254 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
2255 auto t = parseType(); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2256 |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2257 if (token.type == T.Identifier) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2258 { |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
2259 ident = token.identifier; |
95 | 2260 nT(); |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
2261 t = parseDeclaratorSuffix(t); |
95 | 2262 } |
100 | 2263 else if (!identOptional) |
124 | 2264 expected(T.Identifier); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
2265 |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
2266 return t; |
95 | 2267 } |
2268 | |
143 | 2269 Expression[] parseArguments(TOK terminator) |
138 | 2270 { |
155 | 2271 assert(token.type == T.LParen || token.type == T.LBracket || token.type == T.Comma); |
2272 assert(terminator == T.RParen || terminator == T.RBracket); | |
139 | 2273 Expression[] args; |
138 | 2274 |
2275 nT(); | |
2276 if (token.type == terminator) | |
2277 { | |
2278 nT(); | |
2279 return null; | |
2280 } | |
2281 | |
139 | 2282 goto LenterLoop; |
2283 do | |
138 | 2284 { |
139 | 2285 nT(); |
2286 LenterLoop: | |
2287 args ~= parseAssignExpression(); | |
2288 } while (token.type == T.Comma) | |
2289 | |
2290 require(terminator); | |
2291 return args; | |
138 | 2292 } |
2293 | |
143 | 2294 Parameters parseParameterList() |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2295 out(params) |
96 | 2296 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2297 if (params.length > 1) |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2298 foreach (param; params.items[0..$-1]) |
96 | 2299 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2300 if (param.isVariadic()) |
96 | 2301 assert(0, "variadic arguments can only appear at the end of the parameter list."); |
2302 } | |
2303 } | |
2304 body | |
95 | 2305 { |
2306 require(T.LParen); | |
2307 | |
2308 if (token.type == T.RParen) | |
2309 { | |
2310 nT(); | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2311 return Parameters.init; |
95 | 2312 } |
2313 | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2314 Parameters params; |
95 | 2315 StorageClass stc; |
2316 | |
2317 while (1) | |
2318 { | |
2319 stc = StorageClass.In; | |
2320 switch (token.type) | |
2321 { | |
2322 case T.In: stc = StorageClass.In; nT(); goto default; | |
2323 case T.Out: stc = StorageClass.Out; nT(); goto default; | |
2324 case T.Ref: stc = StorageClass.Ref; nT(); goto default; | |
2325 case T.Lazy: stc = StorageClass.Lazy; nT(); goto default; | |
2326 case T.Ellipses: | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2327 params ~= new Parameter(StorageClass.Variadic, null, null, null); |
95 | 2328 break; |
2329 default: | |
2330 string ident; | |
130 | 2331 auto type = parseDeclarator(ident, true); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
2332 |
95 | 2333 Expression assignExpr; |
2334 if (token.type == T.Assign) | |
2335 { | |
2336 nT(); | |
2337 assignExpr = parseAssignExpression(); | |
2338 } | |
2339 | |
2340 if (token.type == T.Ellipses) | |
2341 { | |
2342 stc |= StorageClass.Variadic; | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2343 params ~= new Parameter(stc, type, ident, assignExpr); |
95 | 2344 nT(); |
2345 break; | |
2346 } | |
2347 | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2348 params ~= new Parameter(stc, type, ident, assignExpr); |
95 | 2349 if (token.type == T.Comma) |
2350 { | |
2351 nT(); | |
2352 continue; | |
2353 } | |
2354 break; | |
2355 } | |
2356 break; | |
2357 } | |
2358 require(T.RParen); | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
2359 return params; |
95 | 2360 } |
2361 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
2362 TemplateArguments parseTemplateArguments() |
139 | 2363 { |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
2364 TemplateArguments args; |
139 | 2365 |
2366 require(T.LParen); | |
2367 if (token.type == T.RParen) | |
2368 { | |
2369 nT(); | |
2370 return null; | |
2371 } | |
2372 | |
2373 goto LenterLoop; | |
2374 do | |
2375 { | |
2376 nT(); // Skip comma. | |
2377 LenterLoop: | |
2378 | |
2379 bool failed; | |
2380 auto typeArgument = try_(parseType(), failed); | |
2381 | |
2382 if (!failed) | |
2383 { | |
2384 // TemplateArgument: | |
2385 // Type | |
2386 // Symbol | |
2387 args ~= typeArgument; | |
2388 } | |
2389 else | |
2390 { | |
2391 // TemplateArgument: | |
2392 // AssignExpression | |
2393 args ~= parseAssignExpression(); | |
2394 } | |
2395 } while (token.type == T.Comma) | |
2396 | |
2397 require(T.RParen); | |
2398 return args; | |
2399 } | |
2400 | |
143 | 2401 TemplateParameter[] parseTemplateParameterList() |
137 | 2402 { |
2403 require(T.LParen); | |
2404 if (token.type == T.RParen) | |
2405 return null; | |
2406 | |
2407 TemplateParameter[] tparams; | |
2408 while (1) | |
2409 { | |
2410 TP tp; | |
2411 string ident; | |
2412 Type valueType; | |
2413 Type specType, defType; | |
2414 Expression specValue, defValue; | |
2415 | |
2416 switch (token.type) | |
2417 { | |
2418 case T.Alias: | |
2419 // TemplateAliasParameter: | |
2420 // alias Identifier | |
2421 tp = TP.Alias; | |
2422 nT(); // Skip alias keyword. | |
2423 ident = requireIdentifier(); | |
2424 // : SpecializationType | |
2425 if (token.type == T.Colon) | |
2426 { | |
2427 nT(); | |
2428 specType = parseType(); | |
2429 } | |
2430 // = DefaultType | |
2431 if (token.type == T.Assign) | |
2432 { | |
2433 nT(); | |
2434 defType = parseType(); | |
2435 } | |
2436 break; | |
2437 case T.Identifier: | |
2438 ident = token.identifier; | |
2439 Token peeked; | |
2440 lx.peek(peeked); | |
2441 switch (peeked.type) | |
2442 { | |
2443 case T.Ellipses: | |
2444 // TemplateTupleParameter: | |
2445 // Identifier ... | |
2446 tp = TP.Tuple; | |
2447 nT(); // Skip Identifier. | |
2448 nT(); // Skip Ellipses. | |
2449 // if (token.type == T.Comma) | |
2450 // error(); // TODO: issue error msg for variadic param not being last. | |
2451 break; | |
2452 case T.Comma, T.RParen, T.Colon, T.Assign: | |
2453 // TemplateTypeParameter: | |
2454 // Identifier | |
2455 tp = TP.Type; | |
2456 nT(); // Skip Identifier. | |
2457 // : SpecializationType | |
2458 if (token.type == T.Colon) | |
2459 { | |
2460 nT(); | |
2461 specType = parseType(); | |
2462 } | |
2463 // = DefaultType | |
2464 if (token.type == T.Assign) | |
2465 { | |
2466 nT(); | |
2467 defType = parseType(); | |
2468 } | |
2469 break; | |
2470 default: | |
2471 // TemplateValueParameter: | |
2472 // Declarator | |
2473 ident = null; | |
2474 goto LTemplateValueParameter; | |
2475 } | |
2476 break; | |
2477 default: | |
2478 LTemplateValueParameter: | |
2479 // TemplateValueParameter: | |
2480 // Declarator | |
2481 tp = TP.Value; | |
2482 valueType = parseDeclarator(ident); | |
2483 // : SpecializationValue | |
2484 if (token.type == T.Colon) | |
2485 { | |
2486 nT(); | |
2487 specValue = parseCondExpression(); | |
2488 } | |
2489 // = DefaultValue | |
2490 if (token.type == T.Assign) | |
2491 { | |
2492 nT(); | |
2493 defValue = parseCondExpression(); | |
2494 } | |
2495 } | |
2496 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
2497 tparams ~= new TemplateParameter(tp, valueType, ident, specType, defType, specValue, defValue); |
137 | 2498 |
2499 if (token.type != T.Comma) | |
2500 break; | |
2501 nT(); | |
2502 } | |
2503 require(T.RParen); | |
2504 return tparams; | |
2505 } | |
2506 | |
124 | 2507 void expected(TOK tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2508 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2509 if (token.type != tok) |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2510 error(MID.ExpectedButFound, tok, token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2511 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2512 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2513 void require(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2514 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2515 if (token.type == tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2516 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2517 else |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2518 error(MID.ExpectedButFound, tok, token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2519 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2520 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2521 void requireNext(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2522 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2523 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2524 if (token.type == tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2525 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2526 else |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2527 error(MID.ExpectedButFound, tok, token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2528 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2529 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2530 string requireIdentifier() |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2531 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2532 string identifier; |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2533 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
|
2534 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2535 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
|
2536 nT(); |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2537 } |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2538 else |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2539 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
|
2540 return identifier; |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2541 } |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2542 |
71 | 2543 void error(MID id, ...) |
2544 { | |
94 | 2545 errors ~= new Information(InfoType.Parser, id, lx.loc, arguments(_arguments, _argptr)); |
71 | 2546 } |
65 | 2547 } |