dlang-community / drepl

A REPL for D
Boost Software License 1.0
78 stars 20 forks source link

Error parsing #57

Open WebFreak001 opened 8 years ago

WebFreak001 commented 8 years ago

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

MartinNowak commented 7 years ago

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.