diff --git a/dastworx/dastworx.ce b/dastworx/dastworx.ce index 1ed56a47..34d633c2 100644 --- a/dastworx/dastworx.ce +++ b/dastworx/dastworx.ce @@ -41,7 +41,6 @@ object CurrentProject: TCENativeProject 'src/imports.d' 'src/mainfun.d' 'src/common.d' - 'src/runnableflags.d' ) ConfigurationIndex = 1 end diff --git a/dastworx/src/common.d b/dastworx/src/common.d index e438f771..64d2b0ee 100644 --- a/dastworx/src/common.d +++ b/dastworx/src/common.d @@ -348,7 +348,7 @@ T parseAndVisit(T : ASTVisitor)(const(char)[] source) 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, &handleErrors); + Module mod = parseModule(tokens, "", &allocator, &ignoreErrors); T result = construct!(T); result.visit(mod); return result; @@ -358,7 +358,7 @@ T parseAndVisit(T : ASTVisitor)(const(char)[] source) * By default libdparse outputs errors and warnings to the standard streams. * This function prevents that. */ -void handleErrors(string fname, size_t line, size_t col, string message, +void ignoreErrors(string fname, size_t line, size_t col, string message, bool err) { // dont pollute output diff --git a/dastworx/src/imports.d b/dastworx/src/imports.d index 09849ed7..27f60137 100644 --- a/dastworx/src/imports.d +++ b/dastworx/src/imports.d @@ -53,7 +53,7 @@ void listFilesImports(string[] files) { ubyte[] source = cast(ubyte[]) std.file.read(fname); Module mod = parseModule(getTokensForParser(source, config, &cache), - fname, &allocator, &handleErrors); + fname, &allocator, &ignoreErrors); writeln('"', mod.moduleDeclaration.moduleName.identifiers .map!(a => a.text).join("."), '"'); il.visit(mod); diff --git a/dastworx/src/main.d b/dastworx/src/main.d index 73838990..cc6fa7eb 100644 --- a/dastworx/src/main.d +++ b/dastworx/src/main.d @@ -9,20 +9,14 @@ import import dparse.lexer, dparse.parser, dparse.ast, dparse.rollback_allocator; import - common, todos, symlist, imports, mainfun, runnableflags; + common, todos, symlist, imports, mainfun; -private __gshared bool storeAstErrors = void, deepSymList; -private __gshared const(Token)[] tokens; -private __gshared Module module_ = void; +private __gshared bool deepSymList; private __gshared static Appender!(ubyte[]) source; -private __gshared RollbackAllocator allocator; -private __gshared LexerConfig config; -private __gshared StringCache* cache; private __gshared static Appender!(AstErrors) errors; private __gshared string[] files; - static this() { GC.disable; @@ -35,8 +29,6 @@ void main(string[] args) version(devel) { mixin(logCall); - config = LexerConfig("", StringBehavior.source, WhitespaceBehavior.skip); - cache = construct!(StringCache)(StringCache.defaultBucketCount); File f = File(__FILE__, "r"); foreach(ref buffer; f.byChunk(4096)) source.put(buffer); @@ -53,24 +45,17 @@ void main(string[] args) files = args[1].splitter(pathSeparator).array; version(devel) writeln(files); } - // when files are passed, the global cache & config cant be used - else - { - config = LexerConfig("", StringBehavior.source, WhitespaceBehavior.skip); - cache = construct!(StringCache)(StringCache.defaultBucketCount); - } } - // options for the worxs + // options for the work getopt(args, std.getopt.config.passThrough, "d", &deepSymList ); - // launch a worx directly + // launch directly a work getopt(args, std.getopt.config.passThrough, "i", &handleImportsOption, "m", &handleMainfunOption, - "r", &handleRunnableFlags, "s", &handleSymListOption, "t", &handleTodosOption, ); @@ -81,10 +66,15 @@ void main(string[] args) void handleSymListOption() { mixin(logCall); - storeAstErrors = true; - lex!false; - parseTokens; - listSymbols(module_, errors.data, deepSymList); + + RollbackAllocator alloc; + StringCache cache = StringCache(StringCache.defaultBucketCount); + LexerConfig config = LexerConfig("", StringBehavior.source); + + source.data + .getTokensForParser(config, &cache) + .parseModule("", &alloc, &handleErrors) + .listSymbols(errors.data, deepSymList); } /// Handles the "-t" option: create the list of todo comments in the output @@ -94,14 +84,6 @@ void handleTodosOption() getTodos(files); } -/// Handles the "-r" option: -void handleRunnableFlags() -{ - mixin(logCall); - lex!true; - getRunnableFlags(tokens); -} - /// Handles the "-i" option: create the import list in the output void handleImportsOption() { @@ -112,10 +94,14 @@ void handleImportsOption() } else { - storeAstErrors = false; - lex!false; - parseTokens; - listImports(module_); + RollbackAllocator alloc; + StringCache cache = StringCache(StringCache.defaultBucketCount); + LexerConfig config = LexerConfig("", StringBehavior.source); + + source.data + .getTokensForParser(config, &cache) + .parseModule("", &alloc, &ignoreErrors) + .listImports(); } } @@ -123,31 +109,21 @@ void handleImportsOption() void handleMainfunOption() { mixin(logCall); - storeAstErrors = false; - lex!false; - parseTokens; - detectMainFun(module_); + + RollbackAllocator alloc; + StringCache cache = StringCache(StringCache.defaultBucketCount); + LexerConfig config = LexerConfig("", StringBehavior.source); + + source.data + .getTokensForParser(config, &cache) + .parseModule("", &alloc, &ignoreErrors) + .detectMainFun(); } -private void handleErrors(string fname, size_t line, size_t col, string message, bool err) +private void handleErrors(string fname, size_t line, size_t col, string message, + bool err) { - if (storeAstErrors) - errors ~= construct!(AstError)(cast(ErrorType) err, message, line, col); -} - -private void lex(bool keepComments = false)() -{ - static if (keepComments) - tokens = DLexer(source.data, config, cache).array; - else - tokens = getTokensForParser(source.data, config, cache); -} - -private void parseTokens() -{ - mixin(logCall); - if (!module_) - module_ = parseModule(tokens, "", &allocator, &handleErrors); + errors ~= construct!(AstError)(cast(ErrorType) err, message, line, col); } version(devel) diff --git a/dastworx/src/runnableflags.d b/dastworx/src/runnableflags.d deleted file mode 100644 index bf0750b1..00000000 --- a/dastworx/src/runnableflags.d +++ /dev/null @@ -1,20 +0,0 @@ -module runnableflags; - -import - std.stdio; -import - dparse.lexer; -import - common; - -/** - * Parse the compiler switch defined in the comments located before a - * ModuleDeclaration and that are passed to the compiler when a runnable is - * launched. - * - * each line of the output contains an option. - */ -void getRunnableFlags(const(Token)[] tokens) -{ - mixin(logCall); -} diff --git a/dastworx/src/symlist.d b/dastworx/src/symlist.d index af6e8954..eb8bf199 100644 --- a/dastworx/src/symlist.d +++ b/dastworx/src/symlist.d @@ -15,10 +15,10 @@ private __gshared bool deep = void; /** * Serializes the symbols in the standard output */ -void listSymbols(const(Module) mod, AstErrors errors, bool ddeep = true) +void listSymbols(const(Module) mod, AstErrors errors, bool deep = true) { mixin(logCall); - symlist.deep = ddeep; + symlist.deep = deep; alias SL = SymbolListBuilder!(ListFmt.Pas); SL.addAstErrors(errors); SL sl = construct!(SL);