digitalmars.D - proposal: reading multiple files with dmd -stdin and allow specifying
- Timothee Cour via Digitalmars-d (40/40) Jun 14 2017 Proposal: support reading multiple files (with fake file names) from std...
- Kagamin (2/2) Jun 15 2017 Wouldn't it be better done at the lexer level: it needs to reset
Proposal: support reading multiple files (with fake file names) from stdin. This is a natural extension of https://issues.dlang.org/show_bug.cgi?id=9287 (Issue 9287 - DMD should read from stdin when an input file is "-") Example use case: * simplify writing bug reports and trying out other peoples's bug reports * simplify writing unittests that depend on multiple files * IDE integration where more than 1 file are desired Proposed syntax: use a delimiter to seperate different modules, with a (fake) file name. ``` cat module_list.txt | dmd -stdin ``` with cat module_list.txt: ``` pragma(module, "bar/foo1.d"); module foo1; void test1(){} pragma(module, "bar/foo2.d"); module foo2; // A module name is required void test2(){} // etc ``` Now when sending a bug report involving multiple files, the user doesn't need to manually re-create the file hierarchy, all he needs is copy paste to the terminal after dmd -stdin, followed by ^D (or just cat module_list.txt | dmd -stdin) The other feature here is introduction of fake file names, which should behave exactly as the real file names except for initially reading them. This'll greatly simplify writing compiler unittests, or writing examples for dub / vibe programs that typically rely on a file hierarchy. This'll also allow documentation unittests involving multiple files. There are probably other use cases based on reading entire packages from a url, etc. Implementation: similar to https://github.com/dlang/dmd/pull/6880 : * read from stdin until EOF, then parse into a map string[string] (module_contents[fakefilename]), then insert a simple interception logic that searches inside this map before searching in the filesystem.
Jun 14 2017
Wouldn't it be better done at the lexer level: it needs to reset line count, see https://issues.dlang.org/show_bug.cgi?id=2660#c13
Jun 15 2017