Fix various parsing errors in Kym
continuous-integration/drone/push Build is failing Details

This commit is contained in:
kayomn 2023-04-23 16:25:42 +01:00
parent 2331d99bc9
commit a2990e67c7
1 changed files with 10 additions and 4 deletions

View File

@ -258,7 +258,8 @@ const Parser = struct {
UnexpectedEnd, UnexpectedEnd,
}; };
const operator_tokens = &.{.symbol_assign, .symbol_plus, .symbol_dash, .symbol_asterisk, .symbol_forward_slash}; const operator_tokens = &.{.symbol_assign, .symbol_plus,
.symbol_dash, .symbol_asterisk, .symbol_forward_slash, .symbol_paren_left, .symbol_comma};
fn parse_expression(self: *Parser) ParseError!void { fn parse_expression(self: *Parser) ParseError!void {
var operators = OperatorStack{}; var operators = OperatorStack{};
@ -438,7 +439,7 @@ const Parser = struct {
else => self.parse_expression(), else => self.parse_expression(),
}; };
switch (self.previous_token) { switch (self.current_token) {
.symbol_paren_right => break, .symbol_paren_right => break,
.symbol_comma => {}, .symbol_comma => {},
else => return error.UnexpectedToken, else => return error.UnexpectedToken,
@ -479,6 +480,7 @@ const Parser = struct {
switch (self.current_token) { switch (self.current_token) {
.symbol_assign => { .symbol_assign => {
try self.step();
try self.parse_expression(); try self.parse_expression();
field_count += 1; field_count += 1;
@ -516,6 +518,10 @@ const Parser = struct {
try self.chunk.emit_opcode(.call); try self.chunk.emit_opcode(.call);
try self.chunk.emit_operand(1); try self.chunk.emit_operand(1);
} }
self.step() catch |step_error| switch (step_error) {
error.UnexpectedEnd => return,
};
}, },
else => { else => {
@ -586,7 +592,7 @@ const Parser = struct {
.symbol_period => switch (self.previous_token) { .symbol_period => switch (self.previous_token) {
.global_identifier => { .global_identifier => {
// Create local copy of identifier because step() will overwrite captures. // Create local copy of identifier because step() will overwrite captures.
const identifier = self.previous_token.local_identifier; const identifier = self.previous_token.global_identifier;
try self.step(); try self.step();
try self.current_token.expect(.local_identifier); try self.current_token.expect(.local_identifier);
@ -598,7 +604,7 @@ const Parser = struct {
.local_identifier => { .local_identifier => {
// Create local copy of identifier because step() will overwrite captures. // Create local copy of identifier because step() will overwrite captures.
const identifier = self.previous_token.global_identifier; const identifier = self.previous_token.local_identifier;
try self.step(); try self.step();
try self.current_token.expect(.local_identifier); try self.current_token.expect(.local_identifier);