Skip to content

Commit

Permalink
compiler: Fix various parsing and error handling bugs
Browse files Browse the repository at this point in the history
DCO-1.1-Signed-off-by: Ellie <[email protected]>
  • Loading branch information
ell1e committed Jan 12, 2025
1 parent 53126e8 commit 0c6939f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
44 changes: 29 additions & 15 deletions src/compiler/ast/defer_stmt.h64
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import compiler.token as token

type DeferStmt base ast.StmtNode {
var has_later = no
var has_failed = no
}

func DeferStmt.init {
Expand All @@ -45,6 +46,8 @@ func DeferStmt.init {

func DeferStmt.as_json_obj {
var output = base.as_json_obj()
output["has_later"] = self.has_later
output["has_failed"] = self.has_faileed
return output
}

Expand Down Expand Up @@ -84,6 +87,13 @@ func parse(tokens, pos, msgs, project_file=none,
stmt.col = token.get_col(tokens, pos)
pos += 1

if pos <= tokens_len and
tokens[pos].kind == token.T_KEYWORD and
tokens[pos].str == "failed" {
stmt.has_failed = yes
pos += 1
}

var v = expr.parse_expression(
tokens, pos, msgs,
project_file=project_file,
Expand All @@ -98,14 +108,16 @@ func parse(tokens, pos, msgs, project_file=none,
if v.kind != ast.N_EXPR_BINOP or
v.optoken.kind != token.T_ENCLOSE or
v.optoken.str != "(" {
msgs.add(new msg.FileMsg(
"Unexpected argument expression of type " +
ast.NodeKind.num_label(v.kind) + ", expected " +
"a func call expression instead.",
source_file=project_file,
line=token.get_line(tokens, startpos),
col=token.get_col(tokens, startpos),
))
if not v.damaged {
msgs.add(new msg.FileMsg(
"Unexpected argument expression of type " +
ast.NodeKind.num_label(v.kind) + ", expected " +
"a func call expression instead.",
source_file=project_file,
line=token.get_line(tokens, startpos),
col=token.get_col(tokens, startpos),
))
}
stmt.damaged = yes
}
pos += v.token_len
Expand All @@ -117,13 +129,15 @@ func parse(tokens, pos, msgs, project_file=none,
stmt.has_later = yes
pos += 1
if is_moose64 {
msgs.add(new msg.FileMsg(
"Unexpected 'defer ... later', expected "
"a regular call since 'later' isn't supported.",
source_file=project_file,
line=token.get_line(tokens, startpos),
col=token.get_col(tokens, startpos),
))
if not stmt.damaged {
msgs.add(new msg.FileMsg(
"Unexpected 'defer ... later', expected "
"a regular call since 'later' isn't supported.",
source_file=project_file,
line=token.get_line(tokens, startpos),
col=token.get_col(tokens, startpos),
))
}
stmt.damaged = yes
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/token/token.h64
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ func token_has_lefthand(t) {
}
if t.kind == T_KEYWORD and {
"as", "from", "in", "failable",
"override",
"override", "readonly",
"elseif", "else", "rescue",
"finally", "later",
"protect"}.has(t.str) {
Expand Down

0 comments on commit 0c6939f

Please sign in to comment.