annotate trunk/src/Parser.d @ 117:79857de26e86

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