mirror of https://gitlab.com/basile.b/dexed.git
dastworx uses iz.options, close #275
This commit is contained in:
parent
feec564a35
commit
5aa6d32e7e
|
|
@ -3,116 +3,116 @@ module dastworx;
|
||||||
import
|
import
|
||||||
core.memory;
|
core.memory;
|
||||||
import
|
import
|
||||||
std.array, std.getopt, std.stdio, std.path, std.algorithm, std.functional;
|
std.array, std.getopt, std.stdio, std.path, std.algorithm, std.functional,
|
||||||
|
std.file, std.typecons;
|
||||||
import
|
import
|
||||||
iz.memory;
|
iz.memory, iz.options;
|
||||||
import
|
import
|
||||||
dparse.lexer, dparse.parser, dparse.ast, dparse.rollback_allocator;
|
dparse.lexer, dparse.parser, dparse.ast, dparse.rollback_allocator;
|
||||||
import
|
import
|
||||||
common, todos, symlist, imports, mainfun, halstead, ddoc_template;
|
common, todos, symlist, imports, mainfun, halstead, ddoc_template;
|
||||||
|
|
||||||
|
|
||||||
private __gshared int caretLine;
|
|
||||||
private __gshared bool option1;
|
|
||||||
private __gshared static Appender!(ubyte[]) source;
|
|
||||||
private __gshared string[] files;
|
|
||||||
|
|
||||||
// -o : deep visit the symbols
|
|
||||||
alias deepSymList = option1;
|
|
||||||
// -o : outputs /++ +/ ddoc instead of /** */
|
|
||||||
alias plusComment = option1;
|
|
||||||
|
|
||||||
static this()
|
|
||||||
{
|
|
||||||
GC.disable;
|
|
||||||
source.reserve(1024^^2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main(string[] args)
|
void main(string[] args)
|
||||||
{
|
{
|
||||||
version(devel)
|
foreach(ref buffer; stdin.byChunk(4096))
|
||||||
|
Launcher.source.put(buffer);
|
||||||
|
handleArguments!(Yes.Throw, Launcher)(args[1..$]);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Launcher
|
||||||
|
{
|
||||||
|
static this()
|
||||||
|
{
|
||||||
|
GC.disable;
|
||||||
|
source.reserve(1024^^2);
|
||||||
|
}
|
||||||
|
|
||||||
|
__gshared @Argument("-l") int caretLine;
|
||||||
|
__gshared @Argument("-o") bool option1;
|
||||||
|
|
||||||
|
__gshared static Appender!(ubyte[]) source;
|
||||||
|
__gshared string[] files;
|
||||||
|
|
||||||
|
// -o : deep visit the symbols
|
||||||
|
alias deepSymList = option1;
|
||||||
|
// -o : outputs /++ +/ ddoc instead of /** */
|
||||||
|
alias plusComment = option1;
|
||||||
|
|
||||||
|
/// Writes the list of files to process
|
||||||
|
@Argument("-f")
|
||||||
|
static void setFiles(string value)
|
||||||
|
{
|
||||||
|
files = value
|
||||||
|
.splitter(pathSeparator)
|
||||||
|
.filter!exists
|
||||||
|
.array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Writes the symbol list
|
||||||
|
@Argument("-s", "", ArgFlags(ArgFlag.stopper))
|
||||||
|
static void handleSymListOption()
|
||||||
{
|
{
|
||||||
mixin(logCall);
|
mixin(logCall);
|
||||||
File f = File(__FILE__, "r");
|
|
||||||
foreach(ref buffer; f.byChunk(4096))
|
static struct ErrorHandler
|
||||||
source.put(buffer);
|
|
||||||
f.close;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// get the source to process.
|
|
||||||
// even when files are passed, the std input has to be closed by the IDE
|
|
||||||
foreach(ref buffer; stdin.byChunk(4096))
|
|
||||||
source.put(buffer);
|
|
||||||
if (!source.data.length && args.length > 1)
|
|
||||||
{
|
{
|
||||||
import std.file: exists;
|
static Appender!(AstErrors) _errors;
|
||||||
files = args[1].splitter(pathSeparator).filter!exists.array;
|
|
||||||
version(devel) writeln(files);
|
void handleErrors(string fname, size_t line, size_t col, string message, bool err)
|
||||||
|
{
|
||||||
|
_errors ~= construct!(AstError)(cast(ErrorType) err, message, line, col);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorHandler eh;
|
||||||
|
RollbackAllocator alloc;
|
||||||
|
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
||||||
|
LexerConfig config = LexerConfig("", StringBehavior.source);
|
||||||
|
|
||||||
|
source.data
|
||||||
|
.getTokensForParser(config, &cache)
|
||||||
|
.parseModule("", &alloc, &eh.handleErrors)
|
||||||
|
.listSymbols(eh._errors.data, deepSymList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Writes the list of todo comments
|
||||||
|
@Argument("-t", "", ArgFlags(ArgFlag.stopper))
|
||||||
|
static void handleTodosOption()
|
||||||
|
{
|
||||||
|
mixin(logCall);
|
||||||
|
if (files.length)
|
||||||
|
getTodos(files);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Writes the import list
|
||||||
|
@Argument("-i", "", ArgFlags(ArgFlag.stopper))
|
||||||
|
static void handleImportsOption()
|
||||||
|
{
|
||||||
|
mixin(logCall);
|
||||||
|
if (files.length)
|
||||||
|
{
|
||||||
|
listFilesImports(files);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RollbackAllocator alloc;
|
||||||
|
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
||||||
|
LexerConfig config = LexerConfig("", StringBehavior.source);
|
||||||
|
|
||||||
|
source.data
|
||||||
|
.getTokensForParser(config, &cache)
|
||||||
|
.parseModule("", &alloc, toDelegate(&ignoreErrors))
|
||||||
|
.listImports();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// options for the work
|
/// Writes if a main() is present in the module
|
||||||
getopt(args, std.getopt.config.passThrough,
|
@Argument("-m", "", ArgFlags(ArgFlag.stopper))
|
||||||
"o", &option1,
|
static void handleMainfunOption()
|
||||||
"l", &caretLine
|
|
||||||
);
|
|
||||||
|
|
||||||
// launch directly a work
|
|
||||||
getopt(args, std.getopt.config.passThrough,
|
|
||||||
"i", &handleImportsOption,
|
|
||||||
"m", &handleMainfunOption,
|
|
||||||
"s", &handleSymListOption,
|
|
||||||
"t", &handleTodosOption,
|
|
||||||
"H", &handleHalsteadOption,
|
|
||||||
"K", &handleDdocTemplateOption,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Handles the "-s" option: create the symbol list in the output
|
|
||||||
void handleSymListOption()
|
|
||||||
{
|
|
||||||
mixin(logCall);
|
|
||||||
|
|
||||||
static struct ErrorHandler
|
|
||||||
{
|
{
|
||||||
static Appender!(AstErrors) _errors;
|
mixin(logCall);
|
||||||
|
|
||||||
void handleErrors(string fname, size_t line, size_t col, string message, bool err)
|
|
||||||
{
|
|
||||||
_errors ~= construct!(AstError)(cast(ErrorType) err, message, line, col);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ErrorHandler eh;
|
|
||||||
RollbackAllocator alloc;
|
|
||||||
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
|
||||||
LexerConfig config = LexerConfig("", StringBehavior.source);
|
|
||||||
|
|
||||||
source.data
|
|
||||||
.getTokensForParser(config, &cache)
|
|
||||||
.parseModule("", &alloc, &eh.handleErrors)
|
|
||||||
.listSymbols(eh._errors.data, deepSymList);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Handles the "-t" option: create the list of todo comments in the output
|
|
||||||
void handleTodosOption()
|
|
||||||
{
|
|
||||||
mixin(logCall);
|
|
||||||
if (files.length)
|
|
||||||
getTodos(files);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Handles the "-i" option: create the import list in the output
|
|
||||||
void handleImportsOption()
|
|
||||||
{
|
|
||||||
mixin(logCall);
|
|
||||||
if (files.length)
|
|
||||||
{
|
|
||||||
listFilesImports(files);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
RollbackAllocator alloc;
|
RollbackAllocator alloc;
|
||||||
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
||||||
LexerConfig config = LexerConfig("", StringBehavior.source);
|
LexerConfig config = LexerConfig("", StringBehavior.source);
|
||||||
|
|
@ -120,63 +120,39 @@ void handleImportsOption()
|
||||||
source.data
|
source.data
|
||||||
.getTokensForParser(config, &cache)
|
.getTokensForParser(config, &cache)
|
||||||
.parseModule("", &alloc, toDelegate(&ignoreErrors))
|
.parseModule("", &alloc, toDelegate(&ignoreErrors))
|
||||||
.listImports();
|
.detectMainFun();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Writes the halstead metrics
|
||||||
|
@Argument("-H", "", ArgFlags(ArgFlag.stopper))
|
||||||
|
static void handleHalsteadOption()
|
||||||
|
{
|
||||||
|
mixin(logCall);
|
||||||
|
|
||||||
|
RollbackAllocator alloc;
|
||||||
|
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
||||||
|
LexerConfig config = LexerConfig("", StringBehavior.source);
|
||||||
|
|
||||||
|
source.data
|
||||||
|
.getTokensForParser(config, &cache)
|
||||||
|
.parseModule("", &alloc, toDelegate(&ignoreErrors))
|
||||||
|
.performHalsteadMetrics;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Writes the ddoc template for a given declaration
|
||||||
|
@Argument("-K", "", ArgFlags(ArgFlag.stopper))
|
||||||
|
static void handleDdocTemplateOption()
|
||||||
|
{
|
||||||
|
mixin(logCall);
|
||||||
|
|
||||||
|
RollbackAllocator alloc;
|
||||||
|
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
||||||
|
LexerConfig config = LexerConfig("", StringBehavior.source);
|
||||||
|
|
||||||
|
source.data
|
||||||
|
.getTokensForParser(config, &cache)
|
||||||
|
.parseModule("", &alloc, toDelegate(&ignoreErrors))
|
||||||
|
.getDdocTemplate(caretLine, plusComment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles the "-m" option: writes if a main() is present in the module
|
|
||||||
void handleMainfunOption()
|
|
||||||
{
|
|
||||||
mixin(logCall);
|
|
||||||
|
|
||||||
RollbackAllocator alloc;
|
|
||||||
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
|
||||||
LexerConfig config = LexerConfig("", StringBehavior.source);
|
|
||||||
|
|
||||||
source.data
|
|
||||||
.getTokensForParser(config, &cache)
|
|
||||||
.parseModule("", &alloc, toDelegate(&ignoreErrors))
|
|
||||||
.detectMainFun();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Handles the "-H" option: write the halstead metrics
|
|
||||||
void handleHalsteadOption()
|
|
||||||
{
|
|
||||||
mixin(logCall);
|
|
||||||
|
|
||||||
RollbackAllocator alloc;
|
|
||||||
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
|
||||||
LexerConfig config = LexerConfig("", StringBehavior.source);
|
|
||||||
|
|
||||||
source.data
|
|
||||||
.getTokensForParser(config, &cache)
|
|
||||||
.parseModule("", &alloc, toDelegate(&ignoreErrors))
|
|
||||||
.performHalsteadMetrics;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Handles the "-D" option: write the ddoc template for a given declaration
|
|
||||||
void handleDdocTemplateOption()
|
|
||||||
{
|
|
||||||
mixin(logCall);
|
|
||||||
|
|
||||||
RollbackAllocator alloc;
|
|
||||||
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
|
||||||
LexerConfig config = LexerConfig("", StringBehavior.source);
|
|
||||||
|
|
||||||
source.data
|
|
||||||
.getTokensForParser(config, &cache)
|
|
||||||
.parseModule("", &alloc, toDelegate(&ignoreErrors))
|
|
||||||
.getDdocTemplate(caretLine, plusComment);
|
|
||||||
}
|
|
||||||
|
|
||||||
version(devel)
|
|
||||||
{
|
|
||||||
version(none) import std.compiler;
|
|
||||||
version(all) import std.uri;
|
|
||||||
version(WatchOS) import std.math;
|
|
||||||
mixin(q{import std.c.time;});
|
|
||||||
// TODO: something
|
|
||||||
// NOTE: there was a bug here...
|
|
||||||
// FIXME-cmain-aMrFreeze-p8: there's an infinite recursion whith the option -x
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
2
etc/iz
2
etc/iz
|
|
@ -1 +1 @@
|
||||||
Subproject commit 52288791debfe9b5ebf8691f91178dd525a38661
|
Subproject commit 4124a206ed9c88037f2394887e74b260d05acca4
|
||||||
|
|
@ -75,7 +75,7 @@ begin
|
||||||
prc := TProcess.Create(nil);
|
prc := TProcess.Create(nil);
|
||||||
try
|
try
|
||||||
prc.Executable := str;
|
prc.Executable := str;
|
||||||
prc.Parameters.Add(files);
|
prc.Parameters.Add('-f' + files);
|
||||||
prc.Parameters.Add('-i');
|
prc.Parameters.Add('-i');
|
||||||
prc.Options := [poUsePipes {$IFDEF WINDOWS}, poNewConsole{$ENDIF}];
|
prc.Options := [poUsePipes {$IFDEF WINDOWS}, poNewConsole{$ENDIF}];
|
||||||
prc.ShowWindow := swoHIDE;
|
prc.ShowWindow := swoHIDE;
|
||||||
|
|
@ -138,10 +138,10 @@ begin
|
||||||
prc := TProcess.Create(nil);
|
prc := TProcess.Create(nil);
|
||||||
try
|
try
|
||||||
prc.Executable := str;
|
prc.Executable := str;
|
||||||
prc.Parameters.Add('-K');
|
|
||||||
prc.Parameters.Add('-l' + caretLine.ToString);
|
prc.Parameters.Add('-l' + caretLine.ToString);
|
||||||
if plusComment then
|
if plusComment then
|
||||||
prc.Parameters.Add('-o');
|
prc.Parameters.Add('-o');
|
||||||
|
prc.Parameters.Add('-K');
|
||||||
prc.Options := [poUsePipes {$IFDEF WINDOWS}, poNewConsole{$ENDIF}];
|
prc.Options := [poUsePipes {$IFDEF WINDOWS}, poNewConsole{$ENDIF}];
|
||||||
prc.ShowWindow := swoHIDE;
|
prc.ShowWindow := swoHIDE;
|
||||||
prc.Execute;
|
prc.Execute;
|
||||||
|
|
|
||||||
|
|
@ -456,7 +456,7 @@ begin
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
else str := fDoc.fileName;
|
else str := fDoc.fileName;
|
||||||
fToolProc.Parameters.Add(str);
|
fToolProc.Parameters.Add('-f' + str);
|
||||||
fToolProc.Parameters.Add('-t');
|
fToolProc.Parameters.Add('-t');
|
||||||
//
|
//
|
||||||
fToolProc.Execute;
|
fToolProc.Execute;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue