Mercurial > projects > dil
annotate trunk/src/dil/parser/Parser.d @ 789:c1d5cfd7aa44
Implemented string literal conversion.
Removed two MID messages.
Added MSG.InvalidUTF8SequenceInString.
Added toUTF16() and toUTF32().
Fixed escape sequences.
Added formatBytes() and findInvalidUTF8Sequence().
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Mon, 25 Feb 2008 02:56:22 +0100 |
parents | 846044180d22 |
children | c24be8d4f6ab |
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; |
789
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
20 import dil.Unicode; |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
21 import common; |
65 | 22 |
789
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
23 /// The Parser produces a full parse tree by examining |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
24 /// the list of tokens provided by the Lexer. |
65 | 25 class Parser |
26 { | |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
27 Lexer lexer; /// Used to lex the source code. |
318 | 28 Token* token; /// Current non-whitespace token. |
29 Token* prevToken; /// Previous non-whitespace token. | |
71 | 30 |
532
50e64bab9c7a
Renamed InformationManager to InfoManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
531
diff
changeset
|
31 InfoManager infoMan; |
514
6ddff941862a
Added new error classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
511
diff
changeset
|
32 ParserError[] errors; |
71 | 33 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
34 ImportDeclaration[] imports; /// ImportDeclarations in the source text. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
35 |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
36 // Attributes are evaluated in the parsing phase. |
683
1ae72234db26
Implemented some methods in SemanticPass1.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
682
diff
changeset
|
37 // Will probably be moved to class SemanticPass1. |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
38 LinkageType linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
39 Protection protection; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
40 StorageClass storageClass; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
41 uint alignSize = DEFAULT_ALIGN_SIZE; |
364 | 42 |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
43 private alias TOK T; |
511
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
44 private alias TypeNode Type; |
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
45 |
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
46 /++ |
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
47 Construct a Parser object. |
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
48 Params: |
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
49 text = the UTF-8 source code. |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
50 infoMan = used for collecting error messages. |
511
aa73f669c298
Renamed class Type to TypeNode.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
509
diff
changeset
|
51 +/ |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
750
diff
changeset
|
52 this(SourceText srcText, InfoManager infoMan = null) |
71 | 53 { |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
519
diff
changeset
|
54 this.infoMan = infoMan; |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
750
diff
changeset
|
55 lexer = new Lexer(srcText, infoMan); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
56 } |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
57 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
58 /// 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
|
59 protected void init() |
206 | 60 { |
61 nT(); | |
318 | 62 prevToken = token; |
206 | 63 } |
64 | |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
65 /// Moves to the next token. |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
66 void nT() |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
67 { |
318 | 68 prevToken = token; |
132 | 69 do |
70 { | |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
71 lexer.nextToken(); |
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
72 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
|
73 } while (token.isWhitespace) // Skip whitespace |
71 | 74 } |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
75 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
76 /// 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
|
77 CompoundDeclaration start() |
102 | 78 { |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
79 init(); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
80 auto begin = token; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
81 auto decls = new CompoundDeclaration; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
82 if (token.kind == T.Module) |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
83 decls ~= parseModuleDeclaration(); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
84 decls.addOptChildren(parseDeclarationDefinitions()); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
85 set(decls, begin); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
86 return decls; |
102 | 87 } |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
88 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
89 /// 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
|
90 Expression start2() |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
91 { |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
92 init(); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
93 return parseExpression(); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
94 } |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
95 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
96 // Members related to the method try_(). |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
97 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
|
98 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
|
99 |
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 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
|
102 the state of the lexer and parser are restored. |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
103 +/ |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
104 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
|
105 { |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
106 // Save members. |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
107 auto oldToken = this.token; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
108 auto oldPrevToken = this.prevToken; |
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
109 auto oldCount = this.errorCount; |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
110 |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
111 ++trying; |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
112 auto result = parseMethod(); |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
113 --trying; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
114 // Check if an error occurred. |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
115 if (errorCount != oldCount) |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
116 { // Restore members. |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
117 token = oldToken; |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
118 prevToken = oldPrevToken; |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
119 lexer.token = oldToken; |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
120 errorCount = oldCount; |
214 | 121 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
|
122 } |
214 | 123 else |
124 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
|
125 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
|
126 } |
105 | 127 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
128 /// 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
|
129 Class set(Class)(Class node, Token* begin) |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
130 { |
318 | 131 node.setTokens(begin, this.prevToken); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
132 return node; |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
133 } |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
134 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
135 /// 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
|
136 static bool isNodeSet(Node node) |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
137 { |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
138 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
|
139 } |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
140 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
141 /// 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
|
142 TOK peekNext() |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
143 { |
239
7911f6a92e6e
- Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK.
aziz
parents:
238
diff
changeset
|
144 Token* next = token; |
296 | 145 do |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
146 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
|
147 while (next.isWhitespace) // Skip whitespace |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
148 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
|
149 } |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
150 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
151 /// 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
|
152 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
|
153 { |
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
154 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
|
155 do |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
156 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
|
157 while (next.isWhitespace) // Skip whitespace |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
158 return next.kind; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
159 } |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
160 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
161 /// 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
|
162 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
|
163 { |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
164 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
|
165 } |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
166 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
167 /// 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
|
168 /// 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
|
169 void skip()(TOK expectedKind) |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
170 { |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
171 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
|
172 nT(); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
173 } |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
174 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
175 /+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
176 | Declaration parsing methods | |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
177 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+/ |
102 | 178 |
368 | 179 Declaration parseModuleDeclaration() |
180 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
181 skip(T.Module); |
368 | 182 auto begin = token; |
183 ModuleFQN moduleFQN; | |
184 do | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
185 moduleFQN ~= requireIdentifier(MSG.ExpectedModuleIdentifier); |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
186 while (consumed(T.Dot)) |
368 | 187 require(T.Semicolon); |
188 return set(new ModuleDeclaration(moduleFQN), begin); | |
189 } | |
190 | |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
191 /++ |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
192 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
|
193 DeclDefs: |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
194 DeclDef |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
195 DeclDefs |
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
196 +/ |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
197 Declaration[] parseDeclarationDefinitions() |
102 | 198 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
199 Declaration[] decls; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
200 while (token.kind != T.EOF) |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
201 decls ~= parseDeclarationDefinition(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
202 return decls; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
203 } |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
204 |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
205 /++ |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
206 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
|
207 DeclDefsBlock: |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
208 { } |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
209 { DeclDefs } |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
484
diff
changeset
|
210 +/ |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
211 CompoundDeclaration parseDeclarationDefinitionsBody() |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
212 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
213 // Save attributes. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
214 auto linkageType = this.linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
215 auto protection = this.protection; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
216 auto storageClass = this.storageClass; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
217 // Clear attributes. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
218 this.linkageType = LinkageType.None; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
219 this.protection = Protection.None; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
220 this.storageClass = StorageClass.None; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
221 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
222 // Parse body. |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
223 auto begin = token; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
224 auto decls = new CompoundDeclaration; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
225 require(T.LBrace); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
226 while (token.kind != T.RBrace && token.kind != T.EOF) |
161 | 227 decls ~= parseDeclarationDefinition(); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
228 require(T.RBrace); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
229 set(decls, begin); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
230 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
231 // Restore original values. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
232 this.linkageType = linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
233 this.protection = protection; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
234 this.storageClass = storageClass; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
235 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
236 return decls; |
102 | 237 } |
238 | |
110 | 239 Declaration parseDeclarationDefinition() |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
240 out(decl) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
241 { assert(isNodeSet(decl)); } |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
242 body |
102 | 243 { |
262 | 244 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
|
245 Declaration decl; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
246 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
|
247 { |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
248 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
|
249 T.Pragma, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
250 // Protection attributes |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
251 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
|
252 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
|
253 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
|
254 T.Protected, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
255 T.Public: |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
256 decl = parseAttributeSpecifier(); |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
257 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
258 // Storage classes |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
259 case T.Extern, |
203
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
260 T.Deprecated, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
261 T.Override, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
262 T.Abstract, |
4f949a3a394b
- synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents:
202
diff
changeset
|
263 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
|
264 //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
|
265 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
|
266 T.Const, |
269 | 267 //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
|
268 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
|
269 T.Scope: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
270 case_StaticAttribute: |
269 | 271 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
|
272 return parseStorageAttribute(); |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
273 case T.Alias: |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
274 nT(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
275 decl = new AliasDeclaration(parseVariableOrFunction()); |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
276 break; |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
277 case T.Typedef: |
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
278 nT(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
279 decl = new TypedefDeclaration(parseVariableOrFunction()); |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
280 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
|
281 case T.Static: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
282 switch (peekNext()) |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
283 { |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
284 case T.Import: |
429
052cbacb1642
Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
424
diff
changeset
|
285 goto case_Import; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
286 case T.This: |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
287 decl = parseStaticConstructorDeclaration(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
288 break; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
289 case T.Tilde: |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
290 decl = parseStaticDestructorDeclaration(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
291 break; |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
292 case T.If: |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
293 decl = parseStaticIfDeclaration(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
294 break; |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
295 case T.Assert: |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
296 decl = parseStaticAssertDeclaration(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
297 break; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
298 default: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
299 goto case_StaticAttribute; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
300 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
301 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
|
302 case T.Import: |
429
052cbacb1642
Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
424
diff
changeset
|
303 case_Import: |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
304 decl = parseImportDeclaration(); |
673
64fec49651cf
Renamed VariableDeclaration to VariablesDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
671
diff
changeset
|
305 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
|
306 // 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
|
307 decl.setProtection(this.protection); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
308 return set(decl, begin); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
309 case T.Enum: |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
310 decl = parseEnumDeclaration(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
311 break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
312 case T.Class: |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
313 decl = parseClassDeclaration(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
314 break; |
112 | 315 case T.Interface: |
316 decl = parseInterfaceDeclaration(); | |
317 break; | |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
318 case T.Struct, T.Union: |
638
7131c07997f9
Renamed parseAggregateDeclaration() to parseStructOrUnionDeclaration().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
637
diff
changeset
|
319 decl = parseStructOrUnionDeclaration(); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
320 break; |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
321 case T.This: |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
322 decl = parseConstructorDeclaration(); |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
323 break; |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
324 case T.Tilde: |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
325 decl = parseDestructorDeclaration(); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
326 break; |
120 | 327 case T.Invariant: |
269 | 328 version(D2) |
329 { | |
330 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
|
331 if (peekAfter(next) == T.LParen) |
269 | 332 { |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
333 if (peekAfter(next) != T.RParen) |
269 | 334 goto case_Declaration; |
335 } | |
336 else | |
337 goto case_InvariantAttribute; | |
338 } | |
120 | 339 decl = parseInvariantDeclaration(); |
340 break; | |
121 | 341 case T.Unittest: |
342 decl = parseUnittestDeclaration(); | |
343 break; | |
122 | 344 case T.Debug: |
345 decl = parseDebugDeclaration(); | |
140 | 346 break; |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
347 case T.Version: |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
348 decl = parseVersionDeclaration(); |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
349 break; |
140 | 350 case T.Template: |
351 decl = parseTemplateDeclaration(); | |
352 break; | |
141 | 353 case T.New: |
354 decl = parseNewDeclaration(); | |
355 break; | |
356 case T.Delete: | |
357 decl = parseDeleteDeclaration(); | |
358 break; | |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
359 case T.Mixin: |
256 | 360 decl = parseMixin!(MixinDeclaration)(); |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
361 break; |
129 | 362 case T.Semicolon: |
363 nT(); | |
364 decl = new EmptyDeclaration(); | |
365 break; | |
192 | 366 // Declaration |
367 case T.Identifier, T.Dot, T.Typeof: | |
269 | 368 case_Declaration: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
369 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
|
370 default: |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
371 if (token.isIntegralType) |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
372 goto case_Declaration; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
373 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
|
374 { |
fe66cecb6ec9
Reporting error if module declaration is not first.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
634
diff
changeset
|
375 decl = parseModuleDeclaration(); |
fe66cecb6ec9
Reporting error if module declaration is not first.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
634
diff
changeset
|
376 error(begin, MSG.ModuleDeclarationNotFirst); |
fe66cecb6ec9
Reporting error if module declaration is not first.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
634
diff
changeset
|
377 return decl; |
fe66cecb6ec9
Reporting error if module declaration is not first.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
634
diff
changeset
|
378 } |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
379 |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
380 decl = new IllegalDeclaration(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
381 // Skip to next valid token. |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
382 do |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
383 nT(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
384 while (!token.isDeclDefStart && |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
385 token.kind != T.RBrace && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
386 token.kind != T.EOF) |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
387 auto text = Token.textSpan(begin, this.prevToken); |
616
506ce60760d8
Fixed some error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
608
diff
changeset
|
388 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
|
389 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
390 decl.setProtection(this.protection); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
391 decl.setStorageClass(this.storageClass); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
392 assert(!isNodeSet(decl)); |
262 | 393 set(decl, begin); |
129 | 394 return decl; |
102 | 395 } |
396 | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
397 /++ |
122 | 398 DeclarationsBlock: |
399 : DeclDefs | |
400 { } | |
401 { DeclDefs } | |
402 DeclDef | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
403 +/ |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
404 Declaration parseDeclarationsBlock(/+bool noColon = false+/) |
122 | 405 { |
305 | 406 Declaration d; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
407 switch (token.kind) |
122 | 408 { |
409 case T.LBrace: | |
528
d0ac6faeaf66
Fixed something in dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
524
diff
changeset
|
410 auto begin = token; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
411 nT(); |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
412 auto decls = new CompoundDeclaration; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
413 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
|
414 decls ~= parseDeclarationDefinition(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
415 require(T.RBrace); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
416 d = set(decls, begin); |
122 | 417 break; |
418 case T.Colon: | |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
419 // if (noColon == true) |
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
420 // goto default; |
122 | 421 nT(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
422 auto begin = token; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
423 auto decls = new CompoundDeclaration; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
424 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
|
425 decls ~= parseDeclarationDefinition(); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
426 d = set(decls, begin); |
122 | 427 break; |
428 default: | |
305 | 429 d = parseDeclarationDefinition(); |
122 | 430 } |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
431 assert(isNodeSet(d)); |
305 | 432 return d; |
122 | 433 } |
434 | |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
435 // Declaration parseDeclarationsBlockNoColon() |
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
436 // { |
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
437 // return parseDeclarationsBlock(true); |
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
438 // } |
404
fe46b5ea7a18
Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
400
diff
changeset
|
439 |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
440 /++ |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
441 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
|
442 Params: |
555
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
443 stc = previously parsed storage classes |
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
444 protection = previously parsed protection attribute |
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
445 linkType = previously parsed linkage type |
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
446 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
|
447 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
|
448 +/ |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
449 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
|
450 Protection protection = Protection.None, |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
451 LinkageType linkType = LinkageType.None, |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
452 bool testAutoDeclaration = false, |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
453 bool optionalParameterList = true) |
192 | 454 { |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
455 auto begin = token; |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
456 Type type; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
457 Identifier* name; |
192 | 458 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
459 // Check for AutoDeclaration: StorageClasses Identifier = |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
460 if (testAutoDeclaration && |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
461 token.kind == T.Identifier && |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
462 peekNext() == T.Assign) |
192 | 463 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
464 name = token.ident; |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
465 skip(T.Identifier); |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
466 } |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
467 else |
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
468 { |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
469 type = parseType(); // VariableType or ReturnType |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
470 if (token.kind == T.LParen) |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
471 { |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
472 // 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
|
473 // 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
|
474 // Example: |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
475 // void foo() { |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
476 // // 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
|
477 // some_type (*p_func)(int); |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
478 // // 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
|
479 // 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
|
480 // } |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
481 // // 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
|
482 // something(*p); |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
483 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
|
484 } |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
485 else if (peekNext() == T.LParen) |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
486 { // Type FunctionName ( ParameterList ) FunctionBody |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
487 name = requireIdentifier(MSG.ExpectedFunctionName); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
488 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
|
489 assert(token.kind == T.LParen); |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
490 // It's a function declaration |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
491 TemplateParameters tparams; |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
492 if (tokenAfterParenIs(T.LParen)) |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
493 // ( TemplateParameterList ) ( ParameterList ) |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
494 tparams = parseTemplateParameterList(); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
495 |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
496 auto params = parseParameterList(); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
497 version(D2) |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
498 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
499 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
|
500 { |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
501 case T.Const: |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
502 stc |= StorageClass.Const; |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
503 nT(); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
504 break; |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
505 case T.Invariant: |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
506 stc |= StorageClass.Invariant; |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
507 nT(); |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
508 break; |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
509 default: |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
510 } |
202
8aecf8925c5f
- Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents:
201
diff
changeset
|
511 } |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
512 // ReturnType FunctionName ( ParameterList ) |
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
513 auto funcBody = parseFunctionBody(); |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
514 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
|
515 fd.setStorageClass(stc); |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
516 fd.setLinkageType(linkType); |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
517 fd.setProtection(protection); |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
518 if (tparams) |
765
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
519 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
520 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
|
521 d.setStorageClass(stc); |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
522 d.setProtection(protection); |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
523 return set(d, begin); |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
524 } |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
525 return set(fd, begin); |
530
4b783fa06277
Unindented if-block in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
529
diff
changeset
|
526 } |
535
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
527 else |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
528 { // Type VariableName DeclaratorSuffix |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
529 name = requireIdentifier(MSG.ExpectedVariableName); |
535
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
530 type = parseDeclaratorSuffix(type); |
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
531 } |
192 | 532 } |
533 | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
534 // It's a variables declaration. |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
535 Identifier*[] names = [name]; // One identifier has been parsed already. |
194 | 536 Expression[] values; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
537 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
|
538 while (consumed(T.Comma)) |
194 | 539 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
540 names ~= requireIdentifier(MSG.ExpectedVariableName); |
194 | 541 LenterLoop: |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
542 if (consumed(T.Assign)) |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
543 values ~= parseInitializer(); |
199
a95fee6e4b7e
- Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents:
198
diff
changeset
|
544 else |
a95fee6e4b7e
- Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents:
198
diff
changeset
|
545 values ~= null; |
194 | 546 } |
547 require(T.Semicolon); | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
548 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
|
549 d.setStorageClass(stc); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
550 d.setLinkageType(linkType); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
551 d.setProtection(protection); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
552 return set(d, begin); |
194 | 553 } |
192 | 554 |
194 | 555 Expression parseInitializer() |
556 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
557 if (token.kind == T.Void) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
558 { |
266 | 559 auto begin = token; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
560 auto next = peekNext(); |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
561 if (next == T.Comma || next == T.Semicolon) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
562 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
563 skip(T.Void); |
695
170ddcdc9711
Renamed VoidInitializer, ArrayInitializer and StructInitializer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
564 return set(new VoidInitExpression(), begin); |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
565 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
566 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
567 return parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
568 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
569 |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
570 Expression parseNonVoidInitializer() |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
571 { |
266 | 572 auto begin = token; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
573 Expression init; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
574 switch (token.kind) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
575 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
576 case T.LBracket: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
577 // ArrayInitializer: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
578 // [ ] |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
579 // [ ArrayMemberInitializations ] |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
580 Expression[] keys; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
581 Expression[] values; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
582 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
583 skip(T.LBracket); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
584 while (token.kind != T.RBracket) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
585 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
586 auto e = parseNonVoidInitializer(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
587 if (consumed(T.Colon)) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
588 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
589 keys ~= e; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
590 values ~= parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
591 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
592 else |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
593 { |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
594 keys ~= null; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
595 values ~= e; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
596 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
597 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
598 if (!consumed(T.Comma)) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
599 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
600 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
601 require(T.RBracket); |
695
170ddcdc9711
Renamed VoidInitializer, ArrayInitializer and StructInitializer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
602 init = new ArrayInitExpression(keys, values); |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
603 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
604 case T.LBrace: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
605 // StructInitializer: |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
606 // { } |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
607 // { StructMemberInitializers } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
608 Expression parseStructInitializer() |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
609 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
610 Identifier*[] idents; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
611 Expression[] values; |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
612 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
613 skip(T.LBrace); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
614 while (token.kind != T.RBrace) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
615 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
616 if (token.kind == T.Identifier && |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
617 // 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
|
618 peekNext() == T.Colon) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
619 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
620 idents ~= token.ident; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
621 skip(T.Identifier), skip(T.Colon); |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
622 } |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
623 else |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
624 idents ~= null; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
625 |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
626 // NonVoidInitializer |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
627 values ~= parseNonVoidInitializer(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
628 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
629 if (!consumed(T.Comma)) |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
630 break; |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
631 } |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
632 require(T.RBrace); |
695
170ddcdc9711
Renamed VoidInitializer, ArrayInitializer and StructInitializer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
683
diff
changeset
|
633 return new StructInitExpression(idents, values); |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
634 } |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
635 |
214 | 636 bool success; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
637 auto si = try_(&parseStructInitializer, success); |
214 | 638 if (success) |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
639 { |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
640 init = si; |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
641 break; |
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
642 } |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
643 assert(token.kind == T.LBrace); |
200
61f60112ac63
- Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents:
199
diff
changeset
|
644 //goto default; |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
645 default: |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
646 init = parseAssignExpression(); |
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
647 } |
266 | 648 set(init, begin); |
198
88c1777a9e51
- Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents:
197
diff
changeset
|
649 return init; |
192 | 650 } |
651 | |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
652 FuncBodyStatement parseFunctionBody() |
192 | 653 { |
268 | 654 auto begin = token; |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
655 auto func = new FuncBodyStatement; |
192 | 656 while (1) |
657 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
658 switch (token.kind) |
192 | 659 { |
660 case T.LBrace: | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
661 func.funcBody = parseStatements(); |
192 | 662 break; |
663 case T.Semicolon: | |
664 nT(); | |
665 break; | |
666 case T.In: | |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
667 if (func.inBody) |
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
668 error(MID.InContract); |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
669 nT(); |
192 | 670 func.inBody = parseStatements(); |
671 continue; | |
672 case T.Out: | |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
673 if (func.outBody) |
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
674 error(MID.OutContract); |
192 | 675 nT(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
676 if (consumed(T.LParen)) |
192 | 677 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
678 func.outIdent = requireIdentifier(MSG.ExpectedAnIdentifier); |
192 | 679 require(T.RParen); |
680 } | |
681 func.outBody = parseStatements(); | |
682 continue; | |
683 case T.Body: | |
684 nT(); | |
685 goto case T.LBrace; | |
686 default: | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
687 error(token, MSG.ExpectedFunctionBody, token.srcText); |
192 | 688 } |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
689 break; // Exit loop. |
192 | 690 } |
268 | 691 set(func, begin); |
299
559d5d62e0c1
- Added checks for null before adding member to Node.children.
aziz
parents:
298
diff
changeset
|
692 func.finishConstruction(); |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
693 return func; |
192 | 694 } |
695 | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
696 LinkageType parseLinkageType() |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
697 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
698 LinkageType linkageType; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
699 |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
700 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
|
701 return linkageType; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
702 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
703 if (consumed(T.RParen)) |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
704 { // extern() |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
705 error(MID.MissingLinkageType); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
706 return linkageType; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
707 } |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
708 |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
709 auto identTok = requireId(); |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
710 |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
711 IDK idKind = identTok ? identTok.ident.idKind : IDK.Null; |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
712 |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
713 switch (idKind) |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
714 { |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
715 case IDK.C: |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
716 if (consumed(T.PlusPlus)) |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
717 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
718 linkageType = LinkageType.Cpp; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
719 break; |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
720 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
721 linkageType = LinkageType.C; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
722 break; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
723 case IDK.D: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
724 linkageType = LinkageType.D; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
725 break; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
726 case IDK.Windows: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
727 linkageType = LinkageType.Windows; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
728 break; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
729 case IDK.Pascal: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
730 linkageType = LinkageType.Pascal; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
731 break; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
732 case IDK.System: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
733 linkageType = LinkageType.System; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
734 break; |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
735 default: |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
736 error(MID.UnrecognizedLinkageType, token.srcText); |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
737 } |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
738 require(T.RParen); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
739 return linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
740 } |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
741 |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
742 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
|
743 { |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
744 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
|
745 prev_lt = lt; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
746 else |
616
506ce60760d8
Fixed some error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
608
diff
changeset
|
747 error(begin, MSG.RedundantLinkageType, Token.textSpan(begin, this.prevToken)); |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
748 } |
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
749 |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
750 Declaration parseStorageAttribute() |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
751 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
752 StorageClass stc, stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
753 LinkageType prev_linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
754 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
755 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
|
756 // Nested function. |
305 | 757 Declaration parse() |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
758 { |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
759 Declaration decl; |
359
511c14950cac
- Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents:
358
diff
changeset
|
760 auto begin = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
761 switch (token.kind) |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
762 { |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
763 case T.Extern: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
764 if (peekNext() != T.LParen) |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
765 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
766 stc_tmp = StorageClass.Extern; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
767 goto Lcommon; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
768 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
769 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
770 nT(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
771 auto linkageType = parseLinkageType(); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
772 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
|
773 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
774 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
|
775 this.linkageType = linkageType; // Set. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
776 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
|
777 set(decl, begin); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
778 this.linkageType = saved; // Restore. |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
779 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
780 case T.Override: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
781 stc_tmp = StorageClass.Override; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
782 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
783 case T.Deprecated: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
784 stc_tmp = StorageClass.Deprecated; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
785 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
786 case T.Abstract: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
787 stc_tmp = StorageClass.Abstract; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
788 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
789 case T.Synchronized: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
790 stc_tmp = StorageClass.Synchronized; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
791 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
792 case T.Static: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
793 stc_tmp = StorageClass.Static; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
794 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
795 case T.Final: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
796 stc_tmp = StorageClass.Final; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
797 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
798 case T.Const: |
269 | 799 version(D2) |
800 { | |
801 if (peekNext() == T.LParen) | |
802 goto case_Declaration; | |
803 } | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
804 stc_tmp = StorageClass.Const; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
805 goto Lcommon; |
269 | 806 version(D2) |
807 { | |
808 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
|
809 auto next = token; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
810 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
|
811 { |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
812 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
|
813 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
|
814 decl = parseDeclarationDefinition(); // invariant ( ) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
815 decl.setStorageClass(stc); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
816 break; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
817 } |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
818 // invariant as StorageClass. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
819 stc_tmp = StorageClass.Invariant; |
269 | 820 goto Lcommon; |
821 } | |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
822 case T.Auto: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
823 stc_tmp = StorageClass.Auto; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
824 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
825 case T.Scope: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
826 stc_tmp = StorageClass.Scope; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
827 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
828 Lcommon: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
829 // Issue error if redundant. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
830 if (stc & stc_tmp) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
831 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
|
832 else |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
833 stc |= stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
834 |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
835 nT(); |
650
eb490ba8dba0
Made AttributeDeclaration abstract.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
646
diff
changeset
|
836 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
|
837 set(decl, begin); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
838 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
839 case T.Identifier: |
269 | 840 case_Declaration: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
841 // 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
|
842 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
|
843 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
844 default: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
845 this.storageClass = stc; // Set. |
305 | 846 decl = parseDeclarationsBlock(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
847 this.storageClass = saved_storageClass; // Reset. |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
848 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
849 assert(isNodeSet(decl)); |
305 | 850 return decl; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
851 } |
305 | 852 return parse(); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
853 } |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
854 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
855 uint parseAlignAttribute() |
260 | 856 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
857 skip(T.Align); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
858 uint size = DEFAULT_ALIGN_SIZE; // Global default. |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
859 if (consumed(T.LParen)) |
260 | 860 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
861 if (token.kind == T.Int32) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
862 (size = token.int_), skip(T.Int32); |
260 | 863 else |
864 expected(T.Int32); | |
865 require(T.RParen); | |
866 } | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
867 return size; |
260 | 868 } |
869 | |
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
|
870 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
|
871 { |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
872 Declaration decl; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
873 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
874 switch (token.kind) |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
875 { |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
876 case T.Align: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
877 uint alignSize = parseAlignAttribute(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
878 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
|
879 this.alignSize = alignSize; // Set. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
880 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
|
881 this.alignSize = saved; // Restore. |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
882 break; |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
883 case T.Pragma: |
147 | 884 // Pragma: |
885 // pragma ( Identifier ) | |
886 // pragma ( Identifier , ExpressionList ) | |
887 nT(); | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
888 Identifier* ident; |
147 | 889 Expression[] args; |
890 | |
891 require(T.LParen); | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
892 ident = requireIdentifier(MSG.ExpectedPragmaIdentifier); |
147 | 893 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
894 if (consumed(T.Comma)) |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
895 args = parseExpressionList(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
896 require(T.RParen); |
147 | 897 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
898 decl = new PragmaDeclaration(ident, args, parseDeclarationsBlock()); |
147 | 899 break; |
491
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
900 default: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
901 // Protection attributes |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
902 Protection prot; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
903 switch (token.kind) |
491
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
904 { |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
905 case T.Private: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
906 prot = Protection.Private; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
907 case T.Package: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
908 prot = Protection.Package; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
909 case T.Protected: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
910 prot = Protection.Protected; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
911 case T.Public: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
912 prot = Protection.Public; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
913 case T.Export: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
914 prot = Protection.Export; break; |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
915 default: |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
916 assert(0); |
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
917 } |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
918 nT(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
919 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
|
920 this.protection = prot; // Set. |
491
b991f49628a8
Forgot committing Parser.d as well.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
489
diff
changeset
|
921 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
|
922 this.protection = saved; // Restore. |
146
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
923 } |
8180eb84e69c
- Started implementation of parseAttributeSpecifier().
aziz
parents:
145
diff
changeset
|
924 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
|
925 } |
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 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
|
928 { |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
929 bool isStatic = consumed(T.Static); |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
930 skip(T.Import); |
429
052cbacb1642
Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
424
diff
changeset
|
931 |
364 | 932 ModuleFQN[] moduleFQNs; |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
933 Identifier*[] moduleAliases; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
934 Identifier*[] bindNames; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
935 Identifier*[] bindAliases; |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
936 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
937 do |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
938 { |
364 | 939 ModuleFQN moduleFQN; |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
940 Identifier* moduleAlias; |
115
cea36caeec42
- Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents:
114
diff
changeset
|
941 // AliasName = ModuleName |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
942 if (peekNext() == T.Assign) |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
943 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
944 moduleAlias = requireIdentifier(MSG.ExpectedAliasModuleName); |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
945 skip(T.Assign); |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
946 } |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
947 // Identifier ("." Identifier)* |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
948 do |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
949 moduleFQN ~= requireIdentifier(MSG.ExpectedModuleIdentifier); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
950 while (consumed(T.Dot)) |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
951 // Push identifiers. |
364 | 952 moduleFQNs ~= moduleFQN; |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
953 moduleAliases ~= moduleAlias; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
954 } while (consumed(T.Comma)) |
298 | 955 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
956 if (consumed(T.Colon)) |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
957 { // BindAlias "=" BindName ("," BindAlias "=" BindName)*; |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
958 // BindName ("," BindName)*; |
320
0ce14640eb04
- Fix in parseImportDeclaration(): rewrote while loop and removed a call to nT().
aziz
parents:
319
diff
changeset
|
959 do |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
960 { |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
961 Identifier* bindAlias; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
962 // BindAlias = BindName |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
963 if (peekNext() == T.Assign) |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
964 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
965 bindAlias = requireIdentifier(MSG.ExpectedAliasImportName); |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
966 skip(T.Assign); |
298 | 967 } |
968 // Push identifiers. | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
969 bindNames ~= requireIdentifier(MSG.ExpectedImportName); |
298 | 970 bindAliases ~= bindAlias; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
971 } while (consumed(T.Comma)) |
298 | 972 } |
114
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
973 require(T.Semicolon); |
83bb5190c0fc
- Completed implementation of parseImportDeclaration().
aziz
parents:
113
diff
changeset
|
974 |
366 | 975 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
|
976 } |
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 |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
978 Declaration parseEnumDeclaration() |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
979 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
980 skip(T.Enum); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
981 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
982 Identifier* enumName; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
983 Type baseType; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
984 EnumMemberDeclaration[] members; |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
985 bool hasBody; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
986 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
987 enumName = optionalIdentifier(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
988 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
989 if (consumed(T.Colon)) |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
990 baseType = parseBasicType(); |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
991 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
992 if (enumName && consumed(T.Semicolon)) |
639
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
993 {} |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
994 else if (consumed(T.LBrace)) |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
995 { |
126
0f0e7352e91d
- Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents:
125
diff
changeset
|
996 hasBody = true; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
997 while (token.kind != T.RBrace) |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
998 { |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
999 auto begin = token; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1000 auto name = requireIdentifier(MSG.ExpectedEnumMember); |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1001 Expression value; |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1002 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1003 if (consumed(T.Assign)) |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1004 value = parseAssignExpression(); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1005 else |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1006 value = null; |
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1007 |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1008 members ~= set(new EnumMemberDeclaration(name, value), begin); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1009 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1010 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
|
1011 break; |
398
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1012 } |
f7bb892d64c2
Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
1013 require(T.RBrace); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1014 } |
231 | 1015 else |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1016 error(token, MSG.ExpectedEnumBody, token.srcText); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1017 |
406
e242f0ee2d27
Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
405
diff
changeset
|
1018 return new EnumDeclaration(enumName, baseType, members, hasBody); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1019 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1020 |
765
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1021 /// 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
|
1022 /// Params: |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1023 /// begin = begin token of decl. |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1024 /// name = name of decl. |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1025 /// 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
|
1026 /// tparams = the template parameters. |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1027 TemplateDeclaration putInsideTemplateDeclaration(Token* begin, |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1028 Identifier* name, |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1029 Declaration decl, |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1030 TemplateParameters tparams) |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1031 { |
765
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1032 set(decl, begin); |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1033 auto cd = new CompoundDeclaration; |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1034 cd ~= decl; |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1035 set(cd, begin); |
bc812843603c
Template functions are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
762
diff
changeset
|
1036 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
|
1037 } |
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1038 |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1039 Declaration parseClassDeclaration() |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1040 { |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1041 auto begin = token; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1042 skip(T.Class); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1043 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1044 Identifier* className; |
258 | 1045 TemplateParameters tparams; |
668
a1f8d8f2db38
Renamed some identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
659
diff
changeset
|
1046 BaseClassType[] bases; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1047 CompoundDeclaration decls; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1048 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1049 className = requireIdentifier(MSG.ExpectedClassName); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1050 |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
1051 if (token.kind == T.LParen) |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
1052 tparams = parseTemplateParameterList(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1053 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1054 if (token.kind == T.Colon) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1055 bases = parseBaseClasses(); |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1056 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1057 if (bases.length == 0 && consumed(T.Semicolon)) |
639
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
1058 {} |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1059 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
|
1060 decls = parseDeclarationDefinitionsBody(); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1061 else |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1062 error(token, MSG.ExpectedClassBody, token.srcText); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1063 |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1064 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
|
1065 if (tparams) |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1066 d = putInsideTemplateDeclaration(begin, className, d, tparams); |
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1067 return d; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1068 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1069 |
668
a1f8d8f2db38
Renamed some identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
659
diff
changeset
|
1070 BaseClassType[] parseBaseClasses(bool colonLeadsOff = true) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1071 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1072 colonLeadsOff && skip(T.Colon); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1073 |
668
a1f8d8f2db38
Renamed some identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
659
diff
changeset
|
1074 BaseClassType[] bases; |
646
68953760d569
Added class ParenExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
640
diff
changeset
|
1075 do |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1076 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1077 Protection prot = Protection.Public; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1078 switch (token.kind) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1079 { |
204 | 1080 case T.Identifier, T.Dot, T.Typeof: goto LparseBasicType; |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1081 case T.Private: prot = Protection.Private; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1082 case T.Protected: prot = Protection.Protected; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1083 case T.Package: prot = Protection.Package; break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1084 case T.Public: /*prot = Protection.Public;*/ break; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1085 default: |
405
e2529923a0cb
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
404
diff
changeset
|
1086 error(MID.ExpectedBaseClasses, token.srcText); |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1087 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1088 } |
158
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1089 nT(); // Skip protection attribute. |
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1090 LparseBasicType: |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1091 auto begin = token; |
158
759f437313f9
- Moved enum Protection and class BaseClass to module Types.
aziz
parents:
157
diff
changeset
|
1092 auto type = parseBasicType(); |
668
a1f8d8f2db38
Renamed some identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
659
diff
changeset
|
1093 bases ~= set(new BaseClassType(prot, type), begin); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1094 } while (consumed(T.Comma)) |
109
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1095 return bases; |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1096 } |
d0cc281cacbd
- Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents:
108
diff
changeset
|
1097 |
112 | 1098 Declaration parseInterfaceDeclaration() |
1099 { | |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1100 auto begin = token; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1101 skip(T.Interface); |
112 | 1102 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1103 Identifier* name; |
258 | 1104 TemplateParameters tparams; |
668
a1f8d8f2db38
Renamed some identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
659
diff
changeset
|
1105 BaseClassType[] bases; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1106 CompoundDeclaration decls; |
112 | 1107 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1108 name = requireIdentifier(MSG.ExpectedInterfaceName); |
112 | 1109 |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
1110 if (token.kind == T.LParen) |
195
37c2ffd649c4
- Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents:
194
diff
changeset
|
1111 tparams = parseTemplateParameterList(); |
112 | 1112 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1113 if (token.kind == T.Colon) |
112 | 1114 bases = parseBaseClasses(); |
1115 | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1116 if (bases.length == 0 && consumed(T.Semicolon)) |
639
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
1117 {} |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1118 else if (token.kind == T.LBrace) |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1119 decls = parseDeclarationDefinitionsBody(); |
112 | 1120 else |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1121 error(token, MSG.ExpectedInterfaceBody, token.srcText); |
112 | 1122 |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1123 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
|
1124 if (tparams) |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1125 d = putInsideTemplateDeclaration(begin, name, d, tparams); |
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1126 return d; |
112 | 1127 } |
1128 | |
638
7131c07997f9
Renamed parseAggregateDeclaration() to parseStructOrUnionDeclaration().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
637
diff
changeset
|
1129 Declaration parseStructOrUnionDeclaration() |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1130 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1131 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
|
1132 auto begin = token; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1133 skip(token.kind); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1134 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1135 Identifier* name; |
258 | 1136 TemplateParameters tparams; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1137 CompoundDeclaration decls; |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1138 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1139 name = optionalIdentifier(); |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1140 |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
1141 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
|
1142 tparams = parseTemplateParameterList(); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1143 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1144 if (name && consumed(T.Semicolon)) |
639
1b1315ac27a4
Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
638
diff
changeset
|
1145 {} |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1146 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
|
1147 decls = parseDeclarationDefinitionsBody(); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1148 else |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1149 error(token, begin.kind == T.Struct ? |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
1150 MSG.ExpectedStructBody : |
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
1151 MSG.ExpectedUnionBody, token.srcText); |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1152 |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1153 Declaration d; |
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1154 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
|
1155 { |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1156 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
|
1157 sd.setAlignSize(this.alignSize); |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1158 d = sd; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1159 } |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1160 else |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1161 d = new UnionDeclaration(name, /+tparams, +/decls); |
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1162 |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
1163 if (tparams) |
726
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1164 d = putInsideTemplateDeclaration(begin, name, d, tparams); |
7917811f8116
AggregateDeclarations are wrapped inside TemplateDeclarations now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
706
diff
changeset
|
1165 return d; |
113
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1166 } |
20d8ae8a3fd9
- Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents:
112
diff
changeset
|
1167 |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1168 Declaration parseConstructorDeclaration() |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1169 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1170 skip(T.This); |
143 | 1171 auto parameters = parseParameterList(); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1172 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1173 return new ConstructorDeclaration(parameters, funcBody); |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1174 } |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
1175 |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1176 Declaration parseDestructorDeclaration() |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1177 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1178 skip(T.Tilde); |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1179 require(T.This); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1180 require(T.LParen); |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1181 require(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1182 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1183 return new DestructorDeclaration(funcBody); |
118
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1184 } |
379f33cbd521
- Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents:
117
diff
changeset
|
1185 |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1186 Declaration parseStaticConstructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1187 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1188 skip(T.Static); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1189 skip(T.This); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1190 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1191 require(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1192 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1193 return new StaticConstructorDeclaration(funcBody); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1194 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1195 |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1196 Declaration parseStaticDestructorDeclaration() |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1197 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1198 skip(T.Static); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1199 skip(T.Tilde); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1200 require(T.This); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1201 require(T.LParen); |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1202 require(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1203 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1204 return new StaticDestructorDeclaration(funcBody); |
119
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1205 } |
363cd39022f9
- Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents:
118
diff
changeset
|
1206 |
120 | 1207 Declaration parseInvariantDeclaration() |
1208 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1209 skip(T.Invariant); |
120 | 1210 // 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
|
1211 if (consumed(T.LParen)) |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1212 require(T.RParen); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1213 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1214 return new InvariantDeclaration(funcBody); |
120 | 1215 } |
1216 | |
121 | 1217 Declaration parseUnittestDeclaration() |
1218 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1219 skip(T.Unittest); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1220 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1221 return new UnittestDeclaration(funcBody); |
121 | 1222 } |
1223 | |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1224 Token* parseIdentOrInt() |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1225 { |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1226 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
|
1227 return this.prevToken; |
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1228 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
|
1229 return null; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1230 } |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1231 |
122 | 1232 Declaration parseDebugDeclaration() |
1233 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1234 skip(T.Debug); |
122 | 1235 |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1236 Token* spec; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1237 Token* cond; |
305 | 1238 Declaration decls, elseDecls; |
122 | 1239 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1240 if (consumed(T.Assign)) |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1241 { // debug = Integer ; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1242 // debug = Identifier ; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1243 spec = parseIdentOrInt(); |
122 | 1244 require(T.Semicolon); |
1245 } | |
1246 else | |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1247 { // ( Condition ) |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1248 if (consumed(T.LParen)) |
122 | 1249 { |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1250 cond = parseIdentOrInt(); |
122 | 1251 require(T.RParen); |
1252 } | |
123 | 1253 // debug DeclarationsBlock |
1254 // debug ( Condition ) DeclarationsBlock | |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
1255 decls = parseDeclarationsBlock(); |
123 | 1256 // else DeclarationsBlock |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1257 if (consumed(T.Else)) |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
1258 elseDecls = parseDeclarationsBlock(); |
123 | 1259 } |
1260 | |
264 | 1261 return new DebugDeclaration(spec, cond, decls, elseDecls); |
123 | 1262 } |
1263 | |
1264 Declaration parseVersionDeclaration() | |
1265 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1266 skip(T.Version); |
123 | 1267 |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1268 Token* spec; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1269 Token* cond; |
305 | 1270 Declaration decls, elseDecls; |
122 | 1271 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1272 if (consumed(T.Assign)) |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1273 { // version = Integer ; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1274 // version = Identifier ; |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1275 spec = parseIdentOrInt(); |
123 | 1276 require(T.Semicolon); |
1277 } | |
1278 else | |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1279 { // ( Condition ) |
123 | 1280 require(T.LParen); |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
1281 cond = parseIdentOrInt(); |
123 | 1282 require(T.RParen); |
1283 // version ( Condition ) DeclarationsBlock | |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
1284 decls = parseDeclarationsBlock(); |
123 | 1285 // else DeclarationsBlock |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1286 if (consumed(T.Else)) |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
1287 elseDecls = parseDeclarationsBlock(); |
122 | 1288 } |
1289 | |
264 | 1290 return new VersionDeclaration(spec, cond, decls, elseDecls); |
122 | 1291 } |
1292 | |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1293 Declaration parseStaticIfDeclaration() |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1294 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1295 skip(T.Static); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1296 skip(T.If); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1297 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1298 Expression condition; |
305 | 1299 Declaration ifDecls, elseDecls; |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1300 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1301 require(T.LParen); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1302 condition = parseAssignExpression(); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1303 require(T.RParen); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1304 |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
1305 ifDecls = parseDeclarationsBlock(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1306 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1307 if (consumed(T.Else)) |
750
40a52ea29e3b
Commented out parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
749
diff
changeset
|
1308 elseDecls = parseDeclarationsBlock(); |
125
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1309 |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1310 return new StaticIfDeclaration(condition, ifDecls, elseDecls); |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1311 } |
240a8b053803
- Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents:
124
diff
changeset
|
1312 |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1313 Declaration parseStaticAssertDeclaration() |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1314 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1315 skip(T.Static); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1316 skip(T.Assert); |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1317 Expression condition, message; |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1318 require(T.LParen); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1319 condition = parseAssignExpression(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1320 if (consumed(T.Comma)) |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1321 message = parseAssignExpression(); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1322 require(T.RParen); |
128 | 1323 require(T.Semicolon); |
127
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1324 return new StaticAssertDeclaration(condition, message); |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1325 } |
cb9a97ebb570
- Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents:
126
diff
changeset
|
1326 |
140 | 1327 Declaration parseTemplateDeclaration() |
1328 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1329 skip(T.Template); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1330 auto templateName = requireIdentifier(MSG.ExpectedTemplateName); |
143 | 1331 auto templateParams = parseTemplateParameterList(); |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1332 auto decls = parseDeclarationDefinitionsBody(); |
140 | 1333 return new TemplateDeclaration(templateName, templateParams, decls); |
1334 } | |
1335 | |
141 | 1336 Declaration parseNewDeclaration() |
1337 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1338 skip(T.New); |
143 | 1339 auto parameters = parseParameterList(); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1340 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1341 return new NewDeclaration(parameters, funcBody); |
141 | 1342 } |
1343 | |
1344 Declaration parseDeleteDeclaration() | |
1345 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1346 skip(T.Delete); |
143 | 1347 auto parameters = parseParameterList(); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
1348 auto funcBody = parseFunctionBody(); |
197
ff32eb87300e
- Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents:
196
diff
changeset
|
1349 return new DeleteDeclaration(parameters, funcBody); |
141 | 1350 } |
1351 | |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1352 Type parseTypeofType() |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1353 { |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1354 auto begin = token; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1355 skip(T.Typeof); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1356 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
|
1357 Type type; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1358 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
|
1359 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1360 version(D2) |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1361 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1362 case T.Return: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1363 nT(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1364 type = new TypeofType(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1365 break; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1366 } |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1367 default: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1368 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
|
1369 } |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1370 require(T.RParen); |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1371 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
|
1372 return type; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1373 } |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
1374 |
704
ff4643a4a97c
Wrote code for SemanticPass2.visit(MixinDeclaration).
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
695
diff
changeset
|
1375 /++ |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1376 TemplateMixin: |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1377 mixin ( AssignExpression ) ; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1378 mixin TemplateIdentifier ; |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1379 mixin TemplateIdentifier MixinIdentifier ; |
233 | 1380 mixin TemplateIdentifier !( TemplateArguments ) ; |
1381 mixin TemplateIdentifier !( TemplateArguments ) MixinIdentifier ; | |
704
ff4643a4a97c
Wrote code for SemanticPass2.visit(MixinDeclaration).
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
695
diff
changeset
|
1382 +/ |
256 | 1383 Class parseMixin(Class)() |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1384 { |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
1385 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
|
1386 skip(T.Mixin); |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1387 |
256 | 1388 static if (is(Class == MixinDeclaration)) |
301
caef255a2801
- Fix in some ctors: adding only non-null members to this.children.
aziz
parents:
299
diff
changeset
|
1389 { |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1390 if (consumed(T.LParen)) |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1391 { |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1392 auto e = parseAssignExpression(); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1393 require(T.RParen); |
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1394 require(T.Semicolon); |
262 | 1395 return new MixinDeclaration(e); |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1396 } |
301
caef255a2801
- Fix in some ctors: adding only non-null members to this.children.
aziz
parents:
299
diff
changeset
|
1397 } |
151
2e959f67000b
- Added code for parsing mixin expression declarations.
aziz
parents:
150
diff
changeset
|
1398 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1399 auto begin = token; |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1400 Expression e; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1401 Identifier* mixinIdent; |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1402 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1403 if (consumed(T.Dot)) |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1404 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
|
1405 else |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1406 e = parseIdentifierExpression(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1407 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1408 while (consumed(T.Dot)) |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1409 e = set(new DotExpression(e, parseIdentifierExpression()), begin); |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1410 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1411 mixinIdent = optionalIdentifier(); |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1412 require(T.Semicolon); |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1413 |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
1414 return new Class(e, mixinIdent); |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1415 } |
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
1416 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
1417 /+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
1418 | Statement parsing methods | |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
1419 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+/ |
161 | 1420 |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1421 CompoundStatement parseStatements() |
161 | 1422 { |
262 | 1423 auto begin = token; |
318 | 1424 require(T.LBrace); |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1425 auto statements = new CompoundStatement(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1426 while (token.kind != T.RBrace && token.kind != T.EOF) |
161 | 1427 statements ~= parseStatement(); |
318 | 1428 require(T.RBrace); |
262 | 1429 return set(statements, begin); |
161 | 1430 } |
1431 | |
1432 Statement parseStatement() | |
1433 { | |
261 | 1434 auto begin = token; |
161 | 1435 Statement s; |
188 | 1436 Declaration d; |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1437 |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1438 if (token.isIntegralType) |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1439 { |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1440 d = parseVariableOrFunction(); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1441 goto LreturnDeclarationStatement; |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1442 } |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1443 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1444 switch (token.kind) |
161 | 1445 { |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1446 case T.Align: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1447 uint size = parseAlignAttribute(); |
260 | 1448 // 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
|
1449 StructDeclaration structDecl; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1450 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
|
1451 { |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1452 auto begin2 = token; |
638
7131c07997f9
Renamed parseAggregateDeclaration() to parseStructOrUnionDeclaration().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
637
diff
changeset
|
1453 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
|
1454 structDecl.setAlignSize(size); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1455 set(structDecl, begin2); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1456 } |
260 | 1457 else |
1458 expected(T.Struct); | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1459 |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1460 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
|
1461 goto LreturnDeclarationStatement; |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1462 /+ Not applicable for statements. |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1463 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
|
1464 T.Deprecated, T.Override, T.Abstract,+/ |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1465 case T.Extern, |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1466 T.Final, |
191
3ce110cefbc5
- Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents:
190
diff
changeset
|
1467 T.Const, |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1468 T.Auto: |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1469 //T.Scope |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1470 //T.Static |
201 | 1471 case_parseAttribute: |
1472 s = parseAttributeStatement(); | |
261 | 1473 return s; |
161 | 1474 case T.Identifier: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1475 if (peekNext() == T.Colon) |
161 | 1476 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1477 auto ident = token.ident; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1478 skip(T.Identifier); skip(T.Colon); |
234 | 1479 s = new LabeledStatement(ident, parseNoScopeOrEmptyStatement()); |
161 | 1480 break; |
1481 } | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1482 goto case T.Dot; |
201 | 1483 case T.Dot, T.Typeof: |
214 | 1484 bool success; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1485 d = try_(delegate { |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1486 return parseVariableOrFunction(StorageClass.None, |
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1487 Protection.None, |
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1488 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
|
1489 }, success |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1490 ); |
214 | 1491 if (success) |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1492 goto LreturnDeclarationStatement; // Declaration |
201 | 1493 else |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1494 goto case_parseExpressionStatement; // Expression |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
1495 |
162 | 1496 case T.If: |
1497 s = parseIfStatement(); | |
1498 break; | |
164 | 1499 case T.While: |
1500 s = parseWhileStatement(); | |
1501 break; | |
165 | 1502 case T.Do: |
1503 s = parseDoWhileStatement(); | |
1504 break; | |
216 | 1505 case T.For: |
1506 s = parseForStatement(); | |
1507 break; | |
169 | 1508 case T.Foreach, T.Foreach_reverse: |
1509 s = parseForeachStatement(); | |
1510 break; | |
170 | 1511 case T.Switch: |
1512 s = parseSwitchStatement(); | |
1513 break; | |
171 | 1514 case T.Case: |
1515 s = parseCaseStatement(); | |
1516 break; | |
172 | 1517 case T.Default: |
1518 s = parseDefaultStatement(); | |
1519 break; | |
173 | 1520 case T.Continue: |
1521 s = parseContinueStatement(); | |
1522 break; | |
174 | 1523 case T.Break: |
1524 s = parseBreakStatement(); | |
1525 break; | |
175 | 1526 case T.Return: |
1527 s = parseReturnStatement(); | |
1528 break; | |
176 | 1529 case T.Goto: |
1530 s = parseGotoStatement(); | |
1531 break; | |
177 | 1532 case T.With: |
1533 s = parseWithStatement(); | |
1534 break; | |
178 | 1535 case T.Synchronized: |
1536 s = parseSynchronizedStatement(); | |
1537 break; | |
179 | 1538 case T.Try: |
1539 s = parseTryStatement(); | |
1540 break; | |
180 | 1541 case T.Throw: |
1542 s = parseThrowStatement(); | |
1543 break; | |
181 | 1544 case T.Scope: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1545 if (peekNext() != T.LParen) |
201 | 1546 goto case_parseAttribute; |
181 | 1547 s = parseScopeGuardStatement(); |
1548 break; | |
182 | 1549 case T.Volatile: |
1550 s = parseVolatileStatement(); | |
1551 break; | |
183 | 1552 case T.Asm: |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
1553 s = parseAsmBlockStatement(); |
183 | 1554 break; |
184 | 1555 case T.Pragma: |
1556 s = parsePragmaStatement(); | |
1557 break; | |
185 | 1558 case T.Mixin: |
246
52f4aa097865
- Fix: parse mixin as expression instead of statement when next token is T.LParen.
aziz
parents:
245
diff
changeset
|
1559 if (peekNext() == T.LParen) |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1560 goto case_parseExpressionStatement; // Parse as expression. |
256 | 1561 s = parseMixin!(MixinStatement)(); |
185 | 1562 break; |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1563 case T.Static: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1564 switch (peekNext()) |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1565 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1566 case T.If: |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1567 s = parseStaticIfStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1568 break; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1569 case T.Assert: |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1570 s = parseStaticAssertStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1571 break; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1572 default: |
201 | 1573 goto case_parseAttribute; |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
1574 } |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1575 break; |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1576 case T.Debug: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1577 s = parseDebugStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1578 break; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1579 case T.Version: |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1580 s = parseVersionStatement(); |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
1581 break; |
226
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1582 // DeclDef |
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1583 case T.Alias, T.Typedef: |
aa38e1401217
- Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents:
225
diff
changeset
|
1584 d = parseDeclarationDefinition(); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1585 goto LreturnDeclarationStatement; |
188 | 1586 case T.Enum: |
1587 d = parseEnumDeclaration(); | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1588 goto LreturnDeclarationStatement; |
188 | 1589 case T.Class: |
1590 d = parseClassDeclaration(); | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1591 goto LreturnDeclarationStatement; |
188 | 1592 case T.Interface: |
1593 d = parseInterfaceDeclaration(); | |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1594 goto LreturnDeclarationStatement; |
188 | 1595 case T.Struct, T.Union: |
638
7131c07997f9
Renamed parseAggregateDeclaration() to parseStructOrUnionDeclaration().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
637
diff
changeset
|
1596 d = parseStructOrUnionDeclaration(); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1597 // goto LreturnDeclarationStatement; |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1598 LreturnDeclarationStatement: |
261 | 1599 set(d, begin); |
188 | 1600 s = new DeclarationStatement(d); |
1601 break; | |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1602 case T.LBrace: |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1603 s = parseScopeStatement(); |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
1604 break; |
216 | 1605 case T.Semicolon: |
231 | 1606 nT(); |
216 | 1607 s = new EmptyStatement(); |
1608 break; | |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
1609 // Parse an ExpressionStatement: |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1610 // 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
|
1611 // 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
|
1612 case T.This: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1613 case T.Super: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1614 case T.Null: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1615 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
|
1616 // case T.Dollar: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1617 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
|
1618 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
|
1619 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
|
1620 case T.CharLiteral: |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1621 case T.String: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1622 case T.LBracket: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1623 // case T.LBrace: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1624 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
|
1625 case T.Assert: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1626 // case T.Mixin: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1627 case T.Import: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1628 case T.Typeid: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1629 case T.Is: |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1630 case T.LParen: |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1631 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
|
1632 // 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
|
1633 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
|
1634 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
|
1635 case_parseExpressionStatement: |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1636 s = new ExpressionStatement(parseExpression()); |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1637 require(T.Semicolon); |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1638 break; |
161 | 1639 default: |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1640 if (token.isSpecialToken) |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
1641 goto case_parseExpressionStatement; |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1642 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1643 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
|
1644 // 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
|
1645 assert(delegate bool(){ |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1646 bool success; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1647 auto expression = try_(&parseExpression, success); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1648 return success; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1649 }() == 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
|
1650 ); |
400
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1651 |
a0fa0dcfa50a
Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
399
diff
changeset
|
1652 // 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
|
1653 s = new IllegalStatement(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1654 // Skip to next valid token. |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1655 do |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1656 nT(); |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1657 while (!token.isStatementStart && |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1658 token.kind != T.RBrace && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1659 token.kind != T.EOF) |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1660 auto text = Token.textSpan(begin, this.prevToken); |
616
506ce60760d8
Fixed some error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
608
diff
changeset
|
1661 error(begin, MSG.IllegalStatement, text); |
161 | 1662 } |
205 | 1663 assert(s !is null); |
261 | 1664 set(s, begin); |
161 | 1665 return s; |
1666 } | |
1667 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1668 /++ |
162 | 1669 ScopeStatement: |
219 | 1670 NoScopeStatement |
162 | 1671 +/ |
164 | 1672 Statement parseScopeStatement() |
162 | 1673 { |
219 | 1674 return new ScopeStatement(parseNoScopeStatement()); |
162 | 1675 } |
1676 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1677 /++ |
166 | 1678 NoScopeStatement: |
1679 NonEmptyStatement | |
1680 BlockStatement | |
1681 BlockStatement: | |
1682 { } | |
1683 { StatementList } | |
1684 +/ | |
1685 Statement parseNoScopeStatement() | |
1686 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1687 auto begin = token; |
166 | 1688 Statement s; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1689 if (consumed(T.LBrace)) |
166 | 1690 { |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1691 auto ss = new CompoundStatement(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1692 while (token.kind != T.RBrace && token.kind != T.EOF) |
166 | 1693 ss ~= parseStatement(); |
1694 require(T.RBrace); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1695 s = set(ss, begin); |
166 | 1696 } |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1697 else if (token.kind == T.Semicolon) |
219 | 1698 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1699 error(token, MSG.ExpectedNonEmptyStatement); |
219 | 1700 nT(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1701 s = set(new EmptyStatement(), begin); |
219 | 1702 } |
166 | 1703 else |
1704 s = parseStatement(); | |
1705 return s; | |
1706 } | |
1707 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1708 /++ |
234 | 1709 NoScopeOrEmptyStatement: |
1710 ; | |
1711 NoScopeStatement | |
1712 +/ | |
1713 Statement parseNoScopeOrEmptyStatement() | |
1714 { | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1715 if (consumed(T.Semicolon)) |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
1716 return set(new EmptyStatement(), this.prevToken); |
234 | 1717 else |
1718 return parseNoScopeStatement(); | |
1719 } | |
1720 | |
201 | 1721 Statement parseAttributeStatement() |
1722 { | |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1723 StorageClass stc, stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1724 LinkageType prev_linkageType; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1725 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
1726 Declaration parse() // Nested function. |
201 | 1727 { |
261 | 1728 auto begin = token; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1729 Declaration d; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1730 switch (token.kind) |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1731 { |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1732 case T.Extern: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1733 if (peekNext() != T.LParen) |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1734 { |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1735 stc_tmp = StorageClass.Extern; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1736 goto Lcommon; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1737 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1738 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1739 nT(); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1740 auto linkageType = parseLinkageType(); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
1741 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
|
1742 |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1743 d = new LinkageDeclaration(linkageType, parse()); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1744 break; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1745 case T.Static: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1746 stc_tmp = StorageClass.Static; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1747 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1748 case T.Final: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1749 stc_tmp = StorageClass.Final; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1750 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1751 case T.Const: |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1752 version(D2) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1753 { |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1754 if (peekNext() == T.LParen) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1755 goto case_Declaration; |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1756 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1757 stc_tmp = StorageClass.Const; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1758 goto Lcommon; |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1759 version(D2) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1760 { |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1761 case T.Invariant: // D 2.0 |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1762 if (peekNext() == T.LParen) |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1763 goto case_Declaration; |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1764 stc_tmp = StorageClass.Invariant; |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1765 goto Lcommon; |
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1766 } |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1767 case T.Auto: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1768 stc_tmp = StorageClass.Auto; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1769 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1770 case T.Scope: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1771 stc_tmp = StorageClass.Scope; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1772 goto Lcommon; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1773 Lcommon: |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1774 // Issue error if redundant. |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1775 if (stc & stc_tmp) |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1776 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
|
1777 else |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1778 stc |= stc_tmp; |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1779 |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1780 nT(); |
650
eb490ba8dba0
Made AttributeDeclaration abstract.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
646
diff
changeset
|
1781 d = new StorageClassDeclaration(stc_tmp, parse()); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1782 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
|
1783 // 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
|
1784 //case T.Class: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1785 default: |
270
764eccdf619d
- Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents:
269
diff
changeset
|
1786 case_Declaration: |
501
949a53332c66
Fixed parsing of AutoDeclarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
496
diff
changeset
|
1787 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
|
1788 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1789 return set(d, begin); |
201 | 1790 } |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1791 return new DeclarationStatement(parse()); |
201 | 1792 } |
1793 | |
162 | 1794 Statement parseIfStatement() |
1795 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1796 skip(T.If); |
162 | 1797 |
283 | 1798 Statement variable; |
162 | 1799 Expression condition; |
1800 Statement ifBody, elseBody; | |
1801 | |
1802 require(T.LParen); | |
283 | 1803 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1804 Identifier* ident; |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1805 auto begin = token; // For start of AutoDeclaration or normal Declaration. |
162 | 1806 // auto Identifier = Expression |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1807 if (consumed(T.Auto)) |
162 | 1808 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1809 ident = requireIdentifier(MSG.ExpectedVariableName); |
162 | 1810 require(T.Assign); |
283 | 1811 auto init = parseExpression(); |
673
64fec49651cf
Renamed VariableDeclaration to VariablesDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
671
diff
changeset
|
1812 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
|
1813 set(v, begin.nextNWS); |
650
eb490ba8dba0
Made AttributeDeclaration abstract.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
646
diff
changeset
|
1814 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
|
1815 set(d, begin); |
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
1816 variable = new DeclarationStatement(d); |
484
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1817 set(variable, begin); |
162 | 1818 } |
1819 else | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1820 { // Declarator = Expression |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1821 Type parseDeclaratorAssign() |
162 | 1822 { |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1823 auto type = parseDeclarator(ident); |
162 | 1824 require(T.Assign); |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1825 return type; |
162 | 1826 } |
237
805796880adb
- Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents:
236
diff
changeset
|
1827 bool success; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
1828 auto type = try_(&parseDeclaratorAssign, success); |
283 | 1829 if (success) |
163
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1830 { |
283 | 1831 auto init = parseExpression(); |
673
64fec49651cf
Renamed VariableDeclaration to VariablesDeclaration.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
671
diff
changeset
|
1832 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
|
1833 set(v, begin); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1834 variable = new DeclarationStatement(v); |
265c0b655f18
Added more calls to set().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
483
diff
changeset
|
1835 set(variable, begin); |
163
f27a98bb17c7
- Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents:
162
diff
changeset
|
1836 } |
283 | 1837 else |
1838 condition = parseExpression(); | |
162 | 1839 } |
1840 require(T.RParen); | |
164 | 1841 ifBody = parseScopeStatement(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1842 if (consumed(T.Else)) |
164 | 1843 elseBody = parseScopeStatement(); |
283 | 1844 return new IfStatement(variable, condition, ifBody, elseBody); |
162 | 1845 } |
1846 | |
164 | 1847 Statement parseWhileStatement() |
1848 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1849 skip(T.While); |
166 | 1850 require(T.LParen); |
164 | 1851 auto condition = parseExpression(); |
166 | 1852 require(T.RParen); |
164 | 1853 return new WhileStatement(condition, parseScopeStatement()); |
1854 } | |
1855 | |
165 | 1856 Statement parseDoWhileStatement() |
1857 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1858 skip(T.Do); |
165 | 1859 auto doBody = parseScopeStatement(); |
1860 require(T.While); | |
166 | 1861 require(T.LParen); |
165 | 1862 auto condition = parseExpression(); |
166 | 1863 require(T.RParen); |
1864 return new DoWhileStatement(condition, doBody); | |
1865 } | |
1866 | |
1867 Statement parseForStatement() | |
1868 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1869 skip(T.For); |
166 | 1870 |
1871 Statement init, forBody; | |
1872 Expression condition, increment; | |
1873 | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1874 require(T.LParen); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1875 if (!consumed(T.Semicolon)) |
166 | 1876 init = parseNoScopeStatement(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1877 if (token.kind != T.Semicolon) |
166 | 1878 condition = parseExpression(); |
168 | 1879 require(T.Semicolon); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1880 if (token.kind != T.RParen) |
166 | 1881 increment = parseExpression(); |
168 | 1882 require(T.RParen); |
167 | 1883 forBody = parseScopeStatement(); |
166 | 1884 return new ForStatement(init, condition, increment, forBody); |
165 | 1885 } |
1886 | |
169 | 1887 Statement parseForeachStatement() |
1888 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1889 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
|
1890 TOK tok = token.kind; |
169 | 1891 nT(); |
1892 | |
257 | 1893 auto params = new Parameters; |
269 | 1894 Expression e; // Aggregate or LwrExpression |
169 | 1895 |
1896 require(T.LParen); | |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
1897 auto paramsBegin = token; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
1898 do |
169 | 1899 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
1900 auto paramBegin = token; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1901 StorageClass stc; |
169 | 1902 Type type; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1903 Identifier* ident; |
169 | 1904 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1905 switch (token.kind) |
169 | 1906 { |
236
e961d1b957c3
- Fix in parseForeachStatement(): added T.Inout to case T.Ref; removed break statement.
aziz
parents:
235
diff
changeset
|
1907 case T.Ref, T.Inout: |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1908 stc = StorageClass.Ref; |
169 | 1909 nT(); |
236
e961d1b957c3
- Fix in parseForeachStatement(): added T.Inout to case T.Ref; removed break statement.
aziz
parents:
235
diff
changeset
|
1910 // fall through |
169 | 1911 case T.Identifier: |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1912 auto next = peekNext(); |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
1913 if (next == T.Comma || next == T.Semicolon || next == T.RParen) |
169 | 1914 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1915 ident = requireIdentifier(MSG.ExpectedVariableName); |
169 | 1916 break; |
1917 } | |
1918 // fall through | |
1919 default: | |
1920 type = parseDeclarator(ident); | |
1921 } | |
1922 | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1923 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
|
1924 } while (consumed(T.Comma)) |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
1925 set(params, paramsBegin); |
169 | 1926 require(T.Semicolon); |
269 | 1927 e = parseExpression(); |
1928 version(D2) | |
1929 { //Foreach (ForeachType; LwrExpression .. UprExpression ) ScopeStatement | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
1930 if (consumed(T.Slice)) |
269 | 1931 { |
1932 // if (params.length != 1) | |
1933 // error(MID.XYZ); // TODO: issue error msg | |
1934 auto upper = parseExpression(); | |
1935 require(T.RParen); | |
1936 auto forBody = parseScopeStatement(); | |
1937 return new ForeachRangeStatement(tok, params, e, upper, forBody); | |
1938 } | |
1939 } | |
1940 // Foreach (ForeachTypeList; Aggregate) ScopeStatement | |
169 | 1941 require(T.RParen); |
1942 auto forBody = parseScopeStatement(); | |
269 | 1943 return new ForeachStatement(tok, params, e, forBody); |
169 | 1944 } |
1945 | |
170 | 1946 Statement parseSwitchStatement() |
1947 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1948 skip(T.Switch); |
170 | 1949 require(T.LParen); |
1950 auto condition = parseExpression(); | |
1951 require(T.RParen); | |
1952 auto switchBody = parseScopeStatement(); | |
1953 return new SwitchStatement(condition, switchBody); | |
1954 } | |
1955 | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1956 /// 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
|
1957 Statement parseCaseOrDefaultBody() |
220 | 1958 { |
1959 // 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
|
1960 auto begin = token; |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
1961 auto s = new CompoundStatement(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1962 while (token.kind != T.Case && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1963 token.kind != T.Default && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1964 token.kind != T.RBrace && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
1965 token.kind != T.EOF) |
224 | 1966 s ~= parseStatement(); |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
1967 set(s, begin); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1968 return set(new ScopeStatement(s), begin); |
220 | 1969 } |
1970 | |
171 | 1971 Statement parseCaseStatement() |
1972 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1973 skip(T.Case); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
1974 auto values = parseExpressionList(); |
171 | 1975 require(T.Colon); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1976 auto caseBody = parseCaseOrDefaultBody(); |
171 | 1977 return new CaseStatement(values, caseBody); |
1978 } | |
1979 | |
172 | 1980 Statement parseDefaultStatement() |
1981 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1982 skip(T.Default); |
172 | 1983 require(T.Colon); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1984 auto defaultBody = parseCaseOrDefaultBody(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
1985 return new DefaultStatement(defaultBody); |
172 | 1986 } |
1987 | |
173 | 1988 Statement parseContinueStatement() |
1989 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1990 skip(T.Continue); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1991 auto ident = optionalIdentifier(); |
173 | 1992 require(T.Semicolon); |
1993 return new ContinueStatement(ident); | |
1994 } | |
1995 | |
174 | 1996 Statement parseBreakStatement() |
1997 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
1998 skip(T.Break); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
1999 auto ident = optionalIdentifier(); |
555
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
2000 require(T.Semicolon); |
174 | 2001 return new BreakStatement(ident); |
2002 } | |
2003 | |
175 | 2004 Statement parseReturnStatement() |
2005 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2006 skip(T.Return); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2007 Expression expr; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2008 if (token.kind != T.Semicolon) |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
2009 expr = parseExpression(); |
175 | 2010 require(T.Semicolon); |
2011 return new ReturnStatement(expr); | |
2012 } | |
2013 | |
176 | 2014 Statement parseGotoStatement() |
2015 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2016 skip(T.Goto); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2017 Identifier* ident; |
176 | 2018 Expression caseExpr; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2019 switch (token.kind) |
176 | 2020 { |
2021 case T.Case: | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2022 ident = token.ident; |
176 | 2023 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2024 if (token.kind == T.Semicolon) |
176 | 2025 break; |
2026 caseExpr = parseExpression(); | |
2027 break; | |
2028 case T.Default: | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2029 ident = token.ident; |
176 | 2030 nT(); |
2031 break; | |
2032 default: | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2033 ident = requireIdentifier(MSG.ExpectedAnIdentifier); |
176 | 2034 } |
2035 require(T.Semicolon); | |
2036 return new GotoStatement(ident, caseExpr); | |
2037 } | |
2038 | |
177 | 2039 Statement parseWithStatement() |
2040 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2041 skip(T.With); |
177 | 2042 require(T.LParen); |
2043 auto expr = parseExpression(); | |
2044 require(T.RParen); | |
2045 return new WithStatement(expr, parseScopeStatement()); | |
2046 } | |
2047 | |
178 | 2048 Statement parseSynchronizedStatement() |
2049 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2050 skip(T.Synchronized); |
178 | 2051 Expression expr; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2052 if (consumed(T.LParen)) |
178 | 2053 { |
2054 expr = parseExpression(); | |
2055 require(T.RParen); | |
2056 } | |
2057 return new SynchronizedStatement(expr, parseScopeStatement()); | |
2058 } | |
2059 | |
179 | 2060 Statement parseTryStatement() |
2061 { | |
640
05645f5613c1
Added an error message.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
639
diff
changeset
|
2062 auto begin = token; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2063 skip(T.Try); |
179 | 2064 |
2065 auto tryBody = parseScopeStatement(); | |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
2066 CatchStatement[] catchBodies; |
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
2067 FinallyStatement finBody; |
179 | 2068 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2069 while (consumed(T.Catch)) |
179 | 2070 { |
2071 Parameter param; | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2072 if (consumed(T.LParen)) |
179 | 2073 { |
640
05645f5613c1
Added an error message.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
639
diff
changeset
|
2074 auto begin2 = token; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2075 Identifier* ident; |
369 | 2076 auto type = parseDeclarator(ident, true); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2077 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
|
2078 set(param, begin2); |
179 | 2079 require(T.RParen); |
2080 } | |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
2081 catchBodies ~= set(new CatchStatement(param, parseNoScopeStatement()), begin); |
179 | 2082 if (param is null) |
2083 break; // This is a LastCatch | |
640
05645f5613c1
Added an error message.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
639
diff
changeset
|
2084 begin = token; |
179 | 2085 } |
2086 | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2087 if (consumed(T.Finally)) |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
2088 finBody = set(new FinallyStatement(parseNoScopeStatement()), prevToken); |
179 | 2089 |
396
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
2090 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
|
2091 assert(begin.kind == T.Try), error(begin, MSG.MissingCatchOrFinally); |
179 | 2092 |
2093 return new TryStatement(tryBody, catchBodies, finBody); | |
2094 } | |
2095 | |
180 | 2096 Statement parseThrowStatement() |
2097 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2098 skip(T.Throw); |
180 | 2099 auto expr = parseExpression(); |
2100 require(T.Semicolon); | |
2101 return new ThrowStatement(expr); | |
2102 } | |
2103 | |
181 | 2104 Statement parseScopeGuardStatement() |
2105 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2106 skip(T.Scope); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2107 skip(T.LParen); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2108 auto condition = requireIdentifier(MSG.ExpectedScopeIdentifier); |
264 | 2109 if (condition) |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2110 switch (condition.idKind) |
181 | 2111 { |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2112 case IDK.exit, IDK.success, IDK.failure: |
181 | 2113 break; |
2114 default: | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2115 error(this.prevToken, MSG.InvalidScopeIdentifier, this.prevToken.srcText); |
181 | 2116 } |
2117 require(T.RParen); | |
2118 Statement scopeBody; | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2119 if (token.kind == T.LBrace) |
181 | 2120 scopeBody = parseScopeStatement(); |
2121 else | |
2122 scopeBody = parseNoScopeStatement(); | |
2123 return new ScopeGuardStatement(condition, scopeBody); | |
2124 } | |
2125 | |
182 | 2126 Statement parseVolatileStatement() |
2127 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2128 skip(T.Volatile); |
182 | 2129 Statement volatileBody; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2130 if (token.kind == T.Semicolon) |
182 | 2131 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2132 else if (token.kind == T.LBrace) |
182 | 2133 volatileBody = parseScopeStatement(); |
2134 else | |
219 | 2135 volatileBody = parseStatement(); |
182 | 2136 return new VolatileStatement(volatileBody); |
2137 } | |
2138 | |
184 | 2139 Statement parsePragmaStatement() |
2140 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2141 skip(T.Pragma); |
184 | 2142 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2143 Identifier* ident; |
184 | 2144 Expression[] args; |
2145 Statement pragmaBody; | |
2146 | |
2147 require(T.LParen); | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2148 ident = requireIdentifier(MSG.ExpectedPragmaIdentifier); |
184 | 2149 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2150 if (consumed(T.Comma)) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2151 args = parseExpressionList(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2152 require(T.RParen); |
184 | 2153 |
234 | 2154 pragmaBody = parseNoScopeOrEmptyStatement(); |
184 | 2155 |
2156 return new PragmaStatement(ident, args, pragmaBody); | |
2157 } | |
2158 | |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2159 Statement parseStaticIfStatement() |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2160 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2161 skip(T.Static); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2162 skip(T.If); |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2163 Expression condition; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2164 Statement ifBody, elseBody; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2165 |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2166 require(T.LParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2167 condition = parseExpression(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2168 require(T.RParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2169 ifBody = parseNoScopeStatement(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2170 if (consumed(T.Else)) |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2171 elseBody = parseNoScopeStatement(); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2172 return new StaticIfStatement(condition, ifBody, elseBody); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2173 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2174 |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2175 Statement parseStaticAssertStatement() |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2176 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2177 skip(T.Static); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2178 skip(T.Assert); |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2179 Expression condition, message; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2180 |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2181 require(T.LParen); |
555
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
2182 condition = parseAssignExpression(); // Condition. |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2183 if (consumed(T.Comma)) |
555
d9e328c3bab9
Fixed infinite loop in dil.Parser.parseMixin().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
539
diff
changeset
|
2184 message = parseAssignExpression(); // Error message. |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2185 require(T.RParen); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2186 require(T.Semicolon); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2187 return new StaticAssertStatement(condition, message); |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2188 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
2189 |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2190 Statement parseDebugStatement() |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2191 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2192 skip(T.Debug); |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2193 Token* cond; |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2194 Statement debugBody, elseBody; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2195 |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2196 // ( Condition ) |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2197 if (consumed(T.LParen)) |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2198 { |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2199 cond = parseIdentOrInt(); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2200 require(T.RParen); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2201 } |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2202 // debug Statement |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2203 // debug ( Condition ) Statement |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2204 debugBody = parseNoScopeStatement(); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2205 // else Statement |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2206 if (consumed(T.Else)) |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2207 elseBody = parseNoScopeStatement(); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2208 |
264 | 2209 return new DebugStatement(cond, debugBody, elseBody); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2210 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2211 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2212 Statement parseVersionStatement() |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2213 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2214 skip(T.Version); |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2215 Token* cond; |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2216 Statement versionBody, elseBody; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2217 |
529
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2218 // ( Condition ) |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2219 require(T.LParen); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2220 cond = parseIdentOrInt(); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2221 require(T.RParen); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2222 // version ( Condition ) Statement |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2223 versionBody = parseNoScopeStatement(); |
135e9e6933a7
Tidied up version/debug parser functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
528
diff
changeset
|
2224 // else Statement |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2225 if (consumed(T.Else)) |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2226 elseBody = parseNoScopeStatement(); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2227 |
264 | 2228 return new VersionStatement(cond, versionBody, elseBody); |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2229 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
2230 |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
2231 /+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
2232 | Assembler parsing methods | |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
2233 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+/ |
183 | 2234 |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2235 Statement parseAsmBlockStatement() |
183 | 2236 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2237 skip(T.Asm); |
285 | 2238 require(T.LBrace); |
680
6b3e397229c5
Renamed Statements, Declarations and EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
679
diff
changeset
|
2239 auto ss = new CompoundStatement; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2240 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
|
2241 ss ~= parseAsmStatement(); |
285 | 2242 require(T.RBrace); |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2243 return new AsmBlockStatement(ss); |
285 | 2244 } |
2245 | |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2246 Statement parseAsmStatement() |
285 | 2247 { |
2248 auto begin = token; | |
2249 Statement s; | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2250 Identifier* ident; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2251 switch (token.kind) |
285 | 2252 { |
374 | 2253 // Keywords that are valid opcodes. |
2254 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
|
2255 ident = token.ident; |
374 | 2256 nT(); |
2257 goto LOpcode; | |
285 | 2258 case T.Identifier: |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2259 ident = token.ident; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2260 nT(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2261 if (consumed(T.Colon)) |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
2262 { // Identifier : AsmStatement |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2263 s = new LabeledStatement(ident, parseAsmStatement()); |
285 | 2264 break; |
2265 } | |
2266 | |
374 | 2267 LOpcode: |
285 | 2268 // Opcode ; |
2269 // Opcode Operands ; | |
2270 // Opcode | |
2271 // Identifier | |
2272 Expression[] es; | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2273 if (token.kind != T.Semicolon) |
632
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2274 do |
285 | 2275 es ~= parseAsmExpression(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2276 while (consumed(T.Comma)) |
285 | 2277 require(T.Semicolon); |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2278 s = new AsmStatement(ident, es); |
285 | 2279 break; |
374 | 2280 case T.Align: |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2281 // align Integer; |
374 | 2282 nT(); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2283 int number = -1; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2284 if (token.kind == T.Int32) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2285 (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
|
2286 else |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
2287 error(token, MSG.ExpectedIntegerAfterAlign, token.srcText); |
374 | 2288 require(T.Semicolon); |
2289 s = new AsmAlignStatement(number); | |
2290 break; | |
285 | 2291 case T.Semicolon: |
2292 s = new EmptyStatement(); | |
2293 nT(); | |
2294 break; | |
2295 default: | |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2296 s = new IllegalAsmStatement(); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2297 // Skip to next valid token. |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2298 do |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2299 nT(); |
681
95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
2300 while (!token.isAsmStatementStart && |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2301 token.kind != T.RBrace && |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2302 token.kind != T.EOF) |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
2303 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
|
2304 error(begin, MSG.IllegalAsmStatement, text); |
285 | 2305 } |
2306 set(s, begin); | |
2307 return s; | |
2308 } | |
2309 | |
2310 Expression parseAsmExpression() | |
2311 { | |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2312 auto begin = token; |
374 | 2313 auto e = parseAsmOrOrExpression(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2314 if (consumed(T.Question)) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2315 { |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
2316 auto tok = this.prevToken; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2317 auto iftrue = parseAsmExpression(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2318 require(T.Colon); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2319 auto iffalse = parseAsmExpression(); |
293
418c6548ce17
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
292
diff
changeset
|
2320 e = new CondExpression(e, iftrue, iffalse, tok); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2321 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2322 } |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2323 // TODO: create AsmExpression that contains e? |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2324 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2325 } |
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 Expression parseAsmOrOrExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2328 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
374
diff
changeset
|
2329 alias parseAsmAndAndExpression parseNext; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2330 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2331 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2332 while (token.kind == T.OrLogical) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2333 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2334 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2335 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2336 e = new OrOrExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2337 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2338 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2339 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2340 } |
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 Expression parseAsmAndAndExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2343 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
374
diff
changeset
|
2344 alias parseAsmOrExpression parseNext; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2345 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2346 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2347 while (token.kind == T.AndLogical) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2348 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2349 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2350 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2351 e = new AndAndExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2352 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2353 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2354 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2355 } |
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 Expression parseAsmOrExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2358 { |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
374
diff
changeset
|
2359 alias parseAsmXorExpression parseNext; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2360 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2361 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2362 while (token.kind == T.OrBinary) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2363 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2364 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2365 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2366 e = new OrExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2367 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2368 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2369 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2370 } |
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 Expression parseAsmXorExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2373 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2374 alias parseAsmAndExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2375 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2376 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2377 while (token.kind == T.Xor) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2378 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2379 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2380 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2381 e = new XorExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2382 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2383 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2384 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2385 } |
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 Expression parseAsmAndExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2388 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2389 alias parseAsmCmpExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2390 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2391 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2392 while (token.kind == T.AndBinary) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2393 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2394 auto tok = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2395 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2396 e = new AndExpression(e, parseNext(), tok); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2397 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2398 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2399 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2400 } |
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 Expression parseAsmCmpExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2403 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2404 alias parseAsmShiftExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2405 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2406 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2407 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2408 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2409 switch (operator.kind) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2410 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2411 case T.Equal, T.NotEqual: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2412 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2413 e = new EqualExpression(e, parseNext(), operator); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2414 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2415 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2416 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2417 e = new RelExpression(e, parseNext(), operator); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2418 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2419 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2420 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2421 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2422 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2423 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2424 } |
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 Expression parseAsmShiftExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2427 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2428 alias parseAsmAddExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2429 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2430 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2431 while (1) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2432 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2433 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2434 switch (operator.kind) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2435 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2436 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
|
2437 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
|
2438 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
|
2439 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2440 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2441 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2442 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2443 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2444 assert(0); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2445 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2446 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2447 Expression parseAsmAddExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2448 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2449 alias parseAsmMulExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2450 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2451 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2452 while (1) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2453 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2454 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2455 switch (operator.kind) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2456 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2457 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
|
2458 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
|
2459 // Not allowed in asm |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2460 //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
|
2461 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2462 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2463 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2464 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2465 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2466 assert(0); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2467 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2468 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2469 Expression parseAsmMulExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2470 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2471 alias parseAsmPostExpression parseNext; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2472 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2473 auto e = parseNext(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2474 while (1) |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2475 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2476 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2477 switch (operator.kind) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2478 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2479 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
|
2480 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
|
2481 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
|
2482 default: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2483 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2484 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2485 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2486 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2487 assert(0); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2488 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2489 |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2490 Expression parseAsmPostExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2491 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2492 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2493 auto e = parseAsmUnaryExpression(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2494 while (consumed(T.LBracket)) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2495 { |
632
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2496 e = new AsmPostBracketExpression(e, parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2497 require(T.RBracket); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2498 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2499 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2500 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2501 } |
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 Expression parseAsmUnaryExpression() |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2504 { |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2505 auto begin = token; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2506 Expression e; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2507 switch (token.kind) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2508 { |
374 | 2509 case T.Byte, T.Short, T.Int, |
2510 T.Float, T.Double, T.Real: | |
2511 goto LAsmTypePrefix; | |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2512 case T.Identifier: |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2513 switch (token.ident.idKind) |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2514 { |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2515 case IDK.near, IDK.far,/* "byte", "short", "int",*/ |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2516 IDK.word, IDK.dword, IDK.qword/*, "float", "double", "real"*/: |
374 | 2517 LAsmTypePrefix: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2518 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2519 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
|
2520 skip(T.Identifier); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2521 else |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2522 error(MID.ExpectedButFound, "ptr", token.srcText); |
374 | 2523 e = new AsmTypeExpression(parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2524 break; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2525 case IDK.offset: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2526 nT(); |
374 | 2527 e = new AsmOffsetExpression(parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2528 break; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2529 case IDK.seg: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2530 nT(); |
374 | 2531 e = new AsmSegExpression(parseAsmExpression()); |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2532 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2533 default: |
374 | 2534 goto LparseAsmPrimaryExpression; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2535 } |
374 | 2536 break; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2537 case T.Minus: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2538 case T.Plus: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2539 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2540 e = new SignExpression(parseAsmUnaryExpression()); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2541 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2542 case T.Not: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2543 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2544 e = new NotExpression(parseAsmUnaryExpression()); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2545 break; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2546 case T.Tilde: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2547 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2548 e = new CompExpression(parseAsmUnaryExpression()); |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2549 break; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2550 case T.Dot: |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2551 nT(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2552 e = new ModuleScopeExpression(parseIdentifierExpression()); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2553 while (consumed(TOK.Dot)) |
632
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2554 { |
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2555 e = new DotExpression(e, parseIdentifierExpression()); |
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2556 set(e, begin); |
20dddcc54621
Fixed parsing of AsmPostBracketExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
631
diff
changeset
|
2557 } |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2558 break; |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2559 default: |
374 | 2560 LparseAsmPrimaryExpression: |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2561 e = parseAsmPrimaryExpression(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2562 return e; |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2563 } |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2564 set(e, begin); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2565 return e; |
183 | 2566 } |
2567 | |
285 | 2568 Expression parseAsmPrimaryExpression() |
2569 { | |
2570 auto begin = token; | |
2571 Expression e; | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2572 switch (token.kind) |
285 | 2573 { |
2574 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
|
2575 e = new IntExpression(token); |
285 | 2576 nT(); |
2577 break; | |
2578 case T.Float32, T.Float64, T.Float80, | |
2579 T.Imaginary32, T.Imaginary64, T.Imaginary80: | |
539
3418027c3914
Added semantic() method to RealExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
537
diff
changeset
|
2580 e = new RealExpression(token); |
285 | 2581 nT(); |
2582 break; | |
2583 case T.Dollar: | |
2584 e = new DollarExpression(); | |
2585 nT(); | |
2586 break; | |
287
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2587 case T.LBracket: |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2588 // [ AsmExpression ] |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2589 nT(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2590 e = parseAsmExpression(); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2591 require(T.RBracket); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2592 e = new AsmBracketExpression(e); |
211bdd69397d
- Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents:
285
diff
changeset
|
2593 break; |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2594 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
|
2595 auto register = token.ident; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2596 switch (register.idKind) |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2597 { |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2598 // __LOCAL_SIZE |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2599 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
|
2600 nT(); |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2601 e = new AsmLocalSizeExpression(); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2602 break; |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2603 // Register |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2604 case IDK.ST: |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2605 nT(); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2606 // (1) - (7) |
502
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2607 int number = -1; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2608 if (consumed(T.LParen)) |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2609 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2610 if (token.kind == T.Int32) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2611 (number = token.int_), skip(T.Int32); |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2612 else |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2613 expected(T.Int32); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2614 require(T.RParen); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2615 } |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2616 e = new AsmRegisterExpression(register, number); |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2617 break; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2618 case IDK.FS: |
417
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2619 nT(); |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2620 // 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
|
2621 int number = -1; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2622 if (consumed(T.Colon)) |
417
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2623 { |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2624 // :0, :4, :8 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2625 if (token.kind == T.Int32) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
2626 (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
|
2627 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
|
2628 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
|
2629 } |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2630 e = new AsmRegisterExpression(register, number); |
8af5c7e2f722
Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
415
diff
changeset
|
2631 break; |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2632 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
|
2633 IDK.BL, IDK.BH, IDK.BX, IDK.EBX, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2634 IDK.CL, IDK.CH, IDK.CX, IDK.ECX, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2635 IDK.DL, IDK.DH, IDK.DX, IDK.EDX, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2636 IDK.BP, IDK.EBP, IDK.SP, IDK.ESP, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2637 IDK.DI, IDK.EDI, IDK.SI, IDK.ESI, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2638 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
|
2639 IDK.CR0, IDK.CR2, IDK.CR3, IDK.CR4, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2640 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
|
2641 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
|
2642 IDK.MM0, IDK.MM1, IDK.MM2, IDK.MM3, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2643 IDK.MM4, IDK.MM5, IDK.MM6, IDK.MM7, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2644 IDK.XMM0, IDK.XMM1, IDK.XMM2, IDK.XMM3, |
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
767
diff
changeset
|
2645 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
|
2646 nT(); |
4e14cd1b24da
Refactored code and added modules related to tabulated Identifiers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
501
diff
changeset
|
2647 e = new AsmRegisterExpression(register); |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2648 break; |
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2649 default: |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2650 e = parseIdentifierExpression(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2651 while (consumed(TOK.Dot)) |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2652 { |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2653 e = new DotExpression(e, parseIdentifierExpression()); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2654 set(e, begin); |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2655 } |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2656 } // end of switch |
288
833b301497f4
- Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents:
287
diff
changeset
|
2657 break; |
285 | 2658 default: |
2659 error(MID.ExpectedButFound, "Expression", token.srcText); | |
659
304331ca2f95
Renamed EmptyExpression to IllegalExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
655
diff
changeset
|
2660 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
|
2661 if (!trying) |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2662 { // 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
|
2663 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
|
2664 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
|
2665 } |
285 | 2666 } |
2667 set(e, begin); | |
2668 return e; | |
2669 } | |
2670 | |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
2671 /+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
2672 | Expression parsing methods | |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
2673 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+/ |
102 | 2674 |
72 | 2675 Expression parseExpression() |
2676 { | |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2677 alias parseAssignExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2678 auto begin = token; |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2679 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2680 while (token.kind == T.Comma) |
235 | 2681 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2682 auto comma = token; |
235 | 2683 nT(); |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2684 e = new CommaExpression(e, parseNext(), comma); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2685 set(e, begin); |
235 | 2686 } |
72 | 2687 return e; |
2688 } | |
2689 | |
71 | 2690 Expression parseAssignExpression() |
2691 { | |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2692 alias parseAssignExpression parseNext; |
319
83f1f9a4f248
- Removed assigment to 'begin' from loop. Initializing 'begin' at decl point.
aziz
parents:
318
diff
changeset
|
2693 auto begin = token; |
71 | 2694 auto e = parseCondExpression(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2695 switch (token.kind) |
71 | 2696 { |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2697 case T.Assign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2698 nT(); e = new AssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2699 case T.LShiftAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2700 nT(); e = new LShiftAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2701 case T.RShiftAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2702 nT(); e = new RShiftAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2703 case T.URShiftAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2704 nT(); e = new URShiftAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2705 case T.OrAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2706 nT(); e = new OrAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2707 case T.AndAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2708 nT(); e = new AndAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2709 case T.PlusAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2710 nT(); e = new PlusAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2711 case T.MinusAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2712 nT(); e = new MinusAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2713 case T.DivAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2714 nT(); e = new DivAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2715 case T.MulAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2716 nT(); e = new MulAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2717 case T.ModAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2718 nT(); e = new ModAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2719 case T.XorAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2720 nT(); e = new XorAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2721 case T.CatAssign: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2722 nT(); e = new CatAssignExpression(e, parseNext()); break; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2723 default: |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2724 return e; |
71 | 2725 } |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
2726 set(e, begin); |
71 | 2727 return e; |
2728 } | |
72 | 2729 |
71 | 2730 Expression parseCondExpression() |
2731 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2732 auto begin = token; |
72 | 2733 auto e = parseOrOrExpression(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2734 if (token.kind == T.Question) |
72 | 2735 { |
293
418c6548ce17
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
292
diff
changeset
|
2736 auto tok = token; |
72 | 2737 nT(); |
2738 auto iftrue = parseExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
2739 require(T.Colon); |
72 | 2740 auto iffalse = parseCondExpression(); |
293
418c6548ce17
- Assigning to Node.children in several constructors that inherit from Node.
aziz
parents:
292
diff
changeset
|
2741 e = new CondExpression(e, iftrue, iffalse, tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2742 set(e, begin); |
72 | 2743 } |
2744 return e; | |
2745 } | |
2746 | |
2747 Expression parseOrOrExpression() | |
2748 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2749 alias parseAndAndExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2750 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2751 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2752 while (token.kind == T.OrLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2753 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2754 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2755 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2756 e = new OrOrExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2757 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2758 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2759 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2760 } |
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 Expression parseAndAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2763 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2764 alias parseOrExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2765 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2766 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2767 while (token.kind == T.AndLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2768 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2769 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2770 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2771 e = new AndAndExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2772 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2773 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2774 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2775 } |
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 Expression parseOrExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2778 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2779 alias parseXorExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2780 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2781 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2782 while (token.kind == T.OrBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2783 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2784 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2785 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2786 e = new OrExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2787 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2788 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2789 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2790 } |
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 Expression parseXorExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2793 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2794 alias parseAndExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2795 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2796 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2797 while (token.kind == T.Xor) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2798 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2799 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2800 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2801 e = new XorExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2802 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2803 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2804 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2805 } |
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 Expression parseAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2808 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2809 alias parseCmpExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2810 auto begin = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2811 auto e = parseNext(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2812 while (token.kind == T.AndBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2813 { |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2814 auto tok = token; |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2815 nT(); |
251
67a798459532
- Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents:
250
diff
changeset
|
2816 e = new AndExpression(e, parseNext(), tok); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2817 set(e, begin); |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2818 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2819 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2820 } |
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 Expression parseCmpExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
2823 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2824 alias parseShiftExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2825 auto begin = token; |
74 | 2826 auto e = parseShiftExpression(); |
2827 | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2828 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2829 switch (operator.kind) |
74 | 2830 { |
2831 case T.Equal, T.NotEqual: | |
2832 nT(); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2833 e = new EqualExpression(e, parseNext(), operator); |
74 | 2834 break; |
2835 case T.Not: | |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
2836 if (peekNext() != T.Is) |
74 | 2837 break; |
2838 nT(); | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2839 // fall through |
225 | 2840 case T.Is: |
74 | 2841 nT(); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2842 e = new IdentityExpression(e, parseNext(), operator); |
74 | 2843 break; |
2844 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater, | |
2845 T.Unordered, T.UorE, T.UorG, T.UorGorE, | |
2846 T.UorL, T.UorLorE, T.LorEorG, T.LorG: | |
2847 nT(); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2848 e = new RelExpression(e, parseNext(), operator); |
74 | 2849 break; |
2850 case T.In: | |
2851 nT(); | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2852 e = new InExpression(e, parseNext(), operator); |
74 | 2853 break; |
2854 default: | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2855 return e; |
74 | 2856 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2857 set(e, begin); |
74 | 2858 return e; |
2859 } | |
2860 | |
2861 Expression parseShiftExpression() | |
2862 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2863 alias parseAddExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2864 auto begin = token; |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2865 auto e = parseNext(); |
75 | 2866 while (1) |
2867 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2868 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2869 switch (operator.kind) |
75 | 2870 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2871 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
|
2872 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
|
2873 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
|
2874 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2875 return e; |
75 | 2876 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2877 set(e, begin); |
75 | 2878 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2879 assert(0); |
75 | 2880 } |
2881 | |
2882 Expression parseAddExpression() | |
2883 { | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2884 alias parseMulExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2885 auto begin = token; |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2886 auto e = parseNext(); |
76 | 2887 while (1) |
2888 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2889 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2890 switch (operator.kind) |
76 | 2891 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2892 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
|
2893 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
|
2894 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
|
2895 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2896 return e; |
76 | 2897 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2898 set(e, begin); |
76 | 2899 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2900 assert(0); |
76 | 2901 } |
2902 | |
2903 Expression parseMulExpression() | |
2904 { | |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2905 alias parsePostExpression parseNext; |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2906 auto begin = token; |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2907 auto e = parseNext(); |
77 | 2908 while (1) |
2909 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2910 auto operator = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2911 switch (operator.kind) |
77 | 2912 { |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2913 case T.Mul: nT(); e = new MulExpression(e, parseNext(), operator); break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2914 case T.Div: nT(); e = new DivExpression(e, parseNext(), operator); break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2915 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
|
2916 default: |
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2917 return e; |
77 | 2918 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2919 set(e, begin); |
77 | 2920 } |
228
a4c5ee9527b7
- Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents:
227
diff
changeset
|
2921 assert(0); |
71 | 2922 } |
2923 | |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2924 Expression parsePostExpression() |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2925 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2926 auto begin = token; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2927 auto e = parseUnaryExpression(); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2928 while (1) |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2929 { |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2930 while (consumed(T.Dot)) |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2931 { |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2932 e = new DotExpression(e, parseNewOrIdentifierExpression()); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2933 set(e, begin); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2934 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
2935 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2936 switch (token.kind) |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2937 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2938 case T.PlusPlus: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2939 e = new PostIncrExpression(e); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2940 break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2941 case T.MinusMinus: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2942 e = new PostDecrExpression(e); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2943 break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2944 case T.LParen: |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2945 e = new CallExpression(e, parseArguments()); |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2946 goto Lset; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2947 case T.LBracket: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2948 // parse Slice- and IndexExpression |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2949 nT(); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
2950 // [] is a SliceExpression |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2951 if (token.kind == T.RBracket) |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2952 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2953 e = new SliceExpression(e, null, null); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2954 break; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2955 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2956 |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2957 Expression[] es = [parseAssignExpression()]; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2958 |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
2959 // [ AssignExpression .. AssignExpression ] |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2960 if (consumed(T.Slice)) |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2961 { |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2962 e = new SliceExpression(e, es[0], parseAssignExpression()); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2963 require(T.RBracket); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2964 goto Lset; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2965 } |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2966 |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
2967 // [ ExpressionList ] |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
2968 if (consumed(T.Comma)) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2969 es ~= parseExpressionList(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
2970 require(T.RBracket); |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2971 |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2972 e = new IndexExpression(e, es); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2973 goto Lset; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2974 default: |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2975 return e; |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2976 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2977 nT(); |
489
a7291d3ee9d7
Refactored classes that inherit from Node.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
488
diff
changeset
|
2978 Lset: // Jumped here to skip nT(). |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2979 set(e, begin); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2980 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2981 assert(0); |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2982 } |
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
2983 |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2984 Expression parseUnaryExpression() |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2985 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
2986 auto begin = token; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2987 Expression e; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
2988 switch (token.kind) |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2989 { |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2990 case T.AndBinary: |
257 | 2991 nT(); |
243 | 2992 e = new AddressExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2993 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2994 case T.PlusPlus: |
257 | 2995 nT(); |
243 | 2996 e = new PreIncrExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2997 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
2998 case T.MinusMinus: |
257 | 2999 nT(); |
243 | 3000 e = new PreDecrExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3001 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3002 case T.Mul: |
257 | 3003 nT(); |
243 | 3004 e = new DerefExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3005 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3006 case T.Minus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3007 case T.Plus: |
257 | 3008 nT(); |
243 | 3009 e = new SignExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3010 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3011 case T.Not: |
257 | 3012 nT(); |
243 | 3013 e = new NotExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3014 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3015 case T.Tilde: |
257 | 3016 nT(); |
243 | 3017 e = new CompExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3018 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3019 case T.New: |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3020 e = parseNewExpression(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3021 return e; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3022 case T.Delete: |
257 | 3023 nT(); |
243 | 3024 e = new DeleteExpression(parseUnaryExpression()); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3025 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3026 case T.Cast: |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3027 requireNext(T.LParen); |
269 | 3028 Type type; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3029 switch (token.kind) |
269 | 3030 { |
3031 version(D2) | |
3032 { | |
3033 auto begin2 = token; | |
3034 case T.Const: | |
3035 type = new ConstType(null); | |
3036 goto case_break; | |
3037 case T.Invariant: | |
3038 type = new InvariantType(null); | |
3039 case_break: | |
3040 nT(); | |
3041 set(type, begin2); | |
3042 break; | |
3043 } | |
3044 default: | |
3045 type = parseType(); | |
3046 } | |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3047 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3048 e = new CastExpression(parseUnaryExpression(), type); |
257 | 3049 break; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3050 case T.LParen: |
102 | 3051 // ( Type ) . Identifier |
225 | 3052 Type parseType_() |
3053 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3054 skip(T.LParen); |
225 | 3055 auto type = parseType(); |
3056 require(T.RParen); | |
233 | 3057 require(T.Dot); |
225 | 3058 return type; |
3059 } | |
3060 bool success; | |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
3061 auto type = try_(&parseType_, success); |
225 | 3062 if (success) |
3063 { | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3064 auto ident = requireIdentifier(MSG.ExpectedIdAfterTypeDot); |
225 | 3065 e = new TypeDotIdExpression(type, ident); |
257 | 3066 break; |
225 | 3067 } |
3068 goto default; | |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3069 case T.Dot: |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3070 nT(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3071 e = new ModuleScopeExpression(parseIdentifierExpression()); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3072 break; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3073 default: |
335
b245b234fdd9
- Moved parsePostExpression() above parseUnaryExpression().
aziz
parents:
327
diff
changeset
|
3074 e = parsePrimaryExpression(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3075 return e; |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3076 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3077 assert(e !is null); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3078 set(e, begin); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3079 return e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3080 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
3081 |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3082 /++ |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3083 IdentifierExpression: |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3084 Identifier |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3085 TemplateInstance |
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 Identifier !( TemplateArguments ) |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3088 +/ |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3089 Expression parseIdentifierExpression() |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3090 { |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3091 auto begin = token; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3092 auto ident = requireIdentifier(MSG.ExpectedAnIdentifier); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3093 Expression e; |
634
14e99ce74d06
Fixed parsing of TemplateInstanceExpressions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
632
diff
changeset
|
3094 // 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
|
3095 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
|
3096 { // Identifier !( TemplateArguments ) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3097 skip(T.Not); |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3098 auto tparams = parseTemplateArguments(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3099 e = new TemplateInstanceExpression(ident, tparams); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3100 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3101 else // Identifier |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3102 e = new IdentifierExpression(ident); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3103 return set(e, begin); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3104 } |
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 Expression parseNewOrIdentifierExpression() |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3107 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3108 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
|
3109 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3110 |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
3111 Expression parsePrimaryExpression() |
78
f043759fb59a
- Added code to parseUnaryExpression(); not fully implemented.
aziz
parents:
77
diff
changeset
|
3112 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3113 auto begin = token; |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3114 Expression e; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3115 switch (token.kind) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3116 { |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3117 case T.Identifier: |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3118 e = parseIdentifierExpression(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3119 return e; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3120 case T.Typeof: |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3121 e = new TypeofExpression(parseTypeofType()); |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3122 break; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3123 case T.This: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3124 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3125 e = new ThisExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3126 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3127 case T.Super: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3128 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3129 e = new SuperExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3130 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3131 case T.Null: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3132 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3133 e = new NullExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3134 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3135 case T.True, T.False: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3136 nT(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3137 e = new BoolExpression(); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3138 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3139 case T.Dollar: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3140 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3141 e = new DollarExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3142 break; |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3143 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
|
3144 e = new IntExpression(token); |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3145 nT(); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3146 break; |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3147 case T.Float32, T.Float64, T.Float80, |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3148 T.Imaginary32, T.Imaginary64, T.Imaginary80: |
539
3418027c3914
Added semantic() method to RealExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
537
diff
changeset
|
3149 e = new RealExpression(token); |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
3150 nT(); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3151 break; |
507
996041463028
Removed TOK.WCharLiteral and TOK.DCharLiteral.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
505
diff
changeset
|
3152 case T.CharLiteral: |
536
0781ac288537
Added some semantic() methods.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
535
diff
changeset
|
3153 e = new CharExpression(token.dchar_); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3154 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3155 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3156 case T.String: |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3157 char[] str = token.str; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3158 char postfix = token.pf; |
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3159 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3160 while (token.kind == T.String) |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3161 { |
789
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
3162 /+if (postfix == 0) |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3163 postfix = token.pf; |
789
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
3164 else+/ |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
3165 if (token.pf && token.pf != postfix) |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3166 error(token, MSG.StringPostfixMismatch); |
789
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
3167 str.length = str.length - 1; // Exclude '\0'. |
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) |
789
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
3172 { |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
3173 case 'w': |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
3174 if (checkString(begin, str)) |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
3175 goto default; |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
3176 e = new StringExpression(dil.Unicode.toUTF16(str)); break; |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
3177 case 'd': |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
3178 if (checkString(begin, str)) |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
3179 goto default; |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
3180 e = new StringExpression(dil.Unicode.toUTF32(str)); break; |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3181 case 'c': |
789
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
3182 default: |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
3183 // No checking done to allow for binary data. |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
3184 e = new StringExpression(str); break; |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3185 } |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3186 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3187 case T.LBracket: |
85 | 3188 Expression[] values; |
3189 | |
3190 nT(); | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3191 if (!consumed(T.RBracket)) |
85 | 3192 { |
3193 e = parseAssignExpression(); | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3194 if (consumed(T.Colon)) |
85 | 3195 goto LparseAssocArray; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3196 if (consumed(T.Comma)) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3197 values = [e] ~ parseExpressionList(); |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3198 require(T.RBracket); |
85 | 3199 } |
3200 | |
3201 e = new ArrayLiteralExpression(values); | |
3202 break; | |
3203 | |
3204 LparseAssocArray: | |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3205 Expression[] keys = [e]; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3206 |
271
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3207 goto LenterLoop; |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3208 do |
88 | 3209 { |
271
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3210 keys ~= parseAssignExpression(); |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3211 require(T.Colon); |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3212 LenterLoop: |
68987c1c59b6
- Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents:
270
diff
changeset
|
3213 values ~= parseAssignExpression(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3214 } while (consumed(T.Comma)) |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3215 require(T.RBracket); |
399
ff1d11c27061
Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
398
diff
changeset
|
3216 e = new AArrayLiteralExpression(keys, values); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3217 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3218 case T.LBrace: |
193
2a2975b6d539
- Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents:
192
diff
changeset
|
3219 // DelegateLiteral := { Statements } |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
3220 auto funcBody = parseFunctionBody(); |
289
a99357783c6f
- Fix: assign targs to member targs of TraitsExpression.
aziz
parents:
288
diff
changeset
|
3221 e = new FunctionLiteralExpression(funcBody); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3222 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3223 case T.Function, T.Delegate: |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
3224 // FunctionLiteral := ("function"|"delegate") Type? "(" ArgumentList ")" FunctionBody |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
3225 nT(); // Skip function or delegate keyword. |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3226 Type returnType; |
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3227 Parameters parameters; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3228 if (token.kind != T.LBrace) |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3229 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3230 if (token.kind != T.LParen) // Optional return type |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3231 returnType = parseType(); |
143 | 3232 parameters = parseParameterList(); |
133
3924b1ee1302
- Added code for parsing function and delegate literal expressions.
aziz
parents:
132
diff
changeset
|
3233 } |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
3234 auto funcBody = parseFunctionBody(); |
289
a99357783c6f
- Fix: assign targs to member targs of TraitsExpression.
aziz
parents:
288
diff
changeset
|
3235 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
|
3236 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3237 case T.Assert: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3238 Expression msg; |
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(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3241 if (consumed(T.Comma)) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3242 msg = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3243 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3244 e = new AssertExpression(e, msg); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3245 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3246 case T.Mixin: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3247 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3248 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3249 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3250 e = new MixinExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3251 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3252 case T.Import: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3253 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3254 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3255 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3256 e = new ImportExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3257 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3258 case T.Typeid: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3259 requireNext(T.LParen); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3260 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3261 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
3262 e = new TypeidExpression(type); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3263 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3264 case T.Is: |
100 | 3265 requireNext(T.LParen); |
3266 | |
248 | 3267 Type type, specType; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3268 Identifier* ident; // optional Identifier |
248 | 3269 Token* opTok, specTok; |
100 | 3270 |
3271 type = parseDeclarator(ident, true); | |
3272 | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3273 switch (token.kind) |
100 | 3274 { |
3275 case T.Colon, T.Equal: | |
248 | 3276 opTok = token; |
100 | 3277 nT(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3278 switch (token.kind) |
100 | 3279 { |
3280 case T.Typedef, | |
3281 T.Struct, | |
3282 T.Union, | |
3283 T.Class, | |
3284 T.Interface, | |
3285 T.Enum, | |
3286 T.Function, | |
3287 T.Delegate, | |
3288 T.Super, | |
3289 T.Return: | |
493
d13502b6fa5f
Added code to the Parser and edited main.wiki.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
492
diff
changeset
|
3290 case_Const_Invariant: |
248 | 3291 specTok = token; |
102 | 3292 nT(); |
100 | 3293 break; |
493
d13502b6fa5f
Added code to the Parser and edited main.wiki.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
492
diff
changeset
|
3294 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
|
3295 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
|
3296 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
|
3297 // Fall through. It's a type. |
100 | 3298 default: |
248 | 3299 specType = parseType(); |
100 | 3300 } |
3301 default: | |
3302 } | |
377 | 3303 |
3304 TemplateParameters tparams; | |
3305 version(D2) | |
3306 { | |
3307 // is ( Type Identifier : TypeSpecialization , TemplateParameterList ) | |
3308 // is ( Type Identifier == TypeSpecialization , TemplateParameterList ) | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3309 if (ident && specType && token.kind == T.Comma) |
377 | 3310 tparams = parseTemplateParameterList2(); |
3311 } | |
102 | 3312 require(T.RParen); |
377 | 3313 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
|
3314 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3315 case T.LParen: |
646
68953760d569
Added class ParenExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
640
diff
changeset
|
3316 if (tokenAfterParenIs(T.LBrace)) // Check for "(...) {" |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3317 { // ( ParameterList ) FunctionBody |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3318 auto parameters = parseParameterList(); |
267
f3dfa6208ed3
- Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents:
266
diff
changeset
|
3319 auto funcBody = parseFunctionBody(); |
289
a99357783c6f
- Fix: assign targs to member targs of TraitsExpression.
aziz
parents:
288
diff
changeset
|
3320 e = new FunctionLiteralExpression(null, parameters, funcBody); |
130 | 3321 } |
3322 else | |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3323 { // ( Expression ) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3324 skip(T.LParen); |
130 | 3325 e = parseExpression(); |
3326 require(T.RParen); | |
646
68953760d569
Added class ParenExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
640
diff
changeset
|
3327 e = new ParenExpression(e); |
130 | 3328 } |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3329 break; |
269 | 3330 version(D2) |
3331 { | |
3332 case T.Traits: | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3333 requireNext(T.LParen); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3334 auto id = requireIdentifier(MSG.ExpectedAnIdentifier); |
269 | 3335 TemplateArguments args; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3336 if (token.kind == T.Comma) |
269 | 3337 args = parseTemplateArguments2(); |
3338 else | |
3339 require(T.RParen); | |
3340 e = new TraitsExpression(id, args); | |
3341 break; | |
3342 } | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
3343 default: |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3344 if (token.isIntegralType) |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3345 { // IntegralType . Identifier |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3346 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
|
3347 nT(); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3348 set(type, begin); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3349 require(T.Dot); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3350 auto ident = requireIdentifier(MSG.ExpectedIdAfterTypeDot); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3351 e = new TypeDotIdExpression(type, ident); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3352 } |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3353 else if (token.isSpecialToken) |
343
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3354 { |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3355 e = new SpecialTokenExpression(token); |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3356 nT(); |
95f1b6e43214
- Removed TOK.Special and added an own entry for each special token.
aziz
parents:
342
diff
changeset
|
3357 } |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3358 else |
414
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3359 { |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3360 error(MID.ExpectedButFound, "Expression", token.srcText); |
659
304331ca2f95
Renamed EmptyExpression to IllegalExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
655
diff
changeset
|
3361 e = new IllegalExpression(); |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3362 if (!trying) |
653
29cc5bf3ce89
Refactored StringExpression.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
650
diff
changeset
|
3363 { // 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
|
3364 begin = lexer.insertEmptyTokenBefore(token); |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3365 this.prevToken = begin; |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3366 } |
414
9c69615a4876
Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
409
diff
changeset
|
3367 } |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3368 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3369 set(e, begin); |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
3370 return e; |
77 | 3371 } |
3372 | |
154
0e7cefb15e43
- Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents:
153
diff
changeset
|
3373 Expression parseNewExpression(/*Expression e*/) |
81 | 3374 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3375 auto begin = token; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3376 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
|
3377 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3378 Expression[] newArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3379 Expression[] ctorArguments; |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3380 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3381 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
|
3382 newArguments = parseArguments(); |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3383 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3384 // NewAnonClassExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3385 // 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
|
3386 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
|
3387 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3388 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
|
3389 ctorArguments = parseArguments(); |
144
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3390 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3391 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
|
3392 |
495
b60450804b6e
Attributes are evaluated during the parsing phase now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
494
diff
changeset
|
3393 auto decls = parseDeclarationDefinitionsBody(); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3394 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
|
3395 } |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3396 |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3397 // NewExpression: |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3398 // NewArguments Type [ AssignExpression ] |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3399 // NewArguments Type ( ArgumentList ) |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3400 // NewArguments Type |
cfd890b250e6
- Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents:
143
diff
changeset
|
3401 auto type = parseType(); |
302
d04a79e795a2
- Fix in parseNewExpression(): removed check for type id.
aziz
parents:
301
diff
changeset
|
3402 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3403 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
|
3404 ctorArguments = parseArguments(); |
302
d04a79e795a2
- Fix in parseNewExpression(): removed check for type id.
aziz
parents:
301
diff
changeset
|
3405 |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3406 return set(new NewExpression(/*e, */newArguments, type, ctorArguments), begin); |
81 | 3407 } |
3408 | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3409 Type parseType() |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3410 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
3411 return parseBasicType2(parseBasicType()); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3412 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3413 |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3414 Type parseIdentifierType() |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3415 { |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3416 auto begin = token; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3417 auto ident = requireIdentifier(MSG.ExpectedAnIdentifier); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3418 Type t; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3419 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
|
3420 t = new TemplateInstanceType(ident, parseTemplateArguments()); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3421 else // Identifier |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3422 t = new IdentifierType(ident); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3423 return set(t, begin); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3424 } |
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 parseQualifiedType() |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3427 { |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3428 auto begin = token; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3429 Type type; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3430 if (consumed(T.Dot)) |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3431 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
|
3432 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
|
3433 { |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3434 type = parseTypeofType(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3435 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
|
3436 return type; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3437 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3438 else |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3439 type = parseIdentifierType(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3440 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3441 while (consumed(T.Dot)) |
618
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3442 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
|
3443 return type; |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3444 } |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3445 |
94 | 3446 Type parseBasicType() |
3447 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3448 auto begin = token; |
94 | 3449 Type t; |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3450 |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3451 if (token.isIntegralType) |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3452 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3453 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
|
3454 nT(); |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3455 } |
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3456 else |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3457 switch (token.kind) |
94 | 3458 { |
153 | 3459 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
|
3460 t = parseQualifiedType(); |
07946b379006
Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
616
diff
changeset
|
3461 return t; |
269 | 3462 version(D2) |
3463 { | |
3464 case T.Const: | |
3465 // const ( Type ) | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3466 requireNext(T.LParen); |
269 | 3467 t = parseType(); |
3468 require(T.RParen); | |
3469 t = new ConstType(t); | |
3470 break; | |
3471 case T.Invariant: | |
3472 // invariant ( Type ) | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3473 requireNext(T.LParen); |
269 | 3474 t = parseType(); |
3475 require(T.RParen); | |
3476 t = new InvariantType(t); | |
3477 break; | |
369 | 3478 } // version(D2) |
94 | 3479 default: |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
3480 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
|
3481 t = new IllegalType(); |
259
8118da6fee44
- Moved nT() below statement where an attribute class is constructed.
aziz
parents:
258
diff
changeset
|
3482 nT(); |
94 | 3483 } |
508
943ecc9c133a
Added isIntegralType() to Token and refactored code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
507
diff
changeset
|
3484 return set(t, begin); |
94 | 3485 } |
3486 | |
95 | 3487 Type parseBasicType2(Type t) |
3488 { | |
3489 while (1) | |
3490 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3491 auto begin = token; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3492 switch (token.kind) |
95 | 3493 { |
3494 case T.Mul: | |
3495 t = new PointerType(t); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3496 nT(); |
95 | 3497 break; |
3498 case T.LBracket: | |
106 | 3499 t = parseArrayType(t); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3500 continue; |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3501 case T.Function, T.Delegate: |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3502 TOK tok = token.kind; |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3503 nT(); |
143 | 3504 auto parameters = parseParameterList(); |
135 | 3505 if (tok == T.Function) |
291
c0e857931ff6
- Changed FunctionType and DelegateType. Both receive return type and parameters.
aziz
parents:
290
diff
changeset
|
3506 t = new FunctionType(t, parameters); |
135 | 3507 else |
291
c0e857931ff6
- Changed FunctionType and DelegateType. Both receive return type and parameters.
aziz
parents:
290
diff
changeset
|
3508 t = new DelegateType(t, parameters); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3509 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3510 default: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3511 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3512 } |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3513 set(t, begin); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3514 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3515 assert(0); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3516 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3517 |
232
2a4e2c8ca094
- Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents:
231
diff
changeset
|
3518 bool tokenAfterParenIs(TOK tok) |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3519 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3520 // 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
|
3521 // 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
|
3522 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
|
3523 Token* next = token; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3524 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
|
3525 Loop: |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3526 while (1) |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3527 { |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
3528 lexer.peek(next); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3529 switch (next.kind) |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3530 { |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3531 case T.RParen: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3532 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
|
3533 { // 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
|
3534 do |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
618
diff
changeset
|
3535 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
|
3536 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
|
3537 break Loop; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3538 } |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3539 break; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3540 case T.LParen: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3541 ++level; |
434
cac9c8d637ad
Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
429
diff
changeset
|
3542 break; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3543 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
|
3544 break Loop; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3545 default: |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3546 } |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3547 } |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3548 return next.kind == tok; |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3549 } |
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3550 |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3551 /// Parse the C-style array types after the declarator. |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3552 Type parseDeclaratorSuffix(Type lhsType) |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3553 { |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3554 // The Type chain should be as follows: |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3555 // int[3]* Identifier [][32] |
706
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
3556 // <- <- -> -. |
684ec5932b2e
Tidied up dil.parser.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
704
diff
changeset
|
3557 // ^-----------------´ |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3558 // Resulting chain: [][32]*[3]int |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3559 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
|
3560 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3561 if (token.kind != T.LBracket) |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3562 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
|
3563 |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3564 auto begin = token; |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3565 Type t; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3566 skip(T.LBracket); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3567 if (consumed(T.RBracket)) |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3568 t = new ArrayType(parseNext()); // [ ] |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3569 else |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3570 { |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3571 bool success; |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3572 Type parseAAType() |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3573 { |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3574 auto type = parseType(); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3575 require(T.RBracket); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3576 return type; |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3577 } |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3578 auto assocType = try_(&parseAAType, success); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3579 if (success) |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3580 t = new ArrayType(parseNext(), assocType); // [ Type ] |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3581 else |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3582 { |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3583 Expression e = parseExpression(), e2; |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3584 if (consumed(T.Slice)) |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3585 e2 = parseExpression(); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3586 require(T.RBracket); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3587 t = new ArrayType(parseNext(), e, e2); // [ Expression .. Expression ] |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3588 } |
196
ea3f66901fa4
- Added code for parsing template parameter lists for functions.
aziz
parents:
195
diff
changeset
|
3589 } |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3590 set(t, begin); |
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3591 return t; |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3592 } |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3593 return parseNext(); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3594 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3595 |
106 | 3596 Type parseArrayType(Type t) |
3597 { | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3598 auto begin = token; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3599 skip(T.LBracket); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3600 if (consumed(T.RBracket)) |
106 | 3601 t = new ArrayType(t); |
3602 else | |
3603 { | |
214 | 3604 bool success; |
369 | 3605 Type parseAAType() |
3606 { | |
3607 auto type = parseType(); | |
3608 require(T.RBracket); | |
3609 return type; | |
3610 } | |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
3611 auto assocType = try_(&parseAAType, success); |
214 | 3612 if (success) |
106 | 3613 t = new ArrayType(t, assocType); |
3614 else | |
3615 { | |
3616 Expression e = parseExpression(), e2; | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3617 if (consumed(T.Slice)) |
106 | 3618 e2 = parseExpression(); |
677
118971211c4c
Fixed parseDeclaratorSuffix().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
675
diff
changeset
|
3619 require(T.RBracket); |
106 | 3620 t = new ArrayType(t, e, e2); |
3621 } | |
3622 } | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3623 set(t, begin); |
106 | 3624 return t; |
3625 } | |
3626 | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3627 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
|
3628 { |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3629 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
|
3630 auto begin = token; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3631 skip(T.LParen); |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3632 |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3633 type = parseBasicType2(type); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3634 if (token.kind == T.LParen) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3635 { // Can be nested. |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3636 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
|
3637 } |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3638 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
|
3639 { // 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
|
3640 ident = token.ident; |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3641 nT(); |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3642 type = parseDeclaratorSuffix(type); |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3643 } |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3644 require(T.RParen); |
483
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3645 |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3646 Parameters params; |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3647 if (optionalParamList) |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3648 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
|
3649 else |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3650 params = parseParameterList(); |
180711cc4b66
Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
434
diff
changeset
|
3651 |
535
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
3652 type = new CFuncPointerType(type, params); |
bdd49ad84f5f
Fixed parsing bug in parseVariableOrFunction().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
532
diff
changeset
|
3653 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
|
3654 } |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3655 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3656 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
|
3657 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
3658 auto t = parseType(); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3659 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3660 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
|
3661 t = parseCFunctionPointerType(t, ident, true); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3662 else if (token.kind == T.Identifier) |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3663 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3664 ident = token.ident; |
95 | 3665 nT(); |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
3666 t = parseDeclaratorSuffix(t); |
95 | 3667 } |
409
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3668 |
38fccd2640eb
Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
406
diff
changeset
|
3669 if (ident is null && !identOptional) |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3670 error(token, MSG.ExpectedDeclaratorIdentifier, token.srcText); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
3671 |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
3672 return t; |
95 | 3673 } |
3674 | |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3675 /++ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3676 Parse a list of AssignExpressions. |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3677 ExpressionList: |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3678 AssignExpression |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3679 AssignExpression , ExpressionList |
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 Expression[] parseExpressionList() |
138 | 3682 { |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3683 Expression[] expressions; |
531
315aeb3f7a9b
Added method skipped() to dil.Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
530
diff
changeset
|
3684 do |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3685 expressions ~= parseAssignExpression(); |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3686 while(consumed(T.Comma)) |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3687 return expressions; |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3688 } |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3689 |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3690 /++ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3691 Arguments: |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3692 ( ) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3693 ( ExpressionList ) |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3694 +/ |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3695 Expression[] parseArguments() |
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3696 { |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3697 skip(T.LParen); |
486
bd176bc73e43
Fixed a few things in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
3698 Expression[] args; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3699 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
|
3700 args = parseExpressionList(); |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3701 require(T.RParen); |
139 | 3702 return args; |
138 | 3703 } |
3704 | |
143 | 3705 Parameters parseParameterList() |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3706 out(params) |
96 | 3707 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3708 if (params.length > 1) |
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3709 foreach (param; params.items[0..$-1]) |
96 | 3710 { |
117
79857de26e86
- Moved class Parameter to module Types. Added struct Parameters.
aziz
parents:
116
diff
changeset
|
3711 if (param.isVariadic()) |
96 | 3712 assert(0, "variadic arguments can only appear at the end of the parameter list."); |
3713 } | |
3714 } | |
3715 body | |
95 | 3716 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3717 auto begin = token; |
95 | 3718 require(T.LParen); |
3719 | |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3720 auto params = new Parameters(); |
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3721 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3722 if (consumed(T.RParen)) |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3723 return set(params, begin); |
95 | 3724 |
749 | 3725 do |
95 | 3726 { |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3727 auto paramBegin = token; |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3728 StorageClass stc, stc_; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3729 Type type; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3730 Identifier* ident; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3731 Expression defValue; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3732 |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3733 void pushParameter() |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3734 { |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3735 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
|
3736 } |
269 | 3737 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3738 if (consumed(T.Ellipses)) |
269 | 3739 { |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3740 stc = StorageClass.Variadic; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3741 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
|
3742 break; |
269 | 3743 } |
3744 | |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3745 while (1) |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3746 { // Parse storage classes. |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3747 switch (token.kind) |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3748 { |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3749 version(D2) |
95 | 3750 { |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3751 case T.Invariant: // D2.0 |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3752 if (peekNext() == T.LParen) |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3753 break; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3754 stc_ = StorageClass.Invariant; |
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.Const: // D2.0 |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3757 if (peekNext() == T.LParen) |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3758 break; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3759 stc_ = StorageClass.Const; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3760 goto Lcommon; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3761 case T.Final: // D2.0 |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3762 stc_ = StorageClass.Final; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3763 goto Lcommon; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3764 case T.Scope: // D2.0 |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3765 stc_ = StorageClass.Scope; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3766 goto Lcommon; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3767 case T.Static: // D2.0 |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3768 stc_ = StorageClass.Static; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3769 goto Lcommon; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3770 } |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3771 case T.In: |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3772 stc_ = StorageClass.In; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3773 goto Lcommon; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3774 case T.Out: |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3775 stc_ = StorageClass.Out; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3776 goto Lcommon; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3777 case T.Inout, T.Ref: |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3778 stc_ = StorageClass.Ref; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3779 goto Lcommon; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3780 case T.Lazy: |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3781 stc_ = StorageClass.Lazy; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3782 goto Lcommon; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3783 Lcommon: |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3784 // Check for redundancy. |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3785 if (stc & stc_) |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3786 error(MID.RedundantStorageClass, token.srcText); |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3787 else |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3788 stc |= stc_; |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3789 nT(); |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3790 version(D2) |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3791 continue; |
269 | 3792 else |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3793 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
|
3794 default: |
95 | 3795 } |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3796 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
|
3797 } |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3798 type = parseDeclarator(ident, true); |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3799 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3800 if (consumed(T.Assign)) |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3801 defValue = parseAssignExpression(); |
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 if (consumed(T.Ellipses)) |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3804 { |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3805 stc |= StorageClass.Variadic; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3806 pushParameter(); |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3807 break; |
95 | 3808 } |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3809 pushParameter(); |
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3810 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3811 } while (consumed(T.Comma)) |
95 | 3812 require(T.RParen); |
242
7ec7ad8df9da
- Changed type of member tok in class BinaryExpression to Token*.
aziz
parents:
240
diff
changeset
|
3813 return set(params, begin); |
95 | 3814 } |
3815 | |
150
753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
aziz
parents:
149
diff
changeset
|
3816 TemplateArguments parseTemplateArguments() |
139 | 3817 { |
376 | 3818 TemplateArguments targs; |
139 | 3819 require(T.LParen); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3820 if (token.kind != T.RParen) |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3821 targs = parseTemplateArguments_(); |
139 | 3822 require(T.RParen); |
376 | 3823 return targs; |
139 | 3824 } |
376 | 3825 |
269 | 3826 version(D2) |
3827 { | |
3828 TemplateArguments parseTemplateArguments2() | |
3829 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3830 skip(T.Comma); |
376 | 3831 TemplateArguments targs; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3832 if (token.kind != T.RParen) |
376 | 3833 targs = parseTemplateArguments_(); |
269 | 3834 else |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3835 error(token, MSG.ExpectedTypeOrExpression); |
269 | 3836 require(T.RParen); |
376 | 3837 return targs; |
269 | 3838 } |
3839 } // version(D2) | |
376 | 3840 |
3841 TemplateArguments parseTemplateArguments_() | |
3842 { | |
3843 auto begin = token; | |
3844 auto targs = new TemplateArguments; | |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3845 do |
376 | 3846 { |
379
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
3847 Type parseType_() |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
3848 { |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
3849 auto type = parseType(); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3850 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
|
3851 return type; |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3852 errorCount++; // Cause try_() to fail. |
379
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
3853 return null; |
a92f7826a4fa
- Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents:
377
diff
changeset
|
3854 } |
376 | 3855 bool success; |
423
6057113f9a44
Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
3856 auto typeArgument = try_(&parseType_, success); |
376 | 3857 if (success) |
3858 // TemplateArgument: | |
3859 // Type | |
3860 // Symbol | |
3861 targs ~= typeArgument; | |
3862 else | |
3863 // TemplateArgument: | |
3864 // AssignExpression | |
3865 targs ~= parseAssignExpression(); | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3866 } while (consumed(T.Comma)) |
376 | 3867 set(targs, begin); |
3868 return targs; | |
3869 } | |
3870 | |
258 | 3871 TemplateParameters parseTemplateParameterList() |
137 | 3872 { |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3873 auto begin = token; |
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3874 auto tparams = new TemplateParameters; |
377 | 3875 require(T.LParen); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3876 if (token.kind != T.RParen) |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3877 parseTemplateParameterList_(tparams); |
377 | 3878 require(T.RParen); |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3879 return set(tparams, begin); |
377 | 3880 } |
3881 | |
3882 version(D2) | |
3883 { | |
3884 TemplateParameters parseTemplateParameterList2() | |
3885 { | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3886 skip(T.Comma); |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3887 auto begin = token; |
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3888 auto tparams = new TemplateParameters; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3889 if (token.kind != T.RParen) |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3890 parseTemplateParameterList_(tparams); |
377 | 3891 else |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3892 error(token, MSG.ExpectedTemplateParameters); |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3893 return set(tparams, begin); |
377 | 3894 } |
3895 } // version(D2) | |
3896 | |
766
0af3b145a405
Revised TemplateParameterList parsing functions.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
765
diff
changeset
|
3897 void parseTemplateParameterList_(TemplateParameters tparams) |
377 | 3898 { |
748
efd87fdb1c00
Tidied up dil.parser.Parser a bit.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
726
diff
changeset
|
3899 do |
137 | 3900 { |
258 | 3901 auto paramBegin = token; |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3902 TemplateParameter tp; |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3903 Identifier* ident; |
137 | 3904 Type specType, defType; |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3905 |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3906 void parseSpecAndOrDefaultType() |
137 | 3907 { |
3908 // : SpecializationType | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3909 if (consumed(T.Colon)) |
137 | 3910 specType = parseType(); |
3911 // = DefaultType | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3912 if (consumed(T.Assign)) |
137 | 3913 defType = parseType(); |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3914 } |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3915 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3916 switch (token.kind) |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3917 { |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3918 case T.Alias: |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3919 // TemplateAliasParameter: |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3920 // alias Identifier |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3921 skip(T.Alias); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3922 ident = requireIdentifier(MSG.ExpectedAliasTemplateParam); |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3923 parseSpecAndOrDefaultType(); |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3924 tp = new TemplateAliasParameter(ident, specType, defType); |
137 | 3925 break; |
3926 case T.Identifier: | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3927 ident = token.ident; |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
237
diff
changeset
|
3928 switch (peekNext()) |
137 | 3929 { |
3930 case T.Ellipses: | |
3931 // TemplateTupleParameter: | |
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); skip(T.Ellipses); |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3934 if (token.kind == T.Comma) |
342
f13d551d7c4f
- Added error messages MID.InContract and MID.OutContract.
aziz
parents:
341
diff
changeset
|
3935 error(MID.TemplateTupleParameter); |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3936 tp = new TemplateTupleParameter(ident); |
137 | 3937 break; |
3938 case T.Comma, T.RParen, T.Colon, T.Assign: | |
3939 // TemplateTypeParameter: | |
3940 // Identifier | |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3941 skip(T.Identifier); |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3942 parseSpecAndOrDefaultType(); |
341
3ac651ea83fb
- Fix: created TemplateAliasParameter instead of TemplateTypeParameter.
aziz
parents:
340
diff
changeset
|
3943 tp = new TemplateTypeParameter(ident, specType, defType); |
137 | 3944 break; |
3945 default: | |
3946 // TemplateValueParameter: | |
3947 // Declarator | |
3948 ident = null; | |
3949 goto LTemplateValueParameter; | |
3950 } | |
3951 break; | |
492
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
3952 version(D2) |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
3953 { |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
3954 case T.This: |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
3955 // TemplateThisParameter |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
3956 // this TemplateTypeParameter |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
3957 skip(T.This); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
3958 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
|
3959 parseSpecAndOrDefaultType(); |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
3960 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
|
3961 break; |
9c208925a3d4
Added module ImportParser and new stuff from DMD2.008.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
491
diff
changeset
|
3962 } |
137 | 3963 default: |
3964 LTemplateValueParameter: | |
3965 // TemplateValueParameter: | |
3966 // Declarator | |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3967 Expression specValue, defValue; |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3968 auto valueType = parseDeclarator(ident); |
137 | 3969 // : SpecializationValue |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3970 if (consumed(T.Colon)) |
137 | 3971 specValue = parseCondExpression(); |
3972 // = DefaultValue | |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3973 if (consumed(T.Assign)) |
137 | 3974 defValue = parseCondExpression(); |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3975 tp = new TemplateValueParameter(valueType, ident, specValue, defValue); |
137 | 3976 } |
3977 | |
340
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3978 // Push template parameter. |
1accb3013bd2
- Changed class TemplateParameter to an abstract class.
aziz
parents:
335
diff
changeset
|
3979 tparams ~= set(tp, paramBegin); |
137 | 3980 |
767
1771398583fa
Renamed skipped() to consumed().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
766
diff
changeset
|
3981 } while (consumed(T.Comma)) |
137 | 3982 } |
3983 | |
124 | 3984 void expected(TOK tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3985 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3986 if (token.kind != tok) |
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 require(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3991 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
3992 if (token.kind == tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3993 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3994 else |
327 | 3995 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
|
3996 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3997 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3998 void requireNext(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
3999 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4000 nT(); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4001 require(tok); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4002 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
4003 |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4004 Identifier* optionalIdentifier() |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4005 { |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
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); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4009 return id; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4010 } |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4011 |
504
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4012 Identifier* requireIdentifier() |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4013 { |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4014 Identifier* id; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4015 if (token.kind == T.Identifier) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
4016 (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
|
4017 else |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4018 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
|
4019 return id; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4020 } |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4021 |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
4022 /// Params: |
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
4023 /// 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
|
4024 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
|
4025 { |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4026 Identifier* id; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4027 if (token.kind == T.Identifier) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
4028 (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
|
4029 else |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4030 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
|
4031 return id; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4032 } |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4033 |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4034 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
|
4035 { |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4036 Identifier* id; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4037 if (token.kind == T.Identifier) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
4038 (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
|
4039 else |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4040 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
|
4041 return id; |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4042 } |
9076c4cea2a4
Changed occur. of Token* to Identifier* and refactored Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
502
diff
changeset
|
4043 |
243 | 4044 Token* requireId() |
4045 { | |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4046 if (token.kind == T.Identifier) |
243 | 4047 { |
4048 auto id = token; | |
4049 nT(); | |
4050 return id; | |
4051 } | |
4052 else | |
4053 error(MID.ExpectedButFound, "Identifier", token.srcText); | |
4054 return null; | |
4055 } | |
4056 | |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4057 Token* requireIdToken(char[] errorMsg) |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4058 { |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4059 Token* idtok; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
677
diff
changeset
|
4060 if (token.kind == T.Identifier) |
774
846044180d22
Added method skip() to class Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
4061 (idtok = token), skip(T.Identifier); |
505
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4062 else |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4063 error(token, errorMsg, token.srcText); |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4064 return idtok; |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4065 } |
3bb94ba21490
Refactored a great amount of code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
504
diff
changeset
|
4066 |
789
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
4067 /// Returns true if the string str has an invalid UTF-8 sequence. |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
4068 bool checkString(Token* begin, string str) |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
4069 { |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
4070 auto utf8Seq = Lexer.findInvalidUTF8Sequence(str); |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
4071 if (utf8Seq.length) |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
4072 error(begin, MSG.InvalidUTF8SequenceInString, utf8Seq); |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
4073 return utf8Seq.length != 0; |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
4074 } |
c1d5cfd7aa44
Implemented string literal conversion.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
774
diff
changeset
|
4075 |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4076 /// 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
|
4077 void error(Token* token, char[] formatMsg, ...) |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4078 { |
514
6ddff941862a
Added new error classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
511
diff
changeset
|
4079 error_(token, formatMsg, _arguments, _argptr); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4080 } |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4081 |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
4082 void error(MID mid, ...) |
71 | 4083 { |
514
6ddff941862a
Added new error classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
511
diff
changeset
|
4084 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
|
4085 } |
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4086 |
762
c909a3d3fa52
Fixed vararg issue with gdc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
4087 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
|
4088 { |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4089 if (trying) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4090 { |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4091 ++errorCount; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4092 return; |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
206
diff
changeset
|
4093 } |
675
e7811328e6c7
Made Token.getLocation() a template function and added two aliases.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
673
diff
changeset
|
4094 auto location = token.getErrorLocation(); |
496
5a607597dc22
Improved error recovery in the Parser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
495
diff
changeset
|
4095 auto msg = Format(_arguments, _argptr, formatMsg); |
520
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
519
diff
changeset
|
4096 auto error = new ParserError(location, msg); |
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
519
diff
changeset
|
4097 errors ~= error; |
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
519
diff
changeset
|
4098 if (infoMan !is null) |
f203c5248d0b
Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
519
diff
changeset
|
4099 infoMan ~= error; |
71 | 4100 } |
65 | 4101 } |