dao
dao copied to clipboard
Parsing bug
0$ dao -e '{0, 1, 2}.iterate { io.writeln(X) }; io.writeln("tail")'
[[ERROR]] in file "command line codes":
At line 1 : Invalid expression --- " .iterate { io. writeln(X) }; io ... ";
1$
0$ dao -e '{0, 1, 2}.iterate { io.writeln(X) }'
0
1
2
= none
0$
This is due to the fact that, the parser will attempt to parse the code as a single expression first, if this fails, normal parsing will take place, which will not recognize a list enumeration if it is not already in the state of parsing expressions. When the parser is not the state of parsing expressions, { will be considered as starting a new scope.
The difference between the above two tests is that, the second can be parsed as an expression while the first cannot. So the first { in the first test is parsed as a scope opening, which leaves .iterate as a incomplete expression.
Maybe { should be parsed as scope opening only when it follows statements such as conditional controls and looping controls etc., this will avoid this problem.