Mercurial > projects > dil
annotate trunk/src/Parser.d @ 122:9849a263f148
- Added method parseDeclarationsBlock().
- Added method parseDebugDeclaration().
author | aziz |
---|---|
date | Mon, 09 Jul 2007 20:24:03 +0000 |
parents | 030933c6b5f0 |
children | 0f55c0ac6589 |
rev | line source |
---|---|
0 | 1 /++ |
2 Author: Aziz Köksal | |
3 License: GPL2 | |
4 +/ | |
65 | 5 module Parser; |
69
24db7c5522d5
- Added module Information for compiler messages like warnings, info and errors to the user.
aziz
parents:
68
diff
changeset
|
6 import Lexer; |
71 | 7 import Token; |
8 import Messages; | |
9 import Information; | |
102 | 10 import Declarations; |
11 import Statements; | |
70 | 12 import Expressions; |
94 | 13 import Types; |
65 | 14 |
71 | 15 private alias TOK T; |
16 | |
65 | 17 class Parser |
18 { | |
71 | 19 Lexer lx; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
20 Token* token; |
71 | 21 |
22 Information[] errors; | |
23 | |
24 this(char[] srcText, string fileName) | |
25 { | |
26 lx = new Lexer(srcText, fileName); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
27 } |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
28 |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
29 void nT() |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
30 { |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
31 lx.nextToken(); |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
32 token = &lx.token; |
71 | 33 } |
70 | 34 |
102 | 35 void skipToOnePast(TOK tok) |
36 { | |
37 for (; token.type != tok && token.type != T.EOF; nT()) | |
38 {} | |
39 nT(); | |
40 } | |
105 | 41 |
106 | 42 ReturnType try_(ReturnType)(lazy ReturnType parseMethod, out bool failed) |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
43 { |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
44 auto len = errors.length; |
105 | 45 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
|
46 auto result = parseMethod(); |
105 | 47 // If the length of the array changed we know an error occurred. |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
48 if (errors.length != len) |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
49 { |
105 | 50 lexerState.restore(); // Restore state of the Lexer object. |
51 errors = errors[0..len]; // Remove errors that were added when parseMethod() was called. | |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
52 failed = true; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
53 } |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
54 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
|
55 } |
105 | 56 |
102 | 57 /++++++++++++++++++++++++++++++ |
58 + Declaration parsing methods + | |
59 ++++++++++++++++++++++++++++++/ | |
60 | |
61 Declaration[] parseModule() | |
62 { | |
63 Declaration[] decls; | |
64 | |
65 if (token.type == T.Module) | |
66 { | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
67 ModuleName moduleName; |
102 | 68 do |
69 { | |
70 nT(); | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
71 moduleName ~= requireIdentifier(); |
102 | 72 } while (token.type == T.Dot) |
73 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
|
74 decls ~= new ModuleDeclaration(moduleName); |
102 | 75 } |
110 | 76 decls ~= parseDeclarationDefinitions(); |
102 | 77 return decls; |
78 } | |
79 | |
110 | 80 Declaration[] parseDeclarationDefinitions() |
102 | 81 { |
82 Declaration[] decls; | |
122 | 83 while (token.type != T.RBrace && token.type != T.EOF) |
110 | 84 decls ~= parseDeclarationDefinitions(); |
102 | 85 return decls; |
86 } | |
87 | |
110 | 88 Declaration parseDeclarationDefinition() |
102 | 89 { |
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
|
90 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
|
91 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
|
92 { |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
93 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
|
94 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
|
95 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
|
96 T.Deprecated, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
97 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
|
98 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
|
99 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
|
100 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
|
101 T.Export, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
102 //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
|
103 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
|
104 T.Override, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
105 T.Abstract, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 break; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
112 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
|
113 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
|
114 lx.peek(t); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
115 |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
116 if (t.type == T.Import) |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
117 goto case T.Import; |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
118 else if (t.type == T.This) |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
119 decl = parseStaticConstructorDeclaration(); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
120 else if (t.type == T.Tilde) |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
121 decl = parseStaticDestructorDeclaration(); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
122 else |
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
|
123 goto case_AttributeSpecifier; |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
124 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
|
125 case T.Import: |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
126 decl = parseImportDeclaration(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
127 break; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
128 case T.Enum: |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
129 decl = parseEnumDeclaration(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
130 break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
131 case T.Class: |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
132 decl = parseClassDeclaration(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
133 break; |
112 | 134 case T.Interface: |
135 decl = parseInterfaceDeclaration(); | |
136 break; | |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
137 case T.Struct, T.Union: |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
138 decl = parseAggregateDeclaration(); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
139 break; |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
140 case T.This: |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
141 decl = parseConstructorDeclaration(); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
142 break; |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
143 case T.Tilde: |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
144 decl = parseDestructorDeclaration(); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
145 break; |
120 | 146 case T.Invariant: |
147 decl = parseInvariantDeclaration(); | |
148 break; | |
121 | 149 case T.Unittest: |
150 decl = parseUnittestDeclaration(); | |
151 break; | |
122 | 152 case T.Debug: |
153 decl = parseDebugDeclaration(); | |
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
|
154 case T.Module: |
511a1aa25896
- Added reportErrors 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 // Error: module is optional and can only appear once at the top of the source file. |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
156 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
|
157 default: |
511a1aa25896
- Added reportErrors 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 } |
102 | 159 return null; |
160 } | |
161 | |
122 | 162 /* |
163 DeclarationsBlock: | |
164 : DeclDefs | |
165 { } | |
166 { DeclDefs } | |
167 DeclDef | |
168 */ | |
169 Declaration[] parseDeclarationsBlock() | |
170 { | |
171 Declaration[] decls; | |
172 switch (token.type) | |
173 { | |
174 case T.LBrace: | |
175 nT(); | |
176 if (token.type == T.RBrace) | |
177 nT(); | |
178 else | |
179 { | |
180 decls = parseDeclarationDefinitions(); | |
181 require(T.RBrace); | |
182 } | |
183 break; | |
184 case T.Colon: | |
185 nT(); | |
186 decls = parseDeclarationDefinitions(); | |
187 break; | |
188 default: | |
189 decls ~= parseDeclarationDefinition(); | |
190 } | |
191 return decls; | |
192 } | |
193 | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
194 Statement[] parseStatements() |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
195 { |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
196 return null; |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
197 } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
198 |
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
|
199 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
|
200 { |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
201 // Attribute : |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
202 // Attribute DeclarationBlock |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
203 return null; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
204 } |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
205 |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
206 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
|
207 { |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
208 assert(token.type == T.Import || token.type == T.Static); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
209 |
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
|
210 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
|
211 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
|
212 |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
213 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
|
214 { |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
215 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
|
216 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
|
217 } |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
218 |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
219 ModuleName[] moduleNames; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
220 string[] moduleAliases; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
221 string[] bindNames; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
222 string[] bindAliases; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
223 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
224 nT(); // Skip import keyword. |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
225 do |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
226 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
227 ModuleName moduleName; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
228 string moduleAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
229 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
230 moduleAlias = requireIdentifier(); |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
231 |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
232 // AliasName = ModuleName |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
233 if (token.type == T.Assign) |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
234 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
235 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
236 moduleName ~= requireIdentifier(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
237 } |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
238 else // import Identifier [^=] |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
239 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
240 moduleName ~= moduleAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
241 moduleAlias = null; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
242 } |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
243 |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
244 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
245 // parse Identifier(.Identifier)* |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
246 while (token.type == T.Dot) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
247 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
248 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
249 moduleName ~= requireIdentifier(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
250 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
251 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
252 // Push identifiers. |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
253 moduleNames ~= moduleName; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
254 moduleAliases ~= moduleAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
255 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
256 // parse : BindAlias = BindName(, BindAlias = BindName)*; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
257 // : BindName(, BindName)*; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
258 if (token.type == T.Colon) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
259 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
260 string bindName, bindAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
261 do |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
262 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
263 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
264 bindAlias = requireIdentifier(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
265 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
266 if (token.type == T.Assign) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
267 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
268 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
269 bindName = requireIdentifier(); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
270 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
271 else |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
272 { |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
273 bindName = bindAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
274 bindAlias = null; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
275 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
276 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
277 // Push identifiers. |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
278 bindNames ~= bindName; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
279 bindAliases ~= bindAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
280 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
281 } while (token.type == T.Comma) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
282 break; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
283 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
284 } while (token.type == T.Comma) |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
285 require(T.Semicolon); |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
286 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
287 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
|
288 } |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
289 |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
290 Declaration parseEnumDeclaration() |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
291 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
292 assert(token.type == T.Enum); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
293 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
294 string enumName; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
295 Type baseType; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
296 string[] members; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
297 Expression[] values; |
116 | 298 bool hasDefinition; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
299 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
300 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
|
301 enumName = requireIdentifier(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
302 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
303 if (token.type == T.Colon) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
304 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
305 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
306 baseType = parseBasicType(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
307 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
308 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
309 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
|
310 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
311 //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
|
312 // 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
|
313 nT(); |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
314 } |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
315 else if (token.type == T.LBrace) |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
316 { |
116 | 317 hasDefinition = true; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
318 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
319 do |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
320 { |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
321 members ~= requireIdentifier(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
322 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
323 if (token.type == T.Assign) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
324 { |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
325 nT(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
326 values ~= parseAssignExpression(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
327 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
328 else |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
329 values ~= null; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
330 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
331 if (token.type == T.Comma) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
332 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
333 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
|
334 { |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
335 errorIfNot(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
|
336 break; |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
337 } |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
338 } while (token.type != T.RBrace) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
339 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
340 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
341 |
116 | 342 return new EnumDeclaration(enumName, baseType, members, values, hasDefinition); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
343 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
344 |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
345 Declaration parseClassDeclaration() |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
346 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
347 assert(token.type == T.Class); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
348 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
349 string className; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
350 BaseClass[] bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
351 Declaration[] decls; |
116 | 352 bool hasDefinition; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
353 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
354 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
|
355 className = requireIdentifier(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
356 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
357 if (token.type == T.LParen) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
358 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
359 // TODO: parse template parameters |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
360 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
361 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
362 if (token.type == T.Colon) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
363 bases = parseBaseClasses(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
364 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
365 if (token.type == T.Semicolon) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
366 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
367 //if (bases.length != 0) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
368 // error: bases classes are not allowed in forward declarations. |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
369 nT(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
370 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
371 else if (token.type == T.LBrace) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
372 { |
116 | 373 hasDefinition = true; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
374 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
375 // TODO: think about setting a member status variable to a flag InClassBody... this way we can check for DeclDefs that are illegal in class bodies in the parsing phase. |
110 | 376 decls = parseDeclarationDefinitions(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
377 require(T.RBrace); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
378 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
379 else |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
380 errorIfNot(T.LBrace); // TODO: better error msg |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
381 |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
382 // TODO: error if decls.length == 0 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
383 |
116 | 384 return new ClassDeclaration(className, bases, decls, hasDefinition); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
385 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
386 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
387 BaseClass[] parseBaseClasses() |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
388 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
389 assert(token.type == T.Colon); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
390 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
391 BaseClass[] bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
392 |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
393 nT(); // Skip colon |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
394 |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
395 while (1) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
396 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
397 Protection prot = Protection.Public; |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
398 string name; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
399 switch (token.type) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
400 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
401 case T.Identifier: goto LisIdentifier; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
402 case T.Private: prot = Protection.Private; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
403 case T.Protected: prot = Protection.Protected; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
404 case T.Package: prot = Protection.Package; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
405 case T.Public: /*prot = Protection.Public;*/ break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
406 //case T.Dot: // What about "class Foo : .Bar"? |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
407 default: |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
408 // TODO: issue error msg |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
409 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
410 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
411 nT(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
412 if (token.type == T.Identifier) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
413 { |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
414 LisIdentifier: |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
415 name = token.identifier; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
416 nT(); |
112 | 417 // TODO: handle template instantiations: class Foo : Bar!(int) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
418 } |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
419 else |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
420 errorIfNot(T.Identifier); |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
421 bases ~= new BaseClass(prot, name); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
422 if (token.type != T.Comma) |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
423 break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
424 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
425 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
426 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
427 |
112 | 428 Declaration parseInterfaceDeclaration() |
429 { | |
430 assert(token.type == T.Interface); | |
431 | |
432 string name; | |
433 BaseClass[] bases; | |
434 Declaration[] decls; | |
116 | 435 bool hasDefinition; |
112 | 436 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
437 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
|
438 name = requireIdentifier(); |
112 | 439 |
440 if (token.type == T.LParen) | |
441 { | |
442 // TODO: parse template parameters | |
443 } | |
444 | |
445 if (token.type == T.Colon) | |
446 bases = parseBaseClasses(); | |
447 | |
448 if (token.type == T.Semicolon) | |
449 { | |
450 //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
|
451 // TODO: error: base classes are not allowed in forward declarations. |
112 | 452 nT(); |
453 } | |
454 else if (token.type == T.LBrace) | |
455 { | |
116 | 456 hasDefinition = true; |
112 | 457 nT(); |
458 decls = parseDeclarationDefinitions(); | |
459 require(T.RBrace); | |
460 } | |
461 else | |
462 errorIfNot(T.LBrace); // TODO: better error msg | |
463 | |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
464 // TODO: error if decls.length == 0 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
465 |
116 | 466 return new InterfaceDeclaration(name, bases, decls, hasDefinition); |
112 | 467 } |
468 | |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
469 Declaration parseAggregateDeclaration() |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
470 { |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
471 assert(token.type == T.Struct || token.type == T.Union); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
472 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
473 TOK tok = token.type; |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
474 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
475 string name; |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
476 Declaration[] decls; |
116 | 477 bool hasDefinition; |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
478 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
479 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
|
480 // name is optional. |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
481 if (token.type == T.Identifier) |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
482 { |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
483 name = token.identifier; |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
484 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
485 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
|
486 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
487 // TODO: parse template parameters |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
488 } |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
489 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
490 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
491 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
|
492 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
493 //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
|
494 // TODO: error: forward declarations must have a name. |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
495 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
496 } |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
497 else if (token.type == T.LBrace) |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
498 { |
116 | 499 hasDefinition = true; |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
500 nT(); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
501 decls = parseDeclarationDefinitions(); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
502 require(T.RBrace); |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
503 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
504 else |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
505 errorIfNot(T.LBrace); // TODO: better error msg |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
506 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
507 // TODO: error if decls.length == 0 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
508 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
509 if (tok == T.Struct) |
116 | 510 return new StructDeclaration(name, decls, hasDefinition); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
511 else |
116 | 512 return new UnionDeclaration(name, decls, hasDefinition); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
513 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
514 |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
515 Declaration parseConstructorDeclaration() |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
516 { |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
517 assert(token.type == T.This); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
518 nT(); // Skip 'this' keyword. |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
519 auto parameters = parseParameters(); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
520 require(T.LBrace); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
521 auto statements = parseStatements(); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
522 require(T.RBrace); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
523 return new ConstructorDeclaration(parameters, statements); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
524 } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
525 |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
526 Declaration parseDestructorDeclaration() |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
527 { |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
528 assert(token.type == T.Tilde); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
529 nT(); // Skip ~ |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
530 require(T.This); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
531 require(T.LParen); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
532 require(T.RParen); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
533 require(T.LBrace); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
534 auto statements = parseStatements(); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
535 require(T.RBrace); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
536 return new DestructorDeclaration(statements); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
537 } |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
538 |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
539 Declaration parseStaticConstructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
540 { |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
541 assert(token.type == T.Static); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
542 nT(); // Skip static keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
543 nT(); // Skip 'this' keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
544 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
545 require(T.RParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
546 require(T.LBrace); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
547 auto statements = parseStatements(); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
548 require(T.RBrace); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
549 return new StaticConstructorDeclaration(statements); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
550 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
551 |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
552 Declaration parseStaticDestructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
553 { |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
554 assert(token.type == T.Static); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
555 nT(); // Skip static keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
556 nT(); // Skip ~ |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
557 require(T.This); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
558 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
559 require(T.RParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
560 require(T.LBrace); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
561 auto statements = parseStatements(); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
562 require(T.RBrace); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
563 return new StaticDestructorDeclaration(statements); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
564 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
565 |
120 | 566 Declaration parseInvariantDeclaration() |
567 { | |
568 assert(token.type == T.Invariant); | |
569 nT(); // Skip invariant keyword. | |
570 // Optional () for getting ready porting to D 2.0 | |
571 if (token.type == T.LParen) | |
122 | 572 requireNext(T.RParen); |
120 | 573 require(T.LBrace); |
574 auto statements = parseStatements(); | |
575 require(T.RBrace); | |
576 return new InvariantDeclaration(statements); | |
577 } | |
578 | |
121 | 579 Declaration parseUnittestDeclaration() |
580 { | |
581 assert(token.type == T.Unittest); | |
582 | |
122 | 583 nT(); // Skip unittest keyword. |
121 | 584 require(T.LBrace); |
585 auto statements = parseStatements(); | |
586 require(T.RBrace); | |
587 return new UnittestDeclaration(statements); | |
588 } | |
589 | |
122 | 590 Declaration parseDebugDeclaration() |
591 { | |
592 assert(token.type == T.Debug); | |
593 | |
594 nT(); // Skip debug keyword. | |
595 | |
596 int levelSpec = -1; // debug = Integer ; | |
597 string identSpec; // debug = Identifier ; | |
598 int levelCond = -1; // debug ( Integer ) | |
599 string identCond; // debug ( Identifier ) | |
600 Declaration[] decls, elseDecls; | |
601 | |
602 if (token.type == T.Assign) | |
603 { | |
604 nT(); | |
605 if (token.type == T.Int32) | |
606 levelSpec = token.int_; | |
607 else if (token.type == T.Identifier) | |
608 identSpec = token.identifier; | |
609 else | |
610 errorIfNot(T.Identifier); // TODO: better error msg | |
611 nT(); | |
612 require(T.Semicolon); | |
613 } | |
614 else | |
615 { | |
616 // '(' (Identifier | Integer) ')' | |
617 if (token.type == T.LParen) | |
618 { | |
619 nT(); | |
620 if (token.type == T.Int32) | |
621 levelCond = token.int_; | |
622 else if (token.type == T.Identifier) | |
623 identCond = token.identifier; | |
624 else | |
625 errorIfNot(T.Identifier); // TODO: better error msg | |
626 nT(); | |
627 require(T.RParen); | |
628 } | |
629 | |
630 if (token.type == T.Colon) | |
631 { | |
632 // debug: | |
633 // "debug" '(' (Identifier | Integer) ')': | |
634 nT(); | |
635 decls = parseDeclarationDefinitions(); | |
636 } | |
637 else | |
638 { | |
639 // debug DeclarationsBlock | |
640 // "debug" '(' (Identifier | Integer) ')' DeclarationsBlock | |
641 decls = parseDeclarationsBlock(); | |
642 | |
643 // else DeclarationsBlock | |
644 // debug without condition and else statement makes no sense | |
645 if (token.type == T.Else && (levelCond != -1 || identCond.length != 0)) | |
646 { | |
647 nT(); | |
648 //if (token.type == T.Colon) | |
649 // TODO: avoid "else:"? | |
650 elseDecls = parseDeclarationsBlock(); | |
651 } | |
652 } | |
653 } | |
654 | |
655 return new DebugDeclaration(levelSpec, identSpec, levelCond, identCond, decls, elseDecls); | |
656 } | |
657 | |
102 | 658 /+++++++++++++++++++++++++++++ |
659 + Expression parsing methods + | |
660 +++++++++++++++++++++++++++++/ | |
661 | |
72 | 662 Expression parseExpression() |
663 { | |
664 auto e = parseAssignExpression(); | |
122 | 665 while (token.type == T.Comma) |
81 | 666 e = new CommaExpression(e, parseAssignExpression()); |
72 | 667 return e; |
668 } | |
669 | |
71 | 670 Expression parseAssignExpression() |
671 { | |
672 auto e = parseCondExpression(); | |
72 | 673 while (1) |
71 | 674 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
675 switch (token.type) |
72 | 676 { |
677 case T.Assign: | |
678 nT(); e = new AssignExpression(e, parseAssignExpression()); | |
679 break; | |
680 case T.LShiftAssign: | |
681 nT(); e = new LShiftAssignExpression(e, parseAssignExpression()); | |
682 break; | |
683 case T.RShiftAssign: | |
684 nT(); e = new RShiftAssignExpression(e, parseAssignExpression()); | |
685 break; | |
686 case T.URShiftAssign: | |
687 nT(); e = new URShiftAssignExpression(e, parseAssignExpression()); | |
688 break; | |
689 case T.OrAssign: | |
690 nT(); e = new OrAssignExpression(e, parseAssignExpression()); | |
691 break; | |
692 case T.AndAssign: | |
693 nT(); e = new AndAssignExpression(e, parseAssignExpression()); | |
694 break; | |
695 case T.PlusAssign: | |
696 nT(); e = new PlusAssignExpression(e, parseAssignExpression()); | |
697 break; | |
698 case T.MinusAssign: | |
699 nT(); e = new MinusAssignExpression(e, parseAssignExpression()); | |
700 break; | |
701 case T.DivAssign: | |
702 nT(); e = new DivAssignExpression(e, parseAssignExpression()); | |
703 break; | |
704 case T.MulAssign: | |
705 nT(); e = new MulAssignExpression(e, parseAssignExpression()); | |
706 break; | |
707 case T.ModAssign: | |
708 nT(); e = new ModAssignExpression(e, parseAssignExpression()); | |
709 break; | |
710 case T.XorAssign: | |
711 nT(); e = new XorAssignExpression(e, parseAssignExpression()); | |
712 break; | |
713 case T.CatAssign: | |
714 nT(); e = new CatAssignExpression(e, parseAssignExpression()); | |
715 break; | |
716 default: | |
717 break; | |
718 } | |
71 | 719 break; |
720 } | |
721 return e; | |
722 } | |
72 | 723 |
71 | 724 Expression parseCondExpression() |
725 { | |
72 | 726 auto e = parseOrOrExpression(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
727 if (token.type == T.Question) |
72 | 728 { |
729 nT(); | |
730 auto iftrue = parseExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
731 require(T.Colon); |
72 | 732 auto iffalse = parseCondExpression(); |
733 e = new CondExpression(e, iftrue, iffalse); | |
734 } | |
735 return e; | |
736 } | |
737 | |
738 Expression parseOrOrExpression() | |
739 { | |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
740 alias parseAndAndExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
741 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
742 if (token.type == T.OrLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
743 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
744 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
745 e = new OrOrExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
746 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
747 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
748 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
749 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
750 Expression parseAndAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
751 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
752 alias parseOrExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
753 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
754 if (token.type == T.AndLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
755 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
756 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
757 e = new AndAndExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
758 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
759 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
760 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
761 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
762 Expression parseOrExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
763 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
764 alias parseXorExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
765 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
766 if (token.type == T.OrBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
767 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
768 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
769 e = new OrExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
770 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
771 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
772 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
773 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
774 Expression parseXorExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
775 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
776 alias parseAndExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
777 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
778 if (token.type == T.Xor) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
779 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
780 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
781 e = new XorExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
782 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
783 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
784 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
785 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
786 Expression parseAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
787 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
788 alias parseCmpExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
789 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
790 if (token.type == T.AndBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
791 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
792 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
793 e = new AndExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
794 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
795 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
796 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
797 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
798 Expression parseCmpExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
799 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
800 TOK operator = token.type; |
74 | 801 |
802 auto e = parseShiftExpression(); | |
803 | |
804 switch (operator) | |
805 { | |
806 case T.Equal, T.NotEqual: | |
807 nT(); | |
808 e = new EqualExpression(e, parseShiftExpression(), operator); | |
809 break; | |
810 case T.Not: | |
811 Token t; | |
812 lx.peek(t); | |
813 if (t.type != T.Is) | |
814 break; | |
815 nT(); | |
816 operator = T.NotIdentity; | |
817 goto LNotIdentity; | |
818 case T.Identity: | |
819 operator = T.Identity; | |
820 LNotIdentity: | |
821 nT(); | |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
822 e = new IdentityExpression(e, parseShiftExpression(), operator); |
74 | 823 break; |
824 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater, | |
825 T.Unordered, T.UorE, T.UorG, T.UorGorE, | |
826 T.UorL, T.UorLorE, T.LorEorG, T.LorG: | |
827 nT(); | |
828 e = new RelExpression(e, parseShiftExpression(), operator); | |
829 break; | |
830 case T.In: | |
831 nT(); | |
832 e = new InExpression(e, parseShiftExpression(), operator); | |
833 break; | |
834 default: | |
835 } | |
836 return e; | |
837 } | |
838 | |
839 Expression parseShiftExpression() | |
840 { | |
75 | 841 auto e = parseAddExpression(); |
842 while (1) | |
843 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
844 switch (token.type) |
75 | 845 { |
846 case T.LShift: nT(); e = new LShiftExpression(e, parseAddExpression()); break; | |
847 case T.RShift: nT(); e = new RShiftExpression(e, parseAddExpression()); break; | |
848 case T.URShift: nT(); e = new URShiftExpression(e, parseAddExpression()); break; | |
849 default: break; | |
850 } | |
851 break; | |
852 } | |
853 return e; | |
854 } | |
855 | |
856 Expression parseAddExpression() | |
857 { | |
76 | 858 auto e = parseMulExpression(); |
859 while (1) | |
860 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
861 switch (token.type) |
76 | 862 { |
863 case T.Plus: nT(); e = new PlusExpression(e, parseMulExpression()); break; | |
864 case T.Minus: nT(); e = new MinusExpression(e, parseMulExpression()); break; | |
865 case T.Tilde: nT(); e = new CatExpression(e, parseMulExpression()); break; | |
866 default: break; | |
867 } | |
868 break; | |
869 } | |
870 return new Expression(); | |
871 } | |
872 | |
873 Expression parseMulExpression() | |
874 { | |
77 | 875 auto e = parseUnaryExpression(); |
876 while (1) | |
877 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
878 switch (token.type) |
77 | 879 { |
880 case T.Mul: nT(); e = new MulExpression(e, parseUnaryExpression()); break; | |
881 case T.Div: nT(); e = new DivExpression(e, parseUnaryExpression()); break; | |
882 case T.Mod: nT(); e = new ModExpression(e, parseUnaryExpression()); break; | |
883 default: break; | |
884 } | |
885 break; | |
886 } | |
74 | 887 return new Expression(); |
71 | 888 } |
889 | |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
890 Expression parseUnaryExpression() |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
891 { |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
892 Expression e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
893 switch (token.type) |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
894 { |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
895 case T.AndBinary: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
896 nT(); e = new AddressExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
897 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
898 case T.PlusPlus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
899 nT(); e = new PreIncrExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
900 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
901 case T.MinusMinus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
902 nT(); e = new PreDecrExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
903 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
904 case T.Mul: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
905 nT(); e = new DerefExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
906 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
907 case T.Minus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
908 case T.Plus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
909 nT(); e = new SignExpression(parseUnaryExpression(), token.type); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
910 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
911 case T.Not: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
912 nT(); e = new NotExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
913 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
914 case T.Tilde: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
915 nT(); e = new CompExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
916 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
917 case T.New: |
102 | 918 // TODO: parseNewExpression(); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
919 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
920 case T.Delete: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
921 nT(); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
922 e = new DeleteExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
923 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
924 case T.Cast: |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
925 requireNext(T.LParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
926 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
927 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
928 e = new CastExpression(parseUnaryExpression(), type); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
929 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
930 case T.LParen: |
102 | 931 // ( Type ) . Identifier |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
932 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
933 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
934 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
|
935 string ident = requireIdentifier(); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
936 e = new TypeDotIdExpression(type, ident); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
937 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
938 default: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
939 e = parsePostExpression(parsePrimaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
940 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
941 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
942 assert(e !is null); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
943 return e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
944 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
945 |
90
a02950cb7036
- Fixed order of parsing unary, post and primary expressions.
aziz
parents:
89
diff
changeset
|
946 Expression parsePostExpression(Expression e) |
77 | 947 { |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
948 while (1) |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
949 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
950 switch (token.type) |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
951 { |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
952 case T.Dot: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
953 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
954 if (token.type == T.Identifier) |
92 | 955 { |
108 | 956 e = new DotIdExpression(e, token.identifier); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
957 break; |
92 | 958 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
959 else if (token.type == T.New) |
81 | 960 e = parseNewExpression(e); |
92 | 961 else |
962 errorIfNot(T.Identifier); | |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
963 continue; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
964 case T.PlusPlus: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
965 e = new PostIncrExpression(e); |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
966 break; |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
967 case T.MinusMinus: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
968 e = new PostDecrExpression(e); |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
969 break; |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
970 case T.LParen: |
81 | 971 e = new CallExpression(e, parseArgumentList(T.LParen)); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
972 continue; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
973 case T.LBracket: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
974 // parse Slice- and IndexExpression |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
975 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
976 if (token.type == T.RBracket) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
977 { |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
978 e = new SliceExpression(e, null, null); |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
979 break; |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
980 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
981 |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
982 Expression[] es = [parseAssignExpression()]; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
983 |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
984 if (token.type == T.Slice) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
985 { |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
986 nT(); |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
987 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
|
988 require(T.RBracket); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
989 continue; |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
990 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
991 else if (token.type == T.Comma) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
992 { |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
993 es ~= parseArgumentList(T.RBracket); |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
994 } |
85 | 995 else |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
996 require(T.RBracket); |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
997 |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
998 e = new IndexExpression(e, es); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
999 continue; |
92 | 1000 default: |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1001 return e; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1002 } |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1003 nT(); |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1004 } |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
1005 assert(0); |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1006 } |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1007 |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
1008 Expression parsePrimaryExpression() |
78
f043759fb59a
- Added code to parseUnaryExpression(); not fully implemented.
aziz
parents:
77
diff
changeset
|
1009 { |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1010 Expression e; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1011 switch (token.type) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1012 { |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1013 case T.Identifier: |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1014 e = new IdentifierExpression(token.identifier); |
89 | 1015 nT(); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1016 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1017 case T.Dot: |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1018 requireNext(T.Identifier); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1019 e = new GlobalIdExpression(token.identifier); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1020 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1021 case T.This: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1022 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1023 e = new ThisExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1024 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1025 case T.Super: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1026 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1027 e = new SuperExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1028 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1029 case T.Null: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1030 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1031 e = new NullExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1032 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1033 case T.True, T.False: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1034 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1035 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
|
1036 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1037 case T.Dollar: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1038 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1039 e = new DollarExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1040 break; |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1041 case T.Int32, T.Int64, T.Uint32, T.Uint64: |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1042 nT(); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1043 e = new IntNumberExpression(token.type, token.ulong_); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1044 break; |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1045 case T.Float32, T.Float64, T.Float80, |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1046 T.Imaginary32, T.Imaginary64, T.Imaginary80: |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1047 nT(); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
1048 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
|
1049 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1050 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
|
1051 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1052 e = new CharLiteralExpression(token.type); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1053 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1054 case T.String: |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1055 char[] buffer = token.str; |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1056 char postfix = token.pf; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1057 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1058 while (token.type == T.String) |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1059 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1060 string tmp = token.str; |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1061 // if (postfix != token.pf) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1062 // error(); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1063 if (tmp.length > 1) |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1064 { |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1065 buffer[$-1] = tmp[0]; // replace '\0' |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1066 buffer ~= tmp[1..$]; // append the rest |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1067 } |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1068 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1069 } |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1070 e = new StringLiteralExpression(buffer); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1071 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1072 case T.LBracket: |
85 | 1073 Expression[] values; |
1074 | |
1075 nT(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1076 if (token.type != T.RBracket) |
85 | 1077 { |
1078 e = parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1079 if (token.type == T.Colon) |
85 | 1080 goto LparseAssocArray; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1081 else if (token.type == T.Comma) |
85 | 1082 values = [e] ~ parseArgumentList(T.RBracket); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1083 else |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1084 require(T.RBracket); |
85 | 1085 } |
1086 | |
1087 e = new ArrayLiteralExpression(values); | |
1088 break; | |
1089 | |
1090 LparseAssocArray: | |
1091 Expression[] keys; | |
1092 | |
1093 keys ~= e; | |
1094 nT(); // Skip colon. | |
1095 values ~= parseAssignExpression(); | |
1096 | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1097 if (token.type != T.RBracket) |
88 | 1098 { |
1099 require(T.Comma); | |
85 | 1100 while (1) |
1101 { | |
1102 keys ~= parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1103 if (token.type != T.Colon) |
85 | 1104 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1105 errorIfNot(T.Colon); |
85 | 1106 values ~= null; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1107 if (token.type == T.RBracket) |
85 | 1108 break; |
1109 else | |
1110 continue; | |
1111 } | |
1112 nT(); | |
1113 values ~= parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1114 if (token.type == T.RBracket) |
85 | 1115 break; |
88 | 1116 require(T.Comma); |
85 | 1117 } |
88 | 1118 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1119 assert(token.type == T.RBracket); |
85 | 1120 nT(); |
1121 e = new AssocArrayLiteralExpression(keys, values); | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1122 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1123 case T.LBrace: |
102 | 1124 // TODO: parse delegate literals: FunctionBody |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1125 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1126 case T.Function, T.Delegate: |
102 | 1127 // TODO: parse delegate/function literals: |
1128 // function Type? ( ArgumentList ) FunctionBody | |
1129 // function FunctionBody | |
1130 // delegate Type? ( ArgumentList ) FunctionBody | |
1131 // delegate FunctionBody | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1132 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1133 case T.Assert: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1134 Expression msg; |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1135 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1136 e = parseAssignExpression(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1137 if (token.type == T.Comma) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1138 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1139 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1140 msg = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1141 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1142 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1143 e = new AssertExpression(e, msg); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1144 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1145 case T.Mixin: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1146 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1147 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1148 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1149 e = new MixinExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1150 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1151 case T.Import: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1152 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1153 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1154 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1155 e = new ImportExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1156 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1157 case T.Typeid: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1158 requireNext(T.LParen); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1159 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1160 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1161 e = new TypeidExpression(type); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1162 break; |
101 | 1163 case T.Typeof: |
1164 requireNext(T.LParen); | |
1165 auto type = new TypeofType(parseExpression()); | |
1166 require(T.RParen); | |
1167 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
|
1168 { // typeof ( Expression ) . Identifier |
101 | 1169 nT(); |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1170 string ident = requireIdentifier; |
101 | 1171 e = new TypeDotIdExpression(type, ident); |
1172 } | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1173 else // typeof ( Expression ) |
101 | 1174 e = new TypeofExpression(type); |
1175 break; | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1176 case T.Is: |
100 | 1177 requireNext(T.LParen); |
1178 | |
1179 Type type; | |
1180 SpecializationType specType; | |
1181 string ident; // optional Identifier | |
1182 | |
1183 type = parseDeclarator(ident, true); | |
1184 | |
1185 switch (token.type) | |
1186 { | |
1187 case T.Colon, T.Equal: | |
1188 TOK specTok = token.type; | |
1189 nT(); | |
1190 switch (token.type) | |
1191 { | |
1192 case T.Typedef, | |
1193 T.Struct, | |
1194 T.Union, | |
1195 T.Class, | |
1196 T.Interface, | |
1197 T.Enum, | |
1198 T.Function, | |
1199 T.Delegate, | |
1200 T.Super, | |
1201 T.Return: | |
102 | 1202 nT(); |
100 | 1203 specType = new SpecializationType(specTok, token.type); |
1204 break; | |
1205 default: | |
1206 specType = new SpecializationType(specTok, parseType()); | |
1207 } | |
1208 default: | |
1209 } | |
102 | 1210 require(T.RParen); |
100 | 1211 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
|
1212 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1213 case T.LParen: |
102 | 1214 // TODO: parse ( ArgumentList ) FunctionBody type delegates |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1215 nT(); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1216 e = parseExpression(); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1217 require(T.RParen); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1218 break; |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1219 // BasicType . Identifier |
94 | 1220 case T.Void, T.Char, T.Wchar, T.Dchar, T.Bool, |
1221 T.Byte, T.Ubyte, T.Short, T.Ushort, | |
1222 T.Int, T.Uint, T.Long, T.Ulong, | |
1223 T.Float, T.Double, T.Real, | |
1224 T.Ifloat, T.Idouble, T.Ireal, | |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1225 T.Cfloat, T.Cdouble, T.Creal: |
94 | 1226 auto type = new Type(token.type); |
1227 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
|
1228 auto ident = requireIdentifier(); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1229 |
94 | 1230 e = new TypeDotIdExpression(type, ident); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1231 break; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
1232 default: |
102 | 1233 // TODO: issue error msg and decide what to return. |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1234 } |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
1235 return e; |
77 | 1236 } |
1237 | |
81 | 1238 Expression parseNewExpression(Expression e) |
1239 { | |
102 | 1240 // TODO: implement this method. |
81 | 1241 return null; |
1242 } | |
1243 | |
1244 Expression[] parseArgumentList(TOK terminator) | |
1245 { | |
1246 Expression[] es; | |
1247 | |
1248 nT(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1249 if (token.type == terminator) |
81 | 1250 { |
1251 nT(); | |
1252 return null; | |
1253 } | |
1254 | |
1255 while (1) | |
1256 { | |
1257 es ~= parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1258 if (token.type == terminator) |
81 | 1259 break; |
88 | 1260 require(T.Comma); |
81 | 1261 } |
1262 nT(); | |
1263 return es; | |
1264 } | |
1265 | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1266 Type parseType() |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1267 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
1268 return parseBasicType2(parseBasicType()); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1269 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1270 |
94 | 1271 Type parseBasicType() |
1272 { | |
1273 Type t; | |
1274 IdentifierType tident; | |
1275 | |
1276 switch (token.type) | |
1277 { | |
1278 case T.Void, T.Char, T.Wchar, T.Dchar, T.Bool, | |
1279 T.Byte, T.Ubyte, T.Short, T.Ushort, | |
1280 T.Int, T.Uint, T.Long, T.Ulong, | |
1281 T.Float, T.Double, T.Real, | |
1282 T.Ifloat, T.Idouble, T.Ireal, | |
1283 T.Cfloat, T.Cdouble, T.Creal: | |
1284 t = new Type(token.type); | |
1285 nT(); | |
1286 break; | |
1287 case T.Identifier, T.Dot: | |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1288 tident = new IdentifierType([token.identifier]); |
94 | 1289 nT(); |
102 | 1290 // TODO: parse template instance |
94 | 1291 // if (token.type == T.Not) |
1292 // parse template instance | |
1293 Lident: | |
1294 while (token.type == T.Dot) | |
1295 { | |
1296 nT(); | |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1297 tident ~= requireIdentifier(); |
102 | 1298 // TODO: parse template instance |
94 | 1299 // if (token.type == T.Not) |
1300 // parse template instance | |
1301 } | |
1302 t = tident; | |
1303 break; | |
1304 case T.Typeof: | |
1305 requireNext(T.LParen); | |
1306 tident = new TypeofType(parseExpression()); | |
1307 require(T.RParen); | |
1308 goto Lident; | |
1309 default: | |
102 | 1310 // TODO: issue error msg and return UndefinedType. |
94 | 1311 } |
1312 return t; | |
1313 } | |
1314 | |
95 | 1315 Type parseBasicType2(Type t) |
1316 { | |
1317 while (1) | |
1318 { | |
1319 switch (token.type) | |
1320 { | |
1321 case T.Mul: | |
1322 t = new PointerType(t); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1323 nT(); |
95 | 1324 break; |
1325 case T.LBracket: | |
106 | 1326 t = parseArrayType(t); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1327 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1328 case T.Function, T.Delegate: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1329 TOK tok = token.type; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1330 nT(); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1331 auto args = parseParameters(); |
102 | 1332 // TODO: create appropriate Type. |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1333 // if (tok == T.Function) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1334 // t = new FunctionType(); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1335 // else |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1336 // t = new DelegateType(); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1337 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1338 default: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1339 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1340 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1341 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1342 assert(0); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1343 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1344 |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1345 Type parseDeclaratorSuffix(Type t) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1346 { |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1347 while (1) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1348 { |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1349 switch (token.type) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1350 { |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1351 case T.LBracket: |
106 | 1352 t = parseArrayType(t); |
95 | 1353 continue; |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1354 case T.LParen: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1355 auto params = parseParameters(); |
102 | 1356 // TODO: create FunctionType. |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1357 // new FunctionType(params); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1358 break; |
100 | 1359 default: |
1360 break; | |
95 | 1361 } |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1362 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1363 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1364 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1365 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1366 |
106 | 1367 Type parseArrayType(Type t) |
1368 { | |
1369 assert(token.type == T.LBracket); | |
1370 nT(); | |
1371 if (token.type == T.RBracket) | |
1372 { | |
1373 t = new ArrayType(t); | |
1374 nT(); | |
1375 } | |
1376 else | |
1377 { | |
1378 bool failed; | |
1379 auto assocType = try_(parseType(), failed); | |
1380 if (!failed) | |
1381 t = new ArrayType(t, assocType); | |
1382 else | |
1383 { | |
1384 Expression e = parseExpression(), e2; | |
1385 if (token.type == T.Slice) | |
1386 { | |
1387 nT(); | |
1388 e2 = parseExpression(); | |
1389 } | |
1390 t = new ArrayType(t, e, e2); | |
1391 } | |
1392 require(T.RBracket); | |
1393 } | |
1394 return t; | |
1395 } | |
1396 | |
100 | 1397 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
|
1398 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
1399 auto t = parseType(); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1400 |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1401 if (token.type == T.Identifier) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1402 { |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1403 ident = token.identifier; |
95 | 1404 nT(); |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
1405 t = parseDeclaratorSuffix(t); |
95 | 1406 } |
100 | 1407 else if (!identOptional) |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1408 errorIfNot(T.Identifier); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1409 |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
1410 return t; |
95 | 1411 } |
1412 | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1413 Parameters parseParameters() |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1414 out(params) |
96 | 1415 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1416 if (params.length > 1) |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1417 foreach (param; params.items[0..$-1]) |
96 | 1418 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1419 if (param.isVariadic()) |
96 | 1420 assert(0, "variadic arguments can only appear at the end of the parameter list."); |
1421 } | |
1422 } | |
1423 body | |
95 | 1424 { |
1425 require(T.LParen); | |
1426 | |
1427 if (token.type == T.RParen) | |
1428 { | |
1429 nT(); | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1430 return Parameters.init; |
95 | 1431 } |
1432 | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1433 Parameters params; |
95 | 1434 StorageClass stc; |
1435 | |
1436 while (1) | |
1437 { | |
1438 stc = StorageClass.In; | |
1439 switch (token.type) | |
1440 { | |
1441 case T.In: stc = StorageClass.In; nT(); goto default; | |
1442 case T.Out: stc = StorageClass.Out; nT(); goto default; | |
1443 case T.Ref: stc = StorageClass.Ref; nT(); goto default; | |
1444 case T.Lazy: stc = StorageClass.Lazy; nT(); goto default; | |
1445 case T.Ellipses: | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1446 params ~= new Parameter(StorageClass.Variadic, null, null, null); |
95 | 1447 break; |
1448 default: | |
1449 string ident; | |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1450 auto type = parseDeclarator(ident); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1451 |
95 | 1452 Expression assignExpr; |
1453 if (token.type == T.Assign) | |
1454 { | |
1455 nT(); | |
1456 assignExpr = parseAssignExpression(); | |
1457 } | |
1458 | |
1459 if (token.type == T.Ellipses) | |
1460 { | |
1461 stc |= StorageClass.Variadic; | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1462 params ~= new Parameter(stc, type, ident, assignExpr); |
95 | 1463 nT(); |
1464 break; | |
1465 } | |
1466 | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1467 params ~= new Parameter(stc, type, ident, assignExpr); |
95 | 1468 if (token.type == T.Comma) |
1469 { | |
1470 nT(); | |
1471 continue; | |
1472 } | |
1473 break; | |
1474 } | |
1475 break; | |
1476 } | |
1477 require(T.RParen); | |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1478 return params; |
95 | 1479 } |
1480 | |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1481 void errorIfNot(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1482 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1483 if (token.type != tok) |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1484 error(MID.ExpectedButFound, tok, token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1485 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1486 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1487 void require(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1488 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1489 if (token.type == tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1490 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1491 else |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1492 error(MID.ExpectedButFound, tok, token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1493 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1494 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1495 void requireNext(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1496 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1497 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1498 if (token.type == tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1499 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1500 else |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1501 error(MID.ExpectedButFound, tok, token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1502 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1503 |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1504 string requireIdentifier() |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1505 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1506 string identifier; |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1507 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
|
1508 { |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1509 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
|
1510 nT(); |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1511 } |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1512 else |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1513 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
|
1514 return identifier; |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1515 } |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1516 |
71 | 1517 void error(MID id, ...) |
1518 { | |
94 | 1519 errors ~= new Information(InfoType.Parser, id, lx.loc, arguments(_arguments, _argptr)); |
71 | 1520 } |
65 | 1521 } |