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)
{
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;

View File

@ -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("."), '"');

View File

@ -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;

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