Mercurial > projects > dil
annotate trunk/src/dil/parser/Parser.d @ 683:1ae72234db26
Implemented some methods in SemanticPass1.
Renamed Symbol.ident to name.
Added a constructor to Symbol.
Adapted constructors of classes that inherit from Symbol.
Added Alias and OverloadSet Symbol classes.
Renamed idents and values to names and inits in VariablesDeclaration.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Mon, 21 Jan 2008 17:10:12 +0100 |
parents | 7541c64fc423 |
children | 170ddcdc9711 |
rev | line source |
---|---|
0 | 1 /++ |
2 Author: Aziz Köksal | |
249 | 3 License: GPL3 |
0 | 4 +/ |
578
c769bc239006
Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
576
diff
changeset
|
5 module dil.parser.Parser; |
c769bc239006
Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
576
diff
changeset
|
6 |
576
0df647660e76
Moved Lexer.d to new package 'lexer'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
555
diff
changeset
|
7 import dil.lexer.Lexer; |
588
dcfec202718d
Moved dil.Types to dil.ast.Types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
587
diff
changeset
|
8 import dil.ast.Node; |
585
05c375fb2d5c
Moved dil.Declarations to dil.ast.Declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
9 import dil.ast.Declarations; |
587
7d0ba0c93e95
Moved dil.Statements to dil.ast.Statements.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
586
diff
changeset
|
10 import dil.ast.Statements; |
586
e25345656d10
Moved dil.Expressions to dil.ast.Expressions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
585
diff
changeset
|
11 import dil.ast.Expressions; |
588
dcfec202718d
Moved dil.Types to dil.ast.Types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
587
diff
changeset
|
12 import dil.ast.Types; |
608
fac9e8b258fc
Moved dil.ast.Parameter to dil.ast.Parameters.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
606
diff
changeset
|
13 import dil.ast.Parameters; |
601
9f96fd51cb41
Moved dil.IdTable to dil.lexer.IdTable.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
596
diff
changeset
|
14 import dil.lexer.IdTable; |
596
39fac5531b85
Moved dil.Token to dil.lexer.Token.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
588
diff
changeset
|
15 import dil.Messages; |
39fac5531b85
Moved dil.Token to dil.lexer.Token.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
588
diff
changeset
|
16 import dil.Information; |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
17 import dil.Enums; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
18 import dil.CompilerInfo; |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
19 import common; |
65 | 20 |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
21 /++ |
631
2feb88f5c867
Added dil.parser.ExpressionParser and dil.parser.Factory.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
619
diff
changeset
|
22 The Parser produces a full parse tree by analyzing |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
23 the tokens of the provided source code. |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
24 +/ |
65 | 25 class Parser |
26 { | |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
27 Lexer lexer; |
318 | 28 Token* token; /// Current non-whitespace token. |
29 Token* prevToken; /// Previous non-whitespace token. | |
71 | 30 |
532
50e64bab9c7a
Renamed InformationManager to InfoManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
531
diff
changeset
|
31 InfoManager infoMan; |
514
6ddff941862a
Added new error classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
511
diff
changeset
|
32 ParserError[] errors; |
71 | 33 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
34 ImportDeclaration[] imports; /// ImportDeclarations in the source text. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
35 |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
36 // Attributes are evaluated in the parsing phase. |
683
1ae72234db26
Implemented some methods in SemanticPass1.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
682
diff
changeset
|
37 // Will probably be moved to class SemanticPass1. |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
38 LinkageType linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
39 Protection protection; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
40 StorageClass storageClass; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
41 uint alignSize = DEFAULT_ALIGN_SIZE; |
364 | 42 |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
43 private alias TOK T; |
511
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
44 private alias TypeNode Type; |
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
45 |
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
46 /++ |
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
47 Construct a Parser object. |
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
48 Params: |
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
49 text = the UTF-8 source code. |
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
50 filePath = the path to the source code; used for error messages. |
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
51 +/ |
532
50e64bab9c7a
Renamed InformationManager to InfoManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
531
diff
changeset
|
52 this(char[] srcText, string filePath, InfoManager infoMan = null) |
71 | 53 { |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
519
diff
changeset
|
54 this.infoMan = infoMan; |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
55 lexer = new Lexer(srcText, filePath, infoMan); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
56 } |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
57 |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
58 protected void init() |
206 | 59 { |
60 nT(); | |
318 | 61 prevToken = token; |
206 | 62 } |
63 | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
64 void nT() |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
65 { |
318 | 66 prevToken = token; |
132 | 67 do |
68 { | |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
69 lexer.nextToken(); |
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
70 token = lexer.token; |
314
ebd21bbf296e
- Added Whitespace, Sheband and Hashline to enum TOK. TOK.Whitespace is a flag and tokens that are considered whitespace are flagged as such.
aziz
parents:
313
diff
changeset
|
71 } while (token.isWhitespace) // Skip whitespace |
71 | 72 } |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
73 |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
74 /++ |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
75 Start the parser and return the parsed Declarations. |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
76 +/ |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
77 CompoundDeclaration start() |
102 | 78 { |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
79 init(); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
80 auto begin = token; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
81 auto decls = new CompoundDeclaration; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
82 if (token.kind == T.Module) |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
83 decls ~= parseModuleDeclaration(); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
84 decls.addOptChildren(parseDeclarationDefinitions()); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
85 set(decls, begin); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
86 return decls; |
102 | 87 } |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
88 |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
89 /++ |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
90 Start the parser and return the parsed Expression. |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
91 +/ |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
92 Expression start2() |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
93 { |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
94 init(); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
95 return parseExpression(); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
96 } |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
97 |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
98 uint trying; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
99 uint errorCount; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
100 |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
101 /++ |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
102 This method executes the delegate parseMethod and when an error occurred |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
103 the state of the lexer and parser are restored. |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
104 +/ |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
105 ReturnType try_(ReturnType)(ReturnType delegate() parseMethod, out bool success) |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
106 { |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
107 auto oldToken = this.token; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
108 auto oldPrevToken = this.prevToken; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
109 auto oldCount = this.errorCount; |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
110 |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
111 ++trying; |
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
|
112 auto result = parseMethod(); |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
113 --trying; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
114 // Check if an error occurred. |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
115 if (errorCount != oldCount) |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
116 { |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
117 // Restore members. |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
118 token = oldToken; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
119 prevToken = oldPrevToken; |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
120 lexer.token = oldToken; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
121 errorCount = oldCount; |
214 | 122 success = false; |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
123 } |
214 | 124 else |
125 success = true; | |
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
|
126 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
|
127 } |
105 | 128 |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
129 /++ |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
130 Sets the begin and end tokens of an AST node. |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
131 +/ |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
132 Class set(Class)(Class node, Token* begin) |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
133 { |
318 | 134 node.setTokens(begin, this.prevToken); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
135 return node; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
136 } |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
137 |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
138 /++ |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
139 Returns true if set() has been called on a node. |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
140 +/ |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
141 bool isNodeSet(Node node) |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
142 { |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
143 return node.begin !is null && node.end !is null; |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
144 } |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
145 |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
146 TOK peekNext() |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
147 { |
239
7911f6a92e6e
- Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK.
aziz
parents:
238
diff
changeset
|
148 Token* next = token; |
296 | 149 do |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
150 lexer.peek(next); |
314
ebd21bbf296e
- Added Whitespace, Sheband and Hashline to enum TOK. TOK.Whitespace is a flag and tokens that are considered whitespace are flagged as such.
aziz
parents:
313
diff
changeset
|
151 while (next.isWhitespace) // Skip whitespace |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
152 return next.kind; |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
153 } |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
154 |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
155 TOK peekAfter(ref Token* next) |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
156 { |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
157 assert(next !is null); |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
158 do |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
159 lexer.peek(next); |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
160 while (next.isWhitespace) // Skip whitespace |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
161 return next.kind; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
162 } |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
163 |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
164 /// Skips the current token if its type matches tok and returns true. |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
165 bool skipped()(TOK tok) // Templatized, so it's inlined. |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
166 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
167 return token.kind == tok ? (nT(), true) : false; |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
168 } |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
169 |
102 | 170 /++++++++++++++++++++++++++++++ |
171 + Declaration parsing methods + | |
172 ++++++++++++++++++++++++++++++/ | |
173 | |
368 | 174 Declaration parseModuleDeclaration() |
175 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
176 assert(token.kind == T.Module); |
368 | 177 auto begin = token; |
178 ModuleFQN moduleFQN; | |
179 do | |
180 { | |
181 nT(); | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
182 moduleFQN ~= requireIdentifier(MSG.ExpectedModuleIdentifier); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
183 } while (token.kind == T.Dot) |
368 | 184 require(T.Semicolon); |
185 return set(new ModuleDeclaration(moduleFQN), begin); | |
186 } | |
187 | |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
188 /++ |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
189 Parse DeclarationDefinitions until the end of file is hit. |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
190 DeclDefs: |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
191 DeclDef |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
192 DeclDefs |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
193 +/ |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
194 Declaration[] parseDeclarationDefinitions() |
102 | 195 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
196 Declaration[] decls; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
197 while (token.kind != T.EOF) |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
198 decls ~= parseDeclarationDefinition(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
199 return decls; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
200 } |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
201 |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
202 /++ |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
203 Parse the body of a template, class, interface, struct or union. |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
204 DeclDefsBlock: |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
205 { } |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
206 { DeclDefs } |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
207 +/ |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
208 CompoundDeclaration parseDeclarationDefinitionsBody() |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
209 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
210 // Save attributes. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
211 auto linkageType = this.linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
212 auto protection = this.protection; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
213 auto storageClass = this.storageClass; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
214 // Clear attributes. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
215 this.linkageType = LinkageType.None; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
216 this.protection = Protection.None; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
217 this.storageClass = StorageClass.None; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
218 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
219 // Parse body. |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
220 auto begin = token; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
221 auto decls = new CompoundDeclaration; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
222 require(T.LBrace); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
223 while (token.kind != T.RBrace && token.kind != T.EOF) |
161 | 224 decls ~= parseDeclarationDefinition(); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
225 require(T.RBrace); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
226 set(decls, begin); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
227 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
228 // Restore original values. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
229 this.linkageType = linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
230 this.protection = protection; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
231 this.storageClass = storageClass; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
232 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
233 return decls; |
102 | 234 } |
235 | |
110 | 236 Declaration parseDeclarationDefinition() |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
237 out(decl) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
238 { assert(isNodeSet(decl)); } |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
239 body |
102 | 240 { |
262 | 241 auto begin = token; |
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
|
242 Declaration decl; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
243 switch (token.kind) |
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
|
244 { |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
245 case T.Align, |
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
|
246 T.Pragma, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
247 // Protection attributes |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
248 T.Export, |
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
|
249 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
|
250 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
|
251 T.Protected, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
252 T.Public: |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
253 decl = parseAttributeSpecifier(); |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
254 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
255 // Storage classes |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
256 case T.Extern, |
203
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
257 T.Deprecated, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
258 T.Override, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
259 T.Abstract, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
260 T.Synchronized, |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
261 //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
|
262 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
|
263 T.Const, |
269 | 264 //T.Invariant, // D 2.0 |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
265 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
|
266 T.Scope: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
267 case_StaticAttribute: |
269 | 268 case_InvariantAttribute: // D 2.0 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
269 return parseStorageAttribute(); |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
270 case T.Alias: |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
271 nT(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
272 decl = new AliasDeclaration(parseVariableOrFunction()); |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
273 break; |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
274 case T.Typedef: |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
275 nT(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
276 decl = new TypedefDeclaration(parseVariableOrFunction()); |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
277 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
|
278 case T.Static: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
279 switch (peekNext()) |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
280 { |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
281 case T.Import: |
429
052cbacb1642
Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
424
diff
changeset
|
282 goto case_Import; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
283 case T.This: |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
284 decl = parseStaticConstructorDeclaration(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
285 break; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
286 case T.Tilde: |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
287 decl = parseStaticDestructorDeclaration(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
288 break; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
289 case T.If: |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
290 decl = parseStaticIfDeclaration(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
291 break; |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
292 case T.Assert: |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
293 decl = parseStaticAssertDeclaration(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
294 break; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
295 default: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
296 goto case_StaticAttribute; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
297 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
298 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
|
299 case T.Import: |
429
052cbacb1642
Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
424
diff
changeset
|
300 case_Import: |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
301 decl = parseImportDeclaration(); |
673
64fec49651cf
Renamed VariableDeclaration to VariablesDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
671
diff
changeset
|
302 imports ~= decl.to!(ImportDeclaration); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
303 // Handle specially. StorageClass mustn't be set. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
304 decl.setProtection(this.protection); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
305 return set(decl, begin); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
306 case T.Enum: |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
307 decl = parseEnumDeclaration(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
308 break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
309 case T.Class: |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
310 decl = parseClassDeclaration(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
311 break; |
112 | 312 case T.Interface: |
313 decl = parseInterfaceDeclaration(); | |
314 break; | |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
315 case T.Struct, T.Union: |
638
7131c07997f9
Renamed parseAggregateDeclaration() to parseStructOrUnionDeclaration().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
637
diff
changeset
|
316 decl = parseStructOrUnionDeclaration(); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
317 break; |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
318 case T.This: |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
319 decl = parseConstructorDeclaration(); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
320 break; |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
321 case T.Tilde: |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
322 decl = parseDestructorDeclaration(); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
323 break; |
120 | 324 case T.Invariant: |
269 | 325 version(D2) |
326 { | |
327 auto next = token; | |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
328 if (peekAfter(next) == T.LParen) |
269 | 329 { |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
330 if (peekAfter(next) != T.RParen) |
269 | 331 goto case_Declaration; |
332 } | |
333 else | |
334 goto case_InvariantAttribute; | |
335 } | |
120 | 336 decl = parseInvariantDeclaration(); |
337 break; | |
121 | 338 case T.Unittest: |
339 decl = parseUnittestDeclaration(); | |
340 break; | |
122 | 341 case T.Debug: |
342 decl = parseDebugDeclaration(); | |
140 | 343 break; |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
344 case T.Version: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
345 decl = parseVersionDeclaration(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
346 break; |
140 | 347 case T.Template: |
348 decl = parseTemplateDeclaration(); | |
349 break; | |
141 | 350 case T.New: |
351 decl = parseNewDeclaration(); | |
352 break; | |
353 case T.Delete: | |
354 decl = parseDeleteDeclaration(); | |
355 break; | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
356 case T.Mixin: |
256 | 357 decl = parseMixin!(MixinDeclaration)(); |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
358 break; |
129 | 359 case T.Semicolon: |
360 nT(); | |
361 decl = new EmptyDeclaration(); | |
362 break; | |
192 | 363 // Declaration |
364 case T.Identifier, T.Dot, T.Typeof: | |
269 | 365 case_Declaration: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
366 return parseVariableOrFunction(this.storageClass, this.protection, this.linkageType); |
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
|
367 default: |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
368 if (token.isIntegralType) |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
369 goto case_Declaration; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
370 else if (token.kind == T.Module) |
637
fe66cecb6ec9
Reporting error if module declaration is not first.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
634
diff
changeset
|
371 { |
fe66cecb6ec9
Reporting error if module declaration is not first.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
634
diff
changeset
|
372 decl = parseModuleDeclaration(); |
fe66cecb6ec9
Reporting error if module declaration is not first.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
634
diff
changeset
|
373 error(begin, MSG.ModuleDeclarationNotFirst); |
fe66cecb6ec9
Reporting error if module declaration is not first.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
634
diff
changeset
|
374 return decl; |
fe66cecb6ec9
Reporting error if module declaration is not first.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
634
diff
changeset
|
375 } |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
376 |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
377 decl = new IllegalDeclaration(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
378 // Skip to next valid token. |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
379 do |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
380 nT(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
381 while (!token.isDeclDefStart && |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
382 token.kind != T.RBrace && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
383 token.kind != T.EOF) |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
384 auto text = Token.textSpan(begin, this.prevToken); |
616
506ce60760d8
Fixed some error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
608
diff
changeset
|
385 error(begin, MSG.IllegalDeclaration, text); |
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
|
386 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
387 decl.setProtection(this.protection); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
388 decl.setStorageClass(this.storageClass); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
389 assert(!isNodeSet(decl)); |
262 | 390 set(decl, begin); |
129 | 391 return decl; |
102 | 392 } |
393 | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
394 /++ |
122 | 395 DeclarationsBlock: |
396 : DeclDefs | |
397 { } | |
398 { DeclDefs } | |
399 DeclDef | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
400 +/ |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
401 Declaration parseDeclarationsBlock(bool noColon = false) |
122 | 402 { |
305 | 403 Declaration d; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
404 switch (token.kind) |
122 | 405 { |
406 case T.LBrace: | |
528
d0ac6faeaf66
Fixed something in dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
524
diff
changeset
|
407 auto begin = token; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
408 nT(); |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
409 auto decls = new CompoundDeclaration; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
410 while (token.kind != T.RBrace && token.kind != T.EOF) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
411 decls ~= parseDeclarationDefinition(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
412 require(T.RBrace); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
413 d = set(decls, begin); |
122 | 414 break; |
415 case T.Colon: | |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
416 if (noColon == true) |
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
417 goto default; |
122 | 418 nT(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
419 auto begin = token; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
420 auto decls = new CompoundDeclaration; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
421 while (token.kind != T.RBrace && token.kind != T.EOF) |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
422 decls ~= parseDeclarationDefinition(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
423 d = set(decls, begin); |
122 | 424 break; |
425 default: | |
305 | 426 d = parseDeclarationDefinition(); |
122 | 427 } |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
428 assert(isNodeSet(d)); |
305 | 429 return d; |
122 | 430 } |
431 | |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
432 Declaration parseDeclarationsBlockNoColon() |
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
433 { |
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
434 return parseDeclarationsBlock(true); |
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
435 } |
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
436 |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
437 /++ |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
438 Parses either a VariableDeclaration or a FunctionDeclaration. |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
439 Params: |
555
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
440 stc = previously parsed storage classes |
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
441 protection = previously parsed protection attribute |
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
442 linkType = previously parsed linkage type |
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
443 testAutoDeclaration = whether to check for an AutoDeclaration |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
444 optionalParameterList = a hint for how to parse C-style function pointers |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
445 +/ |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
446 Declaration parseVariableOrFunction(StorageClass stc = StorageClass.None, |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
447 Protection protection = Protection.None, |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
448 LinkageType linkType = LinkageType.None, |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
449 bool testAutoDeclaration = false, |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
450 bool optionalParameterList = true) |
192 | 451 { |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
452 auto begin = token; |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
453 Type type; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
454 Identifier* ident; |
192 | 455 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
456 // Check for AutoDeclaration: StorageClasses Identifier = |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
457 if (testAutoDeclaration && |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
458 token.kind == T.Identifier && |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
459 peekNext() == T.Assign) |
192 | 460 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
461 ident = token.ident; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
462 nT(); |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
463 } |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
464 else |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
465 { |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
466 type = parseType(); // VariableType or ReturnType |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
467 if (token.kind == T.LParen) |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
468 { |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
469 // C-style function pointers make the grammar ambiguous. |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
470 // We have to treat them specially at function scope. |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
471 // Example: |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
472 // void foo() { |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
473 // // A pointer to a function taking an integer and returning 'some_type'. |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
474 // some_type (*p_func)(int); |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
475 // // In the following case precedence is given to a CallExpression. |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
476 // something(*p); // 'something' may be a function/method or an object having opCall overloaded. |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
477 // } |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
478 // // A pointer to a function taking no parameters and returning 'something'. |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
479 // something(*p); |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
480 type = parseCFunctionPointerType(type, ident, optionalParameterList); |
415
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
481 } |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
482 else if (peekNext() == T.LParen) |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
483 { // Type FunctionName ( ParameterList ) FunctionBody |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
484 ident = requireIdentifier(MSG.ExpectedFunctionName); |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
485 ident || nT(); // Skip non-identifier token. |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
486 assert(token.kind == T.LParen); |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
487 // It's a function declaration |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
488 TemplateParameters tparams; |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
489 if (tokenAfterParenIs(T.LParen)) |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
490 { |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
491 // ( TemplateParameterList ) ( ParameterList ) |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
492 tparams = parseTemplateParameterList(); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
493 } |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
494 |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
495 auto params = parseParameterList(); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
496 version(D2) |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
497 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
498 switch (token.kind) |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
499 { |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
500 case T.Const: |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
501 stc |= StorageClass.Const; |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
502 nT(); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
503 break; |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
504 case T.Invariant: |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
505 stc |= StorageClass.Invariant; |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
506 nT(); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
507 break; |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
508 default: |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
509 } |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
510 } |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
511 // ReturnType FunctionName ( ParameterList ) |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
512 auto funcBody = parseFunctionBody(); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
513 auto d = new FunctionDeclaration(type, ident, tparams, params, funcBody); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
514 d.setStorageClass(stc); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
515 d.setLinkageType(linkType); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
516 d.setProtection(protection); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
517 return set(d, begin); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
518 } |
535
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
519 else |
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
520 { |
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
521 // Type VariableName DeclaratorSuffix |
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
522 ident = requireIdentifier(MSG.ExpectedVariableName); |
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
523 type = parseDeclaratorSuffix(type); |
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
524 } |
192 | 525 } |
526 | |
527 // It's a variable declaration. | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
528 Identifier*[] idents = [ident]; |
194 | 529 Expression[] values; |
199
a95fee6e4b7e
- Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents:
198
diff
changeset
|
530 goto LenterLoop; // We've already parsed an identifier. Jump to if statement and check for initializer. |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
531 while (token.kind == T.Comma) |
194 | 532 { |
222
4f31e4671e06
- Fix: nT() wasn't called in while loop to skip T.Comma.
aziz
parents:
220
diff
changeset
|
533 nT(); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
534 idents ~= requireIdentifier(MSG.ExpectedVariableName); |
194 | 535 LenterLoop: |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
536 if (skipped(T.Assign)) |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
537 values ~= parseInitializer(); |
199
a95fee6e4b7e
- Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents:
198
diff
changeset
|
538 else |
a95fee6e4b7e
- Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents:
198
diff
changeset
|
539 values ~= null; |
194 | 540 } |
541 require(T.Semicolon); | |
673
64fec49651cf
Renamed VariableDeclaration to VariablesDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
671
diff
changeset
|
542 auto d = new VariablesDeclaration(type, idents, values); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
543 d.setStorageClass(stc); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
544 d.setLinkageType(linkType); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
545 d.setProtection(protection); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
546 return set(d, begin); |
194 | 547 } |
192 | 548 |
194 | 549 Expression parseInitializer() |
550 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
551 if (token.kind == T.Void) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
552 { |
266 | 553 auto begin = token; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
554 auto next = peekNext(); |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
555 if (next == T.Comma || next == T.Semicolon) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
556 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
557 nT(); |
266 | 558 return set(new VoidInitializer(), begin); |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
559 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
560 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
561 return parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
562 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
563 |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
564 Expression parseNonVoidInitializer() |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
565 { |
266 | 566 auto begin = token; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
567 Expression init; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
568 switch (token.kind) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
569 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
570 case T.LBracket: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
571 // ArrayInitializer: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
572 // [ ] |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
573 // [ ArrayMemberInitializations ] |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
574 Expression[] keys; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
575 Expression[] values; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
576 |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
577 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
578 while (token.kind != T.RBracket) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
579 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
580 auto e = parseNonVoidInitializer(); |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
581 if (skipped(T.Colon)) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
582 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
583 keys ~= e; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
584 values ~= parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
585 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
586 else |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
587 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
588 keys ~= null; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
589 values ~= e; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
590 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
591 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
592 if (token.kind != T.Comma) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
593 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
594 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
595 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
596 require(T.RBracket); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
597 init = new ArrayInitializer(keys, values); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
598 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
599 case T.LBrace: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
600 // StructInitializer: |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
601 // { } |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
602 // { StructMemberInitializers } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
603 Expression parseStructInitializer() |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
604 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
605 Identifier*[] idents; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
606 Expression[] values; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
607 |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
608 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
609 while (token.kind != T.RBrace) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
610 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
611 if (token.kind == T.Identifier && |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
612 // Peek for colon to see if this is a member identifier. |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
613 peekNext() == T.Colon) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
614 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
615 idents ~= token.ident; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
616 nT(), nT(); // Skip Identifier : |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
617 } |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
618 else |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
619 idents ~= null; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
620 |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
621 // NonVoidInitializer |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
622 values ~= parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
623 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
624 if (token.kind != T.Comma) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
625 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
626 nT(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
627 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
628 require(T.RBrace); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
629 return new StructInitializer(idents, values); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
630 } |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
631 |
214 | 632 bool success; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
633 auto si = try_(&parseStructInitializer, success); |
214 | 634 if (success) |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
635 { |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
636 init = si; |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
637 break; |
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
638 } |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
639 assert(token.kind == T.LBrace); |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
640 //goto default; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
641 default: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
642 init = parseAssignExpression(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
643 } |
266 | 644 set(init, begin); |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
645 return init; |
192 | 646 } |
647 | |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
648 FuncBodyStatement parseFunctionBody() |
192 | 649 { |
268 | 650 auto begin = token; |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
651 auto func = new FuncBodyStatement; |
192 | 652 while (1) |
653 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
654 switch (token.kind) |
192 | 655 { |
656 case T.LBrace: | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
657 func.funcBody = parseStatements(); |
192 | 658 break; |
659 case T.Semicolon: | |
660 nT(); | |
661 break; | |
662 case T.In: | |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
663 if (func.inBody) |
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
664 error(MID.InContract); |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
665 nT(); |
192 | 666 func.inBody = parseStatements(); |
667 continue; | |
668 case T.Out: | |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
669 if (func.outBody) |
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
670 error(MID.OutContract); |
192 | 671 nT(); |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
672 if (skipped(T.LParen)) |
192 | 673 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
674 func.outIdent = requireIdentifier(MSG.ExpectedAnIdentifier); |
192 | 675 require(T.RParen); |
676 } | |
677 func.outBody = parseStatements(); | |
678 continue; | |
679 case T.Body: | |
680 nT(); | |
681 goto case T.LBrace; | |
682 default: | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
683 error(token, MSG.ExpectedFunctionBody, token.srcText); |
192 | 684 } |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
685 break; // Exit loop. |
192 | 686 } |
268 | 687 set(func, begin); |
299
559d5d62e0c1
- Added checks for null before adding member to Node.children.
aziz
parents:
298
diff
changeset
|
688 func.finishConstruction(); |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
689 return func; |
192 | 690 } |
691 | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
692 LinkageType parseLinkageType() |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
693 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
694 LinkageType linkageType; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
695 if (token.kind != T.LParen) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
696 return linkageType; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
697 |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
698 nT(); // Skip ( |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
699 if (token.kind == T.RParen) |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
700 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
701 nT(); |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
702 error(MID.MissingLinkageType); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
703 return linkageType; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
704 } |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
705 |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
706 auto identTok = requireId(); |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
707 |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
708 ID identID = identTok ? identTok.ident.identID : ID.Null; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
709 |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
710 switch (identID) |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
711 { |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
712 case ID.C: |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
713 if (skipped(T.PlusPlus)) |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
714 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
715 linkageType = LinkageType.Cpp; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
716 break; |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
717 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
718 linkageType = LinkageType.C; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
719 break; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
720 case ID.D: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
721 linkageType = LinkageType.D; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
722 break; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
723 case ID.Windows: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
724 linkageType = LinkageType.Windows; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
725 break; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
726 case ID.Pascal: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
727 linkageType = LinkageType.Pascal; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
728 break; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
729 case ID.System: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
730 linkageType = LinkageType.System; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
731 break; |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
732 default: |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
733 error(MID.UnrecognizedLinkageType, token.srcText); |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
734 } |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
735 require(T.RParen); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
736 return linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
737 } |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
738 |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
739 void checkLinkageType(ref LinkageType prev_lt, LinkageType lt, Token* begin) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
740 { |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
741 if (prev_lt == LinkageType.None) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
742 prev_lt = lt; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
743 else |
616
506ce60760d8
Fixed some error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
608
diff
changeset
|
744 error(begin, MSG.RedundantLinkageType, Token.textSpan(begin, this.prevToken)); |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
745 } |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
746 |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
747 Declaration parseStorageAttribute() |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
748 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
749 StorageClass stc, stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
750 LinkageType prev_linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
751 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
752 auto saved_storageClass = this.storageClass; // Save. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
753 // Nested function. |
305 | 754 Declaration parse() |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
755 { |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
756 Declaration decl; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
757 auto begin = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
758 switch (token.kind) |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
759 { |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
760 case T.Extern: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
761 if (peekNext() != T.LParen) |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
762 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
763 stc_tmp = StorageClass.Extern; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
764 goto Lcommon; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
765 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
766 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
767 nT(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
768 auto linkageType = parseLinkageType(); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
769 checkLinkageType(prev_linkageType, linkageType, begin); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
770 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
771 auto saved = this.linkageType; // Save. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
772 this.linkageType = linkageType; // Set. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
773 decl = new LinkageDeclaration(linkageType, parse()); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
774 set(decl, begin); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
775 this.linkageType = saved; // Restore. |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
776 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
777 case T.Override: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
778 stc_tmp = StorageClass.Override; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
779 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
780 case T.Deprecated: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
781 stc_tmp = StorageClass.Deprecated; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
782 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
783 case T.Abstract: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
784 stc_tmp = StorageClass.Abstract; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
785 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
786 case T.Synchronized: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
787 stc_tmp = StorageClass.Synchronized; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
788 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
789 case T.Static: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
790 stc_tmp = StorageClass.Static; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
791 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
792 case T.Final: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
793 stc_tmp = StorageClass.Final; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
794 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
795 case T.Const: |
269 | 796 version(D2) |
797 { | |
798 if (peekNext() == T.LParen) | |
799 goto case_Declaration; | |
800 } | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
801 stc_tmp = StorageClass.Const; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
802 goto Lcommon; |
269 | 803 version(D2) |
804 { | |
805 case T.Invariant: // D 2.0 | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
806 auto next = token; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
807 if (peekAfter(next) == T.LParen) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
808 { |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
809 if (peekAfter(next) != T.RParen) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
810 goto case_Declaration; // invariant ( Type ) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
811 decl = parseDeclarationDefinition(); // invariant ( ) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
812 decl.setStorageClass(stc); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
813 break; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
814 } |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
815 // invariant as StorageClass. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
816 stc_tmp = StorageClass.Invariant; |
269 | 817 goto Lcommon; |
818 } | |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
819 case T.Auto: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
820 stc_tmp = StorageClass.Auto; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
821 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
822 case T.Scope: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
823 stc_tmp = StorageClass.Scope; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
824 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
825 Lcommon: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
826 // Issue error if redundant. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
827 if (stc & stc_tmp) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
828 error(MID.RedundantStorageClass, token.srcText); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
829 else |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
830 stc |= stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
831 |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
832 nT(); |
650
eb490ba8dba0
Made AttributeDeclaration abstract.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
646
diff
changeset
|
833 decl = new StorageClassDeclaration(stc_tmp, parse()); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
834 set(decl, begin); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
835 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
836 case T.Identifier: |
269 | 837 case_Declaration: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
838 // This could be a normal Declaration or an AutoDeclaration |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
839 decl = parseVariableOrFunction(stc, this.protection, prev_linkageType, true); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
840 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
841 default: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
842 this.storageClass = stc; // Set. |
305 | 843 decl = parseDeclarationsBlock(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
844 this.storageClass = saved_storageClass; // Reset. |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
845 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
846 assert(isNodeSet(decl)); |
305 | 847 return decl; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
848 } |
305 | 849 return parse(); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
850 } |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
851 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
852 uint parseAlignAttribute() |
260 | 853 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
854 assert(token.kind == T.Align); |
260 | 855 nT(); // Skip align keyword. |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
856 uint size = DEFAULT_ALIGN_SIZE; // Global default. |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
857 if (skipped(T.LParen)) |
260 | 858 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
859 if (token.kind == T.Int32) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
860 (size = token.int_), nT(); |
260 | 861 else |
862 expected(T.Int32); | |
863 require(T.RParen); | |
864 } | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
865 return size; |
260 | 866 } |
867 | |
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
|
868 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
|
869 { |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
870 Declaration decl; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
871 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
872 switch (token.kind) |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
873 { |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
874 case T.Align: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
875 uint alignSize = parseAlignAttribute(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
876 auto saved = this.alignSize; // Save. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
877 this.alignSize = alignSize; // Set. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
878 decl = new AlignDeclaration(alignSize, parseDeclarationsBlock()); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
879 this.alignSize = saved; // Restore. |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
880 break; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
881 case T.Pragma: |
147 | 882 // Pragma: |
883 // pragma ( Identifier ) | |
884 // pragma ( Identifier , ExpressionList ) | |
885 nT(); | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
886 Identifier* ident; |
147 | 887 Expression[] args; |
888 | |
889 require(T.LParen); | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
890 ident = requireIdentifier(MSG.ExpectedPragmaIdentifier); |
147 | 891 |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
892 if (skipped(T.Comma)) |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
893 args = parseExpressionList(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
894 require(T.RParen); |
147 | 895 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
896 decl = new PragmaDeclaration(ident, args, parseDeclarationsBlock()); |
147 | 897 break; |
491
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
898 default: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
899 // Protection attributes |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
900 Protection prot; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
901 switch (token.kind) |
491
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
902 { |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
903 case T.Private: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
904 prot = Protection.Private; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
905 case T.Package: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
906 prot = Protection.Package; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
907 case T.Protected: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
908 prot = Protection.Protected; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
909 case T.Public: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
910 prot = Protection.Public; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
911 case T.Export: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
912 prot = Protection.Export; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
913 default: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
914 assert(0); |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
915 } |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
916 nT(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
917 auto saved = this.protection; // Save. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
918 this.protection = prot; // Set. |
491
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
919 decl = new ProtectionDeclaration(prot, parseDeclarationsBlock()); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
920 this.protection = saved; // Restore. |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
921 } |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
922 return decl; |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
923 } |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
924 |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
925 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
|
926 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
927 assert(token.kind == T.Import || token.kind == T.Static); |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
928 bool isStatic = skipped(T.Static); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
929 assert(token.kind == T.Import); |
555
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
930 nT(); // Skip import keyword. |
429
052cbacb1642
Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
424
diff
changeset
|
931 |
364 | 932 ModuleFQN[] moduleFQNs; |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
933 Identifier*[] moduleAliases; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
934 Identifier*[] bindNames; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
935 Identifier*[] bindAliases; |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
936 |
298 | 937 while (1) |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
938 { |
364 | 939 ModuleFQN moduleFQN; |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
940 Identifier* moduleAlias; |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
941 |
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
942 // AliasName = ModuleName |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
943 if (peekNext() == T.Assign) |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
944 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
945 moduleAlias = requireIdentifier(MSG.ExpectedAliasModuleName); |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
946 nT(); // Skip = |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
947 } |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
948 |
298 | 949 // Identifier(.Identifier)* |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
950 while (1) |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
951 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
952 moduleFQN ~= requireIdentifier(MSG.ExpectedModuleIdentifier); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
953 if (token.kind != T.Dot) |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
954 break; |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
955 nT(); |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
956 } |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
957 |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
958 // Push identifiers. |
364 | 959 moduleFQNs ~= moduleFQN; |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
960 moduleAliases ~= moduleAlias; |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
961 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
962 if (token.kind != T.Comma) |
298 | 963 break; |
964 nT(); | |
965 } | |
966 | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
967 if (token.kind == T.Colon) |
298 | 968 { |
969 // BindAlias = BindName(, BindAlias = BindName)*; | |
970 // BindName(, BindName)*; | |
320
0ce14640eb04
- Fix in parseImportDeclaration(): rewrote while loop and removed a call to nT().
aziz
parents:
319
diff
changeset
|
971 do |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
972 { |
298 | 973 nT(); |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
974 Identifier* bindAlias; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
975 // BindAlias = BindName |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
976 if (peekNext() == T.Assign) |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
977 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
978 bindAlias = requireIdentifier(MSG.ExpectedAliasImportName); |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
979 nT(); // Skip = |
298 | 980 } |
981 // Push identifiers. | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
982 bindNames ~= requireIdentifier(MSG.ExpectedImportName); |
298 | 983 bindAliases ~= bindAlias; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
984 } while (token.kind == T.Comma) |
298 | 985 } |
986 | |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
987 require(T.Semicolon); |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
988 |
366 | 989 return new ImportDeclaration(moduleFQNs, moduleAliases, bindNames, bindAliases, isStatic); |
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
|
990 } |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
991 |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
992 Declaration parseEnumDeclaration() |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
993 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
994 assert(token.kind == T.Enum); |
555
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
995 nT(); // Skip enum keyword. |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
996 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
997 Identifier* enumName; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
998 Type baseType; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
999 EnumMemberDeclaration[] members; |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
1000 bool hasBody; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1001 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1002 enumName = optionalIdentifier(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1003 |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1004 if (skipped(T.Colon)) |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1005 baseType = parseBasicType(); |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1006 |
639
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
1007 if (enumName && skipped(T.Semicolon)) |
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
1008 {} |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1009 else if (skipped(T.LBrace)) |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1010 { |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
1011 hasBody = true; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1012 while (token.kind != T.RBrace) |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1013 { |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1014 auto begin = token; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1015 auto name = requireIdentifier(MSG.ExpectedEnumMember); |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1016 Expression value; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1017 |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1018 if (skipped(T.Assign)) |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1019 value = parseAssignExpression(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1020 else |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1021 value = null; |
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1022 |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1023 members ~= set(new EnumMemberDeclaration(name, value), begin); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1024 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1025 if (token.kind != T.Comma) |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
1026 break; |
398
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1027 nT(); // Skip , |
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1028 } |
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1029 require(T.RBrace); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1030 } |
231 | 1031 else |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1032 error(token, MSG.ExpectedEnumBody, token.srcText); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1033 |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1034 return new EnumDeclaration(enumName, baseType, members, hasBody); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1035 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1036 |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1037 Declaration parseClassDeclaration() |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1038 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1039 assert(token.kind == T.Class); |
555
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
1040 nT(); // Skip class keyword. |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1041 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1042 Identifier* className; |
258 | 1043 TemplateParameters tparams; |
668
a1f8d8f2db38
Renamed some identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
659
diff
changeset
|
1044 BaseClassType[] bases; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1045 CompoundDeclaration decls; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1046 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1047 className = requireIdentifier(MSG.ExpectedClassName); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1048 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1049 if (token.kind == T.LParen) |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
1050 tparams = parseTemplateParameterList(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1051 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1052 if (token.kind == T.Colon) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1053 bases = parseBaseClasses(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1054 |
639
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
1055 if (bases.length == 0 && skipped(T.Semicolon)) |
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
1056 {} |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1057 else if (token.kind == T.LBrace) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1058 decls = parseDeclarationDefinitionsBody(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1059 else |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1060 error(token, MSG.ExpectedClassBody, token.srcText); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1061 |
494
9a7ca8c56e59
Refactored a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
493
diff
changeset
|
1062 return new ClassDeclaration(className, tparams, bases, decls); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1063 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1064 |
668
a1f8d8f2db38
Renamed some identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
659
diff
changeset
|
1065 BaseClassType[] parseBaseClasses(bool colonLeadsOff = true) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1066 { |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1067 if (colonLeadsOff) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1068 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1069 assert(token.kind == T.Colon); |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1070 nT(); // Skip colon |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
1071 } |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1072 |
668
a1f8d8f2db38
Renamed some identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
659
diff
changeset
|
1073 BaseClassType[] bases; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1074 |
646
68953760d569
Added class ParenExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
640
diff
changeset
|
1075 do |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1076 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1077 Protection prot = Protection.Public; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1078 switch (token.kind) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1079 { |
204 | 1080 case T.Identifier, T.Dot, T.Typeof: goto LparseBasicType; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1081 case T.Private: prot = Protection.Private; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1082 case T.Protected: prot = Protection.Protected; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1083 case T.Package: prot = Protection.Package; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1084 case T.Public: /*prot = Protection.Public;*/ break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1085 default: |
405
e2529923a0cb
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
404
diff
changeset
|
1086 error(MID.ExpectedBaseClasses, token.srcText); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1087 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1088 } |
158
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1089 nT(); // Skip protection attribute. |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1090 LparseBasicType: |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1091 auto begin = token; |
158
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1092 auto type = parseBasicType(); |
668
a1f8d8f2db38
Renamed some identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
659
diff
changeset
|
1093 bases ~= set(new BaseClassType(prot, type), begin); |
646
68953760d569
Added class ParenExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
640
diff
changeset
|
1094 } while (skipped(T.Comma)) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1095 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1096 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1097 |
112 | 1098 Declaration parseInterfaceDeclaration() |
1099 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1100 assert(token.kind == T.Interface); |
555
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
1101 nT(); // Skip interface keyword. |
112 | 1102 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1103 Identifier* name; |
258 | 1104 TemplateParameters tparams; |
668
a1f8d8f2db38
Renamed some identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
659
diff
changeset
|
1105 BaseClassType[] bases; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1106 CompoundDeclaration decls; |
112 | 1107 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1108 name = requireIdentifier(MSG.ExpectedInterfaceName); |
112 | 1109 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1110 if (token.kind == T.LParen) |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
1111 tparams = parseTemplateParameterList(); |
112 | 1112 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1113 if (token.kind == T.Colon) |
112 | 1114 bases = parseBaseClasses(); |
1115 | |
639
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
1116 if (bases.length == 0 && skipped(T.Semicolon)) |
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
1117 {} |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1118 else if (token.kind == T.LBrace) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1119 decls = parseDeclarationDefinitionsBody(); |
112 | 1120 else |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1121 error(token, MSG.ExpectedInterfaceBody, token.srcText); |
112 | 1122 |
494
9a7ca8c56e59
Refactored a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
493
diff
changeset
|
1123 return new InterfaceDeclaration(name, tparams, bases, decls); |
112 | 1124 } |
1125 | |
638
7131c07997f9
Renamed parseAggregateDeclaration() to parseStructOrUnionDeclaration().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
637
diff
changeset
|
1126 Declaration parseStructOrUnionDeclaration() |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1127 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1128 assert(token.kind == T.Struct || token.kind == T.Union); |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1129 TOK tok = token.kind; |
555
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
1130 nT(); // Skip struct or union keyword. |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1131 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1132 Identifier* name; |
258 | 1133 TemplateParameters tparams; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1134 CompoundDeclaration decls; |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1135 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1136 name = optionalIdentifier(); |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1137 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1138 if (name && token.kind == T.LParen) |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1139 tparams = parseTemplateParameterList(); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1140 |
639
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
1141 if (name && skipped(T.Semicolon)) |
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
1142 {} |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1143 else if (token.kind == T.LBrace) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1144 decls = parseDeclarationDefinitionsBody(); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1145 else |
639
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
1146 error(token, tok == T.Struct ? |
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
1147 MSG.ExpectedStructBody : |
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
1148 MSG.ExpectedUnionBody, token.srcText); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1149 |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1150 if (tok == T.Struct) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1151 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1152 auto sd = new StructDeclaration(name, tparams, decls); |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1153 sd.setAlignSize(this.alignSize); |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1154 return sd; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1155 } |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1156 else |
494
9a7ca8c56e59
Refactored a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
493
diff
changeset
|
1157 return new UnionDeclaration(name, tparams, decls); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1158 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1159 |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1160 Declaration parseConstructorDeclaration() |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1161 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1162 assert(token.kind == T.This); |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1163 nT(); // Skip 'this' keyword. |
143 | 1164 auto parameters = parseParameterList(); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1165 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1166 return new ConstructorDeclaration(parameters, funcBody); |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1167 } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1168 |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1169 Declaration parseDestructorDeclaration() |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1170 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1171 assert(token.kind == T.Tilde); |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1172 nT(); // Skip ~ |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1173 require(T.This); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1174 require(T.LParen); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1175 require(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1176 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1177 return new DestructorDeclaration(funcBody); |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1178 } |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1179 |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1180 Declaration parseStaticConstructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1181 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1182 assert(token.kind == T.Static); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1183 nT(); // Skip static keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1184 nT(); // Skip 'this' keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1185 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1186 require(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1187 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1188 return new StaticConstructorDeclaration(funcBody); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1189 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1190 |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1191 Declaration parseStaticDestructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1192 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1193 assert(token.kind == T.Static); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1194 nT(); // Skip static keyword. |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1195 nT(); // Skip ~ |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1196 require(T.This); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1197 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1198 require(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1199 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1200 return new StaticDestructorDeclaration(funcBody); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1201 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1202 |
120 | 1203 Declaration parseInvariantDeclaration() |
1204 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1205 assert(token.kind == T.Invariant); |
120 | 1206 nT(); // Skip invariant keyword. |
1207 // Optional () for getting ready porting to D 2.0 | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1208 if (token.kind == T.LParen) |
122 | 1209 requireNext(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1210 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1211 return new InvariantDeclaration(funcBody); |
120 | 1212 } |
1213 | |
121 | 1214 Declaration parseUnittestDeclaration() |
1215 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1216 assert(token.kind == T.Unittest); |
122 | 1217 nT(); // Skip unittest keyword. |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1218 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1219 return new UnittestDeclaration(funcBody); |
121 | 1220 } |
1221 | |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1222 Token* parseIdentOrInt() |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1223 { |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1224 if (skipped(T.Int32) || skipped(T.Identifier)) |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1225 return this.prevToken; |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1226 error(token, MSG.ExpectedIdentOrInt, token.srcText); |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1227 return null; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1228 } |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1229 |
122 | 1230 Declaration parseDebugDeclaration() |
1231 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1232 assert(token.kind == T.Debug); |
122 | 1233 nT(); // Skip debug keyword. |
1234 | |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1235 Token* spec; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1236 Token* cond; |
305 | 1237 Declaration decls, elseDecls; |
122 | 1238 |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1239 if (skipped(T.Assign)) |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1240 { // debug = Integer ; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1241 // debug = Identifier ; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1242 spec = parseIdentOrInt(); |
122 | 1243 require(T.Semicolon); |
1244 } | |
1245 else | |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1246 { // ( Condition ) |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1247 if (skipped(T.LParen)) |
122 | 1248 { |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1249 cond = parseIdentOrInt(); |
122 | 1250 require(T.RParen); |
1251 } | |
123 | 1252 // debug DeclarationsBlock |
1253 // debug ( Condition ) DeclarationsBlock | |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
1254 decls = parseDeclarationsBlockNoColon(); |
123 | 1255 // else DeclarationsBlock |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1256 if (skipped(T.Else)) |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1257 elseDecls = parseDeclarationsBlockNoColon(); |
123 | 1258 } |
1259 | |
264 | 1260 return new DebugDeclaration(spec, cond, decls, elseDecls); |
123 | 1261 } |
1262 | |
1263 Declaration parseVersionDeclaration() | |
1264 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1265 assert(token.kind == T.Version); |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
1266 nT(); // Skip version keyword. |
123 | 1267 |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1268 Token* spec; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1269 Token* cond; |
305 | 1270 Declaration decls, elseDecls; |
122 | 1271 |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1272 if (skipped(T.Assign)) |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1273 { // version = Integer ; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1274 // version = Identifier ; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1275 spec = parseIdentOrInt(); |
123 | 1276 require(T.Semicolon); |
1277 } | |
1278 else | |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1279 { // ( Condition ) |
123 | 1280 require(T.LParen); |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1281 cond = parseIdentOrInt(); |
123 | 1282 require(T.RParen); |
1283 // version ( Condition ) DeclarationsBlock | |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
1284 decls = parseDeclarationsBlockNoColon(); |
123 | 1285 // else DeclarationsBlock |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1286 if (skipped(T.Else)) |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1287 elseDecls = parseDeclarationsBlockNoColon(); |
122 | 1288 } |
1289 | |
264 | 1290 return new VersionDeclaration(spec, cond, decls, elseDecls); |
122 | 1291 } |
1292 | |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1293 Declaration parseStaticIfDeclaration() |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1294 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1295 assert(token.kind == T.Static); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1296 nT(); // Skip static keyword. |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1297 nT(); // Skip if keyword. |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1298 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1299 Expression condition; |
305 | 1300 Declaration ifDecls, elseDecls; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1301 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1302 require(T.LParen); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1303 condition = parseAssignExpression(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1304 require(T.RParen); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1305 |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
1306 ifDecls = parseDeclarationsBlockNoColon(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1307 |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1308 if (skipped(T.Else)) |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
1309 elseDecls = parseDeclarationsBlockNoColon(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1310 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1311 return new StaticIfDeclaration(condition, ifDecls, elseDecls); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1312 } |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1313 |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1314 Declaration parseStaticAssertDeclaration() |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1315 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1316 assert(token.kind == T.Static); |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1317 nT(); // Skip static keyword. |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1318 nT(); // Skip assert keyword. |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1319 Expression condition, message; |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1320 require(T.LParen); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1321 condition = parseAssignExpression(); |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1322 if (skipped(T.Comma)) |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1323 message = parseAssignExpression(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1324 require(T.RParen); |
128 | 1325 require(T.Semicolon); |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1326 return new StaticAssertDeclaration(condition, message); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1327 } |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1328 |
140 | 1329 Declaration parseTemplateDeclaration() |
1330 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1331 assert(token.kind == T.Template); |
140 | 1332 nT(); // Skip template keyword. |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1333 auto templateName = requireIdentifier(MSG.ExpectedTemplateName); |
143 | 1334 auto templateParams = parseTemplateParameterList(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1335 auto decls = parseDeclarationDefinitionsBody(); |
140 | 1336 return new TemplateDeclaration(templateName, templateParams, decls); |
1337 } | |
1338 | |
141 | 1339 Declaration parseNewDeclaration() |
1340 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1341 assert(token.kind == T.New); |
141 | 1342 nT(); // Skip new keyword. |
143 | 1343 auto parameters = parseParameterList(); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1344 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1345 return new NewDeclaration(parameters, funcBody); |
141 | 1346 } |
1347 | |
1348 Declaration parseDeleteDeclaration() | |
1349 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1350 assert(token.kind == T.Delete); |
141 | 1351 nT(); // Skip delete keyword. |
143 | 1352 auto parameters = parseParameterList(); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1353 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1354 return new DeleteDeclaration(parameters, funcBody); |
141 | 1355 } |
1356 | |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1357 Type parseTypeofType() |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1358 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1359 assert(token.kind == T.Typeof); |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1360 auto begin = token; |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1361 Type type; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1362 requireNext(T.LParen); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1363 switch (token.kind) |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1364 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1365 version(D2) |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1366 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1367 case T.Return: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1368 nT(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1369 type = new TypeofType(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1370 break; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1371 } |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1372 default: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1373 type = new TypeofType(parseExpression()); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1374 } |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1375 require(T.RParen); |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1376 set(type, begin); |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1377 return type; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1378 } |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1379 |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1380 /* |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1381 TemplateMixin: |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1382 mixin ( AssignExpression ) ; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1383 mixin TemplateIdentifier ; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1384 mixin TemplateIdentifier MixinIdentifier ; |
233 | 1385 mixin TemplateIdentifier !( TemplateArguments ) ; |
1386 mixin TemplateIdentifier !( TemplateArguments ) MixinIdentifier ; | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1387 */ |
256 | 1388 Class parseMixin(Class)() |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1389 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1390 assert(token.kind == T.Mixin); |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1391 nT(); // Skip mixin keyword. |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1392 |
256 | 1393 static if (is(Class == MixinDeclaration)) |
301
caef255a2801
- Fix in some ctors: adding only non-null members to this.children.
aziz
parents:
299
diff
changeset
|
1394 { |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1395 if (skipped(T.LParen)) |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1396 { |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1397 auto e = parseAssignExpression(); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1398 require(T.RParen); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1399 require(T.Semicolon); |
262 | 1400 return new MixinDeclaration(e); |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1401 } |
301
caef255a2801
- Fix in some ctors: adding only non-null members to this.children.
aziz
parents:
299
diff
changeset
|
1402 } |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1403 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1404 auto begin = token; |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1405 Expression e; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1406 Identifier* mixinIdent; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1407 |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1408 if (skipped(T.Dot)) |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1409 e = set(new ModuleScopeExpression(parseIdentifierExpression()), begin); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1410 else |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1411 e = parseIdentifierExpression(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1412 |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1413 while (skipped(T.Dot)) |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1414 e = set(new DotExpression(e, parseIdentifierExpression()), begin); |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1415 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1416 mixinIdent = optionalIdentifier(); |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1417 require(T.Semicolon); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1418 |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1419 return new Class(e, mixinIdent); |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1420 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1421 |
102 | 1422 /+++++++++++++++++++++++++++++ |
161 | 1423 + Statement parsing methods + |
1424 +++++++++++++++++++++++++++++/ | |
1425 | |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1426 CompoundStatement parseStatements() |
161 | 1427 { |
262 | 1428 auto begin = token; |
318 | 1429 require(T.LBrace); |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1430 auto statements = new CompoundStatement(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1431 while (token.kind != T.RBrace && token.kind != T.EOF) |
161 | 1432 statements ~= parseStatement(); |
318 | 1433 require(T.RBrace); |
262 | 1434 return set(statements, begin); |
161 | 1435 } |
1436 | |
1437 Statement parseStatement() | |
1438 { | |
261 | 1439 auto begin = token; |
161 | 1440 Statement s; |
188 | 1441 Declaration d; |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1442 |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1443 if (token.isIntegralType) |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1444 { |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1445 d = parseVariableOrFunction(); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1446 goto LreturnDeclarationStatement; |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1447 } |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1448 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1449 switch (token.kind) |
161 | 1450 { |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1451 case T.Align: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1452 uint size = parseAlignAttribute(); |
260 | 1453 // Restrict align attribute to structs in parsing phase. |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1454 StructDeclaration structDecl; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1455 if (token.kind == T.Struct) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1456 { |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1457 auto begin2 = token; |
638
7131c07997f9
Renamed parseAggregateDeclaration() to parseStructOrUnionDeclaration().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
637
diff
changeset
|
1458 structDecl = parseStructOrUnionDeclaration().to!(StructDeclaration); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1459 structDecl.setAlignSize(size); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1460 set(structDecl, begin2); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1461 } |
260 | 1462 else |
1463 expected(T.Struct); | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1464 |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1465 d = new AlignDeclaration(size, structDecl ? cast(Declaration)structDecl : new CompoundDeclaration); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1466 goto LreturnDeclarationStatement; |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1467 /+ Not applicable for statements. |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1468 T.Private, T.Package, T.Protected, T.Public, T.Export, |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1469 T.Deprecated, T.Override, T.Abstract,+/ |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1470 case T.Extern, |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1471 T.Final, |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1472 T.Const, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1473 T.Auto: |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1474 //T.Scope |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1475 //T.Static |
201 | 1476 case_parseAttribute: |
1477 s = parseAttributeStatement(); | |
261 | 1478 return s; |
161 | 1479 case T.Identifier: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1480 if (peekNext() == T.Colon) |
161 | 1481 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1482 auto ident = token.ident; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1483 nT(), nT(); // Skip Identifier : |
234 | 1484 s = new LabeledStatement(ident, parseNoScopeOrEmptyStatement()); |
161 | 1485 break; |
1486 } | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1487 goto case T.Dot; |
201 | 1488 case T.Dot, T.Typeof: |
214 | 1489 bool success; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1490 d = try_(delegate { |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1491 return parseVariableOrFunction(StorageClass.None, |
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1492 Protection.None, |
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1493 LinkageType.None, false, false); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1494 }, success |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1495 ); |
214 | 1496 if (success) |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1497 goto LreturnDeclarationStatement; // Declaration |
201 | 1498 else |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1499 goto case_parseExpressionStatement; // Expression |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1500 |
162 | 1501 case T.If: |
1502 s = parseIfStatement(); | |
1503 break; | |
164 | 1504 case T.While: |
1505 s = parseWhileStatement(); | |
1506 break; | |
165 | 1507 case T.Do: |
1508 s = parseDoWhileStatement(); | |
1509 break; | |
216 | 1510 case T.For: |
1511 s = parseForStatement(); | |
1512 break; | |
169 | 1513 case T.Foreach, T.Foreach_reverse: |
1514 s = parseForeachStatement(); | |
1515 break; | |
170 | 1516 case T.Switch: |
1517 s = parseSwitchStatement(); | |
1518 break; | |
171 | 1519 case T.Case: |
1520 s = parseCaseStatement(); | |
1521 break; | |
172 | 1522 case T.Default: |
1523 s = parseDefaultStatement(); | |
1524 break; | |
173 | 1525 case T.Continue: |
1526 s = parseContinueStatement(); | |
1527 break; | |
174 | 1528 case T.Break: |
1529 s = parseBreakStatement(); | |
1530 break; | |
175 | 1531 case T.Return: |
1532 s = parseReturnStatement(); | |
1533 break; | |
176 | 1534 case T.Goto: |
1535 s = parseGotoStatement(); | |
1536 break; | |
177 | 1537 case T.With: |
1538 s = parseWithStatement(); | |
1539 break; | |
178 | 1540 case T.Synchronized: |
1541 s = parseSynchronizedStatement(); | |
1542 break; | |
179 | 1543 case T.Try: |
1544 s = parseTryStatement(); | |
1545 break; | |
180 | 1546 case T.Throw: |
1547 s = parseThrowStatement(); | |
1548 break; | |
181 | 1549 case T.Scope: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1550 if (peekNext() != T.LParen) |
201 | 1551 goto case_parseAttribute; |
181 | 1552 s = parseScopeGuardStatement(); |
1553 break; | |
182 | 1554 case T.Volatile: |
1555 s = parseVolatileStatement(); | |
1556 break; | |
183 | 1557 case T.Asm: |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
1558 s = parseAsmBlockStatement(); |
183 | 1559 break; |
184 | 1560 case T.Pragma: |
1561 s = parsePragmaStatement(); | |
1562 break; | |
185 | 1563 case T.Mixin: |
246
52f4aa097865
- Fix: parse mixin as expression instead of statement when next token is T.LParen.
aziz
parents:
245
diff
changeset
|
1564 if (peekNext() == T.LParen) |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1565 goto case_parseExpressionStatement; // Parse as expression. |
256 | 1566 s = parseMixin!(MixinStatement)(); |
185 | 1567 break; |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1568 case T.Static: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1569 switch (peekNext()) |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1570 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1571 case T.If: |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1572 s = parseStaticIfStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1573 break; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1574 case T.Assert: |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1575 s = parseStaticAssertStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1576 break; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1577 default: |
201 | 1578 goto case_parseAttribute; |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1579 } |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1580 break; |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1581 case T.Debug: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1582 s = parseDebugStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1583 break; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1584 case T.Version: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1585 s = parseVersionStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1586 break; |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1587 // DeclDef |
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1588 case T.Alias, T.Typedef: |
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1589 d = parseDeclarationDefinition(); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1590 goto LreturnDeclarationStatement; |
188 | 1591 case T.Enum: |
1592 d = parseEnumDeclaration(); | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1593 goto LreturnDeclarationStatement; |
188 | 1594 case T.Class: |
1595 d = parseClassDeclaration(); | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1596 goto LreturnDeclarationStatement; |
188 | 1597 case T.Interface: |
1598 d = parseInterfaceDeclaration(); | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1599 goto LreturnDeclarationStatement; |
188 | 1600 case T.Struct, T.Union: |
638
7131c07997f9
Renamed parseAggregateDeclaration() to parseStructOrUnionDeclaration().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
637
diff
changeset
|
1601 d = parseStructOrUnionDeclaration(); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1602 // goto LreturnDeclarationStatement; |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1603 LreturnDeclarationStatement: |
261 | 1604 set(d, begin); |
188 | 1605 s = new DeclarationStatement(d); |
1606 break; | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1607 case T.LBrace: |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1608 s = parseScopeStatement(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1609 break; |
216 | 1610 case T.Semicolon: |
231 | 1611 nT(); |
216 | 1612 s = new EmptyStatement(); |
1613 break; | |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1614 /+ |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1615 Parse ExpressionStatement: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1616 +/ |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1617 // Tokens that start a PrimaryExpression. |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1618 // case T.Identifier, T.Dot, T.Typeof: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1619 case T.This: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1620 case T.Super: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1621 case T.Null: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1622 case T.True, T.False: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1623 // case T.Dollar: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1624 case T.Int32, T.Int64, T.Uint32, T.Uint64: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1625 case T.Float32, T.Float64, T.Float80, |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1626 T.Imaginary32, T.Imaginary64, T.Imaginary80: |
507
996041463028
Removed TOK.WCharLiteral and TOK.DCharLiteral.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
505
diff
changeset
|
1627 case T.CharLiteral: |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1628 case T.String: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1629 case T.LBracket: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1630 // case T.LBrace: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1631 case T.Function, T.Delegate: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1632 case T.Assert: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1633 // case T.Mixin: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1634 case T.Import: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1635 case T.Typeid: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1636 case T.Is: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1637 case T.LParen: |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1638 case T.Traits: // D2.0 |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1639 // Tokens that can start a UnaryExpression: |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1640 case T.AndBinary, T.PlusPlus, T.MinusMinus, T.Mul, T.Minus, |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1641 T.Plus, T.Not, T.Tilde, T.New, T.Delete, T.Cast: |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1642 case_parseExpressionStatement: |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1643 s = new ExpressionStatement(parseExpression()); |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1644 require(T.Semicolon); |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1645 break; |
161 | 1646 default: |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1647 if (token.isSpecialToken) |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1648 goto case_parseExpressionStatement; |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1649 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1650 if (token.kind != T.Dollar) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1651 // Assert that this isn't a valid expression. |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1652 assert(delegate bool(){ |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1653 bool success; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1654 auto expression = try_(&parseExpression, success); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1655 return success; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1656 }() == false, "Didn't expect valid expression." |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1657 ); |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1658 |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1659 // Report error: it's an illegal statement. |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1660 s = new IllegalStatement(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1661 // Skip to next valid token. |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1662 do |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1663 nT(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1664 while (!token.isStatementStart && |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1665 token.kind != T.RBrace && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1666 token.kind != T.EOF) |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1667 auto text = Token.textSpan(begin, this.prevToken); |
616
506ce60760d8
Fixed some error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
608
diff
changeset
|
1668 error(begin, MSG.IllegalStatement, text); |
161 | 1669 } |
205 | 1670 assert(s !is null); |
261 | 1671 set(s, begin); |
161 | 1672 return s; |
1673 } | |
1674 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1675 /++ |
162 | 1676 ScopeStatement: |
219 | 1677 NoScopeStatement |
162 | 1678 +/ |
164 | 1679 Statement parseScopeStatement() |
162 | 1680 { |
219 | 1681 return new ScopeStatement(parseNoScopeStatement()); |
162 | 1682 } |
1683 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1684 /++ |
166 | 1685 NoScopeStatement: |
1686 NonEmptyStatement | |
1687 BlockStatement | |
1688 BlockStatement: | |
1689 { } | |
1690 { StatementList } | |
1691 +/ | |
1692 Statement parseNoScopeStatement() | |
1693 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1694 auto begin = token; |
166 | 1695 Statement s; |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1696 if (skipped(T.LBrace)) |
166 | 1697 { |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1698 auto ss = new CompoundStatement(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1699 while (token.kind != T.RBrace && token.kind != T.EOF) |
166 | 1700 ss ~= parseStatement(); |
1701 require(T.RBrace); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1702 s = set(ss, begin); |
166 | 1703 } |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1704 else if (token.kind == T.Semicolon) |
219 | 1705 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1706 error(token, MSG.ExpectedNonEmptyStatement); |
219 | 1707 nT(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1708 s = set(new EmptyStatement(), begin); |
219 | 1709 } |
166 | 1710 else |
1711 s = parseStatement(); | |
1712 return s; | |
1713 } | |
1714 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1715 /++ |
234 | 1716 NoScopeOrEmptyStatement: |
1717 ; | |
1718 NoScopeStatement | |
1719 +/ | |
1720 Statement parseNoScopeOrEmptyStatement() | |
1721 { | |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1722 if (skipped(T.Semicolon)) |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1723 return set(new EmptyStatement(), this.prevToken); |
234 | 1724 else |
1725 return parseNoScopeStatement(); | |
1726 } | |
1727 | |
201 | 1728 Statement parseAttributeStatement() |
1729 { | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1730 StorageClass stc, stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1731 LinkageType prev_linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1732 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1733 // Nested function. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1734 Declaration parse() |
201 | 1735 { |
261 | 1736 auto begin = token; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1737 Declaration d; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1738 switch (token.kind) |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1739 { |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1740 case T.Extern: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1741 if (peekNext() != T.LParen) |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1742 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1743 stc_tmp = StorageClass.Extern; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1744 goto Lcommon; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1745 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1746 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1747 nT(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1748 auto linkageType = parseLinkageType(); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1749 checkLinkageType(prev_linkageType, linkageType, begin); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1750 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1751 d = new LinkageDeclaration(linkageType, parse()); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1752 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1753 case T.Static: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1754 stc_tmp = StorageClass.Static; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1755 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1756 case T.Final: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1757 stc_tmp = StorageClass.Final; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1758 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1759 case T.Const: |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1760 version(D2) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1761 { |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1762 if (peekNext() == T.LParen) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1763 goto case_Declaration; |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1764 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1765 stc_tmp = StorageClass.Const; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1766 goto Lcommon; |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1767 version(D2) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1768 { |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1769 case T.Invariant: // D 2.0 |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1770 if (peekNext() == T.LParen) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1771 goto case_Declaration; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1772 stc_tmp = StorageClass.Invariant; |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1773 goto Lcommon; |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1774 } |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1775 case T.Auto: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1776 stc_tmp = StorageClass.Auto; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1777 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1778 case T.Scope: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1779 stc_tmp = StorageClass.Scope; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1780 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1781 Lcommon: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1782 // Issue error if redundant. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1783 if (stc & stc_tmp) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1784 error(MID.RedundantStorageClass, token.srcText); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1785 else |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1786 stc |= stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1787 |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1788 nT(); |
650
eb490ba8dba0
Made AttributeDeclaration abstract.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
646
diff
changeset
|
1789 d = new StorageClassDeclaration(stc_tmp, parse()); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1790 break; |
239
7911f6a92e6e
- Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK.
aziz
parents:
238
diff
changeset
|
1791 // TODO: allow "scope class", "abstract scope class" in function bodies? |
7911f6a92e6e
- Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK.
aziz
parents:
238
diff
changeset
|
1792 //case T.Class: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1793 default: |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1794 case_Declaration: |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1795 return parseVariableOrFunction(stc, Protection.None, prev_linkageType, true); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1796 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1797 return set(d, begin); |
201 | 1798 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1799 return new DeclarationStatement(parse()); |
201 | 1800 } |
1801 | |
162 | 1802 Statement parseIfStatement() |
1803 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1804 assert(token.kind == T.If); |
162 | 1805 nT(); |
1806 | |
283 | 1807 Statement variable; |
162 | 1808 Expression condition; |
1809 Statement ifBody, elseBody; | |
1810 | |
1811 require(T.LParen); | |
283 | 1812 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1813 Identifier* ident; |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1814 auto begin = token; // For start of AutoDeclaration or normal Declaration. |
162 | 1815 // auto Identifier = Expression |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1816 if (skipped(T.Auto)) |
162 | 1817 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1818 ident = requireIdentifier(MSG.ExpectedVariableName); |
162 | 1819 require(T.Assign); |
283 | 1820 auto init = parseExpression(); |
673
64fec49651cf
Renamed VariableDeclaration to VariablesDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
671
diff
changeset
|
1821 auto v = new VariablesDeclaration(null, [ident], [init]); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1822 set(v, begin.nextNWS); |
650
eb490ba8dba0
Made AttributeDeclaration abstract.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
646
diff
changeset
|
1823 auto d = new StorageClassDeclaration(StorageClass.Auto, v); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1824 set(d, begin); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1825 variable = new DeclarationStatement(d); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1826 set(variable, begin); |
162 | 1827 } |
1828 else | |
1829 { | |
1830 // Declarator = Expression | |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1831 Type parseDeclaratorAssign() |
162 | 1832 { |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1833 auto type = parseDeclarator(ident); |
162 | 1834 require(T.Assign); |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1835 return type; |
162 | 1836 } |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1837 bool success; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
1838 auto type = try_(&parseDeclaratorAssign, success); |
283 | 1839 if (success) |
163
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1840 { |
283 | 1841 auto init = parseExpression(); |
673
64fec49651cf
Renamed VariableDeclaration to VariablesDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
671
diff
changeset
|
1842 auto v = new VariablesDeclaration(type, [ident], [init]); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1843 set(v, begin); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1844 variable = new DeclarationStatement(v); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1845 set(variable, begin); |
163
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1846 } |
283 | 1847 else |
1848 condition = parseExpression(); | |
162 | 1849 } |
1850 require(T.RParen); | |
164 | 1851 ifBody = parseScopeStatement(); |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1852 if (skipped(T.Else)) |
164 | 1853 elseBody = parseScopeStatement(); |
283 | 1854 return new IfStatement(variable, condition, ifBody, elseBody); |
162 | 1855 } |
1856 | |
164 | 1857 Statement parseWhileStatement() |
1858 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1859 assert(token.kind == T.While); |
164 | 1860 nT(); |
166 | 1861 require(T.LParen); |
164 | 1862 auto condition = parseExpression(); |
166 | 1863 require(T.RParen); |
164 | 1864 return new WhileStatement(condition, parseScopeStatement()); |
1865 } | |
1866 | |
165 | 1867 Statement parseDoWhileStatement() |
1868 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1869 assert(token.kind == T.Do); |
165 | 1870 nT(); |
1871 auto doBody = parseScopeStatement(); | |
1872 require(T.While); | |
166 | 1873 require(T.LParen); |
165 | 1874 auto condition = parseExpression(); |
166 | 1875 require(T.RParen); |
1876 return new DoWhileStatement(condition, doBody); | |
1877 } | |
1878 | |
1879 Statement parseForStatement() | |
1880 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1881 assert(token.kind == T.For); |
166 | 1882 nT(); |
165 | 1883 require(T.LParen); |
166 | 1884 |
1885 Statement init, forBody; | |
1886 Expression condition, increment; | |
1887 | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1888 if (token.kind != T.Semicolon) |
166 | 1889 init = parseNoScopeStatement(); |
230
8f1790d16753
- Fix: added missing call to parseDeclaratorSuffx() in parseDeclaration.
aziz
parents:
229
diff
changeset
|
1890 else |
8f1790d16753
- Fix: added missing call to parseDeclaratorSuffx() in parseDeclaration.
aziz
parents:
229
diff
changeset
|
1891 nT(); // Skip ; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1892 if (token.kind != T.Semicolon) |
166 | 1893 condition = parseExpression(); |
168 | 1894 require(T.Semicolon); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1895 if (token.kind != T.RParen) |
166 | 1896 increment = parseExpression(); |
168 | 1897 require(T.RParen); |
167 | 1898 forBody = parseScopeStatement(); |
166 | 1899 return new ForStatement(init, condition, increment, forBody); |
165 | 1900 } |
1901 | |
169 | 1902 Statement parseForeachStatement() |
1903 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1904 assert(token.kind == T.Foreach || token.kind == T.Foreach_reverse); |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1905 TOK tok = token.kind; |
169 | 1906 nT(); |
1907 | |
257 | 1908 auto params = new Parameters; |
269 | 1909 Expression e; // Aggregate or LwrExpression |
169 | 1910 |
1911 require(T.LParen); | |
1912 while (1) | |
1913 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
1914 auto paramBegin = token; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1915 StorageClass stc; |
169 | 1916 Type type; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1917 Identifier* ident; |
169 | 1918 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1919 switch (token.kind) |
169 | 1920 { |
236
e961d1b957c3
- Fix in parseForeachStatement(): added T.Inout to case T.Ref; removed break statement.
aziz
parents:
235
diff
changeset
|
1921 case T.Ref, T.Inout: |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1922 stc = StorageClass.Ref; |
169 | 1923 nT(); |
236
e961d1b957c3
- Fix in parseForeachStatement(): added T.Inout to case T.Ref; removed break statement.
aziz
parents:
235
diff
changeset
|
1924 // fall through |
169 | 1925 case T.Identifier: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1926 auto next = peekNext(); |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1927 if (next == T.Comma || next == T.Semicolon || next == T.RParen) |
169 | 1928 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1929 ident = requireIdentifier(MSG.ExpectedVariableName); |
169 | 1930 break; |
1931 } | |
1932 // fall through | |
1933 default: | |
1934 type = parseDeclarator(ident); | |
1935 } | |
1936 | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1937 params ~= set(new Parameter(stc, type, ident, null), paramBegin); |
169 | 1938 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1939 if (token.kind != T.Comma) |
169 | 1940 break; |
1941 nT(); | |
1942 } | |
1943 require(T.Semicolon); | |
269 | 1944 e = parseExpression(); |
1945 version(D2) | |
1946 { //Foreach (ForeachType; LwrExpression .. UprExpression ) ScopeStatement | |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1947 if (skipped(T.Slice)) |
269 | 1948 { |
1949 // if (params.length != 1) | |
1950 // error(MID.XYZ); // TODO: issue error msg | |
1951 auto upper = parseExpression(); | |
1952 require(T.RParen); | |
1953 auto forBody = parseScopeStatement(); | |
1954 return new ForeachRangeStatement(tok, params, e, upper, forBody); | |
1955 } | |
1956 } | |
1957 // Foreach (ForeachTypeList; Aggregate) ScopeStatement | |
169 | 1958 require(T.RParen); |
1959 auto forBody = parseScopeStatement(); | |
269 | 1960 return new ForeachStatement(tok, params, e, forBody); |
169 | 1961 } |
1962 | |
170 | 1963 Statement parseSwitchStatement() |
1964 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1965 assert(token.kind == T.Switch); |
170 | 1966 nT(); |
1967 require(T.LParen); | |
1968 auto condition = parseExpression(); | |
1969 require(T.RParen); | |
1970 auto switchBody = parseScopeStatement(); | |
1971 return new SwitchStatement(condition, switchBody); | |
1972 } | |
1973 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1974 /++ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1975 Helper function for parsing the body of |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1976 a default or case statement. |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1977 +/ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1978 Statement parseCaseOrDefaultBody() |
220 | 1979 { |
1980 // This function is similar to parseNoScopeStatement() | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1981 auto begin = token; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1982 auto s = new CompoundStatement(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1983 while (token.kind != T.Case && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1984 token.kind != T.Default && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1985 token.kind != T.RBrace && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1986 token.kind != T.EOF) |
224 | 1987 s ~= parseStatement(); |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
1988 set(s, begin); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1989 return set(new ScopeStatement(s), begin); |
220 | 1990 } |
1991 | |
171 | 1992 Statement parseCaseStatement() |
1993 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1994 assert(token.kind == T.Case); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
1995 nT(); |
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
1996 auto values = parseExpressionList(); |
171 | 1997 require(T.Colon); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1998 auto caseBody = parseCaseOrDefaultBody(); |
171 | 1999 return new CaseStatement(values, caseBody); |
2000 } | |
2001 | |
172 | 2002 Statement parseDefaultStatement() |
2003 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2004 assert(token.kind == T.Default); |
172 | 2005 nT(); |
2006 require(T.Colon); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2007 auto defaultBody = parseCaseOrDefaultBody(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2008 return new DefaultStatement(defaultBody); |
172 | 2009 } |
2010 | |
173 | 2011 Statement parseContinueStatement() |
2012 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2013 assert(token.kind == T.Continue); |
173 | 2014 nT(); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2015 auto ident = optionalIdentifier(); |
173 | 2016 require(T.Semicolon); |
2017 return new ContinueStatement(ident); | |
2018 } | |
2019 | |
174 | 2020 Statement parseBreakStatement() |
2021 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2022 assert(token.kind == T.Break); |
174 | 2023 nT(); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2024 auto ident = optionalIdentifier(); |
555
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
2025 require(T.Semicolon); |
174 | 2026 return new BreakStatement(ident); |
2027 } | |
2028 | |
175 | 2029 Statement parseReturnStatement() |
2030 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2031 assert(token.kind == T.Return); |
175 | 2032 nT(); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2033 Expression expr; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2034 if (token.kind != T.Semicolon) |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2035 expr = parseExpression(); |
175 | 2036 require(T.Semicolon); |
2037 return new ReturnStatement(expr); | |
2038 } | |
2039 | |
176 | 2040 Statement parseGotoStatement() |
2041 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2042 assert(token.kind == T.Goto); |
176 | 2043 nT(); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2044 Identifier* ident; |
176 | 2045 Expression caseExpr; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2046 switch (token.kind) |
176 | 2047 { |
2048 case T.Case: | |
2049 nT(); | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2050 if (token.kind == T.Semicolon) |
176 | 2051 break; |
2052 caseExpr = parseExpression(); | |
2053 break; | |
2054 case T.Default: | |
2055 nT(); | |
2056 break; | |
2057 default: | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2058 ident = requireIdentifier(MSG.ExpectedAnIdentifier); |
176 | 2059 } |
2060 require(T.Semicolon); | |
2061 return new GotoStatement(ident, caseExpr); | |
2062 } | |
2063 | |
177 | 2064 Statement parseWithStatement() |
2065 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2066 assert(token.kind == T.With); |
177 | 2067 nT(); |
2068 require(T.LParen); | |
2069 auto expr = parseExpression(); | |
2070 require(T.RParen); | |
2071 return new WithStatement(expr, parseScopeStatement()); | |
2072 } | |
2073 | |
178 | 2074 Statement parseSynchronizedStatement() |
2075 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2076 assert(token.kind == T.Synchronized); |
178 | 2077 nT(); |
2078 Expression expr; | |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2079 if (skipped(T.LParen)) |
178 | 2080 { |
2081 expr = parseExpression(); | |
2082 require(T.RParen); | |
2083 } | |
2084 return new SynchronizedStatement(expr, parseScopeStatement()); | |
2085 } | |
2086 | |
179 | 2087 Statement parseTryStatement() |
2088 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2089 assert(token.kind == T.Try); |
640
05645f5613c1
Added an error message.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
639
diff
changeset
|
2090 auto begin = token; |
179 | 2091 nT(); |
2092 | |
2093 auto tryBody = parseScopeStatement(); | |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
2094 CatchStatement[] catchBodies; |
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
2095 FinallyStatement finBody; |
179 | 2096 |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2097 while (skipped(T.Catch)) |
179 | 2098 { |
2099 Parameter param; | |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2100 if (skipped(T.LParen)) |
179 | 2101 { |
640
05645f5613c1
Added an error message.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
639
diff
changeset
|
2102 auto begin2 = token; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2103 Identifier* ident; |
369 | 2104 auto type = parseDeclarator(ident, true); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2105 param = new Parameter(StorageClass.None, type, ident, null); |
640
05645f5613c1
Added an error message.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
639
diff
changeset
|
2106 set(param, begin2); |
179 | 2107 require(T.RParen); |
2108 } | |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
2109 catchBodies ~= set(new CatchStatement(param, parseNoScopeStatement()), begin); |
179 | 2110 if (param is null) |
2111 break; // This is a LastCatch | |
640
05645f5613c1
Added an error message.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
639
diff
changeset
|
2112 begin = token; |
179 | 2113 } |
2114 | |
640
05645f5613c1
Added an error message.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
639
diff
changeset
|
2115 if (skipped(T.Finally)) |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
2116 finBody = set(new FinallyStatement(parseNoScopeStatement()), prevToken); |
179 | 2117 |
396
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
2118 if (catchBodies.length == 0 && finBody is null) |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2119 assert(begin.kind == T.Try), error(begin, MSG.MissingCatchOrFinally); |
179 | 2120 |
2121 return new TryStatement(tryBody, catchBodies, finBody); | |
2122 } | |
2123 | |
180 | 2124 Statement parseThrowStatement() |
2125 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2126 assert(token.kind == T.Throw); |
180 | 2127 nT(); |
2128 auto expr = parseExpression(); | |
2129 require(T.Semicolon); | |
2130 return new ThrowStatement(expr); | |
2131 } | |
2132 | |
181 | 2133 Statement parseScopeGuardStatement() |
2134 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2135 assert(token.kind == T.Scope); |
181 | 2136 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2137 assert(token.kind == T.LParen); |
181 | 2138 nT(); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2139 auto condition = requireIdentifier(MSG.ExpectedScopeIdentifier); |
264 | 2140 if (condition) |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2141 switch (condition.identID) |
181 | 2142 { |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2143 case ID.exit, ID.success, ID.failure: |
181 | 2144 break; |
2145 default: | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2146 error(this.prevToken, MSG.InvalidScopeIdentifier, this.prevToken.srcText); |
181 | 2147 } |
2148 require(T.RParen); | |
2149 Statement scopeBody; | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2150 if (token.kind == T.LBrace) |
181 | 2151 scopeBody = parseScopeStatement(); |
2152 else | |
2153 scopeBody = parseNoScopeStatement(); | |
2154 return new ScopeGuardStatement(condition, scopeBody); | |
2155 } | |
2156 | |
182 | 2157 Statement parseVolatileStatement() |
2158 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2159 assert(token.kind == T.Volatile); |
182 | 2160 nT(); |
2161 Statement volatileBody; | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2162 if (token.kind == T.Semicolon) |
182 | 2163 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2164 else if (token.kind == T.LBrace) |
182 | 2165 volatileBody = parseScopeStatement(); |
2166 else | |
219 | 2167 volatileBody = parseStatement(); |
182 | 2168 return new VolatileStatement(volatileBody); |
2169 } | |
2170 | |
184 | 2171 Statement parsePragmaStatement() |
2172 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2173 assert(token.kind == T.Pragma); |
184 | 2174 nT(); |
2175 | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2176 Identifier* ident; |
184 | 2177 Expression[] args; |
2178 Statement pragmaBody; | |
2179 | |
2180 require(T.LParen); | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2181 ident = requireIdentifier(MSG.ExpectedPragmaIdentifier); |
184 | 2182 |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2183 if (skipped(T.Comma)) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2184 args = parseExpressionList(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2185 require(T.RParen); |
184 | 2186 |
234 | 2187 pragmaBody = parseNoScopeOrEmptyStatement(); |
184 | 2188 |
2189 return new PragmaStatement(ident, args, pragmaBody); | |
2190 } | |
2191 | |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2192 Statement parseStaticIfStatement() |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2193 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2194 assert(token.kind == T.Static); |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2195 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2196 assert(token.kind == T.If); |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2197 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2198 Expression condition; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2199 Statement ifBody, elseBody; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2200 |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2201 require(T.LParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2202 condition = parseExpression(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2203 require(T.RParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2204 ifBody = parseNoScopeStatement(); |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2205 if (skipped(T.Else)) |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2206 elseBody = parseNoScopeStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2207 return new StaticIfStatement(condition, ifBody, elseBody); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2208 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2209 |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2210 Statement parseStaticAssertStatement() |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2211 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2212 assert(token.kind == T.Static); |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2213 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2214 assert(token.kind == T.Assert); |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2215 nT(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2216 Expression condition, message; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2217 require(T.LParen); |
555
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
2218 condition = parseAssignExpression(); // Condition. |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2219 if (skipped(T.Comma)) |
555
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
2220 message = parseAssignExpression(); // Error message. |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2221 require(T.RParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2222 require(T.Semicolon); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2223 return new StaticAssertStatement(condition, message); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2224 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2225 |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2226 Statement parseDebugStatement() |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2227 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2228 assert(token.kind == T.Debug); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2229 nT(); // Skip debug keyword. |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2230 |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2231 Token* cond; |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2232 Statement debugBody, elseBody; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2233 |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2234 // ( Condition ) |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2235 if (skipped(T.LParen)) |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2236 { |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2237 cond = parseIdentOrInt(); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2238 require(T.RParen); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2239 } |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2240 // debug Statement |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2241 // debug ( Condition ) Statement |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2242 debugBody = parseNoScopeStatement(); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2243 // else Statement |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2244 if (skipped(T.Else)) |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2245 elseBody = parseNoScopeStatement(); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2246 |
264 | 2247 return new DebugStatement(cond, debugBody, elseBody); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2248 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2249 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2250 Statement parseVersionStatement() |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2251 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2252 assert(token.kind == T.Version); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2253 nT(); // Skip version keyword. |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2254 |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2255 Token* cond; |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2256 Statement versionBody, elseBody; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2257 |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2258 // ( Condition ) |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2259 require(T.LParen); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2260 cond = parseIdentOrInt(); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2261 require(T.RParen); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2262 // version ( Condition ) Statement |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2263 versionBody = parseNoScopeStatement(); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2264 // else Statement |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2265 if (skipped(T.Else)) |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2266 elseBody = parseNoScopeStatement(); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2267 |
264 | 2268 return new VersionStatement(cond, versionBody, elseBody); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2269 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2270 |
161 | 2271 /+++++++++++++++++++++++++++++ |
183 | 2272 + Assembler parsing methods + |
2273 +++++++++++++++++++++++++++++/ | |
2274 | |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2275 Statement parseAsmBlockStatement() |
183 | 2276 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2277 assert(token.kind == T.Asm); |
285 | 2278 nT(); // Skip asm keyword. |
2279 require(T.LBrace); | |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
2280 auto ss = new CompoundStatement; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2281 while (token.kind != T.RBrace && token.kind != T.EOF) |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2282 ss ~= parseAsmStatement(); |
285 | 2283 require(T.RBrace); |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2284 return new AsmBlockStatement(ss); |
285 | 2285 } |
2286 | |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2287 Statement parseAsmStatement() |
285 | 2288 { |
2289 auto begin = token; | |
2290 Statement s; | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2291 Identifier* ident; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2292 switch (token.kind) |
285 | 2293 { |
374 | 2294 // Keywords that are valid opcodes. |
2295 case T.In, T.Int, T.Out: | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2296 ident = token.ident; |
374 | 2297 nT(); |
2298 goto LOpcode; | |
285 | 2299 case T.Identifier: |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2300 ident = token.ident; |
374 | 2301 nT(); // Skip Identifier |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2302 if (skipped(T.Colon)) |
285 | 2303 { |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2304 // Identifier : AsmStatement |
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2305 s = new LabeledStatement(ident, parseAsmStatement()); |
285 | 2306 break; |
2307 } | |
2308 | |
374 | 2309 LOpcode: |
285 | 2310 // Opcode ; |
2311 // Opcode Operands ; | |
2312 // Opcode | |
2313 // Identifier | |
2314 Expression[] es; | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2315 if (token.kind != T.Semicolon) |
632
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2316 do |
285 | 2317 es ~= parseAsmExpression(); |
632
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2318 while (skipped(T.Comma)) |
285 | 2319 require(T.Semicolon); |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2320 s = new AsmStatement(ident, es); |
285 | 2321 break; |
374 | 2322 case T.Align: |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2323 // align Integer; |
374 | 2324 nT(); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2325 int number = -1; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2326 if (token.kind == T.Int32) |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2327 (number = token.int_), nT(); |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2328 else |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2329 error(token, MSG.ExpectedIntegerAfterAlign, token.srcText); |
374 | 2330 require(T.Semicolon); |
2331 s = new AsmAlignStatement(number); | |
2332 break; | |
285 | 2333 case T.Semicolon: |
2334 s = new EmptyStatement(); | |
2335 nT(); | |
2336 break; | |
2337 default: | |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2338 s = new IllegalAsmStatement(); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2339 // Skip to next valid token. |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2340 do |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2341 nT(); |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2342 while (!token.isAsmStatementStart && |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2343 token.kind != T.RBrace && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2344 token.kind != T.EOF) |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2345 auto text = Token.textSpan(begin, this.prevToken); |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2346 error(begin, MSG.IllegalAsmStatement, text); |
285 | 2347 } |
2348 set(s, begin); | |
2349 return s; | |
2350 } | |
2351 | |
2352 Expression parseAsmExpression() | |
2353 { | |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2354 auto begin = token; |
374 | 2355 auto e = parseAsmOrOrExpression(); |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2356 if (skipped(T.Question)) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2357 { |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2358 auto tok = this.prevToken; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2359 auto iftrue = parseAsmExpression(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2360 require(T.Colon); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2361 auto iffalse = parseAsmExpression(); |
293
418c6548ce17
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
292
diff
changeset
|
2362 e = new CondExpression(e, iftrue, iffalse, tok); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2363 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2364 } |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2365 // TODO: create AsmExpression that contains e? |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2366 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2367 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2368 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2369 Expression parseAsmOrOrExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2370 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
374
diff
changeset
|
2371 alias parseAsmAndAndExpression parseNext; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2372 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2373 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2374 while (token.kind == T.OrLogical) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2375 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2376 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2377 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2378 e = new OrOrExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2379 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2380 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2381 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2382 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2383 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2384 Expression parseAsmAndAndExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2385 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
374
diff
changeset
|
2386 alias parseAsmOrExpression parseNext; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2387 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2388 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2389 while (token.kind == T.AndLogical) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2390 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2391 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2392 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2393 e = new AndAndExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2394 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2395 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2396 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2397 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2398 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2399 Expression parseAsmOrExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2400 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
374
diff
changeset
|
2401 alias parseAsmXorExpression parseNext; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2402 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2403 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2404 while (token.kind == T.OrBinary) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2405 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2406 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2407 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2408 e = new OrExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2409 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2410 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2411 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2412 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2413 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2414 Expression parseAsmXorExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2415 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2416 alias parseAsmAndExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2417 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2418 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2419 while (token.kind == T.Xor) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2420 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2421 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2422 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2423 e = new XorExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2424 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2425 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2426 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2427 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2428 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2429 Expression parseAsmAndExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2430 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2431 alias parseAsmCmpExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2432 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2433 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2434 while (token.kind == T.AndBinary) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2435 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2436 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2437 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2438 e = new AndExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2439 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2440 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2441 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2442 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2443 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2444 Expression parseAsmCmpExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2445 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2446 alias parseAsmShiftExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2447 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2448 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2449 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2450 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2451 switch (operator.kind) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2452 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2453 case T.Equal, T.NotEqual: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2454 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2455 e = new EqualExpression(e, parseNext(), operator); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2456 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2457 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2458 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2459 e = new RelExpression(e, parseNext(), operator); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2460 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2461 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2462 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2463 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2464 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2465 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2466 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2467 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2468 Expression parseAsmShiftExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2469 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2470 alias parseAsmAddExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2471 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2472 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2473 while (1) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2474 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2475 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2476 switch (operator.kind) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2477 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2478 case T.LShift: nT(); e = new LShiftExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2479 case T.RShift: nT(); e = new RShiftExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2480 case T.URShift: nT(); e = new URShiftExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2481 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2482 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2483 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2484 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2485 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2486 assert(0); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2487 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2488 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2489 Expression parseAsmAddExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2490 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2491 alias parseAsmMulExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2492 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2493 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2494 while (1) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2495 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2496 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2497 switch (operator.kind) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2498 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2499 case T.Plus: nT(); e = new PlusExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2500 case T.Minus: nT(); e = new MinusExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2501 // Not allowed in asm |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2502 //case T.Tilde: nT(); e = new CatExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2503 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2504 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2505 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2506 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2507 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2508 assert(0); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2509 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2510 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2511 Expression parseAsmMulExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2512 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2513 alias parseAsmPostExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2514 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2515 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2516 while (1) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2517 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2518 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2519 switch (operator.kind) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2520 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2521 case T.Mul: nT(); e = new MulExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2522 case T.Div: nT(); e = new DivExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2523 case T.Mod: nT(); e = new ModExpression(e, parseNext(), operator); break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2524 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2525 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2526 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2527 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2528 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2529 assert(0); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2530 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2531 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2532 Expression parseAsmPostExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2533 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2534 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2535 auto e = parseAsmUnaryExpression(); |
632
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2536 while (skipped(T.LBracket)) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2537 { |
632
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2538 e = new AsmPostBracketExpression(e, parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2539 require(T.RBracket); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2540 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2541 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2542 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2543 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2544 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2545 Expression parseAsmUnaryExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2546 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2547 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2548 Expression e; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2549 switch (token.kind) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2550 { |
374 | 2551 case T.Byte, T.Short, T.Int, |
2552 T.Float, T.Double, T.Real: | |
2553 goto LAsmTypePrefix; | |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2554 case T.Identifier: |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2555 switch (token.ident.identID) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2556 { |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2557 case ID.near, ID.far,/* "byte", "short", "int",*/ |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2558 ID.word, ID.dword, ID.qword/*, "float", "double", "real"*/: |
374 | 2559 LAsmTypePrefix: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2560 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2561 if (token.kind == T.Identifier && token.ident is Ident.ptr) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2562 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2563 else |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2564 error(MID.ExpectedButFound, "ptr", token.srcText); |
374 | 2565 e = new AsmTypeExpression(parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2566 break; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2567 case ID.offset: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2568 nT(); |
374 | 2569 e = new AsmOffsetExpression(parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2570 break; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2571 case ID.seg: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2572 nT(); |
374 | 2573 e = new AsmSegExpression(parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2574 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2575 default: |
374 | 2576 goto LparseAsmPrimaryExpression; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2577 } |
374 | 2578 break; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2579 case T.Minus: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2580 case T.Plus: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2581 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2582 e = new SignExpression(parseAsmUnaryExpression()); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2583 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2584 case T.Not: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2585 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2586 e = new NotExpression(parseAsmUnaryExpression()); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2587 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2588 case T.Tilde: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2589 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2590 e = new CompExpression(parseAsmUnaryExpression()); |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2591 break; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2592 case T.Dot: |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2593 nT(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2594 e = new ModuleScopeExpression(parseIdentifierExpression()); |
632
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2595 while (skipped(TOK.Dot)) |
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2596 { |
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2597 e = new DotExpression(e, parseIdentifierExpression()); |
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2598 set(e, begin); |
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2599 } |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2600 break; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2601 default: |
374 | 2602 LparseAsmPrimaryExpression: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2603 e = parseAsmPrimaryExpression(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2604 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2605 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2606 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2607 return e; |
183 | 2608 } |
2609 | |
285 | 2610 Expression parseAsmPrimaryExpression() |
2611 { | |
2612 auto begin = token; | |
2613 Expression e; | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2614 switch (token.kind) |
285 | 2615 { |
2616 case T.Int32, T.Int64, T.Uint32, T.Uint64: | |
537
db7913148b29
Added constructors and semantic() methods.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
536
diff
changeset
|
2617 e = new IntExpression(token); |
285 | 2618 nT(); |
2619 break; | |
2620 case T.Float32, T.Float64, T.Float80, | |
2621 T.Imaginary32, T.Imaginary64, T.Imaginary80: | |
539
3418027c3914
Added semantic() method to RealExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
537
diff
changeset
|
2622 e = new RealExpression(token); |
285 | 2623 nT(); |
2624 break; | |
2625 case T.Dollar: | |
2626 e = new DollarExpression(); | |
2627 nT(); | |
2628 break; | |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2629 case T.LBracket: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2630 // [ AsmExpression ] |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2631 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2632 e = parseAsmExpression(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2633 require(T.RBracket); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2634 e = new AsmBracketExpression(e); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2635 break; |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2636 case T.Identifier: |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2637 auto register = token.ident; |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2638 switch (register.identID) |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2639 { |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2640 // __LOCAL_SIZE |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2641 case ID.__LOCAL_SIZE: |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2642 nT(); |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2643 e = new AsmLocalSizeExpression(); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2644 break; |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2645 // Register |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2646 case ID.ST: |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2647 nT(); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2648 // (1) - (7) |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2649 int number = -1; |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2650 if (skipped(T.LParen)) |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2651 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2652 if (token.kind == T.Int32) |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2653 (number = token.int_), nT(); |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2654 else |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2655 expected(T.Int32); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2656 require(T.RParen); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2657 } |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2658 e = new AsmRegisterExpression(register, number); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2659 break; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2660 case ID.FS: |
417
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2661 nT(); |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2662 // TODO: is the colon-number part optional? |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2663 int number = -1; |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2664 if (skipped(T.Colon)) |
417
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2665 { |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2666 // :0, :4, :8 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2667 if (token.kind == T.Int32) |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2668 (number = token.int_), nT(); |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2669 if (number != 0 && number != 4 && number != 8) |
417
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2670 error(MID.ExpectedButFound, "0, 4 or 8", token.srcText); |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2671 } |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2672 e = new AsmRegisterExpression(register, number); |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2673 break; |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2674 case ID.AL, ID.AH, ID.AX, ID.EAX, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2675 ID.BL, ID.BH, ID.BX, ID.EBX, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2676 ID.CL, ID.CH, ID.CX, ID.ECX, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2677 ID.DL, ID.DH, ID.DX, ID.EDX, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2678 ID.BP, ID.EBP, ID.SP, ID.ESP, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2679 ID.DI, ID.EDI, ID.SI, ID.ESI, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2680 ID.ES, ID.CS, ID.SS, ID.DS, ID.GS, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2681 ID.CR0, ID.CR2, ID.CR3, ID.CR4, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2682 ID.DR0, ID.DR1, ID.DR2, ID.DR3, ID.DR6, ID.DR7, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2683 ID.TR3, ID.TR4, ID.TR5, ID.TR6, ID.TR7, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2684 ID.MM0, ID.MM1, ID.MM2, ID.MM3, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2685 ID.MM4, ID.MM5, ID.MM6, ID.MM7, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2686 ID.XMM0, ID.XMM1, ID.XMM2, ID.XMM3, |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2687 ID.XMM4, ID.XMM5, ID.XMM6, ID.XMM7: |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2688 nT(); |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2689 e = new AsmRegisterExpression(register); |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2690 break; |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2691 default: |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2692 e = parseIdentifierExpression(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2693 while (skipped(TOK.Dot)) |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2694 { |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2695 e = new DotExpression(e, parseIdentifierExpression()); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2696 set(e, begin); |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2697 } |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2698 } // end of switch |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2699 break; |
285 | 2700 default: |
2701 error(MID.ExpectedButFound, "Expression", token.srcText); | |
659
304331ca2f95
Renamed EmptyExpression to IllegalExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
655
diff
changeset
|
2702 e = new IllegalExpression(); |
414
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
2703 if (!trying) |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2704 { // Insert a dummy token and don't consume current one. |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
2705 begin = lexer.insertEmptyTokenBefore(token); |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2706 this.prevToken = begin; |
414
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
2707 } |
285 | 2708 } |
2709 set(e, begin); | |
2710 return e; | |
2711 } | |
2712 | |
183 | 2713 /+++++++++++++++++++++++++++++ |
102 | 2714 + Expression parsing methods + |
2715 +++++++++++++++++++++++++++++/ | |
2716 | |
72 | 2717 Expression parseExpression() |
2718 { | |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2719 alias parseAssignExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2720 auto begin = token; |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2721 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2722 while (token.kind == T.Comma) |
235 | 2723 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2724 auto comma = token; |
235 | 2725 nT(); |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2726 e = new CommaExpression(e, parseNext(), comma); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2727 set(e, begin); |
235 | 2728 } |
72 | 2729 return e; |
2730 } | |
2731 | |
71 | 2732 Expression parseAssignExpression() |
2733 { | |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2734 alias parseAssignExpression parseNext; |
319
83f1f9a4f248
- Removed assigment to 'begin' from loop. Initializing 'begin' at decl point.
aziz
parents:
318
diff
changeset
|
2735 auto begin = token; |
71 | 2736 auto e = parseCondExpression(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2737 switch (token.kind) |
71 | 2738 { |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2739 case T.Assign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2740 nT(); e = new AssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2741 case T.LShiftAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2742 nT(); e = new LShiftAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2743 case T.RShiftAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2744 nT(); e = new RShiftAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2745 case T.URShiftAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2746 nT(); e = new URShiftAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2747 case T.OrAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2748 nT(); e = new OrAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2749 case T.AndAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2750 nT(); e = new AndAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2751 case T.PlusAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2752 nT(); e = new PlusAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2753 case T.MinusAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2754 nT(); e = new MinusAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2755 case T.DivAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2756 nT(); e = new DivAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2757 case T.MulAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2758 nT(); e = new MulAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2759 case T.ModAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2760 nT(); e = new ModAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2761 case T.XorAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2762 nT(); e = new XorAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2763 case T.CatAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2764 nT(); e = new CatAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2765 default: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2766 return e; |
71 | 2767 } |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2768 set(e, begin); |
71 | 2769 return e; |
2770 } | |
72 | 2771 |
71 | 2772 Expression parseCondExpression() |
2773 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2774 auto begin = token; |
72 | 2775 auto e = parseOrOrExpression(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2776 if (token.kind == T.Question) |
72 | 2777 { |
293
418c6548ce17
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
292
diff
changeset
|
2778 auto tok = token; |
72 | 2779 nT(); |
2780 auto iftrue = parseExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2781 require(T.Colon); |
72 | 2782 auto iffalse = parseCondExpression(); |
293
418c6548ce17
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
292
diff
changeset
|
2783 e = new CondExpression(e, iftrue, iffalse, tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2784 set(e, begin); |
72 | 2785 } |
2786 return e; | |
2787 } | |
2788 | |
2789 Expression parseOrOrExpression() | |
2790 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2791 alias parseAndAndExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2792 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2793 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2794 while (token.kind == T.OrLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2795 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2796 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2797 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2798 e = new OrOrExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2799 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2800 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2801 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2802 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2803 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2804 Expression parseAndAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2805 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2806 alias parseOrExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2807 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2808 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2809 while (token.kind == T.AndLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2810 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2811 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2812 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2813 e = new AndAndExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2814 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2815 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2816 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2817 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2818 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2819 Expression parseOrExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2820 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2821 alias parseXorExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2822 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2823 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2824 while (token.kind == T.OrBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2825 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2826 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2827 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2828 e = new OrExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2829 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2830 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2831 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2832 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2833 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2834 Expression parseXorExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2835 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2836 alias parseAndExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2837 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2838 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2839 while (token.kind == T.Xor) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2840 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2841 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2842 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2843 e = new XorExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2844 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2845 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2846 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2847 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2848 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2849 Expression parseAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2850 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2851 alias parseCmpExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2852 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2853 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2854 while (token.kind == T.AndBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2855 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2856 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2857 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2858 e = new AndExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2859 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2860 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2861 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2862 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2863 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2864 Expression parseCmpExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2865 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2866 alias parseShiftExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2867 auto begin = token; |
74 | 2868 auto e = parseShiftExpression(); |
2869 | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2870 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2871 switch (operator.kind) |
74 | 2872 { |
2873 case T.Equal, T.NotEqual: | |
2874 nT(); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2875 e = new EqualExpression(e, parseNext(), operator); |
74 | 2876 break; |
2877 case T.Not: | |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2878 if (peekNext() != T.Is) |
74 | 2879 break; |
2880 nT(); | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2881 // fall through |
225 | 2882 case T.Is: |
74 | 2883 nT(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2884 e = new IdentityExpression(e, parseNext(), operator); |
74 | 2885 break; |
2886 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater, | |
2887 T.Unordered, T.UorE, T.UorG, T.UorGorE, | |
2888 T.UorL, T.UorLorE, T.LorEorG, T.LorG: | |
2889 nT(); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2890 e = new RelExpression(e, parseNext(), operator); |
74 | 2891 break; |
2892 case T.In: | |
2893 nT(); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2894 e = new InExpression(e, parseNext(), operator); |
74 | 2895 break; |
2896 default: | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2897 return e; |
74 | 2898 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2899 set(e, begin); |
74 | 2900 return e; |
2901 } | |
2902 | |
2903 Expression parseShiftExpression() | |
2904 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2905 alias parseAddExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2906 auto begin = token; |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2907 auto e = parseNext(); |
75 | 2908 while (1) |
2909 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2910 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2911 switch (operator.kind) |
75 | 2912 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2913 case T.LShift: nT(); e = new LShiftExpression(e, parseNext(), operator); break; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2914 case T.RShift: nT(); e = new RShiftExpression(e, parseNext(), operator); break; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2915 case T.URShift: nT(); e = new URShiftExpression(e, parseNext(), operator); break; |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2916 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2917 return e; |
75 | 2918 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2919 set(e, begin); |
75 | 2920 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2921 assert(0); |
75 | 2922 } |
2923 | |
2924 Expression parseAddExpression() | |
2925 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2926 alias parseMulExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2927 auto begin = token; |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2928 auto e = parseNext(); |
76 | 2929 while (1) |
2930 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2931 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2932 switch (operator.kind) |
76 | 2933 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2934 case T.Plus: nT(); e = new PlusExpression(e, parseNext(), operator); break; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2935 case T.Minus: nT(); e = new MinusExpression(e, parseNext(), operator); break; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2936 case T.Tilde: nT(); e = new CatExpression(e, parseNext(), operator); break; |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2937 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2938 return e; |
76 | 2939 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2940 set(e, begin); |
76 | 2941 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2942 assert(0); |
76 | 2943 } |
2944 | |
2945 Expression parseMulExpression() | |
2946 { | |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2947 alias parsePostExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2948 auto begin = token; |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2949 auto e = parseNext(); |
77 | 2950 while (1) |
2951 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2952 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2953 switch (operator.kind) |
77 | 2954 { |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2955 case T.Mul: nT(); e = new MulExpression(e, parseNext(), operator); break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2956 case T.Div: nT(); e = new DivExpression(e, parseNext(), operator); break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2957 case T.Mod: nT(); e = new ModExpression(e, parseNext(), operator); break; |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2958 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2959 return e; |
77 | 2960 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2961 set(e, begin); |
77 | 2962 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2963 assert(0); |
71 | 2964 } |
2965 | |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2966 Expression parsePostExpression() |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2967 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2968 auto begin = token; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2969 auto e = parseUnaryExpression(); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2970 while (1) |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2971 { |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2972 while (skipped(T.Dot)) |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2973 { |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2974 e = new DotExpression(e, parseNewOrIdentifierExpression()); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2975 set(e, begin); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2976 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2977 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2978 switch (token.kind) |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2979 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2980 case T.PlusPlus: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2981 e = new PostIncrExpression(e); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2982 break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2983 case T.MinusMinus: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2984 e = new PostDecrExpression(e); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2985 break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2986 case T.LParen: |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2987 e = new CallExpression(e, parseArguments()); |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2988 goto Lset; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2989 case T.LBracket: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2990 // parse Slice- and IndexExpression |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2991 nT(); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
2992 // [] is a SliceExpression |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2993 if (token.kind == T.RBracket) |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2994 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2995 e = new SliceExpression(e, null, null); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2996 break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2997 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2998 |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2999 Expression[] es = [parseAssignExpression()]; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3000 |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
3001 // [ AssignExpression .. AssignExpression ] |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3002 if (skipped(T.Slice)) |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3003 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3004 e = new SliceExpression(e, es[0], parseAssignExpression()); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3005 require(T.RBracket); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3006 goto Lset; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3007 } |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3008 |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
3009 // [ ExpressionList ] |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3010 if (skipped(T.Comma)) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3011 es ~= parseExpressionList(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3012 require(T.RBracket); |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3013 |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3014 e = new IndexExpression(e, es); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3015 goto Lset; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3016 default: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3017 return e; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3018 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3019 nT(); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
3020 Lset: // Jumped here to skip nT(). |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3021 set(e, begin); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3022 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3023 assert(0); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3024 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3025 |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3026 Expression parseUnaryExpression() |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3027 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3028 auto begin = token; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3029 Expression e; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3030 switch (token.kind) |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3031 { |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3032 case T.AndBinary: |
257 | 3033 nT(); |
243 | 3034 e = new AddressExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3035 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3036 case T.PlusPlus: |
257 | 3037 nT(); |
243 | 3038 e = new PreIncrExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3039 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3040 case T.MinusMinus: |
257 | 3041 nT(); |
243 | 3042 e = new PreDecrExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3043 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3044 case T.Mul: |
257 | 3045 nT(); |
243 | 3046 e = new DerefExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3047 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3048 case T.Minus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3049 case T.Plus: |
257 | 3050 nT(); |
243 | 3051 e = new SignExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3052 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3053 case T.Not: |
257 | 3054 nT(); |
243 | 3055 e = new NotExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3056 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3057 case T.Tilde: |
257 | 3058 nT(); |
243 | 3059 e = new CompExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3060 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3061 case T.New: |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3062 e = parseNewExpression(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3063 return e; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3064 case T.Delete: |
257 | 3065 nT(); |
243 | 3066 e = new DeleteExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3067 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3068 case T.Cast: |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3069 requireNext(T.LParen); |
269 | 3070 Type type; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3071 switch (token.kind) |
269 | 3072 { |
3073 version(D2) | |
3074 { | |
3075 auto begin2 = token; | |
3076 case T.Const: | |
3077 type = new ConstType(null); | |
3078 goto case_break; | |
3079 case T.Invariant: | |
3080 type = new InvariantType(null); | |
3081 case_break: | |
3082 nT(); | |
3083 set(type, begin2); | |
3084 break; | |
3085 } | |
3086 default: | |
3087 type = parseType(); | |
3088 } | |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3089 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3090 e = new CastExpression(parseUnaryExpression(), type); |
257 | 3091 break; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3092 case T.LParen: |
102 | 3093 // ( Type ) . Identifier |
225 | 3094 Type parseType_() |
3095 { | |
3096 nT(); | |
3097 auto type = parseType(); | |
3098 require(T.RParen); | |
233 | 3099 require(T.Dot); |
225 | 3100 return type; |
3101 } | |
3102 bool success; | |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
3103 auto type = try_(&parseType_, success); |
225 | 3104 if (success) |
3105 { | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3106 auto ident = requireIdentifier(MSG.ExpectedIdAfterTypeDot); |
225 | 3107 e = new TypeDotIdExpression(type, ident); |
257 | 3108 break; |
225 | 3109 } |
3110 goto default; | |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3111 case T.Dot: |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3112 nT(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3113 e = new ModuleScopeExpression(parseIdentifierExpression()); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3114 break; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3115 default: |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3116 e = parsePrimaryExpression(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3117 return e; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3118 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3119 assert(e !is null); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3120 set(e, begin); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3121 return e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3122 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3123 |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3124 /++ |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3125 IdentifierExpression: |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3126 Identifier |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3127 TemplateInstance |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3128 TemplateInstance: |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3129 Identifier !( TemplateArguments ) |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3130 +/ |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3131 Expression parseIdentifierExpression() |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3132 { |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3133 auto begin = token; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3134 auto ident = requireIdentifier(MSG.ExpectedAnIdentifier); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3135 Expression e; |
634
14e99ce74d06
Fixed parsing of TemplateInstanceExpressions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
632
diff
changeset
|
3136 // Peek for '(' to avoid matching: id !is id |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3137 if (token.kind == T.Not && peekNext() == T.LParen) |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3138 { // Identifier !( TemplateArguments ) |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3139 nT(); // Skip !. |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3140 auto tparams = parseTemplateArguments(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3141 e = new TemplateInstanceExpression(ident, tparams); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3142 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3143 else // Identifier |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3144 e = new IdentifierExpression(ident); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3145 return set(e, begin); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3146 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3147 |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3148 Expression parseNewOrIdentifierExpression() |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3149 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3150 return token.kind == T.New ? parseNewExpression() : parseIdentifierExpression(); |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3151 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3152 |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
3153 Expression parsePrimaryExpression() |
78
f043759fb59a
- Added code to parseUnaryExpression(); not fully implemented.
aziz
parents:
77
diff
changeset
|
3154 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3155 auto begin = token; |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3156 Expression e; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3157 switch (token.kind) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3158 { |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3159 case T.Identifier: |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3160 e = parseIdentifierExpression(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3161 return e; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3162 case T.Typeof: |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3163 e = new TypeofExpression(parseTypeofType()); |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3164 break; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3165 case T.This: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3166 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3167 e = new ThisExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3168 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3169 case T.Super: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3170 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3171 e = new SuperExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3172 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3173 case T.Null: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3174 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3175 e = new NullExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3176 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3177 case T.True, T.False: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3178 nT(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3179 e = new BoolExpression(); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3180 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3181 case T.Dollar: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3182 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3183 e = new DollarExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3184 break; |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3185 case T.Int32, T.Int64, T.Uint32, T.Uint64: |
537
db7913148b29
Added constructors and semantic() methods.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
536
diff
changeset
|
3186 e = new IntExpression(token); |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3187 nT(); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3188 break; |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3189 case T.Float32, T.Float64, T.Float80, |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3190 T.Imaginary32, T.Imaginary64, T.Imaginary80: |
539
3418027c3914
Added semantic() method to RealExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
537
diff
changeset
|
3191 e = new RealExpression(token); |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3192 nT(); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3193 break; |
507
996041463028
Removed TOK.WCharLiteral and TOK.DCharLiteral.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
505
diff
changeset
|
3194 case T.CharLiteral: |
536
0781ac288537
Added some semantic() methods.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
535
diff
changeset
|
3195 e = new CharExpression(token.dchar_); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3196 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3197 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3198 case T.String: |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3199 char[] str = token.str; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3200 char postfix = token.pf; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3201 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3202 while (token.kind == T.String) |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3203 { |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3204 if (postfix == '\0') |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3205 postfix = token.pf; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3206 else if (token.pf && token.pf != postfix) |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3207 error(token, MSG.StringPostfixMismatch); |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3208 str ~= token.str; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3209 nT(); |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3210 } |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3211 switch (postfix) |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3212 { // TODO: convert string |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3213 case 'w': e = new StringExpression(/+toUTF16+/(str)); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3214 case 'd': e = new StringExpression(/+toUTF32+/(str)); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3215 case 'c': |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3216 default: e = new StringExpression(str); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3217 } |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3218 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3219 case T.LBracket: |
85 | 3220 Expression[] values; |
3221 | |
3222 nT(); | |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3223 if (!skipped(T.RBracket)) |
85 | 3224 { |
3225 e = parseAssignExpression(); | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3226 if (token.kind == T.Colon) |
85 | 3227 goto LparseAssocArray; |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3228 if (skipped(T.Comma)) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3229 values = [e] ~ parseExpressionList(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3230 require(T.RBracket); |
85 | 3231 } |
3232 | |
3233 e = new ArrayLiteralExpression(values); | |
3234 break; | |
3235 | |
3236 LparseAssocArray: | |
3237 Expression[] keys; | |
3238 | |
3239 keys ~= e; | |
3240 nT(); // Skip colon. | |
271
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3241 goto LenterLoop; |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3242 |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3243 while (1) |
88 | 3244 { |
271
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3245 keys ~= parseAssignExpression(); |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3246 require(T.Colon); |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3247 LenterLoop: |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3248 values ~= parseAssignExpression(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3249 if (token.kind != T.Comma) |
271
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3250 break; |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3251 nT(); |
88 | 3252 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3253 require(T.RBracket); |
399
ff1d11c27061
Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
398
diff
changeset
|
3254 e = new AArrayLiteralExpression(keys, values); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3255 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3256 case T.LBrace: |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
3257 // DelegateLiteral := { Statements } |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
3258 auto funcBody = parseFunctionBody(); |
289
a99357783c6f
- Fix: assign targs to member targs of TraitsExpression.
aziz
parents:
288
diff
changeset
|
3259 e = new FunctionLiteralExpression(funcBody); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3260 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3261 case T.Function, T.Delegate: |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
3262 // FunctionLiteral := (function|delegate) Type? '(' ArgumentList ')' '{' Statements '}' |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3263 nT(); // Skip function|delegate token. |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3264 Type returnType; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3265 Parameters parameters; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3266 if (token.kind != T.LBrace) |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3267 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3268 if (token.kind != T.LParen) // Optional return type |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3269 returnType = parseType(); |
143 | 3270 parameters = parseParameterList(); |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3271 } |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
3272 auto funcBody = parseFunctionBody(); |
289
a99357783c6f
- Fix: assign targs to member targs of TraitsExpression.
aziz
parents:
288
diff
changeset
|
3273 e = new FunctionLiteralExpression(returnType, parameters, funcBody); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3274 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3275 case T.Assert: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3276 Expression msg; |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3277 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3278 e = parseAssignExpression(); |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3279 if (skipped(T.Comma)) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3280 msg = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3281 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3282 e = new AssertExpression(e, msg); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3283 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3284 case T.Mixin: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3285 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3286 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3287 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3288 e = new MixinExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3289 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3290 case T.Import: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3291 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3292 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3293 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3294 e = new ImportExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3295 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3296 case T.Typeid: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3297 requireNext(T.LParen); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3298 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3299 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3300 e = new TypeidExpression(type); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3301 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3302 case T.Is: |
100 | 3303 requireNext(T.LParen); |
3304 | |
248 | 3305 Type type, specType; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3306 Identifier* ident; // optional Identifier |
248 | 3307 Token* opTok, specTok; |
100 | 3308 |
3309 type = parseDeclarator(ident, true); | |
3310 | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3311 switch (token.kind) |
100 | 3312 { |
3313 case T.Colon, T.Equal: | |
248 | 3314 opTok = token; |
100 | 3315 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3316 switch (token.kind) |
100 | 3317 { |
3318 case T.Typedef, | |
3319 T.Struct, | |
3320 T.Union, | |
3321 T.Class, | |
3322 T.Interface, | |
3323 T.Enum, | |
3324 T.Function, | |
3325 T.Delegate, | |
3326 T.Super, | |
3327 T.Return: | |
493
d13502b6fa5f
Added code to the Parser and edited main.wiki.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
492
diff
changeset
|
3328 case_Const_Invariant: |
248 | 3329 specTok = token; |
102 | 3330 nT(); |
100 | 3331 break; |
493
d13502b6fa5f
Added code to the Parser and edited main.wiki.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
492
diff
changeset
|
3332 case T.Const, T.Invariant: |
d13502b6fa5f
Added code to the Parser and edited main.wiki.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
492
diff
changeset
|
3333 if (peekNext() != T.LParen) |
d13502b6fa5f
Added code to the Parser and edited main.wiki.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
492
diff
changeset
|
3334 goto case_Const_Invariant; |
d13502b6fa5f
Added code to the Parser and edited main.wiki.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
492
diff
changeset
|
3335 // Fall through. It's a type. |
100 | 3336 default: |
248 | 3337 specType = parseType(); |
100 | 3338 } |
3339 default: | |
3340 } | |
377 | 3341 |
3342 TemplateParameters tparams; | |
3343 version(D2) | |
3344 { | |
3345 // is ( Type Identifier : TypeSpecialization , TemplateParameterList ) | |
3346 // is ( Type Identifier == TypeSpecialization , TemplateParameterList ) | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3347 if (ident && specType && token.kind == T.Comma) |
377 | 3348 tparams = parseTemplateParameterList2(); |
3349 } | |
102 | 3350 require(T.RParen); |
377 | 3351 e = new IsExpression(type, ident, opTok, specTok, specType, tparams); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3352 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3353 case T.LParen: |
646
68953760d569
Added class ParenExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
640
diff
changeset
|
3354 if (tokenAfterParenIs(T.LBrace)) // Check for "(...) {" |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3355 { // ( ParameterList ) FunctionBody |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3356 auto parameters = parseParameterList(); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
3357 auto funcBody = parseFunctionBody(); |
289
a99357783c6f
- Fix: assign targs to member targs of TraitsExpression.
aziz
parents:
288
diff
changeset
|
3358 e = new FunctionLiteralExpression(null, parameters, funcBody); |
130 | 3359 } |
3360 else | |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3361 { // ( Expression ) |
130 | 3362 nT(); |
3363 e = parseExpression(); | |
3364 require(T.RParen); | |
646
68953760d569
Added class ParenExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
640
diff
changeset
|
3365 e = new ParenExpression(e); |
130 | 3366 } |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3367 break; |
269 | 3368 version(D2) |
3369 { | |
3370 case T.Traits: | |
3371 nT(); | |
3372 require(T.LParen); | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3373 auto id = requireIdentifier(MSG.ExpectedAnIdentifier); |
269 | 3374 TemplateArguments args; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3375 if (token.kind == T.Comma) |
269 | 3376 args = parseTemplateArguments2(); |
3377 else | |
3378 require(T.RParen); | |
3379 e = new TraitsExpression(id, args); | |
3380 break; | |
3381 } | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3382 default: |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3383 if (token.isIntegralType) |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3384 { // IntegralType . Identifier |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3385 auto type = new IntegralType(token.kind); |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3386 nT(); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3387 set(type, begin); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3388 require(T.Dot); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3389 auto ident = requireIdentifier(MSG.ExpectedIdAfterTypeDot); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3390 e = new TypeDotIdExpression(type, ident); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3391 } |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3392 else if (token.isSpecialToken) |
343
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3393 { |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3394 e = new SpecialTokenExpression(token); |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3395 nT(); |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3396 } |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3397 else |
414
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3398 { |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3399 error(MID.ExpectedButFound, "Expression", token.srcText); |
659
304331ca2f95
Renamed EmptyExpression to IllegalExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
655
diff
changeset
|
3400 e = new IllegalExpression(); |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3401 if (!trying) |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3402 { // Insert a dummy token and don't consume current one. |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
3403 begin = lexer.insertEmptyTokenBefore(token); |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3404 this.prevToken = begin; |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3405 } |
414
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3406 } |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3407 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3408 set(e, begin); |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3409 return e; |
77 | 3410 } |
3411 | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3412 Expression parseNewExpression(/*Expression e*/) |
81 | 3413 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3414 auto begin = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3415 assert(token.kind == T.New); |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3416 nT(); // Skip new keyword. |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3417 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3418 Expression[] newArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3419 Expression[] ctorArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3420 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3421 if (token.kind == T.LParen) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3422 newArguments = parseArguments(); |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3423 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3424 // NewAnonClassExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3425 // new (ArgumentList)opt class (ArgumentList)opt SuperClassopt InterfaceClassesopt ClassBody |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3426 if (skipped(T.Class)) |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3427 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3428 if (token.kind == T.LParen) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3429 ctorArguments = parseArguments(); |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3430 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3431 BaseClassType[] bases = token.kind != T.LBrace ? parseBaseClasses(false) : null ; |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3432 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
3433 auto decls = parseDeclarationDefinitionsBody(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3434 return set(new NewAnonClassExpression(/*e, */newArguments, bases, ctorArguments, decls), begin); |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3435 } |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3436 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3437 // NewExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3438 // NewArguments Type [ AssignExpression ] |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3439 // NewArguments Type ( ArgumentList ) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3440 // NewArguments Type |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3441 auto type = parseType(); |
302
d04a79e795a2
- Fix in parseNewExpression(): removed check for type id.
aziz
parents:
301
diff
changeset
|
3442 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3443 if (token.kind == T.LParen) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3444 ctorArguments = parseArguments(); |
302
d04a79e795a2
- Fix in parseNewExpression(): removed check for type id.
aziz
parents:
301
diff
changeset
|
3445 |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3446 return set(new NewExpression(/*e, */newArguments, type, ctorArguments), begin); |
81 | 3447 } |
3448 | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3449 Type parseType() |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3450 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
3451 return parseBasicType2(parseBasicType()); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3452 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3453 |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3454 Type parseIdentifierType() |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3455 { |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3456 auto begin = token; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3457 auto ident = requireIdentifier(MSG.ExpectedAnIdentifier); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3458 Type t; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3459 if (skipped(T.Not)) // Identifier !( TemplateArguments ) |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3460 t = new TemplateInstanceType(ident, parseTemplateArguments()); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3461 else // Identifier |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3462 t = new IdentifierType(ident); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3463 return set(t, begin); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3464 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3465 |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3466 Type parseQualifiedType() |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3467 { |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3468 auto begin = token; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3469 Type type; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3470 if (skipped(T.Dot)) |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3471 type = set(new ModuleScopeType(parseIdentifierType()), begin); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3472 else if (token.kind == T.Typeof) |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3473 { |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3474 type = parseTypeofType(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3475 if (token.kind != T.Dot) |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3476 return type; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3477 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3478 else |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3479 type = parseIdentifierType(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3480 |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3481 while (skipped(T.Dot)) |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3482 type = set(new QualifiedType(type, parseIdentifierType()), begin); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3483 return type; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3484 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3485 |
94 | 3486 Type parseBasicType() |
3487 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3488 auto begin = token; |
94 | 3489 Type t; |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3490 |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3491 if (token.isIntegralType) |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3492 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3493 t = new IntegralType(token.kind); |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3494 nT(); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3495 } |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3496 else |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3497 switch (token.kind) |
94 | 3498 { |
153 | 3499 case T.Identifier, T.Typeof, T.Dot: |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3500 t = parseQualifiedType(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3501 return t; |
269 | 3502 version(D2) |
3503 { | |
3504 case T.Const: | |
3505 // const ( Type ) | |
3506 nT(); | |
3507 require(T.LParen); | |
3508 t = parseType(); | |
3509 require(T.RParen); | |
3510 t = new ConstType(t); | |
3511 break; | |
3512 case T.Invariant: | |
3513 // invariant ( Type ) | |
3514 nT(); | |
3515 require(T.LParen); | |
3516 t = parseType(); | |
3517 require(T.RParen); | |
3518 t = new InvariantType(t); | |
3519 break; | |
369 | 3520 } // version(D2) |
94 | 3521 default: |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3522 error(MID.ExpectedButFound, "BasicType", token.srcText); |
671
f1325a4506de
Removed enum TID from dil.ast.Types.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
668
diff
changeset
|
3523 t = new IllegalType(); |
259
8118da6fee44
- Moved nT() below statement where an attribute class is constructed.
aziz
parents:
258
diff
changeset
|
3524 nT(); |
94 | 3525 } |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3526 return set(t, begin); |
94 | 3527 } |
3528 | |
95 | 3529 Type parseBasicType2(Type t) |
3530 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3531 typeof(token) begin; |
95 | 3532 while (1) |
3533 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3534 begin = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3535 switch (token.kind) |
95 | 3536 { |
3537 case T.Mul: | |
3538 t = new PointerType(t); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3539 nT(); |
95 | 3540 break; |
3541 case T.LBracket: | |
106 | 3542 t = parseArrayType(t); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3543 continue; |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3544 case T.Function, T.Delegate: |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3545 TOK tok = token.kind; |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3546 nT(); |
143 | 3547 auto parameters = parseParameterList(); |
135 | 3548 if (tok == T.Function) |
291
c0e857931ff6
- Changed FunctionType and DelegateType. Both receive return type and parameters.
aziz
parents:
290
diff
changeset
|
3549 t = new FunctionType(t, parameters); |
135 | 3550 else |
291
c0e857931ff6
- Changed FunctionType and DelegateType. Both receive return type and parameters.
aziz
parents:
290
diff
changeset
|
3551 t = new DelegateType(t, parameters); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3552 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3553 default: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3554 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3555 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3556 set(t, begin); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3557 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3558 assert(0); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3559 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3560 |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3561 bool tokenAfterParenIs(TOK tok) |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3562 { |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3563 // We count nested parentheses tokens because template types may appear inside parameter lists; e.g. (int x, Foo!(int) y). |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3564 assert(token.kind == T.LParen); |
239
7911f6a92e6e
- Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK.
aziz
parents:
238
diff
changeset
|
3565 Token* next = token; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3566 uint level = 1; |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3567 Loop: |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3568 while (1) |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3569 { |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
3570 lexer.peek(next); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3571 switch (next.kind) |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3572 { |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3573 case T.RParen: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3574 if (--level == 0) |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3575 { // Last, closing parentheses found. |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3576 do |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
3577 lexer.peek(next); |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3578 while (next.isWhitespace) |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3579 break Loop; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3580 } |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3581 break; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3582 case T.LParen: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3583 ++level; |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3584 break; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3585 case T.EOF: |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3586 break Loop; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3587 default: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3588 } |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3589 } |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3590 return next.kind == tok; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3591 } |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3592 |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3593 /// Parse the C-style array types after the declarator. |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3594 Type parseDeclaratorSuffix(Type lhsType) |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3595 { |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3596 // The Type chain should be as follows: |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3597 // int[3]* Identifier [][32] |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3598 // <- <- -> -. |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3599 // ^------------------´ |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3600 // Resulting chain: [][32]*[3]int |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3601 Type parseNext() // Nested function required to accomplish this. |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3602 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3603 if (token.kind != T.LBracket) |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3604 return lhsType; // Break recursion; return Type on the left hand side of the Identifier. |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3605 |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3606 auto begin = token; |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3607 Type t; |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3608 nT(); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3609 if (skipped(T.RBracket)) |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3610 t = new ArrayType(parseNext()); // [ ] |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3611 else |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3612 { |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3613 bool success; |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3614 Type parseAAType() |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3615 { |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3616 auto type = parseType(); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3617 require(T.RBracket); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3618 return type; |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3619 } |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3620 auto assocType = try_(&parseAAType, success); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3621 if (success) |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3622 t = new ArrayType(parseNext(), assocType); // [ Type ] |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3623 else |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3624 { |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3625 Expression e = parseExpression(), e2; |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3626 if (skipped(T.Slice)) |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3627 e2 = parseExpression(); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3628 require(T.RBracket); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3629 t = new ArrayType(parseNext(), e, e2); // [ Expression .. Expression ] |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3630 } |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3631 } |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3632 set(t, begin); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3633 return t; |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3634 } |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3635 return parseNext(); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3636 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3637 |
106 | 3638 Type parseArrayType(Type t) |
3639 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3640 assert(token.kind == T.LBracket); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3641 auto begin = token; |
106 | 3642 nT(); |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3643 if (skipped(T.RBracket)) |
106 | 3644 t = new ArrayType(t); |
3645 else | |
3646 { | |
214 | 3647 bool success; |
369 | 3648 Type parseAAType() |
3649 { | |
3650 auto type = parseType(); | |
3651 require(T.RBracket); | |
3652 return type; | |
3653 } | |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
3654 auto assocType = try_(&parseAAType, success); |
214 | 3655 if (success) |
106 | 3656 t = new ArrayType(t, assocType); |
3657 else | |
3658 { | |
3659 Expression e = parseExpression(), e2; | |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3660 if (skipped(T.Slice)) |
106 | 3661 e2 = parseExpression(); |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3662 require(T.RBracket); |
106 | 3663 t = new ArrayType(t, e, e2); |
3664 } | |
3665 } | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3666 set(t, begin); |
106 | 3667 return t; |
3668 } | |
3669 | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3670 Type parseCFunctionPointerType(Type type, ref Identifier* ident, bool optionalParamList) |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3671 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3672 assert(token.kind == T.LParen); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3673 assert(type !is null); |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3674 auto begin = token; |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3675 nT(); // Skip ( |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3676 type = parseBasicType2(type); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3677 if (token.kind == T.LParen) |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3678 { |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3679 // Can be nested. |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3680 type = parseCFunctionPointerType(type, ident, true); |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3681 } |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3682 else if (token.kind == T.Identifier) |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3683 { |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3684 // The identifier of the function pointer and the declaration. |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3685 ident = token.ident; |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3686 nT(); |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3687 type = parseDeclaratorSuffix(type); |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3688 } |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3689 require(T.RParen); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3690 |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3691 Parameters params; |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3692 if (optionalParamList) |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3693 params = token.kind == T.LParen ? parseParameterList() : null; |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3694 else |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3695 params = parseParameterList(); |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3696 |
535
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
3697 type = new CFuncPointerType(type, params); |
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
3698 return set(type, begin); |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3699 } |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3700 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3701 Type parseDeclarator(ref Identifier* ident, bool identOptional = false) |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3702 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
3703 auto t = parseType(); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3704 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3705 if (token.kind == T.LParen) |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3706 t = parseCFunctionPointerType(t, ident, true); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3707 else if (token.kind == T.Identifier) |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3708 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3709 ident = token.ident; |
95 | 3710 nT(); |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
3711 t = parseDeclaratorSuffix(t); |
95 | 3712 } |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3713 |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3714 if (ident is null && !identOptional) |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3715 error(token, MSG.ExpectedDeclaratorIdentifier, token.srcText); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3716 |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
3717 return t; |
95 | 3718 } |
3719 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3720 /++ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3721 Parse a list of AssignExpressions. |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3722 ExpressionList: |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3723 AssignExpression |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3724 AssignExpression , ExpressionList |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3725 +/ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3726 Expression[] parseExpressionList() |
138 | 3727 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3728 Expression[] expressions; |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3729 do |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3730 expressions ~= parseAssignExpression(); |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3731 while(skipped(T.Comma)) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3732 return expressions; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3733 } |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3734 |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3735 /++ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3736 Arguments: |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3737 ( ) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3738 ( ExpressionList ) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3739 +/ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3740 Expression[] parseArguments() |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3741 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3742 assert(token.kind == T.LParen); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3743 nT(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3744 Expression[] args; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3745 if (token.kind != TOK.RParen) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3746 args = parseExpressionList(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3747 require(TOK.RParen); |
139 | 3748 return args; |
138 | 3749 } |
3750 | |
143 | 3751 Parameters parseParameterList() |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3752 out(params) |
96 | 3753 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3754 if (params.length > 1) |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3755 foreach (param; params.items[0..$-1]) |
96 | 3756 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3757 if (param.isVariadic()) |
96 | 3758 assert(0, "variadic arguments can only appear at the end of the parameter list."); |
3759 } | |
3760 } | |
3761 body | |
95 | 3762 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3763 auto begin = token; |
95 | 3764 require(T.LParen); |
3765 | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3766 auto params = new Parameters(); |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3767 |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3768 if (skipped(T.RParen)) |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3769 return set(params, begin); |
95 | 3770 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3771 Loop: |
95 | 3772 while (1) |
3773 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3774 auto paramBegin = token; |
269 | 3775 StorageClass stc, tmp; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3776 Type type; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3777 Identifier* ident; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3778 Expression defValue; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3779 |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3780 void pushParameter() |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3781 { |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3782 params ~= set(new Parameter(stc, type, ident, defValue), paramBegin); |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3783 } |
269 | 3784 |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3785 if (skipped(T.Ellipses)) |
269 | 3786 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3787 stc = StorageClass.Variadic; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3788 pushParameter(); // type, ident and defValue will be null. |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3789 break Loop; |
269 | 3790 } |
3791 | |
3792 Lstc_loop: | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3793 switch (token.kind) |
95 | 3794 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3795 version(D2) |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3796 { |
269 | 3797 case T.Invariant: // D2.0 |
3798 if (peekNext() == T.LParen) | |
3799 goto default; | |
3800 tmp = StorageClass.Invariant; | |
3801 goto Lcommon; | |
3802 case T.Const: // D2.0 | |
3803 if (peekNext() == T.LParen) | |
3804 goto default; | |
3805 tmp = StorageClass.Const; | |
3806 goto Lcommon; | |
3807 case T.Final: // D2.0 | |
3808 tmp = StorageClass.Final; | |
3809 goto Lcommon; | |
3810 case T.Scope: // D2.0 | |
3811 tmp = StorageClass.Scope; | |
3812 goto Lcommon; | |
3813 case T.Static: // D2.0 | |
3814 tmp = StorageClass.Static; | |
3815 goto Lcommon; | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3816 } |
269 | 3817 case T.In: |
3818 tmp = StorageClass.In; | |
3819 goto Lcommon; | |
3820 case T.Out: | |
282 | 3821 tmp = StorageClass.Out; |
269 | 3822 goto Lcommon; |
3823 case T.Inout, T.Ref: | |
3824 tmp = StorageClass.Ref; | |
3825 goto Lcommon; | |
3826 case T.Lazy: | |
3827 tmp = StorageClass.Lazy; | |
3828 goto Lcommon; | |
3829 Lcommon: | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3830 // Check for redundancy. |
269 | 3831 if (stc & tmp) |
3832 error(MID.RedundantStorageClass, token.srcText); | |
3833 else | |
3834 stc |= tmp; | |
3835 nT(); | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3836 version(D2) |
269 | 3837 goto Lstc_loop; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3838 else |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3839 goto default; // In D1.0 only one stc per parameter is allowed. |
95 | 3840 default: |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3841 type = parseDeclarator(ident, true); |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3842 |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3843 if (skipped(T.Assign)) |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3844 defValue = parseAssignExpression(); |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3845 |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3846 if (skipped(T.Ellipses)) |
95 | 3847 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3848 stc |= StorageClass.Variadic; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3849 pushParameter(); |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3850 break Loop; |
95 | 3851 } |
3852 | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3853 pushParameter(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3854 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3855 if (token.kind != T.Comma) |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3856 break Loop; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3857 nT(); |
95 | 3858 } |
3859 } | |
3860 require(T.RParen); | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3861 return set(params, begin); |
95 | 3862 } |
3863 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
3864 TemplateArguments parseTemplateArguments() |
139 | 3865 { |
376 | 3866 TemplateArguments targs; |
139 | 3867 require(T.LParen); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3868 if (token.kind != T.RParen) |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3869 targs = parseTemplateArguments_(); |
139 | 3870 require(T.RParen); |
376 | 3871 return targs; |
139 | 3872 } |
376 | 3873 |
269 | 3874 version(D2) |
3875 { | |
3876 TemplateArguments parseTemplateArguments2() | |
3877 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3878 assert(token.kind == T.Comma); |
269 | 3879 nT(); |
376 | 3880 TemplateArguments targs; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3881 if (token.kind != T.RParen) |
376 | 3882 targs = parseTemplateArguments_(); |
269 | 3883 else |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3884 error(token, MSG.ExpectedTypeOrExpression); |
269 | 3885 require(T.RParen); |
376 | 3886 return targs; |
269 | 3887 } |
3888 } // version(D2) | |
376 | 3889 |
3890 TemplateArguments parseTemplateArguments_() | |
3891 { | |
3892 auto begin = token; | |
3893 auto targs = new TemplateArguments; | |
3894 while (1) | |
3895 { | |
379
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
3896 Type parseType_() |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
3897 { |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
3898 auto type = parseType(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3899 if (token.kind == T.Comma || token.kind == T.RParen) |
379
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
3900 return type; |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
3901 ++errorCount; // Cause try_() to fail. |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
3902 return null; |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
3903 } |
376 | 3904 bool success; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
3905 auto typeArgument = try_(&parseType_, success); |
376 | 3906 if (success) |
3907 // TemplateArgument: | |
3908 // Type | |
3909 // Symbol | |
3910 targs ~= typeArgument; | |
3911 else | |
3912 // TemplateArgument: | |
3913 // AssignExpression | |
3914 targs ~= parseAssignExpression(); | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3915 if (token.kind != T.Comma) |
376 | 3916 break; // Exit loop. |
3917 nT(); | |
3918 } | |
3919 set(targs, begin); | |
3920 return targs; | |
3921 } | |
3922 | |
258 | 3923 TemplateParameters parseTemplateParameterList() |
137 | 3924 { |
377 | 3925 TemplateParameters tparams; |
3926 require(T.LParen); | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3927 if (token.kind != T.RParen) |
377 | 3928 tparams = parseTemplateParameterList_(); |
3929 require(T.RParen); | |
3930 return tparams; | |
3931 } | |
3932 | |
3933 version(D2) | |
3934 { | |
3935 TemplateParameters parseTemplateParameterList2() | |
3936 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3937 assert(token.kind == T.Comma); |
377 | 3938 nT(); |
3939 TemplateParameters tparams; | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3940 if (token.kind != T.RParen) |
377 | 3941 tparams = parseTemplateParameterList_(); |
3942 else | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3943 error(token, MSG.ExpectedTemplateParameters); |
377 | 3944 return tparams; |
3945 } | |
3946 } // version(D2) | |
3947 | |
3948 TemplateParameters parseTemplateParameterList_() | |
3949 { | |
258 | 3950 auto begin = token; |
295
75b47c71a34c
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
293
diff
changeset
|
3951 auto tparams = new TemplateParameters; |
75b47c71a34c
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
293
diff
changeset
|
3952 |
137 | 3953 while (1) |
3954 { | |
258 | 3955 auto paramBegin = token; |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3956 TemplateParameter tp; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3957 Identifier* ident; |
137 | 3958 Type specType, defType; |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3959 |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3960 void parseSpecAndOrDefaultType() |
137 | 3961 { |
3962 // : SpecializationType | |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3963 if (skipped(T.Colon)) |
137 | 3964 specType = parseType(); |
3965 // = DefaultType | |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3966 if (skipped(T.Assign)) |
137 | 3967 defType = parseType(); |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3968 } |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3969 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3970 switch (token.kind) |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3971 { |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3972 case T.Alias: |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3973 // TemplateAliasParameter: |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3974 // alias Identifier |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3975 nT(); // Skip alias keyword. |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3976 ident = requireIdentifier(MSG.ExpectedAliasTemplateParam); |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3977 parseSpecAndOrDefaultType(); |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3978 tp = new TemplateAliasParameter(ident, specType, defType); |
137 | 3979 break; |
3980 case T.Identifier: | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3981 ident = token.ident; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
3982 switch (peekNext()) |
137 | 3983 { |
3984 case T.Ellipses: | |
3985 // TemplateTupleParameter: | |
3986 // Identifier ... | |
3987 nT(); // Skip Identifier. | |
3988 nT(); // Skip Ellipses. | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3989 if (token.kind == T.Comma) |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
3990 error(MID.TemplateTupleParameter); |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3991 tp = new TemplateTupleParameter(ident); |
137 | 3992 break; |
3993 case T.Comma, T.RParen, T.Colon, T.Assign: | |
3994 // TemplateTypeParameter: | |
3995 // Identifier | |
3996 nT(); // Skip Identifier. | |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3997 parseSpecAndOrDefaultType(); |
341
3ac651ea83fb
- Fix: created TemplateAliasParameter instead of TemplateTypeParameter.
aziz
parents:
340
diff
changeset
|
3998 tp = new TemplateTypeParameter(ident, specType, defType); |
137 | 3999 break; |
4000 default: | |
4001 // TemplateValueParameter: | |
4002 // Declarator | |
4003 ident = null; | |
4004 goto LTemplateValueParameter; | |
4005 } | |
4006 break; | |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4007 version(D2) |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4008 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4009 case T.This: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4010 // TemplateThisParameter |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4011 // this TemplateTypeParameter |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4012 nT(); // Skip 'this' keyword. |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4013 ident = requireIdentifier(MSG.ExpectedNameForThisTempParam); |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4014 parseSpecAndOrDefaultType(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4015 tp = new TemplateThisParameter(ident, specType, defType); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4016 break; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
4017 } |
137 | 4018 default: |
4019 LTemplateValueParameter: | |
4020 // TemplateValueParameter: | |
4021 // Declarator | |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4022 Expression specValue, defValue; |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4023 auto valueType = parseDeclarator(ident); |
137 | 4024 // : SpecializationValue |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
4025 if (skipped(T.Colon)) |
137 | 4026 specValue = parseCondExpression(); |
4027 // = DefaultValue | |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
4028 if (skipped(T.Assign)) |
137 | 4029 defValue = parseCondExpression(); |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4030 tp = new TemplateValueParameter(valueType, ident, specValue, defValue); |
137 | 4031 } |
4032 | |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4033 // Push template parameter. |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
4034 tparams ~= set(tp, paramBegin); |
137 | 4035 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4036 if (token.kind != T.Comma) |
137 | 4037 break; |
4038 nT(); | |
4039 } | |
258 | 4040 set(tparams, begin); |
137 | 4041 return tparams; |
4042 } | |
4043 | |
124 | 4044 void expected(TOK tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4045 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4046 if (token.kind != tok) |
327 | 4047 error(MID.ExpectedButFound, Token.toString(tok), token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4048 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4049 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4050 void require(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4051 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4052 if (token.kind == tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4053 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4054 else |
327 | 4055 error(MID.ExpectedButFound, Token.toString(tok), token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4056 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4057 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4058 void requireNext(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4059 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4060 nT(); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4061 require(tok); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4062 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4063 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4064 Identifier* optionalIdentifier() |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4065 { |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4066 Identifier* id; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4067 if (token.kind == T.Identifier) |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4068 (id = token.ident), nT(); |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4069 return id; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4070 } |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4071 |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4072 Identifier* requireIdentifier() |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4073 { |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4074 Identifier* id; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4075 if (token.kind == T.Identifier) |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4076 (id = token.ident), nT(); |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4077 else |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4078 error(MID.ExpectedButFound, "Identifier", token.srcText); |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4079 return id; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4080 } |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4081 |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4082 /++ |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4083 Params: |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4084 errorMsg = an error that has no message ID yet. |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4085 +/ |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4086 Identifier* requireIdentifier(char[] errorMsg) |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4087 { |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4088 Identifier* id; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4089 if (token.kind == T.Identifier) |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4090 (id = token.ident), nT(); |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4091 else |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4092 error(token, errorMsg, token.srcText); |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4093 return id; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4094 } |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4095 |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4096 Identifier* requireIdentifier(MID mid) |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4097 { |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4098 Identifier* id; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4099 if (token.kind == T.Identifier) |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4100 (id = token.ident), nT(); |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4101 else |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4102 error(mid, token.srcText); |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4103 return id; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4104 } |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4105 |
243 | 4106 Token* requireId() |
4107 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4108 if (token.kind == T.Identifier) |
243 | 4109 { |
4110 auto id = token; | |
4111 nT(); | |
4112 return id; | |
4113 } | |
4114 else | |
4115 error(MID.ExpectedButFound, "Identifier", token.srcText); | |
4116 return null; | |
4117 } | |
4118 | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4119 Token* requireIdToken(char[] errorMsg) |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4120 { |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4121 Token* idtok; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4122 if (token.kind == T.Identifier) |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4123 (idtok = token), nT(); |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4124 else |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4125 error(token, errorMsg, token.srcText); |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4126 return idtok; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4127 } |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4128 |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4129 /// Reports an error that has no message ID yet. |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4130 void error(Token* token, char[] formatMsg, ...) |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4131 { |
514
6ddff941862a
Added new error classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
511
diff
changeset
|
4132 error_(token, formatMsg, _arguments, _argptr); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4133 } |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4134 |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
4135 void error(MID mid, ...) |
71 | 4136 { |
514
6ddff941862a
Added new error classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
511
diff
changeset
|
4137 error_(this.token, GetMsg(mid), _arguments, _argptr); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4138 } |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4139 |
514
6ddff941862a
Added new error classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
511
diff
changeset
|
4140 void error_(Token* token, char[] formatMsg, TypeInfo[] _arguments, void* _argptr) |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4141 { |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4142 if (trying) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4143 { |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4144 ++errorCount; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4145 return; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4146 } |
675
e7811328e6c7
Made Token.getLocation() a template function and added two aliases.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
673
diff
changeset
|
4147 auto location = token.getErrorLocation(); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4148 auto msg = Format(_arguments, _argptr, formatMsg); |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
519
diff
changeset
|
4149 auto error = new ParserError(location, msg); |
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
519
diff
changeset
|
4150 errors ~= error; |
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
519
diff
changeset
|
4151 if (infoMan !is null) |
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
519
diff
changeset
|
4152 infoMan ~= error; |
71 | 4153 } |
65 | 4154 } |