biwascheme
biwascheme copied to clipboard
Parser don't throw error on missing parenthesis
I'm not sure if this is intentional but if you run this code:
(let ((x '()))
(display x)
(newline)
that has missing closing parenthesis. If you try to run this code:
biwas file.scm
()
it will be executed, but it's an invalid Scheme code.
The problem is in the way lists are constructed in the parser. I've based my own parser on BiwaScheme code and I have the same issue jcubic/lips#198. I would prefer not to count parenthesis in front to fix this. Maybe just keep the counter of them while parsing. If the parser finds the end of input (eof) and the counter is not 0 it should throw an error.
I've based my own parser on BiwaScheme code
And I've based biwa's parser on jsScheme code :-) https://web.archive.org/web/20070311211246/http://alex.ability.ru/scheme.html
You can check how I've fixed the issue. I've just counted the parenthesis while parsing. but I also have a single function that returns whole top-level S-Expression:
const parser = new Parser(arg, { env });
while (true) {
const expr = await parser.read_object();
if (!parser.ballanced()) {
parser.ballancing_error(expr);
}
if (expr === eof) {
break;
}
yield expr;
}
}
and inside the parser, I just have a counter that is increased or decreased o parenthesis.
fixed by #309.