update dparse

This commit is contained in:
Basile Burg 2017-07-27 08:50:55 +02:00
parent 61487fd074
commit d2b032447f
No known key found for this signature in database
GPG Key ID: 1868039F415CB8CF
4 changed files with 24 additions and 19 deletions

View File

@ -370,11 +370,13 @@ unittest
*/ */
T parseAndVisit(T : ASTVisitor)(const(char)[] source) T parseAndVisit(T : ASTVisitor)(const(char)[] source)
{ {
import std.functional;
RollbackAllocator allocator; RollbackAllocator allocator;
LexerConfig config = LexerConfig("", StringBehavior.source, WhitespaceBehavior.skip); LexerConfig config = LexerConfig("", StringBehavior.source, WhitespaceBehavior.skip);
StringCache cache = StringCache(StringCache.defaultBucketCount); StringCache cache = StringCache(StringCache.defaultBucketCount);
const(Token)[] tokens = getTokensForParser(cast(ubyte[]) source, config, &cache); const(Token)[] tokens = getTokensForParser(cast(ubyte[]) source, config, &cache);
Module mod = parseModule(tokens, "", &allocator, &ignoreErrors); Module mod = parseModule(tokens, "", &allocator, toDelegate(&ignoreErrors));
T result = construct!(T); T result = construct!(T);
result.visit(mod); result.visit(mod);
return result; return result;

View File

@ -1,7 +1,7 @@
module imports; module imports;
import import
std.stdio, std.algorithm, std.array, std.file; std.stdio, std.algorithm, std.array, std.file, std.functional;
import import
iz.memory; iz.memory;
import import
@ -57,7 +57,7 @@ void listFilesImports(string[] files)
{ {
ubyte[] source = cast(ubyte[]) std.file.read(fname); ubyte[] source = cast(ubyte[]) std.file.read(fname);
Module mod = parseModule(getTokensForParser(source, config, &cache), Module mod = parseModule(getTokensForParser(source, config, &cache),
fname, &allocator, &ignoreErrors); fname, &allocator, toDelegate(&ignoreErrors));
if (mod.moduleDeclaration) if (mod.moduleDeclaration)
writeln('"', mod.moduleDeclaration.moduleName.identifiers writeln('"', mod.moduleDeclaration.moduleName.identifiers
.map!(a => a.text).join("."), '"'); .map!(a => a.text).join("."), '"');

View File

@ -3,7 +3,7 @@ module dastworx;
import import
core.memory; core.memory;
import import
std.array, std.getopt, std.stdio, std.path, std.algorithm; std.array, std.getopt, std.stdio, std.path, std.algorithm, std.functional;
import import
iz.memory; iz.memory;
import import
@ -15,7 +15,6 @@ import
private __gshared int caretLine; private __gshared int caretLine;
private __gshared bool option1; private __gshared bool option1;
private __gshared static Appender!(ubyte[]) source; private __gshared static Appender!(ubyte[]) source;
private __gshared static Appender!(AstErrors) errors;
private __gshared string[] files; private __gshared string[] files;
// -o : deep visit the symbols // -o : deep visit the symbols
@ -27,7 +26,6 @@ static this()
{ {
GC.disable; GC.disable;
source.reserve(1024^^2); source.reserve(1024^^2);
errors.reserve(32);
} }
void main(string[] args) void main(string[] args)
@ -76,14 +74,25 @@ void handleSymListOption()
{ {
mixin(logCall); mixin(logCall);
static struct ErrorHandler
{
Appender!(AstErrors) _errors;
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; RollbackAllocator alloc;
StringCache cache = StringCache(StringCache.defaultBucketCount); StringCache cache = StringCache(StringCache.defaultBucketCount);
LexerConfig config = LexerConfig("", StringBehavior.source); LexerConfig config = LexerConfig("", StringBehavior.source);
source.data source.data
.getTokensForParser(config, &cache) .getTokensForParser(config, &cache)
.parseModule("", &alloc, &handleErrors) .parseModule("", &alloc, &eh.handleErrors)
.listSymbols(errors.data, deepSymList); .listSymbols(eh._errors.data, deepSymList);
} }
/// Handles the "-t" option: create the list of todo comments in the output /// Handles the "-t" option: create the list of todo comments in the output
@ -110,7 +119,7 @@ void handleImportsOption()
source.data source.data
.getTokensForParser(config, &cache) .getTokensForParser(config, &cache)
.parseModule("", &alloc, &ignoreErrors) .parseModule("", &alloc, toDelegate(&ignoreErrors))
.listImports(); .listImports();
} }
} }
@ -126,7 +135,7 @@ void handleMainfunOption()
source.data source.data
.getTokensForParser(config, &cache) .getTokensForParser(config, &cache)
.parseModule("", &alloc, &ignoreErrors) .parseModule("", &alloc, toDelegate(&ignoreErrors))
.detectMainFun(); .detectMainFun();
} }
@ -141,7 +150,7 @@ void handleHalsteadOption()
source.data source.data
.getTokensForParser(config, &cache) .getTokensForParser(config, &cache)
.parseModule("", &alloc, &ignoreErrors) .parseModule("", &alloc, toDelegate(&ignoreErrors))
.performHalsteadMetrics; .performHalsteadMetrics;
} }
@ -156,16 +165,10 @@ void handleDdocTemplateOption()
source.data source.data
.getTokensForParser(config, &cache) .getTokensForParser(config, &cache)
.parseModule("", &alloc, &ignoreErrors) .parseModule("", &alloc, toDelegate(&ignoreErrors))
.getDdocTemplate(caretLine, plusComment); .getDdocTemplate(caretLine, plusComment);
} }
private void handleErrors(string fname, size_t line, size_t col, string message,
bool err)
{
errors ~= construct!(AstError)(cast(ErrorType) err, message, line, col);
}
version(devel) version(devel)
{ {
version(none) import std.compiler; version(none) import std.compiler;

@ -1 +1 @@
Subproject commit 454a95abb2ac7093f1526f262d4a712730dd9ac3 Subproject commit 4229f11828a901ea5379409015f14a033e742906