code cleanup
This commit is contained in:
parent
89d18755b8
commit
119c6b917d
|
@ -1,4 +1,4 @@
|
||||||
create table files (path, mtime, id);
|
create table modules (path, mtime, id);
|
||||||
create table publicImports (importerId, importedId);
|
create table publicImports (importerId, importedId);
|
||||||
create table containers (name, protection, fileId, id);
|
create table containers (name, protection, moduleId, id);
|
||||||
create table symbols (name, type, kind, containerId, id);
|
create table symbols (name, type, kind, containerId, id);
|
||||||
|
|
209
main.d
209
main.d
|
@ -110,9 +110,9 @@ int main(string[] args)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
getopt(args, "I", &importDirs,/+ "dotComplete", &dotComplete,+/ "sloc", &sloc,
|
getopt(args, "I", &importDirs,/+ "dotComplete|d", &dotComplete,+/ "sloc|l", &sloc,
|
||||||
/+"json", &json,+/ /+"parenComplete", &parenComplete,+/ "highlight", &highlight,
|
/+"json|j", &json,+/ /+"parenComplete|p", &parenComplete,+/ "highlight", &highlight,
|
||||||
"ctags", &ctags, "recursive|r|R", &recursiveCtags, "help|h", &help,
|
"ctags|c", &ctags, "recursive|r|R", &recursiveCtags, "help|h", &help,
|
||||||
"tokenCount", &tokenCount, "frequencyCount", &frequencyCount);
|
"tokenCount", &tokenCount, "frequencyCount", &frequencyCount);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -120,188 +120,96 @@ int main(string[] args)
|
||||||
stderr.writeln(e.msg);
|
stderr.writeln(e.msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (help || (!sloc && /+!dotComplete &&+/ /+!json &&+/ /+!parenComplete &&+/ !highlight
|
if (help)
|
||||||
&& !ctags && !format && !tokenCount && !frequencyCount))
|
|
||||||
{
|
|
||||||
printHelp();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
importDirs ~= loadConfig();
|
|
||||||
|
|
||||||
if (tokenCount)
|
|
||||||
{
|
|
||||||
import core.memory;
|
|
||||||
/+if (args.length == 1)
|
|
||||||
{
|
|
||||||
writeln((cast (ubyte[]) stdin.byLine(KeepTerminator.yes).join()).byToken().walkLength());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{+/
|
|
||||||
LexerConfig config;
|
|
||||||
config.tokenStyle = TokenStyle.doNotReplaceSpecial;
|
|
||||||
foreach (arg; args[1..$])
|
|
||||||
{
|
|
||||||
config.fileName = arg;
|
|
||||||
uint count;
|
|
||||||
auto f = File(arg);
|
|
||||||
ubyte[] buffer = uninitializedArray!(ubyte[])(f.size);
|
|
||||||
foreach(t; byToken(f.rawRead(buffer), config))
|
|
||||||
{
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
writefln("%s: %d", arg, count);
|
|
||||||
}
|
|
||||||
/+}+/
|
|
||||||
}
|
|
||||||
/+else if (frequencyCount)
|
|
||||||
{
|
{
|
||||||
uint[TokenType] frequency;
|
printHelp(args[0]);
|
||||||
foreach (t; byToken(cast(ubyte[]) File(args[1]).byLine(KeepTerminator.yes).join()))
|
return 0;
|
||||||
{
|
}
|
||||||
frequency[t.type]++;
|
|
||||||
}
|
|
||||||
foreach (k, v; frequency)
|
|
||||||
{
|
|
||||||
writeln(v, ":", cast(TokenType) k);
|
|
||||||
}
|
|
||||||
}+/
|
|
||||||
|
|
||||||
/+if (sloc)
|
auto optionCount = count!"a"([sloc, highlight, ctags, json, tokenCount]);
|
||||||
|
if (optionCount > 1)
|
||||||
|
{
|
||||||
|
stderr.writeln("Too many options specified");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if (optionCount < 1)
|
||||||
|
{
|
||||||
|
printHelp(args[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tokenCount || sloc)
|
||||||
{
|
{
|
||||||
if (args.length == 1)
|
LexerConfig config;
|
||||||
|
config.tokenStyle = TokenStyle.doNotReplaceSpecial;
|
||||||
|
ulong[] counts = new ulong[args.length - 1];
|
||||||
|
foreach (i, arg; parallel(args[1..$]))
|
||||||
{
|
{
|
||||||
writeln(stdin.byLine(KeepTerminator.yes).join().byToken().count!(a => isLineOfCode(a.type))());
|
config.fileName = arg;
|
||||||
}
|
uint count;
|
||||||
else
|
auto f = File(arg);
|
||||||
{
|
ubyte[] buffer = uninitializedArray!(ubyte[])(f.size);
|
||||||
writeln(args[1..$].map!(a => File(a).byLine(KeepTerminator.yes).join().byToken(a))()
|
foreach (t; byToken(f.rawRead(buffer), config))
|
||||||
.joiner().count!(a => isLineOfCode(a.type))());
|
{
|
||||||
}
|
if (tokenCount)
|
||||||
return 0;
|
++counts[i];
|
||||||
}+/
|
else if (isLineOfCode(t.type))
|
||||||
|
++counts[i];
|
||||||
|
}
|
||||||
|
|
||||||
if (highlight)
|
}
|
||||||
|
foreach(i; 0 .. counts.length)
|
||||||
|
writefln("%s: %d", args[i + 1], counts[i]);
|
||||||
|
}
|
||||||
|
else if (highlight)
|
||||||
{
|
{
|
||||||
LexerConfig config;
|
LexerConfig config;
|
||||||
config.iterStyle = IterationStyle.everything;
|
config.iterStyle = IterationStyle.everything;
|
||||||
config.tokenStyle = TokenStyle.source;
|
config.tokenStyle = TokenStyle.source;
|
||||||
File f = args.length == 1 ? stdin : File(args[1]);
|
File f = args.length == 1 ? stdin : File(args[1]);
|
||||||
highlighter.highlight((cast(ubyte[]) f.byLine(KeepTerminator.yes).join()).byToken(config),
|
ubyte[] buffer = uninitializedArray!(ubyte[])(f.size);
|
||||||
|
highlighter.highlight(byToken(f.rawRead(buffer), config),
|
||||||
args.length == 1 ? "stdin" : args[1]);
|
args.length == 1 ? "stdin" : args[1]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/+if (dotComplete || parenComplete)
|
|
||||||
{
|
|
||||||
if (isAbsolute(args[1]))
|
|
||||||
importDirs ~= dirName(args[1]);
|
|
||||||
else
|
|
||||||
importDirs ~= getcwd();
|
|
||||||
Token[] tokens;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
to!size_t(args[1]);
|
|
||||||
auto f = appender!string();
|
|
||||||
char[] buf;
|
|
||||||
while (stdin.readln(buf))
|
|
||||||
f.put(buf);
|
|
||||||
tokens = f.data.byToken().array();
|
|
||||||
}
|
|
||||||
catch(ConvException e)
|
|
||||||
{
|
|
||||||
tokens = args[1].readText().byToken().array();
|
|
||||||
args.popFront();
|
|
||||||
}
|
|
||||||
auto mod = parseModule(tokens);
|
|
||||||
CompletionContext context = new CompletionContext(mod);
|
|
||||||
context.importDirectories = importDirs;
|
|
||||||
foreach (im; parallel(mod.imports))
|
|
||||||
{
|
|
||||||
auto p = findAbsPath(importDirs, im);
|
|
||||||
if (p is null || !p.exists())
|
|
||||||
continue;
|
|
||||||
context.addModule(p.readText().byToken().array().parseModule());
|
|
||||||
}
|
|
||||||
auto complete = AutoComplete(tokens, context);
|
|
||||||
if (parenComplete)
|
|
||||||
writeln(complete.parenComplete(to!size_t(args[1])));
|
|
||||||
else if (dotComplete)
|
|
||||||
writeln(complete.dotComplete(to!size_t(args[1])));
|
|
||||||
return 0;
|
|
||||||
}+/
|
|
||||||
|
|
||||||
/+if (json)
|
|
||||||
{
|
|
||||||
CircularBuffer!(Token) tokens;
|
|
||||||
File f = args.length == 1 ? stdin : File(args[1]);
|
|
||||||
tokens = new CircularBuffer!(Token)(CIRC_BUFF_SIZE,
|
|
||||||
f.byLine(KeepTerminator.yes).join().byToken!(char[])());
|
|
||||||
auto mod = parseModule(tokens);
|
|
||||||
mod.writeJSONTo(stdout);
|
|
||||||
return 0;
|
|
||||||
}+/
|
|
||||||
|
|
||||||
// if (ctags)
|
|
||||||
// {
|
|
||||||
// if (!recursiveCtags)
|
|
||||||
// {
|
|
||||||
// auto tokens = byToken(readText(args[1]));
|
|
||||||
// auto mod = parseModule(tokens.array());
|
|
||||||
// mod.writeCtagsTo(stdout, args[1]);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// Module m;
|
|
||||||
// foreach (dirEntry; dirEntries(args[1], SpanMode.breadth))
|
|
||||||
// {
|
|
||||||
// if (!dirEntry.name.endsWith(".d", ".di"))
|
|
||||||
// continue;
|
|
||||||
// stderr.writeln("Generating tags for ", dirEntry.name);
|
|
||||||
// auto tokens = byToken(readText(dirEntry.name));
|
|
||||||
// if (m is null)
|
|
||||||
// m = parseModule(tokens.array());
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// auto mod = parseModule(tokens.array());
|
|
||||||
// m.merge(mod);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// m.writeCtagsTo(stdout, "");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printHelp()
|
void printHelp(string programName)
|
||||||
{
|
{
|
||||||
writeln(
|
writefln(
|
||||||
q{
|
`
|
||||||
Usage: dscanner options
|
Usage: %s options
|
||||||
|
|
||||||
options:
|
options:
|
||||||
--help | -h
|
--help | -h
|
||||||
Prints this help message
|
Prints this help message
|
||||||
|
|
||||||
--sloc [sourceFiles]
|
--sloc | -l [sourceFiles]
|
||||||
count the number of logical lines of code in the given
|
count the number of logical lines of code in the given
|
||||||
source files. If no files are specified, a file is read from stdin.
|
source files. If no files are specified, a file is read from stdin.
|
||||||
|
|
||||||
--json [sourceFile]
|
--json | -j [sourceFile]
|
||||||
Generate a JSON summary of the given source file. If no file is
|
Generate a JSON summary of the given source file. If no file is
|
||||||
specifed, the file is read from stdin.
|
specifed, the file is read from stdin.
|
||||||
|
|
||||||
--dotComplete [sourceFile] cursorPosition
|
--dotComplete | -d [sourceFile] cursorPosition
|
||||||
Provide autocompletion for the insertion of the dot operator. The cursor
|
Provide autocompletion for the insertion of the dot operator. The cursor
|
||||||
position is the character position in the *file*, not the position in
|
position is the character position in the *file*, not the position in
|
||||||
the line. If no file is specified, the file is read from stdin.
|
the line. If no file is specified, the file is read from stdin.
|
||||||
|
|
||||||
--parenComplete [sourceFile] cursorPosition
|
--parenComplete | -p [sourceFile] cursorPosition
|
||||||
Provides a listing of function parameters or pre-defined version
|
Provide a listing of function parameters or pre-defined version
|
||||||
identifiers at the cursor position. The cursor position is the character
|
identifiers at the cursor position. The cursor position is the character
|
||||||
position in the *file*, not the line. If no file is specified, the
|
position in the *file*, not the line. If no file is specified, the
|
||||||
contents are read from stdin.
|
contents are read from stdin.
|
||||||
|
|
||||||
|
--symbolComplete | -s [sourceFile] cursorPosition
|
||||||
|
Provide a listing of classes, structs, interfaces, variables, functions,
|
||||||
|
and methods available in the current scope that begin with the text
|
||||||
|
before the cursor position.
|
||||||
|
|
||||||
--highlight [sourceFile] - Syntax-highlight the given source file. The
|
--highlight [sourceFile] - Syntax-highlight the given source file. The
|
||||||
resulting HTML will be written to standard output.
|
resulting HTML will be written to standard output.
|
||||||
|
|
||||||
|
@ -311,12 +219,13 @@ options:
|
||||||
well as any paths specified in /etc/dmd.conf. This is only used for the
|
well as any paths specified in /etc/dmd.conf. This is only used for the
|
||||||
--parenComplete and --dotComplete options.
|
--parenComplete and --dotComplete options.
|
||||||
|
|
||||||
--ctags sourceFile
|
--ctags | -c sourceFile
|
||||||
Generates ctags information from the given source code file. Note that
|
Generates ctags information from the given source code file. Note that
|
||||||
ctags information requires a filename, so stdin cannot be used in place
|
ctags information requires a filename, so stdin cannot be used in place
|
||||||
of a filename.
|
of a filename.
|
||||||
|
|
||||||
--recursive | -R | -r directory
|
--recursive | -R | -r directory
|
||||||
When used with --ctags, dscanner will produce ctags output for all .d
|
When used with --ctags, dscanner will produce ctags output for all .d
|
||||||
and .di files contained within directory and its sub-directories.});
|
and .di files contained within directory and its sub-directories.`,
|
||||||
|
programName);
|
||||||
}
|
}
|
||||||
|
|
3971
std/d/lexer.d
3971
std/d/lexer.d
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue