Allow for outputting to anything supporting the write() method. Make it possible to exclude main.
This commit is contained in:
parent
9e7d57af84
commit
81b17c8f31
16
src/dfmt.d
16
src/dfmt.d
|
|
@ -42,6 +42,9 @@ Formats D code.
|
||||||
-h, --help display this help and exit
|
-h, --help display this help and exit
|
||||||
";
|
";
|
||||||
|
|
||||||
|
version (NoMain)
|
||||||
|
{ }
|
||||||
|
else
|
||||||
int main(string[] args)
|
int main(string[] args)
|
||||||
{
|
{
|
||||||
import std.getopt;
|
import std.getopt;
|
||||||
|
|
@ -103,7 +106,8 @@ int main(string[] args)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void format(string source_desc, ubyte[] buffer, File output)
|
|
||||||
|
void format(Output)(string source_desc, ubyte[] buffer, Output output)
|
||||||
{
|
{
|
||||||
LexerConfig config;
|
LexerConfig config;
|
||||||
config.stringBehavior = StringBehavior.source;
|
config.stringBehavior = StringBehavior.source;
|
||||||
|
|
@ -120,14 +124,14 @@ void format(string source_desc, ubyte[] buffer, File output)
|
||||||
visitor.visit(mod);
|
visitor.visit(mod);
|
||||||
astInformation.cleanup();
|
astInformation.cleanup();
|
||||||
auto tokens = byToken(buffer, config, &cache).array();
|
auto tokens = byToken(buffer, config, &cache).array();
|
||||||
auto tokenFormatter = TokenFormatter(tokens, output, &astInformation,
|
auto tokenFormatter = TokenFormatter!Output(tokens, output, &astInformation,
|
||||||
&formatterConfig);
|
&formatterConfig);
|
||||||
tokenFormatter.format();
|
tokenFormatter.format();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TokenFormatter
|
struct TokenFormatter(Output)
|
||||||
{
|
{
|
||||||
this(const(Token)[] tokens, File output, ASTInformation* astInformation,
|
this(const(Token)[] tokens, Output output, ASTInformation* astInformation,
|
||||||
FormatterConfig* config)
|
FormatterConfig* config)
|
||||||
{
|
{
|
||||||
this.tokens = tokens;
|
this.tokens = tokens;
|
||||||
|
|
@ -745,8 +749,8 @@ private:
|
||||||
/// Length of the current line (so far)
|
/// Length of the current line (so far)
|
||||||
uint currentLineLength = 0;
|
uint currentLineLength = 0;
|
||||||
|
|
||||||
/// File to output to
|
/// Output to write output to
|
||||||
File output;
|
Output output;
|
||||||
|
|
||||||
/// Tokens being formatted
|
/// Tokens being formatted
|
||||||
const(Token)[] tokens;
|
const(Token)[] tokens;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue