Mercurial > projects > dil
annotate trunk/src/dil/parser/Parser.d @ 774:846044180d22
Added method skip() to class Parser.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Mon, 18 Feb 2008 20:03:44 +0100 |
parents | 5e3ef1b2011c |
children | c1d5cfd7aa44 |
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; |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
750
diff
changeset
|
19 import dil.SourceText; |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
20 import common; |
65 | 21 |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
22 /++ |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
23 The Parser produces a full parse tree by examining |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
24 the list of tokens provided by the Lexer. |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
25 +/ |
65 | 26 class Parser |
27 { | |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
28 Lexer lexer; /// Used to lex the source code. |
318 | 29 Token* token; /// Current non-whitespace token. |
30 Token* prevToken; /// Previous non-whitespace token. | |
71 | 31 |
532
50e64bab9c7a
Renamed InformationManager to InfoManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
531
diff
changeset
|
32 InfoManager infoMan; |
514
6ddff941862a
Added new error classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
511
diff
changeset
|
33 ParserError[] errors; |
71 | 34 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
35 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
|
36 |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
37 // 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
|
38 // 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
|
39 LinkageType linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
40 Protection protection; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
41 StorageClass storageClass; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
42 uint alignSize = DEFAULT_ALIGN_SIZE; |
364 | 43 |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
44 private alias TOK T; |
511
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
45 private alias TypeNode Type; |
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 /++ |
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
48 Construct a Parser object. |
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
49 Params: |
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
50 text = the UTF-8 source code. |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
51 infoMan = used for collecting error messages. |
511
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
52 +/ |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
750
diff
changeset
|
53 this(SourceText srcText, InfoManager infoMan = null) |
71 | 54 { |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
519
diff
changeset
|
55 this.infoMan = infoMan; |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
750
diff
changeset
|
56 lexer = new Lexer(srcText, infoMan); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
57 } |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
58 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
59 /// Moves to the first token. |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
60 protected void init() |
206 | 61 { |
62 nT(); | |
318 | 63 prevToken = token; |
206 | 64 } |
65 | |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
66 /// Moves to the next token. |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
67 void nT() |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
68 { |
318 | 69 prevToken = token; |
132 | 70 do |
71 { | |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
72 lexer.nextToken(); |
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
73 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
|
74 } while (token.isWhitespace) // Skip whitespace |
71 | 75 } |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
76 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
77 /// Start the parser and return the parsed Declarations. |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
78 CompoundDeclaration start() |
102 | 79 { |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
80 init(); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
81 auto begin = token; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
82 auto decls = new CompoundDeclaration; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
83 if (token.kind == T.Module) |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
84 decls ~= parseModuleDeclaration(); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
85 decls.addOptChildren(parseDeclarationDefinitions()); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
86 set(decls, begin); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
87 return decls; |
102 | 88 } |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
89 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
90 /// Start the parser and return the parsed Expression. |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
91 Expression start2() |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
92 { |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
93 init(); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
94 return parseExpression(); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
95 } |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
96 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
97 // Members related to the method try_(). |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
98 uint trying; /// Greater than 0 if Parser is in try_(). |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
99 uint errorCount; /// Used to track nr. of errors while being in try_(). |
423
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 { |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
107 // Save members. |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
108 auto oldToken = this.token; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
109 auto oldPrevToken = this.prevToken; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
110 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
|
111 |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
112 ++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
|
113 auto result = parseMethod(); |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
114 --trying; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
115 // Check if an error occurred. |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
116 if (errorCount != oldCount) |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
117 { // Restore members. |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
118 token = oldToken; |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
119 prevToken = oldPrevToken; |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
120 lexer.token = oldToken; |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
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 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
129 /// Sets the begin and end tokens of a syntax tree node. |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
130 Class set(Class)(Class node, Token* begin) |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
131 { |
318 | 132 node.setTokens(begin, this.prevToken); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
133 return node; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
134 } |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
135 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
136 /// Returns true if set() has been called on a node. |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
137 static bool isNodeSet(Node node) |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
138 { |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
139 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
|
140 } |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
141 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
142 /// Returns the token kind of the next token. |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
143 TOK peekNext() |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
144 { |
239
7911f6a92e6e
- Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK.
aziz
parents:
238
diff
changeset
|
145 Token* next = token; |
296 | 146 do |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
147 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
|
148 while (next.isWhitespace) // Skip whitespace |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
149 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
|
150 } |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
151 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
152 /// Returns the token kind of the token after 'next'. |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
153 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
|
154 { |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
155 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
|
156 do |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
157 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
|
158 while (next.isWhitespace) // Skip whitespace |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
159 return next.kind; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
160 } |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
161 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
162 /// Consumes the current token if its kind matches k and returns true. |
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
163 bool consumed()(TOK k) // Templatized, so it's inlined. |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
164 { |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
165 return token.kind == k ? (nT(), true) : false; |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
166 } |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
167 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
168 /// Asserts that the current token is of kind expectedKind, |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
169 /// and then moves to the next token. |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
170 void skip()(TOK expectedKind) |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
171 { |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
172 assert(token.kind == expectedKind /+|| *(int*).init+/, token.srcText()); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
173 nT(); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
174 } |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
175 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
176 /+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
177 | Declaration parsing methods | |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
178 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+/ |
102 | 179 |
368 | 180 Declaration parseModuleDeclaration() |
181 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
182 skip(T.Module); |
368 | 183 auto begin = token; |
184 ModuleFQN moduleFQN; | |
185 do | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
186 moduleFQN ~= requireIdentifier(MSG.ExpectedModuleIdentifier); |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
187 while (consumed(T.Dot)) |
368 | 188 require(T.Semicolon); |
189 return set(new ModuleDeclaration(moduleFQN), begin); | |
190 } | |
191 | |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
192 /++ |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
193 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
|
194 DeclDefs: |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
195 DeclDef |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
196 DeclDefs |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
197 +/ |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
198 Declaration[] parseDeclarationDefinitions() |
102 | 199 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
200 Declaration[] decls; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
201 while (token.kind != T.EOF) |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
202 decls ~= parseDeclarationDefinition(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
203 return decls; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
204 } |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
205 |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
206 /++ |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
207 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
|
208 DeclDefsBlock: |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
209 { } |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
210 { DeclDefs } |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
211 +/ |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
212 CompoundDeclaration parseDeclarationDefinitionsBody() |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
213 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
214 // Save attributes. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
215 auto linkageType = this.linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
216 auto protection = this.protection; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
217 auto storageClass = this.storageClass; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
218 // Clear attributes. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
219 this.linkageType = LinkageType.None; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
220 this.protection = Protection.None; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
221 this.storageClass = StorageClass.None; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
222 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
223 // Parse body. |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
224 auto begin = token; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
225 auto decls = new CompoundDeclaration; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
226 require(T.LBrace); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
227 while (token.kind != T.RBrace && token.kind != T.EOF) |
161 | 228 decls ~= parseDeclarationDefinition(); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
229 require(T.RBrace); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
230 set(decls, begin); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
231 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
232 // Restore original values. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
233 this.linkageType = linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
234 this.protection = protection; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
235 this.storageClass = storageClass; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
236 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
237 return decls; |
102 | 238 } |
239 | |
110 | 240 Declaration parseDeclarationDefinition() |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
241 out(decl) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
242 { assert(isNodeSet(decl)); } |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
243 body |
102 | 244 { |
262 | 245 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
|
246 Declaration decl; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
247 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
|
248 { |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
249 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
|
250 T.Pragma, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
251 // Protection attributes |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
252 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
|
253 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
|
254 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
|
255 T.Protected, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
256 T.Public: |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
257 decl = parseAttributeSpecifier(); |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
258 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
259 // Storage classes |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
260 case T.Extern, |
203
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
261 T.Deprecated, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
262 T.Override, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
263 T.Abstract, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
264 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
|
265 //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
|
266 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
|
267 T.Const, |
269 | 268 //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
|
269 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
|
270 T.Scope: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
271 case_StaticAttribute: |
269 | 272 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
|
273 return parseStorageAttribute(); |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
274 case T.Alias: |
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 AliasDeclaration(parseVariableOrFunction()); |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
277 break; |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
278 case T.Typedef: |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
279 nT(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
280 decl = new TypedefDeclaration(parseVariableOrFunction()); |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
281 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
|
282 case T.Static: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
283 switch (peekNext()) |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
284 { |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
285 case T.Import: |
429
052cbacb1642
Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
424
diff
changeset
|
286 goto case_Import; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
287 case T.This: |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
288 decl = parseStaticConstructorDeclaration(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
289 break; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
290 case T.Tilde: |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
291 decl = parseStaticDestructorDeclaration(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
292 break; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
293 case T.If: |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
294 decl = parseStaticIfDeclaration(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
295 break; |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
296 case T.Assert: |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
297 decl = parseStaticAssertDeclaration(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
298 break; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
299 default: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
300 goto case_StaticAttribute; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
301 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
302 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
|
303 case T.Import: |
429
052cbacb1642
Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
424
diff
changeset
|
304 case_Import: |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
305 decl = parseImportDeclaration(); |
673
64fec49651cf
Renamed VariableDeclaration to VariablesDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
671
diff
changeset
|
306 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
|
307 // 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
|
308 decl.setProtection(this.protection); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
309 return set(decl, begin); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
310 case T.Enum: |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
311 decl = parseEnumDeclaration(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
312 break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
313 case T.Class: |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
314 decl = parseClassDeclaration(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
315 break; |
112 | 316 case T.Interface: |
317 decl = parseInterfaceDeclaration(); | |
318 break; | |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
319 case T.Struct, T.Union: |
638
7131c07997f9
Renamed parseAggregateDeclaration() to parseStructOrUnionDeclaration().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
637
diff
changeset
|
320 decl = parseStructOrUnionDeclaration(); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
321 break; |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
322 case T.This: |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
323 decl = parseConstructorDeclaration(); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
324 break; |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
325 case T.Tilde: |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
326 decl = parseDestructorDeclaration(); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
327 break; |
120 | 328 case T.Invariant: |
269 | 329 version(D2) |
330 { | |
331 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
|
332 if (peekAfter(next) == T.LParen) |
269 | 333 { |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
334 if (peekAfter(next) != T.RParen) |
269 | 335 goto case_Declaration; |
336 } | |
337 else | |
338 goto case_InvariantAttribute; | |
339 } | |
120 | 340 decl = parseInvariantDeclaration(); |
341 break; | |
121 | 342 case T.Unittest: |
343 decl = parseUnittestDeclaration(); | |
344 break; | |
122 | 345 case T.Debug: |
346 decl = parseDebugDeclaration(); | |
140 | 347 break; |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
348 case T.Version: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
349 decl = parseVersionDeclaration(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
350 break; |
140 | 351 case T.Template: |
352 decl = parseTemplateDeclaration(); | |
353 break; | |
141 | 354 case T.New: |
355 decl = parseNewDeclaration(); | |
356 break; | |
357 case T.Delete: | |
358 decl = parseDeleteDeclaration(); | |
359 break; | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
360 case T.Mixin: |
256 | 361 decl = parseMixin!(MixinDeclaration)(); |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
362 break; |
129 | 363 case T.Semicolon: |
364 nT(); | |
365 decl = new EmptyDeclaration(); | |
366 break; | |
192 | 367 // Declaration |
368 case T.Identifier, T.Dot, T.Typeof: | |
269 | 369 case_Declaration: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
370 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
|
371 default: |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
372 if (token.isIntegralType) |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
373 goto case_Declaration; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
374 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
|
375 { |
fe66cecb6ec9
Reporting error if module declaration is not first.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
634
diff
changeset
|
376 decl = parseModuleDeclaration(); |
fe66cecb6ec9
Reporting error if module declaration is not first.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
634
diff
changeset
|
377 error(begin, MSG.ModuleDeclarationNotFirst); |
fe66cecb6ec9
Reporting error if module declaration is not first.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
634
diff
changeset
|
378 return decl; |
fe66cecb6ec9
Reporting error if module declaration is not first.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
634
diff
changeset
|
379 } |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
380 |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
381 decl = new IllegalDeclaration(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
382 // Skip to next valid token. |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
383 do |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
384 nT(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
385 while (!token.isDeclDefStart && |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
386 token.kind != T.RBrace && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
387 token.kind != T.EOF) |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
388 auto text = Token.textSpan(begin, this.prevToken); |
616
506ce60760d8
Fixed some error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
608
diff
changeset
|
389 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
|
390 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
391 decl.setProtection(this.protection); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
392 decl.setStorageClass(this.storageClass); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
393 assert(!isNodeSet(decl)); |
262 | 394 set(decl, begin); |
129 | 395 return decl; |
102 | 396 } |
397 | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
398 /++ |
122 | 399 DeclarationsBlock: |
400 : DeclDefs | |
401 { } | |
402 { DeclDefs } | |
403 DeclDef | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
404 +/ |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
405 Declaration parseDeclarationsBlock(/+bool noColon = false+/) |
122 | 406 { |
305 | 407 Declaration d; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
408 switch (token.kind) |
122 | 409 { |
410 case T.LBrace: | |
528
d0ac6faeaf66
Fixed something in dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
524
diff
changeset
|
411 auto begin = token; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
412 nT(); |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
413 auto decls = new CompoundDeclaration; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
414 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
|
415 decls ~= parseDeclarationDefinition(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
416 require(T.RBrace); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
417 d = set(decls, begin); |
122 | 418 break; |
419 case T.Colon: | |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
420 // if (noColon == true) |
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
421 // goto default; |
122 | 422 nT(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
423 auto begin = token; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
424 auto decls = new CompoundDeclaration; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
425 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
|
426 decls ~= parseDeclarationDefinition(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
427 d = set(decls, begin); |
122 | 428 break; |
429 default: | |
305 | 430 d = parseDeclarationDefinition(); |
122 | 431 } |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
432 assert(isNodeSet(d)); |
305 | 433 return d; |
122 | 434 } |
435 | |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
436 // Declaration parseDeclarationsBlockNoColon() |
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
437 // { |
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
438 // return parseDeclarationsBlock(true); |
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
439 // } |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
440 |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
441 /++ |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
442 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
|
443 Params: |
555
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
444 stc = previously parsed storage classes |
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
445 protection = previously parsed protection attribute |
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
446 linkType = previously parsed linkage type |
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
447 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
|
448 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
|
449 +/ |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
450 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
|
451 Protection protection = Protection.None, |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
452 LinkageType linkType = LinkageType.None, |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
453 bool testAutoDeclaration = false, |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
454 bool optionalParameterList = true) |
192 | 455 { |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
456 auto begin = token; |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
457 Type type; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
458 Identifier* name; |
192 | 459 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
460 // Check for AutoDeclaration: StorageClasses Identifier = |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
461 if (testAutoDeclaration && |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
462 token.kind == T.Identifier && |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
463 peekNext() == T.Assign) |
192 | 464 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
465 name = token.ident; |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
466 skip(T.Identifier); |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
467 } |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
468 else |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
469 { |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
470 type = parseType(); // VariableType or ReturnType |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
471 if (token.kind == T.LParen) |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
472 { |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
473 // 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
|
474 // 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
|
475 // Example: |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
476 // void foo() { |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
477 // // 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
|
478 // some_type (*p_func)(int); |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
479 // // 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
|
480 // 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
|
481 // } |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
482 // // 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
|
483 // something(*p); |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
484 type = parseCFunctionPointerType(type, name, optionalParameterList); |
415
b18b0cd8f8cd
Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
414
diff
changeset
|
485 } |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
486 else if (peekNext() == T.LParen) |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
487 { // Type FunctionName ( ParameterList ) FunctionBody |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
488 name = requireIdentifier(MSG.ExpectedFunctionName); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
489 name || nT(); // Skip non-identifier token. |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
490 assert(token.kind == T.LParen); |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
491 // It's a function declaration |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
492 TemplateParameters tparams; |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
493 if (tokenAfterParenIs(T.LParen)) |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
494 // ( TemplateParameterList ) ( ParameterList ) |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
495 tparams = parseTemplateParameterList(); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
496 |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
497 auto params = parseParameterList(); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
498 version(D2) |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
499 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
500 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
|
501 { |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
502 case T.Const: |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
503 stc |= StorageClass.Const; |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
504 nT(); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
505 break; |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
506 case T.Invariant: |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
507 stc |= StorageClass.Invariant; |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
508 nT(); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
509 break; |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
510 default: |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
511 } |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
512 } |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
513 // ReturnType FunctionName ( ParameterList ) |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
514 auto funcBody = parseFunctionBody(); |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
515 auto fd = new FunctionDeclaration(type, name,/+ tparams,+/ params, funcBody); |
765
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
516 fd.setStorageClass(stc); |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
517 fd.setLinkageType(linkType); |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
518 fd.setProtection(protection); |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
519 if (tparams) |
765
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
520 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
521 auto d = putInsideTemplateDeclaration(begin, name, fd, tparams); |
765
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
522 d.setStorageClass(stc); |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
523 d.setProtection(protection); |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
524 return set(d, begin); |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
525 } |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
526 return set(fd, begin); |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
527 } |
535
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
528 else |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
529 { // Type VariableName DeclaratorSuffix |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
530 name = requireIdentifier(MSG.ExpectedVariableName); |
535
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
531 type = parseDeclaratorSuffix(type); |
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
532 } |
192 | 533 } |
534 | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
535 // It's a variables declaration. |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
536 Identifier*[] names = [name]; // One identifier has been parsed already. |
194 | 537 Expression[] values; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
538 goto LenterLoop; // Enter the loop and check for an initializer. |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
539 while (consumed(T.Comma)) |
194 | 540 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
541 names ~= requireIdentifier(MSG.ExpectedVariableName); |
194 | 542 LenterLoop: |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
543 if (consumed(T.Assign)) |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
544 values ~= parseInitializer(); |
199
a95fee6e4b7e
- Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents:
198
diff
changeset
|
545 else |
a95fee6e4b7e
- Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents:
198
diff
changeset
|
546 values ~= null; |
194 | 547 } |
548 require(T.Semicolon); | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
549 auto d = new VariablesDeclaration(type, names, values); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
550 d.setStorageClass(stc); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
551 d.setLinkageType(linkType); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
552 d.setProtection(protection); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
553 return set(d, begin); |
194 | 554 } |
192 | 555 |
194 | 556 Expression parseInitializer() |
557 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
558 if (token.kind == T.Void) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
559 { |
266 | 560 auto begin = token; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
561 auto next = peekNext(); |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
562 if (next == T.Comma || next == T.Semicolon) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
563 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
564 skip(T.Void); |
695
170ddcdc9711
Renamed VoidInitializer, ArrayInitializer and StructInitializer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
565 return set(new VoidInitExpression(), begin); |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
566 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
567 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
568 return parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
569 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
570 |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
571 Expression parseNonVoidInitializer() |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
572 { |
266 | 573 auto begin = token; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
574 Expression init; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
575 switch (token.kind) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
576 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
577 case T.LBracket: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
578 // ArrayInitializer: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
579 // [ ] |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
580 // [ ArrayMemberInitializations ] |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
581 Expression[] keys; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
582 Expression[] values; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
583 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
584 skip(T.LBracket); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
585 while (token.kind != T.RBracket) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
586 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
587 auto e = parseNonVoidInitializer(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
588 if (consumed(T.Colon)) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
589 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
590 keys ~= e; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
591 values ~= parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
592 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
593 else |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
594 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
595 keys ~= null; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
596 values ~= e; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
597 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
598 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
599 if (!consumed(T.Comma)) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
600 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
601 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
602 require(T.RBracket); |
695
170ddcdc9711
Renamed VoidInitializer, ArrayInitializer and StructInitializer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
603 init = new ArrayInitExpression(keys, values); |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
604 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
605 case T.LBrace: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
606 // StructInitializer: |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
607 // { } |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
608 // { StructMemberInitializers } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
609 Expression parseStructInitializer() |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
610 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
611 Identifier*[] idents; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
612 Expression[] values; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
613 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
614 skip(T.LBrace); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
615 while (token.kind != T.RBrace) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
616 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
617 if (token.kind == T.Identifier && |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
618 // 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
|
619 peekNext() == T.Colon) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
620 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
621 idents ~= token.ident; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
622 skip(T.Identifier), skip(T.Colon); |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
623 } |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
624 else |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
625 idents ~= null; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
626 |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
627 // NonVoidInitializer |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
628 values ~= parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
629 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
630 if (!consumed(T.Comma)) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
631 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
632 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
633 require(T.RBrace); |
695
170ddcdc9711
Renamed VoidInitializer, ArrayInitializer and StructInitializer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
634 return new StructInitExpression(idents, values); |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
635 } |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
636 |
214 | 637 bool success; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
638 auto si = try_(&parseStructInitializer, success); |
214 | 639 if (success) |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
640 { |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
641 init = si; |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
642 break; |
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
643 } |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
644 assert(token.kind == T.LBrace); |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
645 //goto default; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
646 default: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
647 init = parseAssignExpression(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
648 } |
266 | 649 set(init, begin); |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
650 return init; |
192 | 651 } |
652 | |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
653 FuncBodyStatement parseFunctionBody() |
192 | 654 { |
268 | 655 auto begin = token; |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
656 auto func = new FuncBodyStatement; |
192 | 657 while (1) |
658 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
659 switch (token.kind) |
192 | 660 { |
661 case T.LBrace: | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
662 func.funcBody = parseStatements(); |
192 | 663 break; |
664 case T.Semicolon: | |
665 nT(); | |
666 break; | |
667 case T.In: | |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
668 if (func.inBody) |
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
669 error(MID.InContract); |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
670 nT(); |
192 | 671 func.inBody = parseStatements(); |
672 continue; | |
673 case T.Out: | |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
674 if (func.outBody) |
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
675 error(MID.OutContract); |
192 | 676 nT(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
677 if (consumed(T.LParen)) |
192 | 678 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
679 func.outIdent = requireIdentifier(MSG.ExpectedAnIdentifier); |
192 | 680 require(T.RParen); |
681 } | |
682 func.outBody = parseStatements(); | |
683 continue; | |
684 case T.Body: | |
685 nT(); | |
686 goto case T.LBrace; | |
687 default: | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
688 error(token, MSG.ExpectedFunctionBody, token.srcText); |
192 | 689 } |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
690 break; // Exit loop. |
192 | 691 } |
268 | 692 set(func, begin); |
299
559d5d62e0c1
- Added checks for null before adding member to Node.children.
aziz
parents:
298
diff
changeset
|
693 func.finishConstruction(); |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
694 return func; |
192 | 695 } |
696 | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
697 LinkageType parseLinkageType() |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
698 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
699 LinkageType linkageType; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
700 |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
701 if (!consumed(T.LParen)) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
702 return linkageType; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
703 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
704 if (consumed(T.RParen)) |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
705 { // extern() |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
706 error(MID.MissingLinkageType); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
707 return linkageType; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
708 } |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
709 |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
710 auto identTok = requireId(); |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
711 |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
712 IDK idKind = identTok ? identTok.ident.idKind : IDK.Null; |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
713 |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
714 switch (idKind) |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
715 { |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
716 case IDK.C: |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
717 if (consumed(T.PlusPlus)) |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
718 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
719 linkageType = LinkageType.Cpp; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
720 break; |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
721 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
722 linkageType = LinkageType.C; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
723 break; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
724 case IDK.D: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
725 linkageType = LinkageType.D; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
726 break; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
727 case IDK.Windows: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
728 linkageType = LinkageType.Windows; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
729 break; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
730 case IDK.Pascal: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
731 linkageType = LinkageType.Pascal; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
732 break; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
733 case IDK.System: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
734 linkageType = LinkageType.System; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
735 break; |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
736 default: |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
737 error(MID.UnrecognizedLinkageType, token.srcText); |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
738 } |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
739 require(T.RParen); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
740 return linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
741 } |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
742 |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
743 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
|
744 { |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
745 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
|
746 prev_lt = lt; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
747 else |
616
506ce60760d8
Fixed some error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
608
diff
changeset
|
748 error(begin, MSG.RedundantLinkageType, Token.textSpan(begin, this.prevToken)); |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
749 } |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
750 |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
751 Declaration parseStorageAttribute() |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
752 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
753 StorageClass stc, stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
754 LinkageType prev_linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
755 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
756 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
|
757 // Nested function. |
305 | 758 Declaration parse() |
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 Declaration decl; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
761 auto begin = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
762 switch (token.kind) |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
763 { |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
764 case T.Extern: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
765 if (peekNext() != T.LParen) |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
766 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
767 stc_tmp = StorageClass.Extern; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
768 goto Lcommon; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
769 } |
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 nT(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
772 auto linkageType = parseLinkageType(); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
773 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
|
774 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
775 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
|
776 this.linkageType = linkageType; // Set. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
777 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
|
778 set(decl, begin); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
779 this.linkageType = saved; // Restore. |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
780 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
781 case T.Override: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
782 stc_tmp = StorageClass.Override; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
783 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
784 case T.Deprecated: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
785 stc_tmp = StorageClass.Deprecated; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
786 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
787 case T.Abstract: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
788 stc_tmp = StorageClass.Abstract; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
789 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
790 case T.Synchronized: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
791 stc_tmp = StorageClass.Synchronized; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
792 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
793 case T.Static: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
794 stc_tmp = StorageClass.Static; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
795 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
796 case T.Final: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
797 stc_tmp = StorageClass.Final; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
798 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
799 case T.Const: |
269 | 800 version(D2) |
801 { | |
802 if (peekNext() == T.LParen) | |
803 goto case_Declaration; | |
804 } | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
805 stc_tmp = StorageClass.Const; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
806 goto Lcommon; |
269 | 807 version(D2) |
808 { | |
809 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
|
810 auto next = token; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
811 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
|
812 { |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
813 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
|
814 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
|
815 decl = parseDeclarationDefinition(); // invariant ( ) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
816 decl.setStorageClass(stc); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
817 break; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
818 } |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
819 // invariant as StorageClass. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
820 stc_tmp = StorageClass.Invariant; |
269 | 821 goto Lcommon; |
822 } | |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
823 case T.Auto: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
824 stc_tmp = StorageClass.Auto; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
825 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
826 case T.Scope: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
827 stc_tmp = StorageClass.Scope; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
828 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
829 Lcommon: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
830 // Issue error if redundant. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
831 if (stc & stc_tmp) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
832 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
|
833 else |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
834 stc |= stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
835 |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
836 nT(); |
650
eb490ba8dba0
Made AttributeDeclaration abstract.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
646
diff
changeset
|
837 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
|
838 set(decl, begin); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
839 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
840 case T.Identifier: |
269 | 841 case_Declaration: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
842 // 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
|
843 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
|
844 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
845 default: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
846 this.storageClass = stc; // Set. |
305 | 847 decl = parseDeclarationsBlock(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
848 this.storageClass = saved_storageClass; // Reset. |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
849 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
850 assert(isNodeSet(decl)); |
305 | 851 return decl; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
852 } |
305 | 853 return parse(); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
854 } |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
855 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
856 uint parseAlignAttribute() |
260 | 857 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
858 skip(T.Align); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
859 uint size = DEFAULT_ALIGN_SIZE; // Global default. |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
860 if (consumed(T.LParen)) |
260 | 861 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
862 if (token.kind == T.Int32) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
863 (size = token.int_), skip(T.Int32); |
260 | 864 else |
865 expected(T.Int32); | |
866 require(T.RParen); | |
867 } | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
868 return size; |
260 | 869 } |
870 | |
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
|
871 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
|
872 { |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
873 Declaration decl; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
874 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
875 switch (token.kind) |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
876 { |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
877 case T.Align: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
878 uint alignSize = parseAlignAttribute(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
879 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
|
880 this.alignSize = alignSize; // Set. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
881 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
|
882 this.alignSize = saved; // Restore. |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
883 break; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
884 case T.Pragma: |
147 | 885 // Pragma: |
886 // pragma ( Identifier ) | |
887 // pragma ( Identifier , ExpressionList ) | |
888 nT(); | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
889 Identifier* ident; |
147 | 890 Expression[] args; |
891 | |
892 require(T.LParen); | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
893 ident = requireIdentifier(MSG.ExpectedPragmaIdentifier); |
147 | 894 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
895 if (consumed(T.Comma)) |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
896 args = parseExpressionList(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
897 require(T.RParen); |
147 | 898 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
899 decl = new PragmaDeclaration(ident, args, parseDeclarationsBlock()); |
147 | 900 break; |
491
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
901 default: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
902 // Protection attributes |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
903 Protection prot; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
904 switch (token.kind) |
491
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
905 { |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
906 case T.Private: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
907 prot = Protection.Private; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
908 case T.Package: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
909 prot = Protection.Package; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
910 case T.Protected: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
911 prot = Protection.Protected; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
912 case T.Public: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
913 prot = Protection.Public; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
914 case T.Export: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
915 prot = Protection.Export; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
916 default: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
917 assert(0); |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
918 } |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
919 nT(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
920 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
|
921 this.protection = prot; // Set. |
491
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
922 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
|
923 this.protection = saved; // Restore. |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
924 } |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
925 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
|
926 } |
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
|
927 |
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
|
928 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
|
929 { |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
930 bool isStatic = consumed(T.Static); |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
931 skip(T.Import); |
429
052cbacb1642
Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
424
diff
changeset
|
932 |
364 | 933 ModuleFQN[] moduleFQNs; |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
934 Identifier*[] moduleAliases; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
935 Identifier*[] bindNames; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
936 Identifier*[] bindAliases; |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
937 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
938 do |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
939 { |
364 | 940 ModuleFQN moduleFQN; |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
941 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
|
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); |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
946 skip(T.Assign); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
947 } |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
948 // Identifier ("." Identifier)* |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
949 do |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
950 moduleFQN ~= requireIdentifier(MSG.ExpectedModuleIdentifier); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
951 while (consumed(T.Dot)) |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
952 // Push identifiers. |
364 | 953 moduleFQNs ~= moduleFQN; |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
954 moduleAliases ~= moduleAlias; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
955 } while (consumed(T.Comma)) |
298 | 956 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
957 if (consumed(T.Colon)) |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
958 { // BindAlias "=" BindName ("," BindAlias "=" BindName)*; |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
959 // BindName ("," BindName)*; |
320
0ce14640eb04
- Fix in parseImportDeclaration(): rewrote while loop and removed a call to nT().
aziz
parents:
319
diff
changeset
|
960 do |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
961 { |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
962 Identifier* bindAlias; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
963 // BindAlias = BindName |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
964 if (peekNext() == T.Assign) |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
965 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
966 bindAlias = requireIdentifier(MSG.ExpectedAliasImportName); |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
967 skip(T.Assign); |
298 | 968 } |
969 // Push identifiers. | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
970 bindNames ~= requireIdentifier(MSG.ExpectedImportName); |
298 | 971 bindAliases ~= bindAlias; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
972 } while (consumed(T.Comma)) |
298 | 973 } |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
974 require(T.Semicolon); |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
975 |
366 | 976 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
|
977 } |
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
|
978 |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
979 Declaration parseEnumDeclaration() |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
980 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
981 skip(T.Enum); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
982 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
983 Identifier* enumName; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
984 Type baseType; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
985 EnumMemberDeclaration[] members; |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
986 bool hasBody; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
987 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
988 enumName = optionalIdentifier(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
989 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
990 if (consumed(T.Colon)) |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
991 baseType = parseBasicType(); |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
992 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
993 if (enumName && consumed(T.Semicolon)) |
639
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
994 {} |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
995 else if (consumed(T.LBrace)) |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
996 { |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
997 hasBody = true; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
998 while (token.kind != T.RBrace) |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
999 { |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1000 auto begin = token; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1001 auto name = requireIdentifier(MSG.ExpectedEnumMember); |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1002 Expression value; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1003 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1004 if (consumed(T.Assign)) |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1005 value = parseAssignExpression(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1006 else |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1007 value = null; |
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1008 |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1009 members ~= set(new EnumMemberDeclaration(name, value), begin); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1010 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1011 if (!consumed(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
|
1012 break; |
398
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1013 } |
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1014 require(T.RBrace); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1015 } |
231 | 1016 else |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1017 error(token, MSG.ExpectedEnumBody, token.srcText); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1018 |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1019 return new EnumDeclaration(enumName, baseType, members, hasBody); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1020 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1021 |
765
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1022 /// Wraps a declaration inside a template declaration. |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1023 /// Params: |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1024 /// begin = begin token of decl. |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1025 /// name = name of decl. |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1026 /// decl = the declaration to be wrapped. |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1027 /// tparams = the template parameters. |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1028 TemplateDeclaration putInsideTemplateDeclaration(Token* begin, |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1029 Identifier* name, |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1030 Declaration decl, |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1031 TemplateParameters tparams) |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1032 { |
765
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1033 set(decl, begin); |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1034 auto cd = new CompoundDeclaration; |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1035 cd ~= decl; |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1036 set(cd, begin); |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1037 return new TemplateDeclaration(name, tparams, cd); |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1038 } |
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1039 |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1040 Declaration parseClassDeclaration() |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1041 { |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1042 auto begin = token; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1043 skip(T.Class); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1044 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1045 Identifier* className; |
258 | 1046 TemplateParameters tparams; |
668
a1f8d8f2db38
Renamed some identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
659
diff
changeset
|
1047 BaseClassType[] bases; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1048 CompoundDeclaration decls; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1049 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1050 className = requireIdentifier(MSG.ExpectedClassName); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1051 |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
1052 if (token.kind == T.LParen) |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
1053 tparams = parseTemplateParameterList(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1054 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1055 if (token.kind == T.Colon) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1056 bases = parseBaseClasses(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1057 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1058 if (bases.length == 0 && consumed(T.Semicolon)) |
639
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
1059 {} |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1060 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
|
1061 decls = parseDeclarationDefinitionsBody(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1062 else |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1063 error(token, MSG.ExpectedClassBody, token.srcText); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1064 |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1065 Declaration d = new ClassDeclaration(className, /+tparams, +/bases, decls); |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
1066 if (tparams) |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1067 d = putInsideTemplateDeclaration(begin, className, d, tparams); |
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1068 return d; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1069 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1070 |
668
a1f8d8f2db38
Renamed some identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
659
diff
changeset
|
1071 BaseClassType[] parseBaseClasses(bool colonLeadsOff = true) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1072 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1073 colonLeadsOff && skip(T.Colon); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1074 |
668
a1f8d8f2db38
Renamed some identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
659
diff
changeset
|
1075 BaseClassType[] bases; |
646
68953760d569
Added class ParenExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
640
diff
changeset
|
1076 do |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1077 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1078 Protection prot = Protection.Public; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1079 switch (token.kind) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1080 { |
204 | 1081 case T.Identifier, T.Dot, T.Typeof: goto LparseBasicType; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1082 case T.Private: prot = Protection.Private; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1083 case T.Protected: prot = Protection.Protected; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1084 case T.Package: prot = Protection.Package; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1085 case T.Public: /*prot = Protection.Public;*/ break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1086 default: |
405
e2529923a0cb
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
404
diff
changeset
|
1087 error(MID.ExpectedBaseClasses, token.srcText); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1088 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1089 } |
158
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1090 nT(); // Skip protection attribute. |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1091 LparseBasicType: |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1092 auto begin = token; |
158
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1093 auto type = parseBasicType(); |
668
a1f8d8f2db38
Renamed some identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
659
diff
changeset
|
1094 bases ~= set(new BaseClassType(prot, type), begin); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1095 } while (consumed(T.Comma)) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1096 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1097 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1098 |
112 | 1099 Declaration parseInterfaceDeclaration() |
1100 { | |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1101 auto begin = token; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1102 skip(T.Interface); |
112 | 1103 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1104 Identifier* name; |
258 | 1105 TemplateParameters tparams; |
668
a1f8d8f2db38
Renamed some identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
659
diff
changeset
|
1106 BaseClassType[] bases; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1107 CompoundDeclaration decls; |
112 | 1108 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1109 name = requireIdentifier(MSG.ExpectedInterfaceName); |
112 | 1110 |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
1111 if (token.kind == T.LParen) |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
1112 tparams = parseTemplateParameterList(); |
112 | 1113 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1114 if (token.kind == T.Colon) |
112 | 1115 bases = parseBaseClasses(); |
1116 | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1117 if (bases.length == 0 && consumed(T.Semicolon)) |
639
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
1118 {} |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1119 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
|
1120 decls = parseDeclarationDefinitionsBody(); |
112 | 1121 else |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1122 error(token, MSG.ExpectedInterfaceBody, token.srcText); |
112 | 1123 |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1124 Declaration d = new InterfaceDeclaration(name, /+tparams, +/bases, decls); |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
1125 if (tparams) |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1126 d = putInsideTemplateDeclaration(begin, name, d, tparams); |
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1127 return d; |
112 | 1128 } |
1129 | |
638
7131c07997f9
Renamed parseAggregateDeclaration() to parseStructOrUnionDeclaration().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
637
diff
changeset
|
1130 Declaration parseStructOrUnionDeclaration() |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1131 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1132 assert(token.kind == T.Struct || token.kind == T.Union); |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1133 auto begin = token; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1134 skip(token.kind); |
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 Identifier* name; |
258 | 1137 TemplateParameters tparams; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1138 CompoundDeclaration decls; |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1139 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1140 name = optionalIdentifier(); |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1141 |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
1142 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
|
1143 tparams = parseTemplateParameterList(); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1144 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1145 if (name && consumed(T.Semicolon)) |
639
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
1146 {} |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1147 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
|
1148 decls = parseDeclarationDefinitionsBody(); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1149 else |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1150 error(token, begin.kind == T.Struct ? |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
1151 MSG.ExpectedStructBody : |
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
1152 MSG.ExpectedUnionBody, token.srcText); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1153 |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1154 Declaration d; |
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1155 if (begin.kind == T.Struct) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1156 { |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1157 auto sd = new StructDeclaration(name, /+tparams, +/decls); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1158 sd.setAlignSize(this.alignSize); |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1159 d = sd; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1160 } |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1161 else |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1162 d = new UnionDeclaration(name, /+tparams, +/decls); |
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1163 |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
1164 if (tparams) |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1165 d = putInsideTemplateDeclaration(begin, name, d, tparams); |
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1166 return d; |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1167 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1168 |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1169 Declaration parseConstructorDeclaration() |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1170 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1171 skip(T.This); |
143 | 1172 auto parameters = parseParameterList(); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1173 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1174 return new ConstructorDeclaration(parameters, funcBody); |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1175 } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1176 |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1177 Declaration parseDestructorDeclaration() |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1178 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1179 skip(T.Tilde); |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1180 require(T.This); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1181 require(T.LParen); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1182 require(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1183 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1184 return new DestructorDeclaration(funcBody); |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1185 } |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1186 |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1187 Declaration parseStaticConstructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1188 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1189 skip(T.Static); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1190 skip(T.This); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1191 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1192 require(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1193 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1194 return new StaticConstructorDeclaration(funcBody); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1195 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1196 |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1197 Declaration parseStaticDestructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1198 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1199 skip(T.Static); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1200 skip(T.Tilde); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1201 require(T.This); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1202 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1203 require(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1204 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1205 return new StaticDestructorDeclaration(funcBody); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1206 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1207 |
120 | 1208 Declaration parseInvariantDeclaration() |
1209 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1210 skip(T.Invariant); |
120 | 1211 // Optional () for getting ready porting to D 2.0 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1212 if (consumed(T.LParen)) |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1213 require(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1214 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1215 return new InvariantDeclaration(funcBody); |
120 | 1216 } |
1217 | |
121 | 1218 Declaration parseUnittestDeclaration() |
1219 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1220 skip(T.Unittest); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1221 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1222 return new UnittestDeclaration(funcBody); |
121 | 1223 } |
1224 | |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1225 Token* parseIdentOrInt() |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1226 { |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1227 if (consumed(T.Int32) || consumed(T.Identifier)) |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1228 return this.prevToken; |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1229 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
|
1230 return null; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1231 } |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1232 |
122 | 1233 Declaration parseDebugDeclaration() |
1234 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1235 skip(T.Debug); |
122 | 1236 |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1237 Token* spec; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1238 Token* cond; |
305 | 1239 Declaration decls, elseDecls; |
122 | 1240 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1241 if (consumed(T.Assign)) |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1242 { // debug = Integer ; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1243 // debug = Identifier ; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1244 spec = parseIdentOrInt(); |
122 | 1245 require(T.Semicolon); |
1246 } | |
1247 else | |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1248 { // ( Condition ) |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1249 if (consumed(T.LParen)) |
122 | 1250 { |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1251 cond = parseIdentOrInt(); |
122 | 1252 require(T.RParen); |
1253 } | |
123 | 1254 // debug DeclarationsBlock |
1255 // debug ( Condition ) DeclarationsBlock | |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
1256 decls = parseDeclarationsBlock(); |
123 | 1257 // else DeclarationsBlock |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1258 if (consumed(T.Else)) |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
1259 elseDecls = parseDeclarationsBlock(); |
123 | 1260 } |
1261 | |
264 | 1262 return new DebugDeclaration(spec, cond, decls, elseDecls); |
123 | 1263 } |
1264 | |
1265 Declaration parseVersionDeclaration() | |
1266 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1267 skip(T.Version); |
123 | 1268 |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1269 Token* spec; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1270 Token* cond; |
305 | 1271 Declaration decls, elseDecls; |
122 | 1272 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1273 if (consumed(T.Assign)) |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1274 { // version = Integer ; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1275 // version = Identifier ; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1276 spec = parseIdentOrInt(); |
123 | 1277 require(T.Semicolon); |
1278 } | |
1279 else | |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1280 { // ( Condition ) |
123 | 1281 require(T.LParen); |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1282 cond = parseIdentOrInt(); |
123 | 1283 require(T.RParen); |
1284 // version ( Condition ) DeclarationsBlock | |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
1285 decls = parseDeclarationsBlock(); |
123 | 1286 // else DeclarationsBlock |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1287 if (consumed(T.Else)) |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
1288 elseDecls = parseDeclarationsBlock(); |
122 | 1289 } |
1290 | |
264 | 1291 return new VersionDeclaration(spec, cond, decls, elseDecls); |
122 | 1292 } |
1293 | |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1294 Declaration parseStaticIfDeclaration() |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1295 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1296 skip(T.Static); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1297 skip(T.If); |
125
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 |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
1306 ifDecls = parseDeclarationsBlock(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1307 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1308 if (consumed(T.Else)) |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
1309 elseDecls = parseDeclarationsBlock(); |
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 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1316 skip(T.Static); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1317 skip(T.Assert); |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1318 Expression condition, message; |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1319 require(T.LParen); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1320 condition = parseAssignExpression(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1321 if (consumed(T.Comma)) |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1322 message = parseAssignExpression(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1323 require(T.RParen); |
128 | 1324 require(T.Semicolon); |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1325 return new StaticAssertDeclaration(condition, message); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1326 } |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1327 |
140 | 1328 Declaration parseTemplateDeclaration() |
1329 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1330 skip(T.Template); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1331 auto templateName = requireIdentifier(MSG.ExpectedTemplateName); |
143 | 1332 auto templateParams = parseTemplateParameterList(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1333 auto decls = parseDeclarationDefinitionsBody(); |
140 | 1334 return new TemplateDeclaration(templateName, templateParams, decls); |
1335 } | |
1336 | |
141 | 1337 Declaration parseNewDeclaration() |
1338 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1339 skip(T.New); |
143 | 1340 auto parameters = parseParameterList(); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1341 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1342 return new NewDeclaration(parameters, funcBody); |
141 | 1343 } |
1344 | |
1345 Declaration parseDeleteDeclaration() | |
1346 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1347 skip(T.Delete); |
143 | 1348 auto parameters = parseParameterList(); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1349 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1350 return new DeleteDeclaration(parameters, funcBody); |
141 | 1351 } |
1352 | |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1353 Type parseTypeofType() |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1354 { |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1355 auto begin = token; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1356 skip(T.Typeof); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1357 require(T.LParen); |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1358 Type type; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1359 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
|
1360 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1361 version(D2) |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1362 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1363 case T.Return: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1364 nT(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1365 type = new TypeofType(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1366 break; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1367 } |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1368 default: |
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(parseExpression()); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1370 } |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1371 require(T.RParen); |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1372 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
|
1373 return type; |
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 |
704
ff4643a4a97c
Wrote code for SemanticPass2.visit(MixinDeclaration).
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
695
diff
changeset
|
1376 /++ |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1377 TemplateMixin: |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1378 mixin ( AssignExpression ) ; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1379 mixin TemplateIdentifier ; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1380 mixin TemplateIdentifier MixinIdentifier ; |
233 | 1381 mixin TemplateIdentifier !( TemplateArguments ) ; |
1382 mixin TemplateIdentifier !( TemplateArguments ) MixinIdentifier ; | |
704
ff4643a4a97c
Wrote code for SemanticPass2.visit(MixinDeclaration).
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
695
diff
changeset
|
1383 +/ |
256 | 1384 Class parseMixin(Class)() |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1385 { |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
1386 static assert(is(Class == MixinDeclaration) || is(Class == MixinStatement)); |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1387 skip(T.Mixin); |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1388 |
256 | 1389 static if (is(Class == MixinDeclaration)) |
301
caef255a2801
- Fix in some ctors: adding only non-null members to this.children.
aziz
parents:
299
diff
changeset
|
1390 { |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1391 if (consumed(T.LParen)) |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1392 { |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1393 auto e = parseAssignExpression(); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1394 require(T.RParen); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1395 require(T.Semicolon); |
262 | 1396 return new MixinDeclaration(e); |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1397 } |
301
caef255a2801
- Fix in some ctors: adding only non-null members to this.children.
aziz
parents:
299
diff
changeset
|
1398 } |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1399 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1400 auto begin = token; |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1401 Expression e; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1402 Identifier* mixinIdent; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1403 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1404 if (consumed(T.Dot)) |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1405 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
|
1406 else |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1407 e = parseIdentifierExpression(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1408 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1409 while (consumed(T.Dot)) |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1410 e = set(new DotExpression(e, parseIdentifierExpression()), begin); |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1411 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1412 mixinIdent = optionalIdentifier(); |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1413 require(T.Semicolon); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1414 |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1415 return new Class(e, mixinIdent); |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1416 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1417 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
1418 /+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
1419 | Statement parsing methods | |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
1420 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+/ |
161 | 1421 |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1422 CompoundStatement parseStatements() |
161 | 1423 { |
262 | 1424 auto begin = token; |
318 | 1425 require(T.LBrace); |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1426 auto statements = new CompoundStatement(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1427 while (token.kind != T.RBrace && token.kind != T.EOF) |
161 | 1428 statements ~= parseStatement(); |
318 | 1429 require(T.RBrace); |
262 | 1430 return set(statements, begin); |
161 | 1431 } |
1432 | |
1433 Statement parseStatement() | |
1434 { | |
261 | 1435 auto begin = token; |
161 | 1436 Statement s; |
188 | 1437 Declaration d; |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1438 |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1439 if (token.isIntegralType) |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1440 { |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1441 d = parseVariableOrFunction(); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1442 goto LreturnDeclarationStatement; |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1443 } |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1444 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1445 switch (token.kind) |
161 | 1446 { |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1447 case T.Align: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1448 uint size = parseAlignAttribute(); |
260 | 1449 // 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
|
1450 StructDeclaration structDecl; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1451 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
|
1452 { |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1453 auto begin2 = token; |
638
7131c07997f9
Renamed parseAggregateDeclaration() to parseStructOrUnionDeclaration().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
637
diff
changeset
|
1454 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
|
1455 structDecl.setAlignSize(size); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1456 set(structDecl, begin2); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1457 } |
260 | 1458 else |
1459 expected(T.Struct); | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1460 |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1461 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
|
1462 goto LreturnDeclarationStatement; |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1463 /+ Not applicable for statements. |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1464 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
|
1465 T.Deprecated, T.Override, T.Abstract,+/ |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1466 case T.Extern, |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1467 T.Final, |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1468 T.Const, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1469 T.Auto: |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1470 //T.Scope |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1471 //T.Static |
201 | 1472 case_parseAttribute: |
1473 s = parseAttributeStatement(); | |
261 | 1474 return s; |
161 | 1475 case T.Identifier: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1476 if (peekNext() == T.Colon) |
161 | 1477 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1478 auto ident = token.ident; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1479 skip(T.Identifier); skip(T.Colon); |
234 | 1480 s = new LabeledStatement(ident, parseNoScopeOrEmptyStatement()); |
161 | 1481 break; |
1482 } | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1483 goto case T.Dot; |
201 | 1484 case T.Dot, T.Typeof: |
214 | 1485 bool success; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1486 d = try_(delegate { |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1487 return parseVariableOrFunction(StorageClass.None, |
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1488 Protection.None, |
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1489 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
|
1490 }, success |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1491 ); |
214 | 1492 if (success) |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1493 goto LreturnDeclarationStatement; // Declaration |
201 | 1494 else |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1495 goto case_parseExpressionStatement; // Expression |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1496 |
162 | 1497 case T.If: |
1498 s = parseIfStatement(); | |
1499 break; | |
164 | 1500 case T.While: |
1501 s = parseWhileStatement(); | |
1502 break; | |
165 | 1503 case T.Do: |
1504 s = parseDoWhileStatement(); | |
1505 break; | |
216 | 1506 case T.For: |
1507 s = parseForStatement(); | |
1508 break; | |
169 | 1509 case T.Foreach, T.Foreach_reverse: |
1510 s = parseForeachStatement(); | |
1511 break; | |
170 | 1512 case T.Switch: |
1513 s = parseSwitchStatement(); | |
1514 break; | |
171 | 1515 case T.Case: |
1516 s = parseCaseStatement(); | |
1517 break; | |
172 | 1518 case T.Default: |
1519 s = parseDefaultStatement(); | |
1520 break; | |
173 | 1521 case T.Continue: |
1522 s = parseContinueStatement(); | |
1523 break; | |
174 | 1524 case T.Break: |
1525 s = parseBreakStatement(); | |
1526 break; | |
175 | 1527 case T.Return: |
1528 s = parseReturnStatement(); | |
1529 break; | |
176 | 1530 case T.Goto: |
1531 s = parseGotoStatement(); | |
1532 break; | |
177 | 1533 case T.With: |
1534 s = parseWithStatement(); | |
1535 break; | |
178 | 1536 case T.Synchronized: |
1537 s = parseSynchronizedStatement(); | |
1538 break; | |
179 | 1539 case T.Try: |
1540 s = parseTryStatement(); | |
1541 break; | |
180 | 1542 case T.Throw: |
1543 s = parseThrowStatement(); | |
1544 break; | |
181 | 1545 case T.Scope: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1546 if (peekNext() != T.LParen) |
201 | 1547 goto case_parseAttribute; |
181 | 1548 s = parseScopeGuardStatement(); |
1549 break; | |
182 | 1550 case T.Volatile: |
1551 s = parseVolatileStatement(); | |
1552 break; | |
183 | 1553 case T.Asm: |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
1554 s = parseAsmBlockStatement(); |
183 | 1555 break; |
184 | 1556 case T.Pragma: |
1557 s = parsePragmaStatement(); | |
1558 break; | |
185 | 1559 case T.Mixin: |
246
52f4aa097865
- Fix: parse mixin as expression instead of statement when next token is T.LParen.
aziz
parents:
245
diff
changeset
|
1560 if (peekNext() == T.LParen) |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1561 goto case_parseExpressionStatement; // Parse as expression. |
256 | 1562 s = parseMixin!(MixinStatement)(); |
185 | 1563 break; |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1564 case T.Static: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1565 switch (peekNext()) |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1566 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1567 case T.If: |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1568 s = parseStaticIfStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1569 break; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1570 case T.Assert: |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1571 s = parseStaticAssertStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1572 break; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1573 default: |
201 | 1574 goto case_parseAttribute; |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1575 } |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1576 break; |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1577 case T.Debug: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1578 s = parseDebugStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1579 break; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1580 case T.Version: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1581 s = parseVersionStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1582 break; |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1583 // DeclDef |
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1584 case T.Alias, T.Typedef: |
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1585 d = parseDeclarationDefinition(); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1586 goto LreturnDeclarationStatement; |
188 | 1587 case T.Enum: |
1588 d = parseEnumDeclaration(); | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1589 goto LreturnDeclarationStatement; |
188 | 1590 case T.Class: |
1591 d = parseClassDeclaration(); | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1592 goto LreturnDeclarationStatement; |
188 | 1593 case T.Interface: |
1594 d = parseInterfaceDeclaration(); | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1595 goto LreturnDeclarationStatement; |
188 | 1596 case T.Struct, T.Union: |
638
7131c07997f9
Renamed parseAggregateDeclaration() to parseStructOrUnionDeclaration().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
637
diff
changeset
|
1597 d = parseStructOrUnionDeclaration(); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1598 // goto LreturnDeclarationStatement; |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1599 LreturnDeclarationStatement: |
261 | 1600 set(d, begin); |
188 | 1601 s = new DeclarationStatement(d); |
1602 break; | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1603 case T.LBrace: |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1604 s = parseScopeStatement(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1605 break; |
216 | 1606 case T.Semicolon: |
231 | 1607 nT(); |
216 | 1608 s = new EmptyStatement(); |
1609 break; | |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
1610 // Parse an ExpressionStatement: |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1611 // 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
|
1612 // 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
|
1613 case T.This: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1614 case T.Super: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1615 case T.Null: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1616 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
|
1617 // case T.Dollar: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1618 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
|
1619 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
|
1620 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
|
1621 case T.CharLiteral: |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1622 case T.String: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1623 case T.LBracket: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1624 // case T.LBrace: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1625 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
|
1626 case T.Assert: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1627 // case T.Mixin: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1628 case T.Import: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1629 case T.Typeid: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1630 case T.Is: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1631 case T.LParen: |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1632 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
|
1633 // 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
|
1634 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
|
1635 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
|
1636 case_parseExpressionStatement: |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1637 s = new ExpressionStatement(parseExpression()); |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1638 require(T.Semicolon); |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1639 break; |
161 | 1640 default: |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1641 if (token.isSpecialToken) |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1642 goto case_parseExpressionStatement; |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1643 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1644 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
|
1645 // 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
|
1646 assert(delegate bool(){ |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1647 bool success; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1648 auto expression = try_(&parseExpression, success); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1649 return success; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1650 }() == 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
|
1651 ); |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1652 |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1653 // 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
|
1654 s = new IllegalStatement(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1655 // Skip to next valid token. |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1656 do |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1657 nT(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1658 while (!token.isStatementStart && |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1659 token.kind != T.RBrace && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1660 token.kind != T.EOF) |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1661 auto text = Token.textSpan(begin, this.prevToken); |
616
506ce60760d8
Fixed some error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
608
diff
changeset
|
1662 error(begin, MSG.IllegalStatement, text); |
161 | 1663 } |
205 | 1664 assert(s !is null); |
261 | 1665 set(s, begin); |
161 | 1666 return s; |
1667 } | |
1668 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1669 /++ |
162 | 1670 ScopeStatement: |
219 | 1671 NoScopeStatement |
162 | 1672 +/ |
164 | 1673 Statement parseScopeStatement() |
162 | 1674 { |
219 | 1675 return new ScopeStatement(parseNoScopeStatement()); |
162 | 1676 } |
1677 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1678 /++ |
166 | 1679 NoScopeStatement: |
1680 NonEmptyStatement | |
1681 BlockStatement | |
1682 BlockStatement: | |
1683 { } | |
1684 { StatementList } | |
1685 +/ | |
1686 Statement parseNoScopeStatement() | |
1687 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1688 auto begin = token; |
166 | 1689 Statement s; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1690 if (consumed(T.LBrace)) |
166 | 1691 { |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1692 auto ss = new CompoundStatement(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1693 while (token.kind != T.RBrace && token.kind != T.EOF) |
166 | 1694 ss ~= parseStatement(); |
1695 require(T.RBrace); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1696 s = set(ss, begin); |
166 | 1697 } |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1698 else if (token.kind == T.Semicolon) |
219 | 1699 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1700 error(token, MSG.ExpectedNonEmptyStatement); |
219 | 1701 nT(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1702 s = set(new EmptyStatement(), begin); |
219 | 1703 } |
166 | 1704 else |
1705 s = parseStatement(); | |
1706 return s; | |
1707 } | |
1708 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1709 /++ |
234 | 1710 NoScopeOrEmptyStatement: |
1711 ; | |
1712 NoScopeStatement | |
1713 +/ | |
1714 Statement parseNoScopeOrEmptyStatement() | |
1715 { | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1716 if (consumed(T.Semicolon)) |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1717 return set(new EmptyStatement(), this.prevToken); |
234 | 1718 else |
1719 return parseNoScopeStatement(); | |
1720 } | |
1721 | |
201 | 1722 Statement parseAttributeStatement() |
1723 { | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1724 StorageClass stc, stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1725 LinkageType prev_linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1726 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
1727 Declaration parse() // Nested function. |
201 | 1728 { |
261 | 1729 auto begin = token; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1730 Declaration d; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1731 switch (token.kind) |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1732 { |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1733 case T.Extern: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1734 if (peekNext() != T.LParen) |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1735 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1736 stc_tmp = StorageClass.Extern; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1737 goto Lcommon; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1738 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1739 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1740 nT(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1741 auto linkageType = parseLinkageType(); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1742 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
|
1743 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1744 d = new LinkageDeclaration(linkageType, parse()); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1745 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1746 case T.Static: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1747 stc_tmp = StorageClass.Static; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1748 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1749 case T.Final: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1750 stc_tmp = StorageClass.Final; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1751 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1752 case T.Const: |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1753 version(D2) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1754 { |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1755 if (peekNext() == T.LParen) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1756 goto case_Declaration; |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1757 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1758 stc_tmp = StorageClass.Const; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1759 goto Lcommon; |
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 case T.Invariant: // D 2.0 |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1763 if (peekNext() == T.LParen) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1764 goto case_Declaration; |
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.Invariant; |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1766 goto Lcommon; |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1767 } |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1768 case T.Auto: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1769 stc_tmp = StorageClass.Auto; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1770 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1771 case T.Scope: |
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.Scope; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1773 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1774 Lcommon: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1775 // Issue error if redundant. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1776 if (stc & stc_tmp) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1777 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
|
1778 else |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1779 stc |= stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1780 |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1781 nT(); |
650
eb490ba8dba0
Made AttributeDeclaration abstract.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
646
diff
changeset
|
1782 d = new StorageClassDeclaration(stc_tmp, parse()); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1783 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
|
1784 // 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
|
1785 //case T.Class: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1786 default: |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1787 case_Declaration: |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1788 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
|
1789 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1790 return set(d, begin); |
201 | 1791 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1792 return new DeclarationStatement(parse()); |
201 | 1793 } |
1794 | |
162 | 1795 Statement parseIfStatement() |
1796 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1797 skip(T.If); |
162 | 1798 |
283 | 1799 Statement variable; |
162 | 1800 Expression condition; |
1801 Statement ifBody, elseBody; | |
1802 | |
1803 require(T.LParen); | |
283 | 1804 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1805 Identifier* ident; |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1806 auto begin = token; // For start of AutoDeclaration or normal Declaration. |
162 | 1807 // auto Identifier = Expression |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1808 if (consumed(T.Auto)) |
162 | 1809 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1810 ident = requireIdentifier(MSG.ExpectedVariableName); |
162 | 1811 require(T.Assign); |
283 | 1812 auto init = parseExpression(); |
673
64fec49651cf
Renamed VariableDeclaration to VariablesDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
671
diff
changeset
|
1813 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
|
1814 set(v, begin.nextNWS); |
650
eb490ba8dba0
Made AttributeDeclaration abstract.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
646
diff
changeset
|
1815 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
|
1816 set(d, begin); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1817 variable = new DeclarationStatement(d); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1818 set(variable, begin); |
162 | 1819 } |
1820 else | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1821 { // Declarator = Expression |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1822 Type parseDeclaratorAssign() |
162 | 1823 { |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1824 auto type = parseDeclarator(ident); |
162 | 1825 require(T.Assign); |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1826 return type; |
162 | 1827 } |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1828 bool success; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
1829 auto type = try_(&parseDeclaratorAssign, success); |
283 | 1830 if (success) |
163
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1831 { |
283 | 1832 auto init = parseExpression(); |
673
64fec49651cf
Renamed VariableDeclaration to VariablesDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
671
diff
changeset
|
1833 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
|
1834 set(v, begin); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1835 variable = new DeclarationStatement(v); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1836 set(variable, begin); |
163
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1837 } |
283 | 1838 else |
1839 condition = parseExpression(); | |
162 | 1840 } |
1841 require(T.RParen); | |
164 | 1842 ifBody = parseScopeStatement(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1843 if (consumed(T.Else)) |
164 | 1844 elseBody = parseScopeStatement(); |
283 | 1845 return new IfStatement(variable, condition, ifBody, elseBody); |
162 | 1846 } |
1847 | |
164 | 1848 Statement parseWhileStatement() |
1849 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1850 skip(T.While); |
166 | 1851 require(T.LParen); |
164 | 1852 auto condition = parseExpression(); |
166 | 1853 require(T.RParen); |
164 | 1854 return new WhileStatement(condition, parseScopeStatement()); |
1855 } | |
1856 | |
165 | 1857 Statement parseDoWhileStatement() |
1858 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1859 skip(T.Do); |
165 | 1860 auto doBody = parseScopeStatement(); |
1861 require(T.While); | |
166 | 1862 require(T.LParen); |
165 | 1863 auto condition = parseExpression(); |
166 | 1864 require(T.RParen); |
1865 return new DoWhileStatement(condition, doBody); | |
1866 } | |
1867 | |
1868 Statement parseForStatement() | |
1869 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1870 skip(T.For); |
166 | 1871 |
1872 Statement init, forBody; | |
1873 Expression condition, increment; | |
1874 | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1875 require(T.LParen); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1876 if (!consumed(T.Semicolon)) |
166 | 1877 init = parseNoScopeStatement(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1878 if (token.kind != T.Semicolon) |
166 | 1879 condition = parseExpression(); |
168 | 1880 require(T.Semicolon); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1881 if (token.kind != T.RParen) |
166 | 1882 increment = parseExpression(); |
168 | 1883 require(T.RParen); |
167 | 1884 forBody = parseScopeStatement(); |
166 | 1885 return new ForStatement(init, condition, increment, forBody); |
165 | 1886 } |
1887 | |
169 | 1888 Statement parseForeachStatement() |
1889 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1890 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
|
1891 TOK tok = token.kind; |
169 | 1892 nT(); |
1893 | |
257 | 1894 auto params = new Parameters; |
269 | 1895 Expression e; // Aggregate or LwrExpression |
169 | 1896 |
1897 require(T.LParen); | |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
1898 auto paramsBegin = token; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
1899 do |
169 | 1900 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
1901 auto paramBegin = token; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1902 StorageClass stc; |
169 | 1903 Type type; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1904 Identifier* ident; |
169 | 1905 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1906 switch (token.kind) |
169 | 1907 { |
236
e961d1b957c3
- Fix in parseForeachStatement(): added T.Inout to case T.Ref; removed break statement.
aziz
parents:
235
diff
changeset
|
1908 case T.Ref, T.Inout: |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1909 stc = StorageClass.Ref; |
169 | 1910 nT(); |
236
e961d1b957c3
- Fix in parseForeachStatement(): added T.Inout to case T.Ref; removed break statement.
aziz
parents:
235
diff
changeset
|
1911 // fall through |
169 | 1912 case T.Identifier: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1913 auto next = peekNext(); |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1914 if (next == T.Comma || next == T.Semicolon || next == T.RParen) |
169 | 1915 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1916 ident = requireIdentifier(MSG.ExpectedVariableName); |
169 | 1917 break; |
1918 } | |
1919 // fall through | |
1920 default: | |
1921 type = parseDeclarator(ident); | |
1922 } | |
1923 | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1924 params ~= set(new Parameter(stc, type, ident, null), paramBegin); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1925 } while (consumed(T.Comma)) |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
1926 set(params, paramsBegin); |
169 | 1927 require(T.Semicolon); |
269 | 1928 e = parseExpression(); |
1929 version(D2) | |
1930 { //Foreach (ForeachType; LwrExpression .. UprExpression ) ScopeStatement | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1931 if (consumed(T.Slice)) |
269 | 1932 { |
1933 // if (params.length != 1) | |
1934 // error(MID.XYZ); // TODO: issue error msg | |
1935 auto upper = parseExpression(); | |
1936 require(T.RParen); | |
1937 auto forBody = parseScopeStatement(); | |
1938 return new ForeachRangeStatement(tok, params, e, upper, forBody); | |
1939 } | |
1940 } | |
1941 // Foreach (ForeachTypeList; Aggregate) ScopeStatement | |
169 | 1942 require(T.RParen); |
1943 auto forBody = parseScopeStatement(); | |
269 | 1944 return new ForeachStatement(tok, params, e, forBody); |
169 | 1945 } |
1946 | |
170 | 1947 Statement parseSwitchStatement() |
1948 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1949 skip(T.Switch); |
170 | 1950 require(T.LParen); |
1951 auto condition = parseExpression(); | |
1952 require(T.RParen); | |
1953 auto switchBody = parseScopeStatement(); | |
1954 return new SwitchStatement(condition, switchBody); | |
1955 } | |
1956 | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1957 /// Helper function for parsing the body of a default or case statement. |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1958 Statement parseCaseOrDefaultBody() |
220 | 1959 { |
1960 // 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
|
1961 auto begin = token; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1962 auto s = new CompoundStatement(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1963 while (token.kind != T.Case && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1964 token.kind != T.Default && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1965 token.kind != T.RBrace && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1966 token.kind != T.EOF) |
224 | 1967 s ~= parseStatement(); |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
1968 set(s, begin); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1969 return set(new ScopeStatement(s), begin); |
220 | 1970 } |
1971 | |
171 | 1972 Statement parseCaseStatement() |
1973 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1974 skip(T.Case); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
1975 auto values = parseExpressionList(); |
171 | 1976 require(T.Colon); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1977 auto caseBody = parseCaseOrDefaultBody(); |
171 | 1978 return new CaseStatement(values, caseBody); |
1979 } | |
1980 | |
172 | 1981 Statement parseDefaultStatement() |
1982 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1983 skip(T.Default); |
172 | 1984 require(T.Colon); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1985 auto defaultBody = parseCaseOrDefaultBody(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1986 return new DefaultStatement(defaultBody); |
172 | 1987 } |
1988 | |
173 | 1989 Statement parseContinueStatement() |
1990 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1991 skip(T.Continue); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1992 auto ident = optionalIdentifier(); |
173 | 1993 require(T.Semicolon); |
1994 return new ContinueStatement(ident); | |
1995 } | |
1996 | |
174 | 1997 Statement parseBreakStatement() |
1998 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1999 skip(T.Break); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2000 auto ident = optionalIdentifier(); |
555
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
2001 require(T.Semicolon); |
174 | 2002 return new BreakStatement(ident); |
2003 } | |
2004 | |
175 | 2005 Statement parseReturnStatement() |
2006 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2007 skip(T.Return); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2008 Expression expr; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2009 if (token.kind != T.Semicolon) |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2010 expr = parseExpression(); |
175 | 2011 require(T.Semicolon); |
2012 return new ReturnStatement(expr); | |
2013 } | |
2014 | |
176 | 2015 Statement parseGotoStatement() |
2016 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2017 skip(T.Goto); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2018 Identifier* ident; |
176 | 2019 Expression caseExpr; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2020 switch (token.kind) |
176 | 2021 { |
2022 case T.Case: | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2023 ident = token.ident; |
176 | 2024 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2025 if (token.kind == T.Semicolon) |
176 | 2026 break; |
2027 caseExpr = parseExpression(); | |
2028 break; | |
2029 case T.Default: | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2030 ident = token.ident; |
176 | 2031 nT(); |
2032 break; | |
2033 default: | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2034 ident = requireIdentifier(MSG.ExpectedAnIdentifier); |
176 | 2035 } |
2036 require(T.Semicolon); | |
2037 return new GotoStatement(ident, caseExpr); | |
2038 } | |
2039 | |
177 | 2040 Statement parseWithStatement() |
2041 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2042 skip(T.With); |
177 | 2043 require(T.LParen); |
2044 auto expr = parseExpression(); | |
2045 require(T.RParen); | |
2046 return new WithStatement(expr, parseScopeStatement()); | |
2047 } | |
2048 | |
178 | 2049 Statement parseSynchronizedStatement() |
2050 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2051 skip(T.Synchronized); |
178 | 2052 Expression expr; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2053 if (consumed(T.LParen)) |
178 | 2054 { |
2055 expr = parseExpression(); | |
2056 require(T.RParen); | |
2057 } | |
2058 return new SynchronizedStatement(expr, parseScopeStatement()); | |
2059 } | |
2060 | |
179 | 2061 Statement parseTryStatement() |
2062 { | |
640
05645f5613c1
Added an error message.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
639
diff
changeset
|
2063 auto begin = token; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2064 skip(T.Try); |
179 | 2065 |
2066 auto tryBody = parseScopeStatement(); | |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
2067 CatchStatement[] catchBodies; |
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
2068 FinallyStatement finBody; |
179 | 2069 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2070 while (consumed(T.Catch)) |
179 | 2071 { |
2072 Parameter param; | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2073 if (consumed(T.LParen)) |
179 | 2074 { |
640
05645f5613c1
Added an error message.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
639
diff
changeset
|
2075 auto begin2 = token; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2076 Identifier* ident; |
369 | 2077 auto type = parseDeclarator(ident, true); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2078 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
|
2079 set(param, begin2); |
179 | 2080 require(T.RParen); |
2081 } | |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
2082 catchBodies ~= set(new CatchStatement(param, parseNoScopeStatement()), begin); |
179 | 2083 if (param is null) |
2084 break; // This is a LastCatch | |
640
05645f5613c1
Added an error message.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
639
diff
changeset
|
2085 begin = token; |
179 | 2086 } |
2087 | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2088 if (consumed(T.Finally)) |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
2089 finBody = set(new FinallyStatement(parseNoScopeStatement()), prevToken); |
179 | 2090 |
396
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
2091 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
|
2092 assert(begin.kind == T.Try), error(begin, MSG.MissingCatchOrFinally); |
179 | 2093 |
2094 return new TryStatement(tryBody, catchBodies, finBody); | |
2095 } | |
2096 | |
180 | 2097 Statement parseThrowStatement() |
2098 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2099 skip(T.Throw); |
180 | 2100 auto expr = parseExpression(); |
2101 require(T.Semicolon); | |
2102 return new ThrowStatement(expr); | |
2103 } | |
2104 | |
181 | 2105 Statement parseScopeGuardStatement() |
2106 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2107 skip(T.Scope); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2108 skip(T.LParen); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2109 auto condition = requireIdentifier(MSG.ExpectedScopeIdentifier); |
264 | 2110 if (condition) |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2111 switch (condition.idKind) |
181 | 2112 { |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2113 case IDK.exit, IDK.success, IDK.failure: |
181 | 2114 break; |
2115 default: | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2116 error(this.prevToken, MSG.InvalidScopeIdentifier, this.prevToken.srcText); |
181 | 2117 } |
2118 require(T.RParen); | |
2119 Statement scopeBody; | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2120 if (token.kind == T.LBrace) |
181 | 2121 scopeBody = parseScopeStatement(); |
2122 else | |
2123 scopeBody = parseNoScopeStatement(); | |
2124 return new ScopeGuardStatement(condition, scopeBody); | |
2125 } | |
2126 | |
182 | 2127 Statement parseVolatileStatement() |
2128 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2129 skip(T.Volatile); |
182 | 2130 Statement volatileBody; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2131 if (token.kind == T.Semicolon) |
182 | 2132 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2133 else if (token.kind == T.LBrace) |
182 | 2134 volatileBody = parseScopeStatement(); |
2135 else | |
219 | 2136 volatileBody = parseStatement(); |
182 | 2137 return new VolatileStatement(volatileBody); |
2138 } | |
2139 | |
184 | 2140 Statement parsePragmaStatement() |
2141 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2142 skip(T.Pragma); |
184 | 2143 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2144 Identifier* ident; |
184 | 2145 Expression[] args; |
2146 Statement pragmaBody; | |
2147 | |
2148 require(T.LParen); | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2149 ident = requireIdentifier(MSG.ExpectedPragmaIdentifier); |
184 | 2150 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2151 if (consumed(T.Comma)) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2152 args = parseExpressionList(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2153 require(T.RParen); |
184 | 2154 |
234 | 2155 pragmaBody = parseNoScopeOrEmptyStatement(); |
184 | 2156 |
2157 return new PragmaStatement(ident, args, pragmaBody); | |
2158 } | |
2159 | |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2160 Statement parseStaticIfStatement() |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2161 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2162 skip(T.Static); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2163 skip(T.If); |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2164 Expression condition; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2165 Statement ifBody, elseBody; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2166 |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2167 require(T.LParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2168 condition = parseExpression(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2169 require(T.RParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2170 ifBody = parseNoScopeStatement(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2171 if (consumed(T.Else)) |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2172 elseBody = parseNoScopeStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2173 return new StaticIfStatement(condition, ifBody, elseBody); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2174 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2175 |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2176 Statement parseStaticAssertStatement() |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2177 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2178 skip(T.Static); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2179 skip(T.Assert); |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2180 Expression condition, message; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2181 |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2182 require(T.LParen); |
555
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
2183 condition = parseAssignExpression(); // Condition. |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2184 if (consumed(T.Comma)) |
555
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
2185 message = parseAssignExpression(); // Error message. |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2186 require(T.RParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2187 require(T.Semicolon); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2188 return new StaticAssertStatement(condition, message); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2189 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2190 |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2191 Statement parseDebugStatement() |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2192 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2193 skip(T.Debug); |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2194 Token* cond; |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2195 Statement debugBody, elseBody; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2196 |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2197 // ( Condition ) |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2198 if (consumed(T.LParen)) |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2199 { |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2200 cond = parseIdentOrInt(); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2201 require(T.RParen); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2202 } |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2203 // debug Statement |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2204 // debug ( Condition ) Statement |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2205 debugBody = parseNoScopeStatement(); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2206 // else Statement |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2207 if (consumed(T.Else)) |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2208 elseBody = parseNoScopeStatement(); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2209 |
264 | 2210 return new DebugStatement(cond, debugBody, elseBody); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2211 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2212 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2213 Statement parseVersionStatement() |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2214 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2215 skip(T.Version); |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2216 Token* cond; |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2217 Statement versionBody, elseBody; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2218 |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2219 // ( Condition ) |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2220 require(T.LParen); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2221 cond = parseIdentOrInt(); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2222 require(T.RParen); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2223 // version ( Condition ) Statement |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2224 versionBody = parseNoScopeStatement(); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2225 // else Statement |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2226 if (consumed(T.Else)) |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2227 elseBody = parseNoScopeStatement(); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2228 |
264 | 2229 return new VersionStatement(cond, versionBody, elseBody); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2230 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2231 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
2232 /+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
2233 | Assembler parsing methods | |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
2234 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+/ |
183 | 2235 |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2236 Statement parseAsmBlockStatement() |
183 | 2237 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2238 skip(T.Asm); |
285 | 2239 require(T.LBrace); |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
2240 auto ss = new CompoundStatement; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2241 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
|
2242 ss ~= parseAsmStatement(); |
285 | 2243 require(T.RBrace); |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2244 return new AsmBlockStatement(ss); |
285 | 2245 } |
2246 | |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2247 Statement parseAsmStatement() |
285 | 2248 { |
2249 auto begin = token; | |
2250 Statement s; | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2251 Identifier* ident; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2252 switch (token.kind) |
285 | 2253 { |
374 | 2254 // Keywords that are valid opcodes. |
2255 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
|
2256 ident = token.ident; |
374 | 2257 nT(); |
2258 goto LOpcode; | |
285 | 2259 case T.Identifier: |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2260 ident = token.ident; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2261 nT(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2262 if (consumed(T.Colon)) |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
2263 { // Identifier : AsmStatement |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2264 s = new LabeledStatement(ident, parseAsmStatement()); |
285 | 2265 break; |
2266 } | |
2267 | |
374 | 2268 LOpcode: |
285 | 2269 // Opcode ; |
2270 // Opcode Operands ; | |
2271 // Opcode | |
2272 // Identifier | |
2273 Expression[] es; | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2274 if (token.kind != T.Semicolon) |
632
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2275 do |
285 | 2276 es ~= parseAsmExpression(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2277 while (consumed(T.Comma)) |
285 | 2278 require(T.Semicolon); |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2279 s = new AsmStatement(ident, es); |
285 | 2280 break; |
374 | 2281 case T.Align: |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2282 // align Integer; |
374 | 2283 nT(); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2284 int number = -1; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2285 if (token.kind == T.Int32) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2286 (number = token.int_), skip(T.Int32); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2287 else |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2288 error(token, MSG.ExpectedIntegerAfterAlign, token.srcText); |
374 | 2289 require(T.Semicolon); |
2290 s = new AsmAlignStatement(number); | |
2291 break; | |
285 | 2292 case T.Semicolon: |
2293 s = new EmptyStatement(); | |
2294 nT(); | |
2295 break; | |
2296 default: | |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2297 s = new IllegalAsmStatement(); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2298 // Skip to next valid token. |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2299 do |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2300 nT(); |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2301 while (!token.isAsmStatementStart && |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2302 token.kind != T.RBrace && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2303 token.kind != T.EOF) |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2304 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
|
2305 error(begin, MSG.IllegalAsmStatement, text); |
285 | 2306 } |
2307 set(s, begin); | |
2308 return s; | |
2309 } | |
2310 | |
2311 Expression parseAsmExpression() | |
2312 { | |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2313 auto begin = token; |
374 | 2314 auto e = parseAsmOrOrExpression(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2315 if (consumed(T.Question)) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2316 { |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2317 auto tok = this.prevToken; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2318 auto iftrue = parseAsmExpression(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2319 require(T.Colon); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2320 auto iffalse = parseAsmExpression(); |
293
418c6548ce17
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
292
diff
changeset
|
2321 e = new CondExpression(e, iftrue, iffalse, tok); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2322 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2323 } |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2324 // TODO: create AsmExpression that contains e? |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2325 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2326 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2327 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2328 Expression parseAsmOrOrExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2329 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
374
diff
changeset
|
2330 alias parseAsmAndAndExpression parseNext; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2331 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2332 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2333 while (token.kind == T.OrLogical) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2334 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2335 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2336 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2337 e = new OrOrExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2338 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2339 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2340 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2341 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2342 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2343 Expression parseAsmAndAndExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2344 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
374
diff
changeset
|
2345 alias parseAsmOrExpression parseNext; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2346 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2347 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2348 while (token.kind == T.AndLogical) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2349 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2350 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2351 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2352 e = new AndAndExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2353 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2354 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2355 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2356 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2357 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2358 Expression parseAsmOrExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2359 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
374
diff
changeset
|
2360 alias parseAsmXorExpression parseNext; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2361 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2362 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2363 while (token.kind == T.OrBinary) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2364 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2365 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2366 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2367 e = new OrExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2368 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2369 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2370 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2371 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2372 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2373 Expression parseAsmXorExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2374 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2375 alias parseAsmAndExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2376 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2377 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2378 while (token.kind == T.Xor) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2379 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2380 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2381 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2382 e = new XorExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2383 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2384 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2385 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2386 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2387 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2388 Expression parseAsmAndExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2389 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2390 alias parseAsmCmpExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2391 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2392 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2393 while (token.kind == T.AndBinary) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2394 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2395 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2396 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2397 e = new AndExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2398 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2399 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2400 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2401 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2402 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2403 Expression parseAsmCmpExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2404 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2405 alias parseAsmShiftExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2406 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2407 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2408 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2409 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2410 switch (operator.kind) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2411 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2412 case T.Equal, T.NotEqual: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2413 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2414 e = new EqualExpression(e, parseNext(), operator); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2415 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2416 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2417 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2418 e = new RelExpression(e, parseNext(), operator); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2419 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2420 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2421 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2422 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2423 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2424 return e; |
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 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2427 Expression parseAsmShiftExpression() |
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 alias parseAsmAddExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2430 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2431 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2432 while (1) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2433 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2434 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2435 switch (operator.kind) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2436 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2437 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
|
2438 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
|
2439 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
|
2440 default: |
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 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2444 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2445 assert(0); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2446 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2447 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2448 Expression parseAsmAddExpression() |
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 alias parseAsmMulExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2451 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2452 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2453 while (1) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2454 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2455 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2456 switch (operator.kind) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2457 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2458 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
|
2459 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
|
2460 // Not allowed in asm |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2461 //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
|
2462 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2463 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2464 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2465 set(e, begin); |
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 assert(0); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2468 } |
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 Expression parseAsmMulExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2471 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2472 alias parseAsmPostExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2473 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2474 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2475 while (1) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2476 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2477 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2478 switch (operator.kind) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2479 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2480 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
|
2481 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
|
2482 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
|
2483 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2484 return e; |
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 set(e, begin); |
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 assert(0); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2489 } |
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 Expression parseAsmPostExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2492 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2493 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2494 auto e = parseAsmUnaryExpression(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2495 while (consumed(T.LBracket)) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2496 { |
632
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2497 e = new AsmPostBracketExpression(e, parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2498 require(T.RBracket); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2499 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2500 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2501 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2502 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2503 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2504 Expression parseAsmUnaryExpression() |
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 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2507 Expression e; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2508 switch (token.kind) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2509 { |
374 | 2510 case T.Byte, T.Short, T.Int, |
2511 T.Float, T.Double, T.Real: | |
2512 goto LAsmTypePrefix; | |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2513 case T.Identifier: |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2514 switch (token.ident.idKind) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2515 { |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2516 case IDK.near, IDK.far,/* "byte", "short", "int",*/ |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2517 IDK.word, IDK.dword, IDK.qword/*, "float", "double", "real"*/: |
374 | 2518 LAsmTypePrefix: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2519 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2520 if (token.kind == T.Identifier && token.ident is Ident.ptr) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2521 skip(T.Identifier); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2522 else |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2523 error(MID.ExpectedButFound, "ptr", token.srcText); |
374 | 2524 e = new AsmTypeExpression(parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2525 break; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2526 case IDK.offset: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2527 nT(); |
374 | 2528 e = new AsmOffsetExpression(parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2529 break; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2530 case IDK.seg: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2531 nT(); |
374 | 2532 e = new AsmSegExpression(parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2533 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2534 default: |
374 | 2535 goto LparseAsmPrimaryExpression; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2536 } |
374 | 2537 break; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2538 case T.Minus: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2539 case T.Plus: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2540 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2541 e = new SignExpression(parseAsmUnaryExpression()); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2542 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2543 case T.Not: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2544 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2545 e = new NotExpression(parseAsmUnaryExpression()); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2546 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2547 case T.Tilde: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2548 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2549 e = new CompExpression(parseAsmUnaryExpression()); |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2550 break; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2551 case T.Dot: |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2552 nT(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2553 e = new ModuleScopeExpression(parseIdentifierExpression()); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2554 while (consumed(TOK.Dot)) |
632
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2555 { |
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2556 e = new DotExpression(e, parseIdentifierExpression()); |
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2557 set(e, begin); |
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2558 } |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2559 break; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2560 default: |
374 | 2561 LparseAsmPrimaryExpression: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2562 e = parseAsmPrimaryExpression(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2563 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2564 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2565 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2566 return e; |
183 | 2567 } |
2568 | |
285 | 2569 Expression parseAsmPrimaryExpression() |
2570 { | |
2571 auto begin = token; | |
2572 Expression e; | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2573 switch (token.kind) |
285 | 2574 { |
2575 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
|
2576 e = new IntExpression(token); |
285 | 2577 nT(); |
2578 break; | |
2579 case T.Float32, T.Float64, T.Float80, | |
2580 T.Imaginary32, T.Imaginary64, T.Imaginary80: | |
539
3418027c3914
Added semantic() method to RealExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
537
diff
changeset
|
2581 e = new RealExpression(token); |
285 | 2582 nT(); |
2583 break; | |
2584 case T.Dollar: | |
2585 e = new DollarExpression(); | |
2586 nT(); | |
2587 break; | |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2588 case T.LBracket: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2589 // [ AsmExpression ] |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2590 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2591 e = parseAsmExpression(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2592 require(T.RBracket); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2593 e = new AsmBracketExpression(e); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2594 break; |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2595 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
|
2596 auto register = token.ident; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2597 switch (register.idKind) |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2598 { |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2599 // __LOCAL_SIZE |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2600 case IDK.__LOCAL_SIZE: |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2601 nT(); |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2602 e = new AsmLocalSizeExpression(); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2603 break; |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2604 // Register |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2605 case IDK.ST: |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2606 nT(); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2607 // (1) - (7) |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2608 int number = -1; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2609 if (consumed(T.LParen)) |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2610 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2611 if (token.kind == T.Int32) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2612 (number = token.int_), skip(T.Int32); |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2613 else |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2614 expected(T.Int32); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2615 require(T.RParen); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2616 } |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2617 e = new AsmRegisterExpression(register, number); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2618 break; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2619 case IDK.FS: |
417
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2620 nT(); |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2621 // 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
|
2622 int number = -1; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2623 if (consumed(T.Colon)) |
417
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2624 { |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2625 // :0, :4, :8 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2626 if (token.kind == T.Int32) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2627 (number = token.int_), skip(T.Int32); |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2628 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
|
2629 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
|
2630 } |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2631 e = new AsmRegisterExpression(register, number); |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2632 break; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2633 case IDK.AL, IDK.AH, IDK.AX, IDK.EAX, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2634 IDK.BL, IDK.BH, IDK.BX, IDK.EBX, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2635 IDK.CL, IDK.CH, IDK.CX, IDK.ECX, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2636 IDK.DL, IDK.DH, IDK.DX, IDK.EDX, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2637 IDK.BP, IDK.EBP, IDK.SP, IDK.ESP, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2638 IDK.DI, IDK.EDI, IDK.SI, IDK.ESI, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2639 IDK.ES, IDK.CS, IDK.SS, IDK.DS, IDK.GS, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2640 IDK.CR0, IDK.CR2, IDK.CR3, IDK.CR4, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2641 IDK.DR0, IDK.DR1, IDK.DR2, IDK.DR3, IDK.DR6, IDK.DR7, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2642 IDK.TR3, IDK.TR4, IDK.TR5, IDK.TR6, IDK.TR7, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2643 IDK.MM0, IDK.MM1, IDK.MM2, IDK.MM3, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2644 IDK.MM4, IDK.MM5, IDK.MM6, IDK.MM7, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2645 IDK.XMM0, IDK.XMM1, IDK.XMM2, IDK.XMM3, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2646 IDK.XMM4, IDK.XMM5, IDK.XMM6, IDK.XMM7: |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2647 nT(); |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2648 e = new AsmRegisterExpression(register); |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2649 break; |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2650 default: |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2651 e = parseIdentifierExpression(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2652 while (consumed(TOK.Dot)) |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2653 { |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2654 e = new DotExpression(e, parseIdentifierExpression()); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2655 set(e, begin); |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2656 } |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2657 } // end of switch |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2658 break; |
285 | 2659 default: |
2660 error(MID.ExpectedButFound, "Expression", token.srcText); | |
659
304331ca2f95
Renamed EmptyExpression to IllegalExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
655
diff
changeset
|
2661 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
|
2662 if (!trying) |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2663 { // 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
|
2664 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
|
2665 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
|
2666 } |
285 | 2667 } |
2668 set(e, begin); | |
2669 return e; | |
2670 } | |
2671 | |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
2672 /+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
2673 | Expression parsing methods | |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
2674 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+/ |
102 | 2675 |
72 | 2676 Expression parseExpression() |
2677 { | |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2678 alias parseAssignExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2679 auto begin = token; |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2680 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2681 while (token.kind == T.Comma) |
235 | 2682 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2683 auto comma = token; |
235 | 2684 nT(); |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2685 e = new CommaExpression(e, parseNext(), comma); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2686 set(e, begin); |
235 | 2687 } |
72 | 2688 return e; |
2689 } | |
2690 | |
71 | 2691 Expression parseAssignExpression() |
2692 { | |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2693 alias parseAssignExpression parseNext; |
319
83f1f9a4f248
- Removed assigment to 'begin' from loop. Initializing 'begin' at decl point.
aziz
parents:
318
diff
changeset
|
2694 auto begin = token; |
71 | 2695 auto e = parseCondExpression(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2696 switch (token.kind) |
71 | 2697 { |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2698 case T.Assign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2699 nT(); e = new AssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2700 case T.LShiftAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2701 nT(); e = new LShiftAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2702 case T.RShiftAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2703 nT(); e = new RShiftAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2704 case T.URShiftAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2705 nT(); e = new URShiftAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2706 case T.OrAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2707 nT(); e = new OrAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2708 case T.AndAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2709 nT(); e = new AndAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2710 case T.PlusAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2711 nT(); e = new PlusAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2712 case T.MinusAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2713 nT(); e = new MinusAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2714 case T.DivAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2715 nT(); e = new DivAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2716 case T.MulAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2717 nT(); e = new MulAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2718 case T.ModAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2719 nT(); e = new ModAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2720 case T.XorAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2721 nT(); e = new XorAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2722 case T.CatAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2723 nT(); e = new CatAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2724 default: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2725 return e; |
71 | 2726 } |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2727 set(e, begin); |
71 | 2728 return e; |
2729 } | |
72 | 2730 |
71 | 2731 Expression parseCondExpression() |
2732 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2733 auto begin = token; |
72 | 2734 auto e = parseOrOrExpression(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2735 if (token.kind == T.Question) |
72 | 2736 { |
293
418c6548ce17
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
292
diff
changeset
|
2737 auto tok = token; |
72 | 2738 nT(); |
2739 auto iftrue = parseExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2740 require(T.Colon); |
72 | 2741 auto iffalse = parseCondExpression(); |
293
418c6548ce17
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
292
diff
changeset
|
2742 e = new CondExpression(e, iftrue, iffalse, tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2743 set(e, begin); |
72 | 2744 } |
2745 return e; | |
2746 } | |
2747 | |
2748 Expression parseOrOrExpression() | |
2749 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2750 alias parseAndAndExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2751 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2752 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2753 while (token.kind == T.OrLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2754 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2755 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2756 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2757 e = new OrOrExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2758 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2759 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2760 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2761 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2762 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2763 Expression parseAndAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2764 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2765 alias parseOrExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2766 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2767 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2768 while (token.kind == T.AndLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2769 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2770 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2771 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2772 e = new AndAndExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2773 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2774 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2775 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2776 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2777 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2778 Expression parseOrExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2779 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2780 alias parseXorExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2781 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2782 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2783 while (token.kind == T.OrBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2784 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2785 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2786 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2787 e = new OrExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2788 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2789 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2790 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2791 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2792 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2793 Expression parseXorExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2794 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2795 alias parseAndExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2796 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2797 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2798 while (token.kind == T.Xor) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2799 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2800 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2801 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2802 e = new XorExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2803 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2804 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2805 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2806 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2807 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2808 Expression parseAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2809 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2810 alias parseCmpExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2811 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2812 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2813 while (token.kind == T.AndBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2814 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2815 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2816 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2817 e = new AndExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2818 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2819 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2820 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2821 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2822 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2823 Expression parseCmpExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2824 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2825 alias parseShiftExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2826 auto begin = token; |
74 | 2827 auto e = parseShiftExpression(); |
2828 | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2829 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2830 switch (operator.kind) |
74 | 2831 { |
2832 case T.Equal, T.NotEqual: | |
2833 nT(); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2834 e = new EqualExpression(e, parseNext(), operator); |
74 | 2835 break; |
2836 case T.Not: | |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2837 if (peekNext() != T.Is) |
74 | 2838 break; |
2839 nT(); | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2840 // fall through |
225 | 2841 case T.Is: |
74 | 2842 nT(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2843 e = new IdentityExpression(e, parseNext(), operator); |
74 | 2844 break; |
2845 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater, | |
2846 T.Unordered, T.UorE, T.UorG, T.UorGorE, | |
2847 T.UorL, T.UorLorE, T.LorEorG, T.LorG: | |
2848 nT(); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2849 e = new RelExpression(e, parseNext(), operator); |
74 | 2850 break; |
2851 case T.In: | |
2852 nT(); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2853 e = new InExpression(e, parseNext(), operator); |
74 | 2854 break; |
2855 default: | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2856 return e; |
74 | 2857 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2858 set(e, begin); |
74 | 2859 return e; |
2860 } | |
2861 | |
2862 Expression parseShiftExpression() | |
2863 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2864 alias parseAddExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2865 auto begin = token; |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2866 auto e = parseNext(); |
75 | 2867 while (1) |
2868 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2869 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2870 switch (operator.kind) |
75 | 2871 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2872 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
|
2873 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
|
2874 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
|
2875 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2876 return e; |
75 | 2877 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2878 set(e, begin); |
75 | 2879 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2880 assert(0); |
75 | 2881 } |
2882 | |
2883 Expression parseAddExpression() | |
2884 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2885 alias parseMulExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2886 auto begin = token; |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2887 auto e = parseNext(); |
76 | 2888 while (1) |
2889 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2890 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2891 switch (operator.kind) |
76 | 2892 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2893 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
|
2894 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
|
2895 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
|
2896 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2897 return e; |
76 | 2898 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2899 set(e, begin); |
76 | 2900 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2901 assert(0); |
76 | 2902 } |
2903 | |
2904 Expression parseMulExpression() | |
2905 { | |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2906 alias parsePostExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2907 auto begin = token; |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2908 auto e = parseNext(); |
77 | 2909 while (1) |
2910 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2911 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2912 switch (operator.kind) |
77 | 2913 { |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2914 case T.Mul: nT(); e = new MulExpression(e, parseNext(), operator); break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2915 case T.Div: nT(); e = new DivExpression(e, parseNext(), operator); break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2916 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
|
2917 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2918 return e; |
77 | 2919 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2920 set(e, begin); |
77 | 2921 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2922 assert(0); |
71 | 2923 } |
2924 | |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2925 Expression parsePostExpression() |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2926 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2927 auto begin = token; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2928 auto e = parseUnaryExpression(); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2929 while (1) |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2930 { |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2931 while (consumed(T.Dot)) |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2932 { |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2933 e = new DotExpression(e, parseNewOrIdentifierExpression()); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2934 set(e, begin); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2935 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2936 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2937 switch (token.kind) |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2938 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2939 case T.PlusPlus: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2940 e = new PostIncrExpression(e); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2941 break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2942 case T.MinusMinus: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2943 e = new PostDecrExpression(e); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2944 break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2945 case T.LParen: |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2946 e = new CallExpression(e, parseArguments()); |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2947 goto Lset; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2948 case T.LBracket: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2949 // parse Slice- and IndexExpression |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2950 nT(); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
2951 // [] is a SliceExpression |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2952 if (token.kind == T.RBracket) |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2953 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2954 e = new SliceExpression(e, null, null); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2955 break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2956 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2957 |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2958 Expression[] es = [parseAssignExpression()]; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2959 |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
2960 // [ AssignExpression .. AssignExpression ] |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2961 if (consumed(T.Slice)) |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2962 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2963 e = new SliceExpression(e, es[0], parseAssignExpression()); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2964 require(T.RBracket); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2965 goto Lset; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2966 } |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2967 |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
2968 // [ ExpressionList ] |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2969 if (consumed(T.Comma)) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2970 es ~= parseExpressionList(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2971 require(T.RBracket); |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2972 |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2973 e = new IndexExpression(e, es); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2974 goto Lset; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2975 default: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2976 return e; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2977 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2978 nT(); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
2979 Lset: // Jumped here to skip nT(). |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2980 set(e, begin); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2981 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2982 assert(0); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2983 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2984 |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2985 Expression parseUnaryExpression() |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2986 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2987 auto begin = token; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2988 Expression e; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2989 switch (token.kind) |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2990 { |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2991 case T.AndBinary: |
257 | 2992 nT(); |
243 | 2993 e = new AddressExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2994 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2995 case T.PlusPlus: |
257 | 2996 nT(); |
243 | 2997 e = new PreIncrExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2998 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2999 case T.MinusMinus: |
257 | 3000 nT(); |
243 | 3001 e = new PreDecrExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3002 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3003 case T.Mul: |
257 | 3004 nT(); |
243 | 3005 e = new DerefExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3006 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3007 case T.Minus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3008 case T.Plus: |
257 | 3009 nT(); |
243 | 3010 e = new SignExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3011 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3012 case T.Not: |
257 | 3013 nT(); |
243 | 3014 e = new NotExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3015 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3016 case T.Tilde: |
257 | 3017 nT(); |
243 | 3018 e = new CompExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3019 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3020 case T.New: |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3021 e = parseNewExpression(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3022 return e; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3023 case T.Delete: |
257 | 3024 nT(); |
243 | 3025 e = new DeleteExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3026 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3027 case T.Cast: |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3028 requireNext(T.LParen); |
269 | 3029 Type type; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3030 switch (token.kind) |
269 | 3031 { |
3032 version(D2) | |
3033 { | |
3034 auto begin2 = token; | |
3035 case T.Const: | |
3036 type = new ConstType(null); | |
3037 goto case_break; | |
3038 case T.Invariant: | |
3039 type = new InvariantType(null); | |
3040 case_break: | |
3041 nT(); | |
3042 set(type, begin2); | |
3043 break; | |
3044 } | |
3045 default: | |
3046 type = parseType(); | |
3047 } | |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3048 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3049 e = new CastExpression(parseUnaryExpression(), type); |
257 | 3050 break; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3051 case T.LParen: |
102 | 3052 // ( Type ) . Identifier |
225 | 3053 Type parseType_() |
3054 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3055 skip(T.LParen); |
225 | 3056 auto type = parseType(); |
3057 require(T.RParen); | |
233 | 3058 require(T.Dot); |
225 | 3059 return type; |
3060 } | |
3061 bool success; | |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
3062 auto type = try_(&parseType_, success); |
225 | 3063 if (success) |
3064 { | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3065 auto ident = requireIdentifier(MSG.ExpectedIdAfterTypeDot); |
225 | 3066 e = new TypeDotIdExpression(type, ident); |
257 | 3067 break; |
225 | 3068 } |
3069 goto default; | |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3070 case T.Dot: |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3071 nT(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3072 e = new ModuleScopeExpression(parseIdentifierExpression()); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3073 break; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3074 default: |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3075 e = parsePrimaryExpression(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3076 return e; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3077 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3078 assert(e !is null); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3079 set(e, begin); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3080 return e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3081 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3082 |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3083 /++ |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3084 IdentifierExpression: |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3085 Identifier |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3086 TemplateInstance |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3087 TemplateInstance: |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3088 Identifier !( TemplateArguments ) |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3089 +/ |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3090 Expression parseIdentifierExpression() |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3091 { |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3092 auto begin = token; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3093 auto ident = requireIdentifier(MSG.ExpectedAnIdentifier); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3094 Expression e; |
634
14e99ce74d06
Fixed parsing of TemplateInstanceExpressions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
632
diff
changeset
|
3095 // 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
|
3096 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
|
3097 { // Identifier !( TemplateArguments ) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3098 skip(T.Not); |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3099 auto tparams = parseTemplateArguments(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3100 e = new TemplateInstanceExpression(ident, tparams); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3101 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3102 else // Identifier |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3103 e = new IdentifierExpression(ident); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3104 return set(e, begin); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3105 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3106 |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3107 Expression parseNewOrIdentifierExpression() |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3108 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3109 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
|
3110 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3111 |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
3112 Expression parsePrimaryExpression() |
78
f043759fb59a
- Added code to parseUnaryExpression(); not fully implemented.
aziz
parents:
77
diff
changeset
|
3113 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3114 auto begin = token; |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3115 Expression e; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3116 switch (token.kind) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3117 { |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3118 case T.Identifier: |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3119 e = parseIdentifierExpression(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3120 return e; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3121 case T.Typeof: |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3122 e = new TypeofExpression(parseTypeofType()); |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3123 break; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3124 case T.This: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3125 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3126 e = new ThisExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3127 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3128 case T.Super: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3129 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3130 e = new SuperExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3131 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3132 case T.Null: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3133 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3134 e = new NullExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3135 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3136 case T.True, T.False: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3137 nT(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3138 e = new BoolExpression(); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3139 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3140 case T.Dollar: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3141 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3142 e = new DollarExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3143 break; |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3144 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
|
3145 e = new IntExpression(token); |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3146 nT(); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3147 break; |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3148 case T.Float32, T.Float64, T.Float80, |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3149 T.Imaginary32, T.Imaginary64, T.Imaginary80: |
539
3418027c3914
Added semantic() method to RealExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
537
diff
changeset
|
3150 e = new RealExpression(token); |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3151 nT(); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3152 break; |
507
996041463028
Removed TOK.WCharLiteral and TOK.DCharLiteral.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
505
diff
changeset
|
3153 case T.CharLiteral: |
536
0781ac288537
Added some semantic() methods.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
535
diff
changeset
|
3154 e = new CharExpression(token.dchar_); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3155 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3156 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3157 case T.String: |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3158 char[] str = token.str; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3159 char postfix = token.pf; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3160 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3161 while (token.kind == T.String) |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3162 { |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3163 if (postfix == '\0') |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3164 postfix = token.pf; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3165 else if (token.pf && token.pf != postfix) |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3166 error(token, MSG.StringPostfixMismatch); |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
755
diff
changeset
|
3167 str.length = str.length - 1; |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3168 str ~= token.str; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3169 nT(); |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3170 } |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3171 switch (postfix) |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3172 { // TODO: convert string |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3173 case 'w': e = new StringExpression(/+toUTF16+/(str)); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3174 case 'd': e = new StringExpression(/+toUTF32+/(str)); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3175 case 'c': |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3176 default: e = new StringExpression(str); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3177 } |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3178 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3179 case T.LBracket: |
85 | 3180 Expression[] values; |
3181 | |
3182 nT(); | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3183 if (!consumed(T.RBracket)) |
85 | 3184 { |
3185 e = parseAssignExpression(); | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3186 if (consumed(T.Colon)) |
85 | 3187 goto LparseAssocArray; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3188 if (consumed(T.Comma)) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3189 values = [e] ~ parseExpressionList(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3190 require(T.RBracket); |
85 | 3191 } |
3192 | |
3193 e = new ArrayLiteralExpression(values); | |
3194 break; | |
3195 | |
3196 LparseAssocArray: | |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3197 Expression[] keys = [e]; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3198 |
271
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3199 goto LenterLoop; |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3200 do |
88 | 3201 { |
271
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3202 keys ~= parseAssignExpression(); |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3203 require(T.Colon); |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3204 LenterLoop: |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3205 values ~= parseAssignExpression(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3206 } while (consumed(T.Comma)) |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3207 require(T.RBracket); |
399
ff1d11c27061
Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
398
diff
changeset
|
3208 e = new AArrayLiteralExpression(keys, values); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3209 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3210 case T.LBrace: |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
3211 // DelegateLiteral := { Statements } |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
3212 auto funcBody = parseFunctionBody(); |
289
a99357783c6f
- Fix: assign targs to member targs of TraitsExpression.
aziz
parents:
288
diff
changeset
|
3213 e = new FunctionLiteralExpression(funcBody); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3214 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3215 case T.Function, T.Delegate: |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
3216 // FunctionLiteral := ("function"|"delegate") Type? "(" ArgumentList ")" FunctionBody |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
3217 nT(); // Skip function or delegate keyword. |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3218 Type returnType; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3219 Parameters parameters; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3220 if (token.kind != T.LBrace) |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3221 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3222 if (token.kind != T.LParen) // Optional return type |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3223 returnType = parseType(); |
143 | 3224 parameters = parseParameterList(); |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3225 } |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
3226 auto funcBody = parseFunctionBody(); |
289
a99357783c6f
- Fix: assign targs to member targs of TraitsExpression.
aziz
parents:
288
diff
changeset
|
3227 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
|
3228 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3229 case T.Assert: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3230 Expression msg; |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3231 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3232 e = parseAssignExpression(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3233 if (consumed(T.Comma)) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3234 msg = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3235 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3236 e = new AssertExpression(e, msg); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3237 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3238 case T.Mixin: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3239 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3240 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3241 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3242 e = new MixinExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3243 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3244 case T.Import: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3245 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3246 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3247 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3248 e = new ImportExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3249 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3250 case T.Typeid: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3251 requireNext(T.LParen); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3252 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3253 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3254 e = new TypeidExpression(type); |
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.Is: |
100 | 3257 requireNext(T.LParen); |
3258 | |
248 | 3259 Type type, specType; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3260 Identifier* ident; // optional Identifier |
248 | 3261 Token* opTok, specTok; |
100 | 3262 |
3263 type = parseDeclarator(ident, true); | |
3264 | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3265 switch (token.kind) |
100 | 3266 { |
3267 case T.Colon, T.Equal: | |
248 | 3268 opTok = token; |
100 | 3269 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3270 switch (token.kind) |
100 | 3271 { |
3272 case T.Typedef, | |
3273 T.Struct, | |
3274 T.Union, | |
3275 T.Class, | |
3276 T.Interface, | |
3277 T.Enum, | |
3278 T.Function, | |
3279 T.Delegate, | |
3280 T.Super, | |
3281 T.Return: | |
493
d13502b6fa5f
Added code to the Parser and edited main.wiki.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
492
diff
changeset
|
3282 case_Const_Invariant: |
248 | 3283 specTok = token; |
102 | 3284 nT(); |
100 | 3285 break; |
493
d13502b6fa5f
Added code to the Parser and edited main.wiki.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
492
diff
changeset
|
3286 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
|
3287 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
|
3288 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
|
3289 // Fall through. It's a type. |
100 | 3290 default: |
248 | 3291 specType = parseType(); |
100 | 3292 } |
3293 default: | |
3294 } | |
377 | 3295 |
3296 TemplateParameters tparams; | |
3297 version(D2) | |
3298 { | |
3299 // is ( Type Identifier : TypeSpecialization , TemplateParameterList ) | |
3300 // is ( Type Identifier == TypeSpecialization , TemplateParameterList ) | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3301 if (ident && specType && token.kind == T.Comma) |
377 | 3302 tparams = parseTemplateParameterList2(); |
3303 } | |
102 | 3304 require(T.RParen); |
377 | 3305 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
|
3306 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3307 case T.LParen: |
646
68953760d569
Added class ParenExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
640
diff
changeset
|
3308 if (tokenAfterParenIs(T.LBrace)) // Check for "(...) {" |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3309 { // ( ParameterList ) FunctionBody |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3310 auto parameters = parseParameterList(); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
3311 auto funcBody = parseFunctionBody(); |
289
a99357783c6f
- Fix: assign targs to member targs of TraitsExpression.
aziz
parents:
288
diff
changeset
|
3312 e = new FunctionLiteralExpression(null, parameters, funcBody); |
130 | 3313 } |
3314 else | |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3315 { // ( Expression ) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3316 skip(T.LParen); |
130 | 3317 e = parseExpression(); |
3318 require(T.RParen); | |
646
68953760d569
Added class ParenExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
640
diff
changeset
|
3319 e = new ParenExpression(e); |
130 | 3320 } |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3321 break; |
269 | 3322 version(D2) |
3323 { | |
3324 case T.Traits: | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3325 requireNext(T.LParen); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3326 auto id = requireIdentifier(MSG.ExpectedAnIdentifier); |
269 | 3327 TemplateArguments args; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3328 if (token.kind == T.Comma) |
269 | 3329 args = parseTemplateArguments2(); |
3330 else | |
3331 require(T.RParen); | |
3332 e = new TraitsExpression(id, args); | |
3333 break; | |
3334 } | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3335 default: |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3336 if (token.isIntegralType) |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3337 { // IntegralType . Identifier |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3338 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
|
3339 nT(); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3340 set(type, begin); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3341 require(T.Dot); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3342 auto ident = requireIdentifier(MSG.ExpectedIdAfterTypeDot); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3343 e = new TypeDotIdExpression(type, ident); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3344 } |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3345 else if (token.isSpecialToken) |
343
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3346 { |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3347 e = new SpecialTokenExpression(token); |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3348 nT(); |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3349 } |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3350 else |
414
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3351 { |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3352 error(MID.ExpectedButFound, "Expression", token.srcText); |
659
304331ca2f95
Renamed EmptyExpression to IllegalExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
655
diff
changeset
|
3353 e = new IllegalExpression(); |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3354 if (!trying) |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3355 { // 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
|
3356 begin = lexer.insertEmptyTokenBefore(token); |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3357 this.prevToken = begin; |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3358 } |
414
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3359 } |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3360 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3361 set(e, begin); |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3362 return e; |
77 | 3363 } |
3364 | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3365 Expression parseNewExpression(/*Expression e*/) |
81 | 3366 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3367 auto begin = token; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3368 skip(T.New); |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3369 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3370 Expression[] newArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3371 Expression[] ctorArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3372 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3373 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
|
3374 newArguments = parseArguments(); |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3375 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3376 // NewAnonClassExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3377 // new (ArgumentList)opt class (ArgumentList)opt SuperClassopt InterfaceClassesopt ClassBody |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3378 if (consumed(T.Class)) |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3379 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3380 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
|
3381 ctorArguments = parseArguments(); |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3382 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3383 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
|
3384 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
3385 auto decls = parseDeclarationDefinitionsBody(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3386 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
|
3387 } |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3388 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3389 // NewExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3390 // NewArguments Type [ AssignExpression ] |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3391 // NewArguments Type ( ArgumentList ) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3392 // NewArguments Type |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3393 auto type = parseType(); |
302
d04a79e795a2
- Fix in parseNewExpression(): removed check for type id.
aziz
parents:
301
diff
changeset
|
3394 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3395 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
|
3396 ctorArguments = parseArguments(); |
302
d04a79e795a2
- Fix in parseNewExpression(): removed check for type id.
aziz
parents:
301
diff
changeset
|
3397 |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3398 return set(new NewExpression(/*e, */newArguments, type, ctorArguments), begin); |
81 | 3399 } |
3400 | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3401 Type parseType() |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3402 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
3403 return parseBasicType2(parseBasicType()); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3404 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3405 |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3406 Type parseIdentifierType() |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3407 { |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3408 auto begin = token; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3409 auto ident = requireIdentifier(MSG.ExpectedAnIdentifier); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3410 Type t; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3411 if (consumed(T.Not)) // Identifier !( TemplateArguments ) |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3412 t = new TemplateInstanceType(ident, parseTemplateArguments()); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3413 else // Identifier |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3414 t = new IdentifierType(ident); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3415 return set(t, begin); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3416 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3417 |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3418 Type parseQualifiedType() |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3419 { |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3420 auto begin = token; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3421 Type type; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3422 if (consumed(T.Dot)) |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3423 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
|
3424 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
|
3425 { |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3426 type = parseTypeofType(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3427 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
|
3428 return type; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3429 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3430 else |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3431 type = parseIdentifierType(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3432 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3433 while (consumed(T.Dot)) |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3434 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
|
3435 return type; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3436 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3437 |
94 | 3438 Type parseBasicType() |
3439 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3440 auto begin = token; |
94 | 3441 Type t; |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3442 |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3443 if (token.isIntegralType) |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3444 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3445 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
|
3446 nT(); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3447 } |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3448 else |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3449 switch (token.kind) |
94 | 3450 { |
153 | 3451 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
|
3452 t = parseQualifiedType(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3453 return t; |
269 | 3454 version(D2) |
3455 { | |
3456 case T.Const: | |
3457 // const ( Type ) | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3458 requireNext(T.LParen); |
269 | 3459 t = parseType(); |
3460 require(T.RParen); | |
3461 t = new ConstType(t); | |
3462 break; | |
3463 case T.Invariant: | |
3464 // invariant ( Type ) | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3465 requireNext(T.LParen); |
269 | 3466 t = parseType(); |
3467 require(T.RParen); | |
3468 t = new InvariantType(t); | |
3469 break; | |
369 | 3470 } // version(D2) |
94 | 3471 default: |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3472 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
|
3473 t = new IllegalType(); |
259
8118da6fee44
- Moved nT() below statement where an attribute class is constructed.
aziz
parents:
258
diff
changeset
|
3474 nT(); |
94 | 3475 } |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3476 return set(t, begin); |
94 | 3477 } |
3478 | |
95 | 3479 Type parseBasicType2(Type t) |
3480 { | |
3481 while (1) | |
3482 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3483 auto begin = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3484 switch (token.kind) |
95 | 3485 { |
3486 case T.Mul: | |
3487 t = new PointerType(t); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3488 nT(); |
95 | 3489 break; |
3490 case T.LBracket: | |
106 | 3491 t = parseArrayType(t); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3492 continue; |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3493 case T.Function, T.Delegate: |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3494 TOK tok = token.kind; |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3495 nT(); |
143 | 3496 auto parameters = parseParameterList(); |
135 | 3497 if (tok == T.Function) |
291
c0e857931ff6
- Changed FunctionType and DelegateType. Both receive return type and parameters.
aziz
parents:
290
diff
changeset
|
3498 t = new FunctionType(t, parameters); |
135 | 3499 else |
291
c0e857931ff6
- Changed FunctionType and DelegateType. Both receive return type and parameters.
aziz
parents:
290
diff
changeset
|
3500 t = new DelegateType(t, parameters); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3501 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3502 default: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3503 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3504 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3505 set(t, begin); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3506 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3507 assert(0); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3508 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3509 |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3510 bool tokenAfterParenIs(TOK tok) |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3511 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3512 // We count nested parentheses tokens because template types |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3513 // 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
|
3514 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
|
3515 Token* next = token; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3516 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
|
3517 Loop: |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3518 while (1) |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3519 { |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
3520 lexer.peek(next); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3521 switch (next.kind) |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3522 { |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3523 case T.RParen: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3524 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
|
3525 { // 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
|
3526 do |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
3527 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
|
3528 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
|
3529 break Loop; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3530 } |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3531 break; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3532 case T.LParen: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3533 ++level; |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3534 break; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3535 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
|
3536 break Loop; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3537 default: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3538 } |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3539 } |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3540 return next.kind == tok; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3541 } |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3542 |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3543 /// Parse the C-style array types after the declarator. |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3544 Type parseDeclaratorSuffix(Type lhsType) |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3545 { |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3546 // The Type chain should be as follows: |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3547 // int[3]* Identifier [][32] |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
3548 // <- <- -> -. |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
3549 // ^-----------------´ |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3550 // Resulting chain: [][32]*[3]int |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3551 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
|
3552 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3553 if (token.kind != T.LBracket) |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3554 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
|
3555 |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3556 auto begin = token; |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3557 Type t; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3558 skip(T.LBracket); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3559 if (consumed(T.RBracket)) |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3560 t = new ArrayType(parseNext()); // [ ] |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3561 else |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3562 { |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3563 bool success; |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3564 Type parseAAType() |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3565 { |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3566 auto type = parseType(); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3567 require(T.RBracket); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3568 return type; |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3569 } |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3570 auto assocType = try_(&parseAAType, success); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3571 if (success) |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3572 t = new ArrayType(parseNext(), assocType); // [ Type ] |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3573 else |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3574 { |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3575 Expression e = parseExpression(), e2; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3576 if (consumed(T.Slice)) |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3577 e2 = parseExpression(); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3578 require(T.RBracket); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3579 t = new ArrayType(parseNext(), e, e2); // [ Expression .. Expression ] |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3580 } |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3581 } |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3582 set(t, begin); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3583 return t; |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3584 } |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3585 return parseNext(); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3586 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3587 |
106 | 3588 Type parseArrayType(Type t) |
3589 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3590 auto begin = token; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3591 skip(T.LBracket); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3592 if (consumed(T.RBracket)) |
106 | 3593 t = new ArrayType(t); |
3594 else | |
3595 { | |
214 | 3596 bool success; |
369 | 3597 Type parseAAType() |
3598 { | |
3599 auto type = parseType(); | |
3600 require(T.RBracket); | |
3601 return type; | |
3602 } | |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
3603 auto assocType = try_(&parseAAType, success); |
214 | 3604 if (success) |
106 | 3605 t = new ArrayType(t, assocType); |
3606 else | |
3607 { | |
3608 Expression e = parseExpression(), e2; | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3609 if (consumed(T.Slice)) |
106 | 3610 e2 = parseExpression(); |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3611 require(T.RBracket); |
106 | 3612 t = new ArrayType(t, e, e2); |
3613 } | |
3614 } | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3615 set(t, begin); |
106 | 3616 return t; |
3617 } | |
3618 | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3619 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
|
3620 { |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3621 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
|
3622 auto begin = token; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3623 skip(T.LParen); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3624 |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3625 type = parseBasicType2(type); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3626 if (token.kind == T.LParen) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3627 { // Can be nested. |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3628 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
|
3629 } |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3630 else if (token.kind == T.Identifier) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3631 { // 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
|
3632 ident = token.ident; |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3633 nT(); |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3634 type = parseDeclaratorSuffix(type); |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3635 } |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3636 require(T.RParen); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3637 |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3638 Parameters params; |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3639 if (optionalParamList) |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3640 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
|
3641 else |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3642 params = parseParameterList(); |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3643 |
535
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
3644 type = new CFuncPointerType(type, params); |
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
3645 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
|
3646 } |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3647 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3648 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
|
3649 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
3650 auto t = parseType(); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3651 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3652 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
|
3653 t = parseCFunctionPointerType(t, ident, true); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3654 else if (token.kind == T.Identifier) |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3655 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3656 ident = token.ident; |
95 | 3657 nT(); |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
3658 t = parseDeclaratorSuffix(t); |
95 | 3659 } |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3660 |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3661 if (ident is null && !identOptional) |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3662 error(token, MSG.ExpectedDeclaratorIdentifier, token.srcText); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3663 |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
3664 return t; |
95 | 3665 } |
3666 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3667 /++ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3668 Parse a list of AssignExpressions. |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3669 ExpressionList: |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3670 AssignExpression |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3671 AssignExpression , ExpressionList |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3672 +/ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3673 Expression[] parseExpressionList() |
138 | 3674 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3675 Expression[] expressions; |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3676 do |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3677 expressions ~= parseAssignExpression(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3678 while(consumed(T.Comma)) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3679 return expressions; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3680 } |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3681 |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3682 /++ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3683 Arguments: |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3684 ( ) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3685 ( ExpressionList ) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3686 +/ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3687 Expression[] parseArguments() |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3688 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3689 skip(T.LParen); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3690 Expression[] args; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3691 if (token.kind != T.RParen) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3692 args = parseExpressionList(); |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3693 require(T.RParen); |
139 | 3694 return args; |
138 | 3695 } |
3696 | |
143 | 3697 Parameters parseParameterList() |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3698 out(params) |
96 | 3699 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3700 if (params.length > 1) |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3701 foreach (param; params.items[0..$-1]) |
96 | 3702 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3703 if (param.isVariadic()) |
96 | 3704 assert(0, "variadic arguments can only appear at the end of the parameter list."); |
3705 } | |
3706 } | |
3707 body | |
95 | 3708 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3709 auto begin = token; |
95 | 3710 require(T.LParen); |
3711 | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3712 auto params = new Parameters(); |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3713 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3714 if (consumed(T.RParen)) |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3715 return set(params, begin); |
95 | 3716 |
749 | 3717 do |
95 | 3718 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3719 auto paramBegin = token; |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3720 StorageClass stc, stc_; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3721 Type type; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3722 Identifier* ident; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3723 Expression defValue; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3724 |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3725 void pushParameter() |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3726 { |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3727 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
|
3728 } |
269 | 3729 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3730 if (consumed(T.Ellipses)) |
269 | 3731 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3732 stc = StorageClass.Variadic; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3733 pushParameter(); // type, ident and defValue will be null. |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3734 break; |
269 | 3735 } |
3736 | |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3737 while (1) |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3738 { // Parse storage classes. |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3739 switch (token.kind) |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3740 { |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3741 version(D2) |
95 | 3742 { |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3743 case T.Invariant: // D2.0 |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3744 if (peekNext() == T.LParen) |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3745 break; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3746 stc_ = StorageClass.Invariant; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3747 goto Lcommon; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3748 case T.Const: // D2.0 |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3749 if (peekNext() == T.LParen) |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3750 break; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3751 stc_ = StorageClass.Const; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3752 goto Lcommon; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3753 case T.Final: // D2.0 |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3754 stc_ = StorageClass.Final; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3755 goto Lcommon; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3756 case T.Scope: // D2.0 |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3757 stc_ = StorageClass.Scope; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3758 goto Lcommon; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3759 case T.Static: // D2.0 |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3760 stc_ = StorageClass.Static; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3761 goto Lcommon; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3762 } |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3763 case T.In: |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3764 stc_ = StorageClass.In; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3765 goto Lcommon; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3766 case T.Out: |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3767 stc_ = StorageClass.Out; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3768 goto Lcommon; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3769 case T.Inout, T.Ref: |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3770 stc_ = StorageClass.Ref; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3771 goto Lcommon; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3772 case T.Lazy: |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3773 stc_ = StorageClass.Lazy; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3774 goto Lcommon; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3775 Lcommon: |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3776 // Check for redundancy. |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3777 if (stc & stc_) |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3778 error(MID.RedundantStorageClass, token.srcText); |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3779 else |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3780 stc |= stc_; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3781 nT(); |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3782 version(D2) |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3783 continue; |
269 | 3784 else |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3785 break; // In D1.0 the grammar only allows one storage class. |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3786 default: |
95 | 3787 } |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3788 break; // Break out of inner loop. |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3789 } |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3790 type = parseDeclarator(ident, true); |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3791 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3792 if (consumed(T.Assign)) |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3793 defValue = parseAssignExpression(); |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3794 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3795 if (consumed(T.Ellipses)) |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3796 { |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3797 stc |= StorageClass.Variadic; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3798 pushParameter(); |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3799 break; |
95 | 3800 } |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3801 pushParameter(); |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3802 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3803 } while (consumed(T.Comma)) |
95 | 3804 require(T.RParen); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3805 return set(params, begin); |
95 | 3806 } |
3807 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
3808 TemplateArguments parseTemplateArguments() |
139 | 3809 { |
376 | 3810 TemplateArguments targs; |
139 | 3811 require(T.LParen); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3812 if (token.kind != T.RParen) |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3813 targs = parseTemplateArguments_(); |
139 | 3814 require(T.RParen); |
376 | 3815 return targs; |
139 | 3816 } |
376 | 3817 |
269 | 3818 version(D2) |
3819 { | |
3820 TemplateArguments parseTemplateArguments2() | |
3821 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3822 skip(T.Comma); |
376 | 3823 TemplateArguments targs; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3824 if (token.kind != T.RParen) |
376 | 3825 targs = parseTemplateArguments_(); |
269 | 3826 else |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3827 error(token, MSG.ExpectedTypeOrExpression); |
269 | 3828 require(T.RParen); |
376 | 3829 return targs; |
269 | 3830 } |
3831 } // version(D2) | |
376 | 3832 |
3833 TemplateArguments parseTemplateArguments_() | |
3834 { | |
3835 auto begin = token; | |
3836 auto targs = new TemplateArguments; | |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3837 do |
376 | 3838 { |
379
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
3839 Type parseType_() |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
3840 { |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
3841 auto type = parseType(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3842 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
|
3843 return type; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3844 errorCount++; // Cause try_() to fail. |
379
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
3845 return null; |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
3846 } |
376 | 3847 bool success; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
3848 auto typeArgument = try_(&parseType_, success); |
376 | 3849 if (success) |
3850 // TemplateArgument: | |
3851 // Type | |
3852 // Symbol | |
3853 targs ~= typeArgument; | |
3854 else | |
3855 // TemplateArgument: | |
3856 // AssignExpression | |
3857 targs ~= parseAssignExpression(); | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3858 } while (consumed(T.Comma)) |
376 | 3859 set(targs, begin); |
3860 return targs; | |
3861 } | |
3862 | |
258 | 3863 TemplateParameters parseTemplateParameterList() |
137 | 3864 { |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3865 auto begin = token; |
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3866 auto tparams = new TemplateParameters; |
377 | 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) |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3869 parseTemplateParameterList_(tparams); |
377 | 3870 require(T.RParen); |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3871 return set(tparams, begin); |
377 | 3872 } |
3873 | |
3874 version(D2) | |
3875 { | |
3876 TemplateParameters parseTemplateParameterList2() | |
3877 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3878 skip(T.Comma); |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3879 auto begin = token; |
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3880 auto tparams = new TemplateParameters; |
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) |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3882 parseTemplateParameterList_(tparams); |
377 | 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.ExpectedTemplateParameters); |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3885 return set(tparams, begin); |
377 | 3886 } |
3887 } // version(D2) | |
3888 | |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3889 void parseTemplateParameterList_(TemplateParameters tparams) |
377 | 3890 { |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3891 do |
137 | 3892 { |
258 | 3893 auto paramBegin = token; |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3894 TemplateParameter tp; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3895 Identifier* ident; |
137 | 3896 Type specType, defType; |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3897 |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3898 void parseSpecAndOrDefaultType() |
137 | 3899 { |
3900 // : SpecializationType | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3901 if (consumed(T.Colon)) |
137 | 3902 specType = parseType(); |
3903 // = DefaultType | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3904 if (consumed(T.Assign)) |
137 | 3905 defType = parseType(); |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3906 } |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3907 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3908 switch (token.kind) |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3909 { |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3910 case T.Alias: |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3911 // TemplateAliasParameter: |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3912 // alias Identifier |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3913 skip(T.Alias); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3914 ident = requireIdentifier(MSG.ExpectedAliasTemplateParam); |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3915 parseSpecAndOrDefaultType(); |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3916 tp = new TemplateAliasParameter(ident, specType, defType); |
137 | 3917 break; |
3918 case T.Identifier: | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3919 ident = token.ident; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
3920 switch (peekNext()) |
137 | 3921 { |
3922 case T.Ellipses: | |
3923 // TemplateTupleParameter: | |
3924 // Identifier ... | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3925 skip(T.Identifier); skip(T.Ellipses); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3926 if (token.kind == T.Comma) |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
3927 error(MID.TemplateTupleParameter); |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3928 tp = new TemplateTupleParameter(ident); |
137 | 3929 break; |
3930 case T.Comma, T.RParen, T.Colon, T.Assign: | |
3931 // TemplateTypeParameter: | |
3932 // Identifier | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3933 skip(T.Identifier); |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3934 parseSpecAndOrDefaultType(); |
341
3ac651ea83fb
- Fix: created TemplateAliasParameter instead of TemplateTypeParameter.
aziz
parents:
340
diff
changeset
|
3935 tp = new TemplateTypeParameter(ident, specType, defType); |
137 | 3936 break; |
3937 default: | |
3938 // TemplateValueParameter: | |
3939 // Declarator | |
3940 ident = null; | |
3941 goto LTemplateValueParameter; | |
3942 } | |
3943 break; | |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
3944 version(D2) |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
3945 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
3946 case T.This: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
3947 // TemplateThisParameter |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
3948 // this TemplateTypeParameter |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3949 skip(T.This); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3950 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
|
3951 parseSpecAndOrDefaultType(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
3952 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
|
3953 break; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
3954 } |
137 | 3955 default: |
3956 LTemplateValueParameter: | |
3957 // TemplateValueParameter: | |
3958 // Declarator | |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3959 Expression specValue, defValue; |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3960 auto valueType = parseDeclarator(ident); |
137 | 3961 // : SpecializationValue |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3962 if (consumed(T.Colon)) |
137 | 3963 specValue = parseCondExpression(); |
3964 // = DefaultValue | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3965 if (consumed(T.Assign)) |
137 | 3966 defValue = parseCondExpression(); |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3967 tp = new TemplateValueParameter(valueType, ident, specValue, defValue); |
137 | 3968 } |
3969 | |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3970 // Push template parameter. |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3971 tparams ~= set(tp, paramBegin); |
137 | 3972 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3973 } while (consumed(T.Comma)) |
137 | 3974 } |
3975 | |
124 | 3976 void expected(TOK tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3977 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3978 if (token.kind != tok) |
327 | 3979 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
|
3980 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3981 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3982 void require(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3983 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3984 if (token.kind == tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3985 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3986 else |
327 | 3987 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
|
3988 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3989 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3990 void requireNext(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3991 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3992 nT(); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3993 require(tok); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3994 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3995 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3996 Identifier* optionalIdentifier() |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3997 { |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3998 Identifier* id; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3999 if (token.kind == T.Identifier) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
4000 (id = token.ident), skip(T.Identifier); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4001 return id; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4002 } |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4003 |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4004 Identifier* requireIdentifier() |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4005 { |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4006 Identifier* id; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4007 if (token.kind == T.Identifier) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
4008 (id = token.ident), skip(T.Identifier); |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4009 else |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4010 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
|
4011 return id; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4012 } |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4013 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
4014 /// Params: |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
4015 /// errorMsg = an error that has no message ID yet. |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4016 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
|
4017 { |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4018 Identifier* id; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4019 if (token.kind == T.Identifier) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
4020 (id = token.ident), skip(T.Identifier); |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4021 else |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4022 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
|
4023 return id; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4024 } |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4025 |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4026 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
|
4027 { |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4028 Identifier* id; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4029 if (token.kind == T.Identifier) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
4030 (id = token.ident), skip(T.Identifier); |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4031 else |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4032 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
|
4033 return id; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4034 } |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4035 |
243 | 4036 Token* requireId() |
4037 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4038 if (token.kind == T.Identifier) |
243 | 4039 { |
4040 auto id = token; | |
4041 nT(); | |
4042 return id; | |
4043 } | |
4044 else | |
4045 error(MID.ExpectedButFound, "Identifier", token.srcText); | |
4046 return null; | |
4047 } | |
4048 | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4049 Token* requireIdToken(char[] errorMsg) |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4050 { |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4051 Token* idtok; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4052 if (token.kind == T.Identifier) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
4053 (idtok = token), skip(T.Identifier); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4054 else |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4055 error(token, errorMsg, token.srcText); |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4056 return idtok; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4057 } |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4058 |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4059 /// 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
|
4060 void error(Token* token, char[] formatMsg, ...) |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4061 { |
514
6ddff941862a
Added new error classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
511
diff
changeset
|
4062 error_(token, formatMsg, _arguments, _argptr); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4063 } |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4064 |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
4065 void error(MID mid, ...) |
71 | 4066 { |
514
6ddff941862a
Added new error classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
511
diff
changeset
|
4067 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
|
4068 } |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4069 |
762
c909a3d3fa52
Fixed vararg issue with gdc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
4070 void error_(Token* token, char[] formatMsg, TypeInfo[] _arguments, Arg _argptr) |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4071 { |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4072 if (trying) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4073 { |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4074 ++errorCount; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4075 return; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4076 } |
675
e7811328e6c7
Made Token.getLocation() a template function and added two aliases.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
673
diff
changeset
|
4077 auto location = token.getErrorLocation(); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4078 auto msg = Format(_arguments, _argptr, formatMsg); |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
519
diff
changeset
|
4079 auto error = new ParserError(location, msg); |
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
519
diff
changeset
|
4080 errors ~= error; |
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
519
diff
changeset
|
4081 if (infoMan !is null) |
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
519
diff
changeset
|
4082 infoMan ~= error; |
71 | 4083 } |
65 | 4084 } |