Mercurial > projects > dil
annotate trunk/src/Parser.d @ 152:fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
author | aziz |
---|---|
date | Thu, 12 Jul 2007 21:23:00 +0000 |
parents | 2e959f67000b |
children | 66790fc2c0a2 |
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) |
110 | 87 decls ~= parseDeclarationDefinitions(); |
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 | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
230 Statement[] parseStatements() |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
231 { |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
232 return null; |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
233 } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
234 |
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
|
235 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
|
236 { |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
237 Declaration decl; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
238 |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
239 switch (token.type) |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
240 { |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
241 case T.Extern: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
242 nT(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
243 string linkage; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
244 if (token.type == T.LParen) |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
245 { |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
246 nT(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
247 linkage = requireIdentifier(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
248 require(T.RParen); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
249 } |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
250 decl = new ExternDeclaration(linkage, parseDeclarationsBlock()); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
251 break; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
252 case T.Align: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
253 nT(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
254 int size = -1; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
255 if (token.type == T.LParen) |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
256 { |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
257 nT(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
258 if (token.type == T.Int32) |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
259 { |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
260 size = token.int_; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
261 nT(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
262 } |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
263 else |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
264 expected(T.Int32); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
265 require(T.RParen); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
266 } |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
267 decl = new AlignDeclaration(size, parseDeclarationsBlock()); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
268 break; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
269 case T.Pragma: |
147 | 270 // Pragma: |
271 // pragma ( Identifier ) | |
272 // pragma ( Identifier , ExpressionList ) | |
273 // ExpressionList: | |
274 // AssignExpression | |
275 // AssignExpression , ExpressionList | |
276 nT(); | |
277 string ident; | |
278 Expression[] args; | |
279 Declaration[] decls; | |
280 | |
281 require(T.LParen); | |
282 ident = requireIdentifier(); | |
283 | |
284 if (token.type == T.Comma) | |
285 args = parseArguments(T.RParen); | |
286 else | |
287 require(T.RParen); | |
288 | |
289 if (token.type == T.Semicolon) | |
290 nT(); | |
291 else | |
292 decls = parseDeclarationsBlock(); | |
293 | |
294 decl = new PragmaDeclaration(ident, args, decls); | |
295 break; | |
149 | 296 // Protection attributes |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
297 case T.Private: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
298 case T.Package: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
299 case T.Protected: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
300 case T.Public: |
148 | 301 case T.Export: |
149 | 302 // StorageClass attributes |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
303 case T.Override: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
304 case T.Deprecated: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
305 case T.Abstract: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
306 case T.Static: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
307 case T.Final: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
308 case T.Const: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
309 case T.Auto: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
310 case T.Scope: |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
311 nT(); |
149 | 312 decl = new AttributeDeclaration(token.type, parseDeclarationsBlock()); |
313 break; | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
314 default: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
315 assert(0); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
316 } |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
317 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
|
318 } |
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
|
319 |
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
|
320 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
|
321 { |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
322 assert(token.type == T.Import || token.type == T.Static); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
323 |
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
|
324 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
|
325 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
|
326 |
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
|
327 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
|
328 { |
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
|
329 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
|
330 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
|
331 } |
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
|
332 |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
333 ModuleName[] moduleNames; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
334 string[] moduleAliases; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
335 string[] bindNames; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
336 string[] bindAliases; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
337 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
338 nT(); // Skip import keyword. |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
339 do |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
340 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
341 ModuleName moduleName; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
342 string moduleAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
343 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
344 moduleAlias = requireIdentifier(); |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
345 |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
346 // AliasName = ModuleName |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
347 if (token.type == T.Assign) |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
348 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
349 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
350 moduleName ~= requireIdentifier(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
351 } |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
352 else // import Identifier [^=] |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
353 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
354 moduleName ~= moduleAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
355 moduleAlias = null; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
356 } |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
357 |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
358 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
359 // parse Identifier(.Identifier)* |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
360 while (token.type == T.Dot) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
361 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
362 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
363 moduleName ~= requireIdentifier(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
364 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
365 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
366 // Push identifiers. |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
367 moduleNames ~= moduleName; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
368 moduleAliases ~= moduleAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
369 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
370 // parse : BindAlias = BindName(, BindAlias = BindName)*; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
371 // : BindName(, BindName)*; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
372 if (token.type == T.Colon) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
373 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
374 string bindName, bindAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
375 do |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
376 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
377 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
378 bindAlias = requireIdentifier(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
379 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
380 if (token.type == T.Assign) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
381 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
382 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
383 bindName = requireIdentifier(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
384 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
385 else |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
386 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
387 bindName = bindAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
388 bindAlias = null; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
389 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
390 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
391 // Push identifiers. |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
392 bindNames ~= bindName; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
393 bindAliases ~= bindAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
394 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
395 } while (token.type == T.Comma) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
396 break; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
397 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
398 } while (token.type == T.Comma) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
399 require(T.Semicolon); |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
400 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
401 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
|
402 } |
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
|
403 |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
404 Declaration parseEnumDeclaration() |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
405 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
406 assert(token.type == T.Enum); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
407 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
408 string enumName; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
409 Type baseType; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
410 string[] members; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
411 Expression[] values; |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
412 bool hasBody; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
413 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
414 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
|
415 enumName = requireIdentifier(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
416 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
417 if (token.type == T.Colon) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
418 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
419 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
420 baseType = parseBasicType(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
421 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
422 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
423 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
|
424 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
425 //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
|
426 // 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
|
427 nT(); |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
428 } |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
429 else if (token.type == T.LBrace) |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
430 { |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
431 hasBody = true; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
432 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
433 do |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
434 { |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
435 members ~= requireIdentifier(); |
107
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 if (token.type == T.Assign) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
438 { |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
439 nT(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
440 values ~= parseAssignExpression(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
441 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
442 else |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
443 values ~= null; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
444 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
445 if (token.type == T.Comma) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
446 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
447 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
|
448 { |
124 | 449 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
|
450 break; |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
451 } |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
452 } while (token.type != T.RBrace) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
453 nT(); |
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 |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
456 return new EnumDeclaration(enumName, baseType, members, values, hasBody); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
457 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
458 |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
459 Declaration parseClassDeclaration() |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
460 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
461 assert(token.type == T.Class); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
462 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
463 string className; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
464 BaseClass[] bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
465 Declaration[] decls; |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
466 bool hasBody; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
467 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
468 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
|
469 className = requireIdentifier(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
470 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
471 if (token.type == T.LParen) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
472 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
473 // TODO: parse template parameters |
140 | 474 // parseTemplateParameters(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
475 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
476 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
477 if (token.type == T.Colon) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
478 bases = parseBaseClasses(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
479 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
480 if (token.type == T.Semicolon) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
481 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
482 //if (bases.length != 0) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
483 // error: bases classes are not allowed in forward declarations. |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
484 nT(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
485 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
486 else if (token.type == T.LBrace) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
487 { |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
488 hasBody = true; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
489 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
490 // 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 | 491 decls = parseDeclarationDefinitions(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
492 require(T.RBrace); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
493 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
494 else |
124 | 495 expected(T.LBrace); // TODO: better error msg |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
496 |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
497 // TODO: error if decls.length == 0 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
498 |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
499 return new ClassDeclaration(className, bases, decls, hasBody); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
500 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
501 |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
502 BaseClass[] parseBaseClasses(bool colonLeadsOff = true) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
503 { |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
504 if (colonLeadsOff) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
505 { |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
506 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
|
507 nT(); // Skip colon |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
508 } |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
509 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
510 BaseClass[] bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
511 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
512 while (1) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
513 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
514 Protection prot = Protection.Public; |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
515 string name; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
516 switch (token.type) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
517 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
518 case T.Identifier: goto LisIdentifier; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
519 case T.Private: prot = Protection.Private; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
520 case T.Protected: prot = Protection.Protected; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
521 case T.Package: prot = Protection.Package; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
522 case T.Public: /*prot = Protection.Public;*/ break; |
140 | 523 //case T.Dot: // TODO: What about "class Foo : .Bar"? |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
524 default: |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
525 // TODO: issue error msg |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
526 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
527 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
528 nT(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
529 if (token.type == T.Identifier) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
530 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
531 LisIdentifier: |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
532 name = token.identifier; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
533 nT(); |
112 | 534 // TODO: handle template instantiations: class Foo : Bar!(int) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
535 } |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
536 else |
124 | 537 expected(T.Identifier); |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
538 bases ~= new BaseClass(prot, name); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
539 if (token.type != T.Comma) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
540 break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
541 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
542 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
543 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
544 |
112 | 545 Declaration parseInterfaceDeclaration() |
546 { | |
547 assert(token.type == T.Interface); | |
548 | |
549 string name; | |
550 BaseClass[] bases; | |
551 Declaration[] decls; | |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
552 bool hasBody; |
112 | 553 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
554 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
|
555 name = requireIdentifier(); |
112 | 556 |
557 if (token.type == T.LParen) | |
558 { | |
559 // TODO: parse template parameters | |
560 } | |
561 | |
562 if (token.type == T.Colon) | |
563 bases = parseBaseClasses(); | |
564 | |
565 if (token.type == T.Semicolon) | |
566 { | |
567 //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
|
568 // TODO: error: base classes are not allowed in forward declarations. |
112 | 569 nT(); |
570 } | |
571 else if (token.type == T.LBrace) | |
572 { | |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
573 hasBody = true; |
112 | 574 nT(); |
575 decls = parseDeclarationDefinitions(); | |
576 require(T.RBrace); | |
577 } | |
578 else | |
124 | 579 expected(T.LBrace); // TODO: better error msg |
112 | 580 |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
581 // TODO: error if decls.length == 0 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
582 |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
583 return new InterfaceDeclaration(name, bases, decls, hasBody); |
112 | 584 } |
585 | |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
586 Declaration parseAggregateDeclaration() |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
587 { |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
588 assert(token.type == T.Struct || token.type == T.Union); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
589 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
590 TOK tok = token.type; |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
591 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
592 string name; |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
593 Declaration[] decls; |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
594 bool hasBody; |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
595 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
596 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
|
597 // name is optional. |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
598 if (token.type == T.Identifier) |
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 name = token.identifier; |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
601 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
602 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
|
603 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
604 // 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
|
605 } |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
606 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
607 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
608 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
|
609 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
610 //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
|
611 // TODO: error: forward declarations must have a name. |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
612 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
613 } |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
614 else if (token.type == T.LBrace) |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
615 { |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
616 hasBody = true; |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
617 nT(); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
618 decls = parseDeclarationDefinitions(); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
619 require(T.RBrace); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
620 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
621 else |
124 | 622 expected(T.LBrace); // TODO: better error msg |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
623 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
624 // TODO: error if decls.length == 0 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
625 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
626 if (tok == T.Struct) |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
627 return new StructDeclaration(name, decls, hasBody); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
628 else |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
629 return new UnionDeclaration(name, decls, hasBody); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
630 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
631 |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
632 Declaration parseConstructorDeclaration() |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
633 { |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
634 assert(token.type == T.This); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
635 nT(); // Skip 'this' keyword. |
143 | 636 auto parameters = parseParameterList(); |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
637 require(T.LBrace); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
638 auto statements = parseStatements(); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
639 require(T.RBrace); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
640 return new ConstructorDeclaration(parameters, statements); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
641 } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
642 |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
643 Declaration parseDestructorDeclaration() |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
644 { |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
645 assert(token.type == T.Tilde); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
646 nT(); // Skip ~ |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
647 require(T.This); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
648 require(T.LParen); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
649 require(T.RParen); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
650 require(T.LBrace); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
651 auto statements = parseStatements(); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
652 require(T.RBrace); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
653 return new DestructorDeclaration(statements); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
654 } |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
655 |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
656 Declaration parseStaticConstructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
657 { |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
658 assert(token.type == T.Static); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
659 nT(); // Skip static keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
660 nT(); // Skip 'this' keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
661 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
662 require(T.RParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
663 require(T.LBrace); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
664 auto statements = parseStatements(); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
665 require(T.RBrace); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
666 return new StaticConstructorDeclaration(statements); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
667 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
668 |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
669 Declaration parseStaticDestructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
670 { |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
671 assert(token.type == T.Static); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
672 nT(); // Skip static keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
673 nT(); // Skip ~ |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
674 require(T.This); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
675 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
676 require(T.RParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
677 require(T.LBrace); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
678 auto statements = parseStatements(); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
679 require(T.RBrace); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
680 return new StaticDestructorDeclaration(statements); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
681 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
682 |
120 | 683 Declaration parseInvariantDeclaration() |
684 { | |
685 assert(token.type == T.Invariant); | |
686 nT(); // Skip invariant keyword. | |
687 // Optional () for getting ready porting to D 2.0 | |
688 if (token.type == T.LParen) | |
122 | 689 requireNext(T.RParen); |
120 | 690 require(T.LBrace); |
691 auto statements = parseStatements(); | |
692 require(T.RBrace); | |
693 return new InvariantDeclaration(statements); | |
694 } | |
695 | |
121 | 696 Declaration parseUnittestDeclaration() |
697 { | |
698 assert(token.type == T.Unittest); | |
699 | |
122 | 700 nT(); // Skip unittest keyword. |
121 | 701 require(T.LBrace); |
702 auto statements = parseStatements(); | |
703 require(T.RBrace); | |
704 return new UnittestDeclaration(statements); | |
705 } | |
706 | |
122 | 707 Declaration parseDebugDeclaration() |
708 { | |
709 assert(token.type == T.Debug); | |
710 | |
711 nT(); // Skip debug keyword. | |
712 | |
713 int levelSpec = -1; // debug = Integer ; | |
714 string identSpec; // debug = Identifier ; | |
715 int levelCond = -1; // debug ( Integer ) | |
716 string identCond; // debug ( Identifier ) | |
717 Declaration[] decls, elseDecls; | |
718 | |
123 | 719 void parseIdentOrInt(ref string ident, ref int level) |
122 | 720 { |
721 nT(); | |
722 if (token.type == T.Int32) | |
123 | 723 level = token.int_; |
122 | 724 else if (token.type == T.Identifier) |
123 | 725 ident = token.identifier; |
122 | 726 else |
124 | 727 expected(T.Identifier); // TODO: better error msg |
122 | 728 nT(); |
123 | 729 } |
730 | |
731 if (token.type == T.Assign) | |
732 { | |
733 parseIdentOrInt(identSpec, levelSpec); | |
122 | 734 require(T.Semicolon); |
735 } | |
736 else | |
737 { | |
123 | 738 // Condition: |
739 // Integer | |
740 // Identifier | |
741 // ( Condition ) | |
122 | 742 if (token.type == T.LParen) |
743 { | |
123 | 744 parseIdentOrInt(identCond, levelCond); |
122 | 745 require(T.RParen); |
746 } | |
747 | |
123 | 748 // debug DeclarationsBlock |
749 // debug ( Condition ) DeclarationsBlock | |
750 decls = parseDeclarationsBlock(); | |
751 | |
752 // else DeclarationsBlock | |
753 // debug without condition and else statement makes no sense | |
754 if (token.type == T.Else && (levelCond != -1 || identCond.length != 0)) | |
122 | 755 { |
123 | 756 nT(); |
757 //if (token.type == T.Colon) | |
758 // TODO: avoid "else:"? | |
759 elseDecls = parseDeclarationsBlock(); | |
760 } | |
761 // else | |
762 // TODO: issue error msg | |
763 } | |
764 | |
765 return new DebugDeclaration(levelSpec, identSpec, levelCond, identCond, decls, elseDecls); | |
766 } | |
767 | |
768 Declaration parseVersionDeclaration() | |
769 { | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
770 assert(token.type == T.Version); |
123 | 771 |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
772 nT(); // Skip version keyword. |
123 | 773 |
774 int levelSpec = -1; // version = Integer ; | |
775 string identSpec; // version = Identifier ; | |
776 int levelCond = -1; // version ( Integer ) | |
777 string identCond; // version ( Identifier ) | |
778 Declaration[] decls, elseDecls; | |
122 | 779 |
123 | 780 void parseIdentOrInt(ref string ident, ref int level) |
781 { | |
782 nT(); | |
783 if (token.type == T.Int32) | |
784 level = token.int_; | |
785 else if (token.type == T.Identifier) | |
786 ident = token.identifier; | |
787 else | |
124 | 788 expected(T.Identifier); // TODO: better error msg |
123 | 789 nT(); |
790 } | |
791 | |
792 if (token.type == T.Assign) | |
793 { | |
794 parseIdentOrInt(identSpec, levelSpec); | |
795 require(T.Semicolon); | |
796 } | |
797 else | |
798 { | |
799 // Condition: | |
800 // Integer | |
801 // Identifier | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
802 |
123 | 803 // ( Condition ) |
804 require(T.LParen); | |
805 parseIdentOrInt(identCond, levelCond); | |
806 require(T.RParen); | |
807 | |
808 // version ( Condition ) DeclarationsBlock | |
809 decls = parseDeclarationsBlock(); | |
810 | |
811 // else DeclarationsBlock | |
812 if (token.type == T.Else) | |
813 { | |
814 nT(); | |
815 //if (token.type == T.Colon) | |
816 // TODO: avoid "else:"? | |
817 elseDecls = parseDeclarationsBlock(); | |
122 | 818 } |
819 } | |
820 | |
123 | 821 return new VersionDeclaration(levelSpec, identSpec, levelCond, identCond, decls, elseDecls); |
122 | 822 } |
823 | |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
824 Declaration parseStaticIfDeclaration() |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
825 { |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
826 assert(token.type == T.Static); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
827 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
828 nT(); // Skip static keyword. |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
829 nT(); // Skip if keyword. |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
830 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
831 Expression condition; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
832 Declaration[] ifDecls, elseDecls; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
833 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
834 require(T.LParen); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
835 condition = parseAssignExpression(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
836 require(T.RParen); |
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 if (token.type != T.Colon) |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
839 ifDecls = parseDeclarationsBlock(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
840 else |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
841 expected(T.LBrace); // TODO: better error msg |
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 if (token.type == T.Else) |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
844 { |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
845 nT(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
846 if (token.type != T.Colon) |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
847 elseDecls = parseDeclarationsBlock(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
848 else |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
849 expected(T.LBrace); // TODO: better error msg |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
850 } |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
851 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
852 return new StaticIfDeclaration(condition, ifDecls, elseDecls); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
853 } |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
854 |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
855 Declaration parseStaticAssertDeclaration() |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
856 { |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
857 assert(token.type == T.Static); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
858 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
859 nT(); // Skip static keyword. |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
860 nT(); // Skip assert keyword. |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
861 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
862 Expression condition, message; |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
863 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
864 require(T.LParen); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
865 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
866 condition = parseAssignExpression(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
867 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
868 if (token.type == T.Comma) |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
869 { |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
870 nT(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
871 message = parseAssignExpression(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
872 } |
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 require(T.RParen); |
128 | 875 require(T.Semicolon); |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
876 |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
877 return new StaticAssertDeclaration(condition, message); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
878 } |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
879 |
140 | 880 Declaration parseTemplateDeclaration() |
881 { | |
882 assert(token.type == T.Template); | |
883 nT(); // Skip template keyword. | |
884 auto templateName = requireIdentifier(); | |
143 | 885 auto templateParams = parseTemplateParameterList(); |
140 | 886 require(T.LBrace); |
887 auto decls = parseDeclarationDefinitions(); | |
888 require(T.RBrace); | |
889 return new TemplateDeclaration(templateName, templateParams, decls); | |
890 } | |
891 | |
141 | 892 Declaration parseNewDeclaration() |
893 { | |
894 assert(token.type == T.New); | |
895 nT(); // Skip new keyword. | |
143 | 896 auto parameters = parseParameterList(); |
141 | 897 require(T.LBrace); |
898 auto decls = parseDeclarationDefinitions(); | |
899 require(T.RBrace); | |
900 return new NewDeclaration(parameters, decls); | |
901 } | |
902 | |
903 Declaration parseDeleteDeclaration() | |
904 { | |
905 assert(token.type == T.Delete); | |
906 nT(); // Skip delete keyword. | |
143 | 907 auto parameters = parseParameterList(); |
141 | 908 // TODO: only one parameter of type void* allowed. |
909 require(T.LBrace); | |
910 auto decls = parseDeclarationDefinitions(); | |
911 require(T.RBrace); | |
912 return new DeleteDeclaration(parameters, decls); | |
913 } | |
914 | |
152
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
915 // IdentifierListExpression: |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
916 // .IdentifierList |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
917 // IdentifierList |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
918 // Typeof |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
919 // Typeof . IdentifierList |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
920 // IdentifierList: |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
921 // Identifier |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
922 // Identifier . IdentifierList |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
923 // TemplateInstance |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
924 // TemplateInstance . IdentifierList |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
925 // TemplateInstance: |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
926 // Identifier !( TemplateArgumentList ) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
927 IdentifierListExpression parseIdentifierListExpression() |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
928 { |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
929 Expression[] identList; |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
930 if (token.type == T.Dot) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
931 { |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
932 nT(); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
933 identList ~= new IdentifierExpression("."); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
934 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
935 else if (token.type == T.Typeof) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
936 { |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
937 requireNext(T.LParen); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
938 auto type = new TypeofType(parseExpression()); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
939 require(T.RParen); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
940 identList ~= new TypeofExpression(type); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
941 if (token.type != T.Dot) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
942 return new IdentifierListExpression(identList); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
943 nT(); |
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 |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
946 while (1) |
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 string ident = requireIdentifier(); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
949 Token next; |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
950 lx.peek(next); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
951 if (token.type == T.Not && next.type == T.LParen) // Identifier !( TemplateArguments ) |
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 nT(); // Skip !. |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
954 identList ~= new TemplateInstanceExpression(ident, parseTemplateArguments()); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
955 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
956 else // Identifier |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
957 identList ~= new IdentifierExpression(ident); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
958 |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
959 if (token.type != T.Dot) |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
960 break; |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
961 nT(); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
962 } |
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 return new IdentifierListExpression(identList); |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
965 } |
fe2e36eb4b45
- Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents:
151
diff
changeset
|
966 |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
967 /* |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
968 TemplateMixin: |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
969 mixin ( AssignExpression ) ; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
970 mixin TemplateIdentifier ; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
971 mixin TemplateIdentifier MixinIdentifier ; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
972 mixin TemplateIdentifier !( TemplateArgumentList ) ; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
973 mixin TemplateIdentifier !( TemplateArgumentList ) MixinIdentifier ; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
974 */ |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
975 Declaration parseMixinDeclaration() |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
976 { |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
977 assert(token.type == T.Mixin); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
978 nT(); // Skip mixin keyword. |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
979 |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
980 if (token.type == T.LParen) |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
981 { |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
982 // TODO: What about mixin(...).ident;? |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
983 nT(); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
984 auto e = parseAssignExpression(); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
985 require(T.RParen); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
986 require(T.Semicolon); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
987 return new MixinDeclaration(e); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
988 } |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
989 |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
990 Expression[] templateIdent; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
991 string mixinIdent; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
992 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
993 if (token.type == T.Dot) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
994 { |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
995 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
996 templateIdent ~= new IdentifierExpression("."); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
997 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
998 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
999 while (1) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1000 { |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1001 string ident = requireIdentifier(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1002 if (token.type == T.Not) // Identifier !( TemplateArguments ) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1003 { |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1004 // 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
|
1005 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1006 templateIdent ~= new TemplateInstanceExpression(ident, parseTemplateArguments()); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1007 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1008 else // Identifier |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1009 templateIdent ~= new IdentifierExpression(ident); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1010 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1011 if (token.type != T.Dot) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1012 break; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1013 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1014 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1015 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1016 if (token.type == T.Identifier) |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1017 { |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1018 mixinIdent = token.identifier; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1019 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1020 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1021 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1022 require(T.Semicolon); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1023 |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1024 return new MixinDeclaration(templateIdent, mixinIdent); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1025 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1026 |
102 | 1027 /+++++++++++++++++++++++++++++ |
1028 + Expression parsing methods + | |
1029 +++++++++++++++++++++++++++++/ | |
1030 | |
72 | 1031 Expression parseExpression() |
1032 { | |
1033 auto e = parseAssignExpression(); | |
122 | 1034 while (token.type == T.Comma) |
81 | 1035 e = new CommaExpression(e, parseAssignExpression()); |
72 | 1036 return e; |
1037 } | |
1038 | |
71 | 1039 Expression parseAssignExpression() |
1040 { | |
1041 auto e = parseCondExpression(); | |
72 | 1042 while (1) |
71 | 1043 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1044 switch (token.type) |
72 | 1045 { |
1046 case T.Assign: | |
1047 nT(); e = new AssignExpression(e, parseAssignExpression()); | |
1048 break; | |
1049 case T.LShiftAssign: | |
1050 nT(); e = new LShiftAssignExpression(e, parseAssignExpression()); | |
1051 break; | |
1052 case T.RShiftAssign: | |
1053 nT(); e = new RShiftAssignExpression(e, parseAssignExpression()); | |
1054 break; | |
1055 case T.URShiftAssign: | |
1056 nT(); e = new URShiftAssignExpression(e, parseAssignExpression()); | |
1057 break; | |
1058 case T.OrAssign: | |
1059 nT(); e = new OrAssignExpression(e, parseAssignExpression()); | |
1060 break; | |
1061 case T.AndAssign: | |
1062 nT(); e = new AndAssignExpression(e, parseAssignExpression()); | |
1063 break; | |
1064 case T.PlusAssign: | |
1065 nT(); e = new PlusAssignExpression(e, parseAssignExpression()); | |
1066 break; | |
1067 case T.MinusAssign: | |
1068 nT(); e = new MinusAssignExpression(e, parseAssignExpression()); | |
1069 break; | |
1070 case T.DivAssign: | |
1071 nT(); e = new DivAssignExpression(e, parseAssignExpression()); | |
1072 break; | |
1073 case T.MulAssign: | |
1074 nT(); e = new MulAssignExpression(e, parseAssignExpression()); | |
1075 break; | |
1076 case T.ModAssign: | |
1077 nT(); e = new ModAssignExpression(e, parseAssignExpression()); | |
1078 break; | |
1079 case T.XorAssign: | |
1080 nT(); e = new XorAssignExpression(e, parseAssignExpression()); | |
1081 break; | |
1082 case T.CatAssign: | |
1083 nT(); e = new CatAssignExpression(e, parseAssignExpression()); | |
1084 break; | |
1085 default: | |
1086 break; | |
1087 } | |
71 | 1088 break; |
1089 } | |
1090 return e; | |
1091 } | |
72 | 1092 |
71 | 1093 Expression parseCondExpression() |
1094 { | |
72 | 1095 auto e = parseOrOrExpression(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1096 if (token.type == T.Question) |
72 | 1097 { |
1098 nT(); | |
1099 auto iftrue = parseExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1100 require(T.Colon); |
72 | 1101 auto iffalse = parseCondExpression(); |
1102 e = new CondExpression(e, iftrue, iffalse); | |
1103 } | |
1104 return e; | |
1105 } | |
1106 | |
1107 Expression parseOrOrExpression() | |
1108 { | |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1109 alias parseAndAndExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1110 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1111 if (token.type == T.OrLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1112 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1113 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1114 e = new OrOrExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1115 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1116 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1117 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1118 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1119 Expression parseAndAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1120 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1121 alias parseOrExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1122 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1123 if (token.type == T.AndLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1124 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1125 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1126 e = new AndAndExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1127 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1128 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1129 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1130 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1131 Expression parseOrExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1132 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1133 alias parseXorExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1134 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1135 if (token.type == T.OrBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1136 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1137 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1138 e = new OrExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1139 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1140 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1141 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1142 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1143 Expression parseXorExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1144 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1145 alias parseAndExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1146 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1147 if (token.type == T.Xor) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1148 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1149 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1150 e = new XorExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1151 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1152 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1153 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1154 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1155 Expression parseAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1156 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1157 alias parseCmpExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1158 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1159 if (token.type == T.AndBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1160 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1161 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1162 e = new AndExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1163 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1164 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1165 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1166 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1167 Expression parseCmpExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
1168 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1169 TOK operator = token.type; |
74 | 1170 |
1171 auto e = parseShiftExpression(); | |
1172 | |
1173 switch (operator) | |
1174 { | |
1175 case T.Equal, T.NotEqual: | |
1176 nT(); | |
1177 e = new EqualExpression(e, parseShiftExpression(), operator); | |
1178 break; | |
1179 case T.Not: | |
1180 Token t; | |
1181 lx.peek(t); | |
1182 if (t.type != T.Is) | |
1183 break; | |
1184 nT(); | |
1185 operator = T.NotIdentity; | |
1186 goto LNotIdentity; | |
1187 case T.Identity: | |
1188 operator = T.Identity; | |
1189 LNotIdentity: | |
1190 nT(); | |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1191 e = new IdentityExpression(e, parseShiftExpression(), operator); |
74 | 1192 break; |
1193 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater, | |
1194 T.Unordered, T.UorE, T.UorG, T.UorGorE, | |
1195 T.UorL, T.UorLorE, T.LorEorG, T.LorG: | |
1196 nT(); | |
1197 e = new RelExpression(e, parseShiftExpression(), operator); | |
1198 break; | |
1199 case T.In: | |
1200 nT(); | |
1201 e = new InExpression(e, parseShiftExpression(), operator); | |
1202 break; | |
1203 default: | |
1204 } | |
1205 return e; | |
1206 } | |
1207 | |
1208 Expression parseShiftExpression() | |
1209 { | |
75 | 1210 auto e = parseAddExpression(); |
1211 while (1) | |
1212 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1213 switch (token.type) |
75 | 1214 { |
1215 case T.LShift: nT(); e = new LShiftExpression(e, parseAddExpression()); break; | |
1216 case T.RShift: nT(); e = new RShiftExpression(e, parseAddExpression()); break; | |
1217 case T.URShift: nT(); e = new URShiftExpression(e, parseAddExpression()); break; | |
1218 default: break; | |
1219 } | |
1220 break; | |
1221 } | |
1222 return e; | |
1223 } | |
1224 | |
1225 Expression parseAddExpression() | |
1226 { | |
76 | 1227 auto e = parseMulExpression(); |
1228 while (1) | |
1229 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1230 switch (token.type) |
76 | 1231 { |
1232 case T.Plus: nT(); e = new PlusExpression(e, parseMulExpression()); break; | |
1233 case T.Minus: nT(); e = new MinusExpression(e, parseMulExpression()); break; | |
1234 case T.Tilde: nT(); e = new CatExpression(e, parseMulExpression()); break; | |
1235 default: break; | |
1236 } | |
1237 break; | |
1238 } | |
1239 return new Expression(); | |
1240 } | |
1241 | |
1242 Expression parseMulExpression() | |
1243 { | |
77 | 1244 auto e = parseUnaryExpression(); |
1245 while (1) | |
1246 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1247 switch (token.type) |
77 | 1248 { |
1249 case T.Mul: nT(); e = new MulExpression(e, parseUnaryExpression()); break; | |
1250 case T.Div: nT(); e = new DivExpression(e, parseUnaryExpression()); break; | |
1251 case T.Mod: nT(); e = new ModExpression(e, parseUnaryExpression()); break; | |
1252 default: break; | |
1253 } | |
1254 break; | |
1255 } | |
74 | 1256 return new Expression(); |
71 | 1257 } |
1258 | |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1259 Expression parseUnaryExpression() |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1260 { |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1261 Expression e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1262 switch (token.type) |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1263 { |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1264 case T.AndBinary: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1265 nT(); e = new AddressExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1266 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1267 case T.PlusPlus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1268 nT(); e = new PreIncrExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1269 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1270 case T.MinusMinus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1271 nT(); e = new PreDecrExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1272 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1273 case T.Mul: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1274 nT(); e = new DerefExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1275 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1276 case T.Minus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1277 case T.Plus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1278 nT(); e = new SignExpression(parseUnaryExpression(), token.type); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1279 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1280 case T.Not: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1281 nT(); e = new NotExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1282 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1283 case T.Tilde: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1284 nT(); e = new CompExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1285 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1286 case T.New: |
145
f401bd3feb2d
- Removed TODO and added call to parseNewExpression().
aziz
parents:
144
diff
changeset
|
1287 e = parseNewExpression(null); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1288 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1289 case T.Delete: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1290 nT(); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1291 e = new DeleteExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1292 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1293 case T.Cast: |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1294 requireNext(T.LParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1295 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1296 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1297 e = new CastExpression(parseUnaryExpression(), type); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1298 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1299 case T.LParen: |
102 | 1300 // ( Type ) . Identifier |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1301 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1302 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1303 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
|
1304 string ident = requireIdentifier(); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1305 e = new TypeDotIdExpression(type, ident); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1306 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1307 default: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1308 e = parsePostExpression(parsePrimaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1309 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1310 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1311 assert(e !is null); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1312 return e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1313 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
1314 |
90
a02950cb7036
- Fixed order of parsing unary, post and primary expressions.
aziz
parents:
89
diff
changeset
|
1315 Expression parsePostExpression(Expression e) |
77 | 1316 { |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1317 while (1) |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1318 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1319 switch (token.type) |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1320 { |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1321 case T.Dot: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1322 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1323 if (token.type == T.Identifier) |
92 | 1324 { |
108 | 1325 e = new DotIdExpression(e, token.identifier); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1326 break; |
92 | 1327 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1328 else if (token.type == T.New) |
81 | 1329 e = parseNewExpression(e); |
92 | 1330 else |
124 | 1331 expected(T.Identifier); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1332 continue; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1333 case T.PlusPlus: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1334 e = new PostIncrExpression(e); |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1335 break; |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1336 case T.MinusMinus: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1337 e = new PostDecrExpression(e); |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1338 break; |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1339 case T.LParen: |
143 | 1340 e = new CallExpression(e, parseArguments(T.LParen)); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1341 continue; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1342 case T.LBracket: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1343 // parse Slice- and IndexExpression |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1344 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1345 if (token.type == T.RBracket) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1346 { |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1347 e = new SliceExpression(e, null, null); |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1348 break; |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1349 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1350 |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1351 Expression[] es = [parseAssignExpression()]; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1352 |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1353 if (token.type == T.Slice) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1354 { |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1355 nT(); |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1356 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
|
1357 require(T.RBracket); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1358 continue; |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1359 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1360 else if (token.type == T.Comma) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1361 { |
143 | 1362 es ~= parseArguments(T.RBracket); |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1363 } |
85 | 1364 else |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1365 require(T.RBracket); |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1366 |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1367 e = new IndexExpression(e, es); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1368 continue; |
92 | 1369 default: |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1370 return e; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1371 } |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1372 nT(); |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1373 } |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1374 assert(0); |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1375 } |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1376 |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1377 Expression parsePrimaryExpression() |
78
f043759fb59a
- Added code to parseUnaryExpression(); not fully implemented.
aziz
parents:
77
diff
changeset
|
1378 { |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1379 Expression e; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1380 switch (token.type) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1381 { |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1382 case T.Identifier: |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1383 e = new IdentifierExpression(token.identifier); |
89 | 1384 nT(); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1385 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1386 case T.Dot: |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1387 nT(); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1388 e = new IdentifierExpression("."); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1389 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1390 case T.This: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1391 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1392 e = new ThisExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1393 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1394 case T.Super: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1395 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1396 e = new SuperExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1397 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1398 case T.Null: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1399 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1400 e = new NullExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1401 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1402 case T.True, T.False: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1403 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1404 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
|
1405 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1406 case T.Dollar: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1407 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1408 e = new DollarExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1409 break; |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1410 case T.Int32, T.Int64, T.Uint32, T.Uint64: |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1411 nT(); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1412 e = new IntNumberExpression(token.type, token.ulong_); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1413 break; |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1414 case T.Float32, T.Float64, T.Float80, |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1415 T.Imaginary32, T.Imaginary64, T.Imaginary80: |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1416 nT(); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1417 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
|
1418 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1419 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
|
1420 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1421 e = new CharLiteralExpression(token.type); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1422 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1423 case T.String: |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1424 char[] buffer = token.str; |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1425 char postfix = token.pf; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1426 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1427 while (token.type == T.String) |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1428 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1429 string tmp = token.str; |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1430 // if (postfix != token.pf) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1431 // error(); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1432 if (tmp.length > 1) |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1433 { |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1434 buffer[$-1] = tmp[0]; // replace '\0' |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1435 buffer ~= tmp[1..$]; // append the rest |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1436 } |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1437 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1438 } |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1439 e = new StringLiteralExpression(buffer); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1440 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1441 case T.LBracket: |
85 | 1442 Expression[] values; |
1443 | |
1444 nT(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1445 if (token.type != T.RBracket) |
85 | 1446 { |
1447 e = parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1448 if (token.type == T.Colon) |
85 | 1449 goto LparseAssocArray; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1450 else if (token.type == T.Comma) |
143 | 1451 values = [e] ~ parseArguments(T.RBracket); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1452 else |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1453 require(T.RBracket); |
85 | 1454 } |
1455 | |
1456 e = new ArrayLiteralExpression(values); | |
1457 break; | |
1458 | |
1459 LparseAssocArray: | |
1460 Expression[] keys; | |
1461 | |
1462 keys ~= e; | |
1463 nT(); // Skip colon. | |
1464 values ~= parseAssignExpression(); | |
1465 | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1466 if (token.type != T.RBracket) |
88 | 1467 { |
1468 require(T.Comma); | |
85 | 1469 while (1) |
1470 { | |
1471 keys ~= parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1472 if (token.type != T.Colon) |
85 | 1473 { |
124 | 1474 expected(T.Colon); |
85 | 1475 values ~= null; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1476 if (token.type == T.RBracket) |
85 | 1477 break; |
1478 else | |
1479 continue; | |
1480 } | |
1481 nT(); | |
1482 values ~= parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1483 if (token.type == T.RBracket) |
85 | 1484 break; |
88 | 1485 require(T.Comma); |
85 | 1486 } |
88 | 1487 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1488 assert(token.type == T.RBracket); |
85 | 1489 nT(); |
1490 e = new AssocArrayLiteralExpression(keys, values); | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1491 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1492 case T.LBrace: |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1493 // DelegateLiteral := { DeclDefs } |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1494 require(T.LBrace); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1495 auto decls = parseDeclarationDefinitions(); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1496 require(T.RBrace); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1497 auto func = new FunctionType(null, Parameters.init); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1498 e = new FunctionLiteralExpression(func, decls); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1499 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1500 case T.Function, T.Delegate: |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1501 // FunctionLiteral := (function|delegate) Type? '(' ArgumentList ')' '{' DeclDefs '}' |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1502 TOK funcTok = token.type; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1503 nT(); // Skip function|delegate token. |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1504 Type returnType; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1505 Parameters parameters; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1506 if (token.type != T.LBrace) |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1507 { |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1508 if (token.type != T.LParen) // Optional return type |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1509 returnType = parseType(); |
143 | 1510 parameters = parseParameterList(); |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1511 } |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1512 require(T.LBrace); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1513 auto decls = parseDeclarationDefinitions(); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1514 require(T.RBrace); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1515 auto func = new FunctionType(returnType, parameters); |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
1516 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
|
1517 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1518 case T.Assert: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1519 Expression msg; |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1520 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1521 e = parseAssignExpression(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1522 if (token.type == T.Comma) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1523 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1524 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1525 msg = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1526 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1527 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1528 e = new AssertExpression(e, msg); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1529 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1530 case T.Mixin: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1531 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1532 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1533 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1534 e = new MixinExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1535 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1536 case T.Import: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1537 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1538 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1539 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1540 e = new ImportExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1541 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1542 case T.Typeid: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1543 requireNext(T.LParen); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1544 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1545 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1546 e = new TypeidExpression(type); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1547 break; |
101 | 1548 case T.Typeof: |
1549 requireNext(T.LParen); | |
1550 auto type = new TypeofType(parseExpression()); | |
1551 require(T.RParen); | |
1552 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
|
1553 { // typeof ( Expression ) . Identifier |
101 | 1554 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1555 string ident = requireIdentifier; |
101 | 1556 e = new TypeDotIdExpression(type, ident); |
1557 } | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1558 else // typeof ( Expression ) |
101 | 1559 e = new TypeofExpression(type); |
1560 break; | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1561 case T.Is: |
100 | 1562 requireNext(T.LParen); |
1563 | |
1564 Type type; | |
1565 SpecializationType specType; | |
1566 string ident; // optional Identifier | |
1567 | |
1568 type = parseDeclarator(ident, true); | |
1569 | |
1570 switch (token.type) | |
1571 { | |
1572 case T.Colon, T.Equal: | |
1573 TOK specTok = token.type; | |
1574 nT(); | |
1575 switch (token.type) | |
1576 { | |
1577 case T.Typedef, | |
1578 T.Struct, | |
1579 T.Union, | |
1580 T.Class, | |
1581 T.Interface, | |
1582 T.Enum, | |
1583 T.Function, | |
1584 T.Delegate, | |
1585 T.Super, | |
1586 T.Return: | |
102 | 1587 nT(); |
100 | 1588 specType = new SpecializationType(specTok, token.type); |
1589 break; | |
1590 default: | |
1591 specType = new SpecializationType(specTok, parseType()); | |
1592 } | |
1593 default: | |
1594 } | |
102 | 1595 require(T.RParen); |
100 | 1596 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
|
1597 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1598 case T.LParen: |
130 | 1599 Token t; |
1600 bool failed; | |
143 | 1601 auto parameters = try_(parseParameterList(), failed); |
130 | 1602 if (!failed) |
1603 { | |
143 | 1604 // ( ParameterList ) FunctionBody |
130 | 1605 require(T.LBrace); |
1606 auto decls = parseDeclarationDefinitions(); | |
1607 require(T.RBrace); | |
1608 auto func = new FunctionType(null, parameters); | |
1609 e = new FunctionLiteralExpression(func, decls); | |
1610 } | |
1611 else | |
1612 { | |
131 | 1613 // ( Expression ) |
130 | 1614 nT(); |
1615 e = parseExpression(); | |
1616 require(T.RParen); | |
1617 } | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1618 break; |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1619 // BasicType . Identifier |
94 | 1620 case T.Void, T.Char, T.Wchar, T.Dchar, T.Bool, |
1621 T.Byte, T.Ubyte, T.Short, T.Ushort, | |
1622 T.Int, T.Uint, T.Long, T.Ulong, | |
1623 T.Float, T.Double, T.Real, | |
1624 T.Ifloat, T.Idouble, T.Ireal, | |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1625 T.Cfloat, T.Cdouble, T.Creal: |
94 | 1626 auto type = new Type(token.type); |
1627 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
|
1628 auto ident = requireIdentifier(); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1629 |
94 | 1630 e = new TypeDotIdExpression(type, ident); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1631 break; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1632 default: |
136
96468715ea79
- Returning EmptyExpression in parsePrimaryExpression() when no token matched.
aziz
parents:
135
diff
changeset
|
1633 // TODO: issue error msg. |
96468715ea79
- Returning EmptyExpression in parsePrimaryExpression() when no token matched.
aziz
parents:
135
diff
changeset
|
1634 e = new EmptyExpression(); |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1635 } |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1636 return e; |
77 | 1637 } |
1638 | |
81 | 1639 Expression parseNewExpression(Expression e) |
1640 { | |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1641 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
|
1642 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
|
1643 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1644 Expression[] newArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1645 Expression[] ctorArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1646 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1647 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
|
1648 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
|
1649 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1650 // NewAnonClassExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1651 // 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
|
1652 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
|
1653 { |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1654 nT(); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1655 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
|
1656 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
|
1657 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1658 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
|
1659 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1660 require(T.LBrace); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1661 auto decls = parseDeclarationDefinitions(); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1662 require(T.RBrace); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1663 return new NewAnonClassExpression(e, newArguments, bases, ctorArguments, decls); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1664 } |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1665 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1666 // NewExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1667 // NewArguments Type [ AssignExpression ] |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1668 // NewArguments Type ( ArgumentList ) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1669 // NewArguments Type |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1670 auto type = parseType(); |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1671 // TODO: consider "new Foo!(int)(1,2,3)" |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1672 if (type.tid == TID.Identifier) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1673 { |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1674 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
|
1675 } |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1676 return new NewExpression(e, newArguments, type, ctorArguments); |
81 | 1677 } |
1678 | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1679 Type parseType() |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1680 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
1681 return parseBasicType2(parseBasicType()); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1682 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1683 |
94 | 1684 Type parseBasicType() |
1685 { | |
1686 Type t; | |
1687 IdentifierType tident; | |
1688 | |
1689 switch (token.type) | |
1690 { | |
1691 case T.Void, T.Char, T.Wchar, T.Dchar, T.Bool, | |
1692 T.Byte, T.Ubyte, T.Short, T.Ushort, | |
1693 T.Int, T.Uint, T.Long, T.Ulong, | |
1694 T.Float, T.Double, T.Real, | |
1695 T.Ifloat, T.Idouble, T.Ireal, | |
1696 T.Cfloat, T.Cdouble, T.Creal: | |
1697 t = new Type(token.type); | |
1698 nT(); | |
1699 break; | |
1700 case T.Identifier, T.Dot: | |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1701 tident = new IdentifierType([token.identifier]); |
94 | 1702 nT(); |
102 | 1703 // TODO: parse template instance |
94 | 1704 // if (token.type == T.Not) |
1705 // parse template instance | |
1706 Lident: | |
1707 while (token.type == T.Dot) | |
1708 { | |
1709 nT(); | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1710 tident ~= requireIdentifier(); |
102 | 1711 // TODO: parse template instance |
94 | 1712 // if (token.type == T.Not) |
1713 // parse template instance | |
1714 } | |
1715 t = tident; | |
1716 break; | |
1717 case T.Typeof: | |
1718 requireNext(T.LParen); | |
1719 tident = new TypeofType(parseExpression()); | |
1720 require(T.RParen); | |
1721 goto Lident; | |
1722 default: | |
136
96468715ea79
- Returning EmptyExpression in parsePrimaryExpression() when no token matched.
aziz
parents:
135
diff
changeset
|
1723 // 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
|
1724 t = new UndefinedType(); |
94 | 1725 } |
1726 return t; | |
1727 } | |
1728 | |
95 | 1729 Type parseBasicType2(Type t) |
1730 { | |
1731 while (1) | |
1732 { | |
1733 switch (token.type) | |
1734 { | |
1735 case T.Mul: | |
1736 t = new PointerType(t); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1737 nT(); |
95 | 1738 break; |
1739 case T.LBracket: | |
106 | 1740 t = parseArrayType(t); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1741 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1742 case T.Function, T.Delegate: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1743 TOK tok = token.type; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1744 nT(); |
143 | 1745 auto parameters = parseParameterList(); |
135 | 1746 t = new FunctionType(t, parameters); |
1747 if (tok == T.Function) | |
1748 t = new PointerType(t); | |
1749 else | |
1750 t = new DelegateType(t); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1751 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1752 default: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1753 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1754 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1755 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1756 assert(0); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1757 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1758 |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1759 Type parseDeclaratorSuffix(Type t) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1760 { |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1761 while (1) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1762 { |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1763 switch (token.type) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1764 { |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1765 case T.LBracket: |
131 | 1766 // Type Identifier ArrayType |
1767 // ArrayType := [] or [Type] or [Expression..Expression] | |
106 | 1768 t = parseArrayType(t); |
95 | 1769 continue; |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1770 case T.LParen: |
143 | 1771 auto params = parseParameterList(); |
131 | 1772 // TODO: handle ( TemplateParameterList ) ( ParameterList ) |
1773 // ReturnType FunctionName ( ParameterList ) | |
1774 t = new FunctionType(t, params); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1775 break; |
100 | 1776 default: |
1777 break; | |
95 | 1778 } |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1779 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1780 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1781 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1782 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1783 |
106 | 1784 Type parseArrayType(Type t) |
1785 { | |
1786 assert(token.type == T.LBracket); | |
1787 nT(); | |
1788 if (token.type == T.RBracket) | |
1789 { | |
1790 t = new ArrayType(t); | |
1791 nT(); | |
1792 } | |
1793 else | |
1794 { | |
1795 bool failed; | |
1796 auto assocType = try_(parseType(), failed); | |
1797 if (!failed) | |
1798 t = new ArrayType(t, assocType); | |
1799 else | |
1800 { | |
1801 Expression e = parseExpression(), e2; | |
1802 if (token.type == T.Slice) | |
1803 { | |
1804 nT(); | |
1805 e2 = parseExpression(); | |
1806 } | |
1807 t = new ArrayType(t, e, e2); | |
1808 } | |
1809 require(T.RBracket); | |
1810 } | |
1811 return t; | |
1812 } | |
1813 | |
100 | 1814 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
|
1815 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
1816 auto t = parseType(); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1817 |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1818 if (token.type == T.Identifier) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1819 { |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1820 ident = token.identifier; |
95 | 1821 nT(); |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
1822 t = parseDeclaratorSuffix(t); |
95 | 1823 } |
100 | 1824 else if (!identOptional) |
124 | 1825 expected(T.Identifier); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1826 |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
1827 return t; |
95 | 1828 } |
1829 | |
143 | 1830 Expression[] parseArguments(TOK terminator) |
138 | 1831 { |
139 | 1832 Expression[] args; |
138 | 1833 |
1834 nT(); | |
1835 if (token.type == terminator) | |
1836 { | |
1837 nT(); | |
1838 return null; | |
1839 } | |
1840 | |
139 | 1841 goto LenterLoop; |
1842 do | |
138 | 1843 { |
139 | 1844 nT(); |
1845 LenterLoop: | |
1846 args ~= parseAssignExpression(); | |
1847 } while (token.type == T.Comma) | |
1848 | |
1849 require(terminator); | |
1850 return args; | |
138 | 1851 } |
1852 | |
143 | 1853 Parameters parseParameterList() |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1854 out(params) |
96 | 1855 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1856 if (params.length > 1) |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1857 foreach (param; params.items[0..$-1]) |
96 | 1858 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1859 if (param.isVariadic()) |
96 | 1860 assert(0, "variadic arguments can only appear at the end of the parameter list."); |
1861 } | |
1862 } | |
1863 body | |
95 | 1864 { |
1865 require(T.LParen); | |
1866 | |
1867 if (token.type == T.RParen) | |
1868 { | |
1869 nT(); | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1870 return Parameters.init; |
95 | 1871 } |
1872 | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1873 Parameters params; |
95 | 1874 StorageClass stc; |
1875 | |
1876 while (1) | |
1877 { | |
1878 stc = StorageClass.In; | |
1879 switch (token.type) | |
1880 { | |
1881 case T.In: stc = StorageClass.In; nT(); goto default; | |
1882 case T.Out: stc = StorageClass.Out; nT(); goto default; | |
1883 case T.Ref: stc = StorageClass.Ref; nT(); goto default; | |
1884 case T.Lazy: stc = StorageClass.Lazy; nT(); goto default; | |
1885 case T.Ellipses: | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1886 params ~= new Parameter(StorageClass.Variadic, null, null, null); |
95 | 1887 break; |
1888 default: | |
1889 string ident; | |
130 | 1890 auto type = parseDeclarator(ident, true); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1891 |
95 | 1892 Expression assignExpr; |
1893 if (token.type == T.Assign) | |
1894 { | |
1895 nT(); | |
1896 assignExpr = parseAssignExpression(); | |
1897 } | |
1898 | |
1899 if (token.type == T.Ellipses) | |
1900 { | |
1901 stc |= StorageClass.Variadic; | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1902 params ~= new Parameter(stc, type, ident, assignExpr); |
95 | 1903 nT(); |
1904 break; | |
1905 } | |
1906 | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1907 params ~= new Parameter(stc, type, ident, assignExpr); |
95 | 1908 if (token.type == T.Comma) |
1909 { | |
1910 nT(); | |
1911 continue; | |
1912 } | |
1913 break; | |
1914 } | |
1915 break; | |
1916 } | |
1917 require(T.RParen); | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1918 return params; |
95 | 1919 } |
1920 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1921 TemplateArguments parseTemplateArguments() |
139 | 1922 { |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1923 TemplateArguments args; |
139 | 1924 |
1925 require(T.LParen); | |
1926 if (token.type == T.RParen) | |
1927 { | |
1928 nT(); | |
1929 return null; | |
1930 } | |
1931 | |
1932 goto LenterLoop; | |
1933 do | |
1934 { | |
1935 nT(); // Skip comma. | |
1936 LenterLoop: | |
1937 | |
1938 bool failed; | |
1939 auto typeArgument = try_(parseType(), failed); | |
1940 | |
1941 if (!failed) | |
1942 { | |
1943 // TemplateArgument: | |
1944 // Type | |
1945 // Symbol | |
1946 args ~= typeArgument; | |
1947 } | |
1948 else | |
1949 { | |
1950 // TemplateArgument: | |
1951 // AssignExpression | |
1952 args ~= parseAssignExpression(); | |
1953 } | |
1954 } while (token.type == T.Comma) | |
1955 | |
1956 require(T.RParen); | |
1957 return args; | |
1958 } | |
1959 | |
143 | 1960 TemplateParameter[] parseTemplateParameterList() |
137 | 1961 { |
1962 require(T.LParen); | |
1963 if (token.type == T.RParen) | |
1964 return null; | |
1965 | |
1966 TemplateParameter[] tparams; | |
1967 while (1) | |
1968 { | |
1969 TP tp; | |
1970 string ident; | |
1971 Type valueType; | |
1972 Type specType, defType; | |
1973 Expression specValue, defValue; | |
1974 | |
1975 switch (token.type) | |
1976 { | |
1977 case T.Alias: | |
1978 // TemplateAliasParameter: | |
1979 // alias Identifier | |
1980 tp = TP.Alias; | |
1981 nT(); // Skip alias keyword. | |
1982 ident = requireIdentifier(); | |
1983 // : SpecializationType | |
1984 if (token.type == T.Colon) | |
1985 { | |
1986 nT(); | |
1987 specType = parseType(); | |
1988 } | |
1989 // = DefaultType | |
1990 if (token.type == T.Assign) | |
1991 { | |
1992 nT(); | |
1993 defType = parseType(); | |
1994 } | |
1995 break; | |
1996 case T.Identifier: | |
1997 ident = token.identifier; | |
1998 Token peeked; | |
1999 lx.peek(peeked); | |
2000 switch (peeked.type) | |
2001 { | |
2002 case T.Ellipses: | |
2003 // TemplateTupleParameter: | |
2004 // Identifier ... | |
2005 tp = TP.Tuple; | |
2006 nT(); // Skip Identifier. | |
2007 nT(); // Skip Ellipses. | |
2008 // if (token.type == T.Comma) | |
2009 // error(); // TODO: issue error msg for variadic param not being last. | |
2010 break; | |
2011 case T.Comma, T.RParen, T.Colon, T.Assign: | |
2012 // TemplateTypeParameter: | |
2013 // Identifier | |
2014 tp = TP.Type; | |
2015 nT(); // Skip Identifier. | |
2016 // : SpecializationType | |
2017 if (token.type == T.Colon) | |
2018 { | |
2019 nT(); | |
2020 specType = parseType(); | |
2021 } | |
2022 // = DefaultType | |
2023 if (token.type == T.Assign) | |
2024 { | |
2025 nT(); | |
2026 defType = parseType(); | |
2027 } | |
2028 break; | |
2029 default: | |
2030 // TemplateValueParameter: | |
2031 // Declarator | |
2032 ident = null; | |
2033 goto LTemplateValueParameter; | |
2034 } | |
2035 break; | |
2036 default: | |
2037 LTemplateValueParameter: | |
2038 // TemplateValueParameter: | |
2039 // Declarator | |
2040 tp = TP.Value; | |
2041 valueType = parseDeclarator(ident); | |
2042 // : SpecializationValue | |
2043 if (token.type == T.Colon) | |
2044 { | |
2045 nT(); | |
2046 specValue = parseCondExpression(); | |
2047 } | |
2048 // = DefaultValue | |
2049 if (token.type == T.Assign) | |
2050 { | |
2051 nT(); | |
2052 defValue = parseCondExpression(); | |
2053 } | |
2054 } | |
2055 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
2056 tparams ~= new TemplateParameter(tp, valueType, ident, specType, defType, specValue, defValue); |
137 | 2057 |
2058 if (token.type != T.Comma) | |
2059 break; | |
2060 nT(); | |
2061 } | |
2062 require(T.RParen); | |
2063 return tparams; | |
2064 } | |
2065 | |
124 | 2066 void expected(TOK tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2067 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2068 if (token.type != tok) |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2069 error(MID.ExpectedButFound, tok, token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2070 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2071 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2072 void require(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2073 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2074 if (token.type == tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2075 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2076 else |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2077 error(MID.ExpectedButFound, tok, token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2078 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2079 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2080 void requireNext(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2081 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2082 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2083 if (token.type == tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2084 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2085 else |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2086 error(MID.ExpectedButFound, tok, token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2087 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
2088 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2089 string requireIdentifier() |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2090 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2091 string identifier; |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2092 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
|
2093 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2094 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
|
2095 nT(); |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2096 } |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2097 else |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2098 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
|
2099 return identifier; |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2100 } |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
2101 |
71 | 2102 void error(MID id, ...) |
2103 { | |
94 | 2104 errors ~= new Information(InfoType.Parser, id, lx.loc, arguments(_arguments, _argptr)); |
71 | 2105 } |
65 | 2106 } |