libdparse
libdparse copied to clipboard
`parseModule` overload set should take the parser type as template parameter
Since we can make derived Parser
classes.
updated functions would then be like:
/**
* Params:
* parserConfig = a parser configuration.
* Returns:
* The parsed module.
*/
Module parseModule(P = .Parser)(auto ref ParserConfig parserConfig)
{
auto parser = new P();
with (parserConfig)
{
parser.fileName = fileName;
parser.tokens = tokens;
parser.messageFunction = messageFunction;
parser.messageDelegate = messageDelegate;
parser.allocator = allocator;
}
Module mod = parser.parseModule();
with (parserConfig)
{
if (warningCount !is null)
*warningCount = parser.warningCount;
if (errorCount !is null)
*errorCount = parser.errorCount;
}
return mod;
}
/**
* Params:
* tokens = The tokens parsed by dparse.lexer.
* fileName = The name of the file being parsed.
* allocator = A pointer to a rollback allocator.
* messageFuncOrDg = Either a function or a delegate that receives the parser messages.
* errorCount = An optional pointer to a variable receiving the error count.
* warningCount = An optional pointer to a variable receiving the warning count.
* Returns:
* The parsed module.
*/
Module parseModule(P = .Parser,F)(const(Token)[] tokens, string fileName, RollbackAllocator* allocator,
F messageFuncOrDg = null, uint* errorCount = null, uint* warningCount = null)
{
static if (is(F))
{
static if (is(F : MessageFunction))
return ParserConfig(tokens, fileName, allocator, messageFuncOrDg, null,
errorCount, warningCount).parseModule();
else static if (is(F : MessageDelegate))
return ParserConfig(tokens, fileName, allocator, null, messageFuncOrDg,
errorCount, warningCount).parseModule();
else static assert(0, "F must be a MessageFunction or a MessageDelegate");
}
else
{
return ParserConfig(tokens, fileName, allocator, null, null, null, null).parseModule!P();
}
}
seems like an easy change, can you make a PR to let CI run over it?