drepl icon indicating copy to clipboard operation
drepl copied to clipboard

Error parsing

Open WebFreak001 opened this issue 9 years ago • 1 comments

I just quickly wanted to find the smallest file in a directory with this code:

D> size_t minSize = size_t.max; string minName = "invalid"; foreach (file; dirEntries(getcwd, SpanMode.breadth)) {
 | if (file.isFile && file.size < minSize) {
 | minSize = file.size;
 | minName = cast(string) file;
 | }
 | } writefln("%s with %s bytes", minName, minSize);

It didn't even try to run that code and just said "Error parsing", however it is valid D code because running it using rdmd --eval worked

WebFreak001 avatar Oct 30 '16 18:10 WebFreak001

It doesn't support multi statement evaluation atm. A REPL needs to perform some transformations to support declaring variables, thus we first need to classify the input into expression (returned from function), statement (evaluated in function), declaration (evaluated at module level). That parsing is done using libdparse and still has some gotchas atm.

MartinNowak avatar Sep 28 '17 22:09 MartinNowak