sin-ack / zigself

An implementation of the Self programming language in Zig
GNU General Public License v3.0
161 stars 5 forks source link

Lexer fails when input does not end in whitespace #2

Closed sin-ack closed 2 years ago

sin-ack commented 2 years ago

Noticed while using the REPL script.

Typing in the following works:

> 'Hello world' printLine
Hello world

Typing in the following fails:

> 'Hello world' printLine.
thread 14593 panic: Shouldn't reach here!
self/src/language/lexer.zig:113:5: 0x25d0d7 in language.lexer.nextToken (self)
    @panic("Shouldn't reach here!");
    ^
self/src/language/parser.zig:123:41: 0x25d264 in language.parser.parseStatement (self)
            _ = try self.lexer.nextToken();
                                        ^
self/src/language/parser.zig:88:36: 0x25c806 in language.parser.parse (self)
        if (try self.parseStatement(.EOF)) |*statement| {
                                   ^
self/src/language/script.zig:83:42: 0x253ac8 in language.script.parseScript (self)
    self.ast_root = try self.parser.parse();
                                         ^
...

It seems like we are not setting the EOF condition correctly when the input does not end in whitespace.

sin-ack commented 2 years ago

Fixed by 9386c38