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