diff options
| author | Mustafa Quraish <[email protected]> | 2022-02-01 04:08:59 -0500 |
|---|---|---|
| committer | Mustafa Quraish <[email protected]> | 2022-02-01 04:08:59 -0500 |
| commit | d471a41369690a9d2d9b8862ea5ff0ae9cbe40fc (patch) | |
| tree | 9399d12700c3d975a95b0946833dc419b3268419 /src/parser.c | |
| parent | Testing: Add support for testing stdout results, check builtins (diff) | |
| download | cup-d471a41369690a9d2d9b8862ea5ff0ae9cbe40fc.tar.xz cup-d471a41369690a9d2d9b8862ea5ff0ae9cbe40fc.zip | |
Add basic `defer` implementation.
We don't have any closures yet, so it's essentially the same as just
moving the statement after the `defer` keyword to the end of the block/
right before returning from the function.
Diffstat (limited to 'src/parser.c')
| -rw-r--r-- | src/parser.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/parser.c b/src/parser.c index a0ec7a1..0cd0e5f 100644 --- a/src/parser.c +++ b/src/parser.c @@ -507,6 +507,10 @@ Node *parse_statement(Lexer *lexer) node->loop.body = parse_statement(lexer); } else if (token.type == TOKEN_OPEN_BRACE) { node = parse_block(lexer); + } else if (token.type == TOKEN_DEFER) { + Lexer_next(lexer); + node = Node_new(AST_DEFER); + node->unary_expr = parse_statement(lexer); } else { // Default to trying to handle it as an expression node = parse_expression(lexer); |