Skip to content

Commit abeefa2

Browse files
committed
Add scope to foreach
1 parent fc790d9 commit abeefa2

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

src/dparse/ast.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,6 +1696,7 @@ final class ForeachType : BaseNode
16961696
/** */ bool isAlias;
16971697
/** */ bool isEnum;
16981698
/** */ bool isRef;
1699+
/** */ bool isScope;
16991700
/** */ IdType[] typeConstructors;
17001701
/** */ Type type;
17011702
/** */ Token identifier;

src/dparse/astprinter.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ class XMLPrinter : ASTVisitor
393393
override void visit(const ForeachType foreachType)
394394
{
395395
output.writeln("<foreachType>");
396+
if (foreachType.isAlias) output.writeln("<alias/>");
397+
if (foreachType.isEnum) output.writeln("<enum/>");
398+
if (foreachType.isRef) output.writeln("<ref/>");
399+
if (foreachType.isScope) output.writeln("<scope/>");
396400
foreach (constructor; foreachType.typeConstructors)
397401
{
398402
output.writeln("<typeConstructor>", str(constructor), "</typeConstructor>");

src/dparse/parser.d

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3287,7 +3287,7 @@ class Parser
32873287
* Parses a ForeachType
32883288
*
32893289
* $(GRAMMAR $(RULEDEF foreachType):
3290-
* ($(LITERAL 'ref') | $(LITERAL 'alias') | $(LITERAL 'enum') | $(RULE typeConstructor))* $(RULE type)? $(LITERAL Identifier)
3290+
* ($(LITERAL 'ref') | $(LITERAL 'alias') | $(LITERAL 'enum') | $(LITERAL 'scope') | $(RULE typeConstructor))* $(RULE type)? $(LITERAL Identifier)
32913291
* ;)
32923292
*/
32933293
ForeachType parseForeachType()
@@ -3313,6 +3313,11 @@ class Parser
33133313
node.isEnum = true;
33143314
advance();
33153315
}
3316+
else if (currentIs(tok!"scope"))
3317+
{
3318+
node.isScope = true;
3319+
advance();
3320+
}
33163321
else if (tok!"" != (typeConstructor = parseTypeConstructor(false)))
33173322
{
33183323
trace("\033[01;36mType constructor");

test/ast_checks/foreach.d

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
void foo(T)(T[] arr)
2+
{
3+
foreach (enum ref scope const inout alias f; arr) {}
4+
}

test/ast_checks/foreach.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//functionDeclaration//foreachStatement//foreachType/alias
2+
//functionDeclaration//foreachStatement//foreachType/enum
3+
//functionDeclaration//foreachStatement//foreachType/ref
4+
//functionDeclaration//foreachStatement//foreachType/scope
5+
//functionDeclaration//foreachStatement//foreachType/typeConstructor[text()='const']
6+
//functionDeclaration//foreachStatement//foreachType/typeConstructor[text()='inout']

0 commit comments

Comments
 (0)