From d2b032447f51d86e782e0155be33a7962d72ebda Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Thu, 27 Jul 2017 08:50:55 +0200 Subject: [PATCH] update dparse --- dastworx/src/common.d | 4 +++- dastworx/src/imports.d | 4 ++-- dastworx/src/main.d | 33 ++++++++++++++++++--------------- etc/libdparse | 2 +- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/dastworx/src/common.d b/dastworx/src/common.d index 82f81c13..e52877d7 100644 --- a/dastworx/src/common.d +++ b/dastworx/src/common.d @@ -370,11 +370,13 @@ unittest */ T parseAndVisit(T : ASTVisitor)(const(char)[] source) { + import std.functional; + RollbackAllocator allocator; LexerConfig config = LexerConfig("", StringBehavior.source, WhitespaceBehavior.skip); StringCache cache = StringCache(StringCache.defaultBucketCount); 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); result.visit(mod); return result; diff --git a/dastworx/src/imports.d b/dastworx/src/imports.d index 3b9f1186..a8a2af1d 100644 --- a/dastworx/src/imports.d +++ b/dastworx/src/imports.d @@ -1,7 +1,7 @@ module imports; import - std.stdio, std.algorithm, std.array, std.file; + std.stdio, std.algorithm, std.array, std.file, std.functional; import iz.memory; import @@ -57,7 +57,7 @@ void listFilesImports(string[] files) { ubyte[] source = cast(ubyte[]) std.file.read(fname); Module mod = parseModule(getTokensForParser(source, config, &cache), - fname, &allocator, &ignoreErrors); + fname, &allocator, toDelegate(&ignoreErrors)); if (mod.moduleDeclaration) writeln('"', mod.moduleDeclaration.moduleName.identifiers .map!(a => a.text).join("."), '"'); diff --git a/dastworx/src/main.d b/dastworx/src/main.d index f3caa75b..ed639398 100644 --- a/dastworx/src/main.d +++ b/dastworx/src/main.d @@ -3,7 +3,7 @@ module dastworx; import core.memory; import - std.array, std.getopt, std.stdio, std.path, std.algorithm; + std.array, std.getopt, std.stdio, std.path, std.algorithm, std.functional; import iz.memory; import @@ -15,7 +15,6 @@ import private __gshared int caretLine; private __gshared bool option1; private __gshared static Appender!(ubyte[]) source; -private __gshared static Appender!(AstErrors) errors; private __gshared string[] files; // -o : deep visit the symbols @@ -27,7 +26,6 @@ static this() { GC.disable; source.reserve(1024^^2); - errors.reserve(32); } void main(string[] args) @@ -76,14 +74,25 @@ void handleSymListOption() { 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; StringCache cache = StringCache(StringCache.defaultBucketCount); LexerConfig config = LexerConfig("", StringBehavior.source); source.data .getTokensForParser(config, &cache) - .parseModule("", &alloc, &handleErrors) - .listSymbols(errors.data, deepSymList); + .parseModule("", &alloc, &eh.handleErrors) + .listSymbols(eh._errors.data, deepSymList); } /// Handles the "-t" option: create the list of todo comments in the output @@ -110,7 +119,7 @@ void handleImportsOption() source.data .getTokensForParser(config, &cache) - .parseModule("", &alloc, &ignoreErrors) + .parseModule("", &alloc, toDelegate(&ignoreErrors)) .listImports(); } } @@ -126,7 +135,7 @@ void handleMainfunOption() source.data .getTokensForParser(config, &cache) - .parseModule("", &alloc, &ignoreErrors) + .parseModule("", &alloc, toDelegate(&ignoreErrors)) .detectMainFun(); } @@ -141,7 +150,7 @@ void handleHalsteadOption() source.data .getTokensForParser(config, &cache) - .parseModule("", &alloc, &ignoreErrors) + .parseModule("", &alloc, toDelegate(&ignoreErrors)) .performHalsteadMetrics; } @@ -156,16 +165,10 @@ void handleDdocTemplateOption() source.data .getTokensForParser(config, &cache) - .parseModule("", &alloc, &ignoreErrors) + .parseModule("", &alloc, toDelegate(&ignoreErrors)) .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(none) import std.compiler; diff --git a/etc/libdparse b/etc/libdparse index 454a95ab..4229f118 160000 --- a/etc/libdparse +++ b/etc/libdparse @@ -1 +1 @@ -Subproject commit 454a95abb2ac7093f1526f262d4a712730dd9ac3 +Subproject commit 4229f11828a901ea5379409015f14a033e742906