biwascheme icon indicating copy to clipboard operation
biwascheme copied to clipboard

Parser don't throw error on missing parenthesis

Open jcubic opened this issue 3 years ago • 3 comments

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.

jcubic avatar Nov 11 '21 09:11 jcubic

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.

jcubic avatar Nov 11 '21 09:11 jcubic

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

yhara avatar Nov 18 '21 13:11 yhara

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.

jcubic avatar Nov 18 '21 14:11 jcubic

fixed by #309.

yhara avatar Mar 20 '23 14:03 yhara