Use libdparse to check for named arg

Remove custom named arg parser
This commit is contained in:
Daniel Zuncke 2023-10-26 16:21:03 +02:00 committed by Jan Jurzitza
parent 9f377100f0
commit 2ea6c43a66
1 changed files with 8 additions and 17 deletions

View File

@ -461,33 +461,24 @@ final class FormatVisitor : ASTVisitor
return; return;
} }
/+
Items are function arguments: f(<item>, <item>);
Iterate them and check if they are named arguments: tok!":" belongs to a
named argument if it is preceeded by one tok!"identifier" (+ any number
of comments):
+/
foreach (item; functionCall.arguments.namedArgumentList.items) foreach (item; functionCall.arguments.namedArgumentList.items)
{ {
// Set to true after first tok!"identifier". // Do nothing if not a named argument.
auto foundIdentifier = false; if (item.name == tok!"")
foreach (t; item.tokens)
{ {
if (t.type == tok!"identifier" && !foundIdentifier)
{
foundIdentifier = true;
continue; continue;
} }
if (t.type == tok!":" && foundIdentifier) // Find first colon if named argument.
foreach (t; item.tokens)
{
if (t.type == tok!":")
{ {
astInformation.namedArgumentColonLocations ~= t.index; astInformation.namedArgumentColonLocations ~= t.index;
}
break; break;
} }
} }
}
functionCall.accept(this); functionCall.accept(this);
} }