Skip to content

Commit

Permalink
compiler: Add basic AST handling of "later" calls and returns
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 Oct 11, 2023
1 parent 719dc3a commit c376d87
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/compiler/ast/call_or_assign_stmt.h64
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import compiler.msg as msg
import compiler.token as token

type CallStmt base ast.StmtNode {
var has_later = no
var has_later_ignore = no
}

func CallStmt.init {
Expand Down Expand Up @@ -164,6 +166,33 @@ func parse(tokens, pos, msgs, project_file=none, debug=no) {
)
pos += skiplen
}

if pos <= token_len and
tokens[pos].kind == token.T_KEYWORD and
tokens[pos].str == "later" {
if pos + 1 > token_len or
(tokens[pos + 1].kind != token.T_COLON and
(tokens[pos + 1].kind != token.T_KEYWORD or
tokens[pos + 1].str != "ignore")) {
msgs.add(new msg.FileMsg(
"Unexpected " +
if pos + 1 <= token_len
(token.describe_token(tokens[pos + 1])) else
("end of tokens") +
", expected ':' or 'ignore' following 'later'.",
source_file=project_file,
line=token.get_line(tokens, pos),
col=token.get_col(tokens, pos),
))
} else {
stmt.has_later = yes
stmt.has_later_ignore = (
tokens[pos + 1].kind == token.T_KEYWORD
)
pos += 2
}
}

stmt.token_len = (pos - startpos)
return later stmt
}
Expand Down
7 changes: 7 additions & 0 deletions src/compiler/ast/return_stmt.h64
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import compiler.msg as msg
import compiler.token as token

type ReturnStmt base ast.StmtNode {
var has_later = no
}

func ReturnStmt.init {
Expand All @@ -58,6 +59,12 @@ func parse(tokens, pos, msgs, project_file=none, debug=no) {
stmt.pos = token.get_line(tokens, pos)
stmt.col = token.get_col(tokens, pos)
pos += 1
if pos <= tokens_len and
tokens[pos].kind == token.T_KEYWORD and
tokens[pos].str == "later" {
stmt.has_later = yes
pos += 1
}

# See if this return has an argument at all:
if pos > tokens_len or
Expand Down

0 comments on commit c376d87

Please sign in to comment.