commit
0c6f6f0577
|
@ -1,2 +1,5 @@
|
||||||
*.o
|
*.o
|
||||||
bin
|
bin
|
||||||
|
*.d.out
|
||||||
|
.dub
|
||||||
|
dfmt
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "dfmt",
|
||||||
|
"description": "Dfmt is a formatter for D source code",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"targetType": "executable",
|
||||||
|
"dependencies": {
|
||||||
|
"libdparse": "~master"
|
||||||
|
},
|
||||||
|
}
|
2
makefile
2
makefile
|
@ -6,3 +6,5 @@ FLAGS := -g -w $(INCLUDE_PATHS)
|
||||||
all: $(SRC)
|
all: $(SRC)
|
||||||
$(COMPILER) $(FLAGS) $(SRC) -ofbin/dfmt
|
$(COMPILER) $(FLAGS) $(SRC) -ofbin/dfmt
|
||||||
|
|
||||||
|
test: bin/dfmt
|
||||||
|
cd tests && ./test.sh
|
||||||
|
|
|
@ -33,9 +33,14 @@ import std.d.parser;
|
||||||
import std.d.formatter;
|
import std.d.formatter;
|
||||||
import std.d.ast;
|
import std.d.ast;
|
||||||
import std.array;
|
import std.array;
|
||||||
|
import std.getopt;
|
||||||
|
|
||||||
int main(string[] args)
|
int main(string[] args)
|
||||||
{
|
{
|
||||||
|
bool inplace = false;
|
||||||
|
getopt(args,
|
||||||
|
"inplace", &inplace);
|
||||||
|
File output = stdout;
|
||||||
ubyte[] buffer;
|
ubyte[] buffer;
|
||||||
if (args.length == 1)
|
if (args.length == 1)
|
||||||
{
|
{
|
||||||
|
@ -55,6 +60,8 @@ int main(string[] args)
|
||||||
File f = File(args[1]);
|
File f = File(args[1]);
|
||||||
buffer = new ubyte[](cast(size_t)f.size);
|
buffer = new ubyte[](cast(size_t)f.size);
|
||||||
f.rawRead(buffer);
|
f.rawRead(buffer);
|
||||||
|
if (inplace)
|
||||||
|
output = File(args[1], "w");
|
||||||
}
|
}
|
||||||
LexerConfig config;
|
LexerConfig config;
|
||||||
config.stringBehavior = StringBehavior.source;
|
config.stringBehavior = StringBehavior.source;
|
||||||
|
@ -71,7 +78,7 @@ int main(string[] args)
|
||||||
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, stdout, &astInformation,
|
auto tokenFormatter = TokenFormatter(tokens, output, &astInformation,
|
||||||
&formatterConfig);
|
&formatterConfig);
|
||||||
tokenFormatter.format();
|
tokenFormatter.format();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Computes average line length for standard input.
|
||||||
|
import std.stdio;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
ulong lines = 0;
|
||||||
|
double sumLength = 0;
|
||||||
|
foreach (line; stdin.byLine())
|
||||||
|
{
|
||||||
|
++lines;
|
||||||
|
sumLength += line.length;
|
||||||
|
}
|
||||||
|
writeln("Average line length: ",
|
||||||
|
lines ? sumLength / lines : 0);
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Computes average line length for standard input.
|
||||||
|
import std.stdio;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
ulong lines = 0;
|
||||||
|
double sumLength = 0;
|
||||||
|
foreach (line; stdin.byLine())
|
||||||
|
{
|
||||||
|
++lines;
|
||||||
|
sumLength += line.length;
|
||||||
|
}
|
||||||
|
writeln("Average line length: ", lines ? sumLength / lines:0);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
import std.stdio; void main() { writeln("Hello, world without explicit compilations!"); }
|
|
@ -0,0 +1,7 @@
|
||||||
|
import std.stdio;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
writeln("Hello, world without explicit compilations!");
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
for source in *.d
|
||||||
|
do
|
||||||
|
../bin/dfmt "${source}" >"${source}.out"
|
||||||
|
diff -u "${source}.ref" "${source}.out" || echo "fail ${source}"
|
||||||
|
done
|
Loading…
Reference in New Issue