diff options
-rw-r--r-- | src/parser.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/parser.c b/src/parser.c index c042f5d..ef7d336 100644 --- a/src/parser.c +++ b/src/parser.c | |||
@@ -121,15 +121,26 @@ parse_lambda(Parser *parser, Errors *errors) { | |||
121 | } | 121 | } |
122 | 122 | ||
123 | // Parse body. | 123 | // Parse body. |
124 | bool done = false; | ||
124 | while (has_next_token(parser)) { | 125 | while (has_next_token(parser)) { |
125 | Token tok = peek_token(parser); | 126 | Token tok = peek_token(parser); |
126 | if (tok.type == TOKEN_RPAREN) { | 127 | if (tok.type == TOKEN_RPAREN) { |
127 | next_token(parser); | 128 | next_token(parser); |
129 | done = true; | ||
128 | break; | 130 | break; |
129 | } | 131 | } |
130 | Object *expr = parse_tree(parser, errors); | 132 | Object *expr = parse_tree(parser, errors); |
131 | array_push(lambda->body, expr); | 133 | array_push(lambda->body, expr); |
132 | } | 134 | } |
135 | if (!done) { | ||
136 | error_push(errors, (Error){ | ||
137 | .type = ERR_TYPE_PARSER, | ||
138 | .value = ERR_UNBALANCED_PAREN, | ||
139 | .line = tok.line, | ||
140 | .col = tok.col, | ||
141 | }); | ||
142 | return NULL; | ||
143 | } | ||
133 | if (array_size(lambda->body) == 0) { | 144 | if (array_size(lambda->body) == 0) { |
134 | error_push(errors, (Error){ | 145 | error_push(errors, (Error){ |
135 | .type = ERR_TYPE_PARSER, | 146 | .type = ERR_TYPE_PARSER, |
@@ -181,6 +192,15 @@ parse_if(Parser *parser, Errors *errors) { | |||
181 | ret->expr_false = parse_tree(parser, errors); | 192 | ret->expr_false = parse_tree(parser, errors); |
182 | 193 | ||
183 | tok = peek_token(parser); | 194 | tok = peek_token(parser); |
195 | if (tok.type == TOKEN_EOF) { | ||
196 | error_push(errors, (Error){ | ||
197 | .type = ERR_TYPE_PARSER, | ||
198 | .value = ERR_UNBALANCED_PAREN, | ||
199 | .line = tok.line, | ||
200 | .col = tok.col, | ||
201 | }); | ||
202 | return NULL; | ||
203 | } | ||
184 | if (tok.type != TOKEN_RPAREN) { | 204 | if (tok.type != TOKEN_RPAREN) { |
185 | error_push(errors, (Error){ | 205 | error_push(errors, (Error){ |
186 | .type = ERR_TYPE_PARSER, | 206 | .type = ERR_TYPE_PARSER, |
@@ -236,6 +256,15 @@ parse_var(Parser *parser, Errors *errors) { | |||
236 | ret->var_expr = parse_tree(parser, errors); | 256 | ret->var_expr = parse_tree(parser, errors); |
237 | 257 | ||
238 | tok = peek_token(parser); | 258 | tok = peek_token(parser); |
259 | if (tok.type == TOKEN_EOF) { | ||
260 | error_push(errors, (Error){ | ||
261 | .type = ERR_TYPE_PARSER, | ||
262 | .value = ERR_UNBALANCED_PAREN, | ||
263 | .line = tok.line, | ||
264 | .col = tok.col, | ||
265 | }); | ||
266 | return NULL; | ||
267 | } | ||
239 | if (tok.type != TOKEN_RPAREN) { | 268 | if (tok.type != TOKEN_RPAREN) { |
240 | error_push(errors, (Error){ | 269 | error_push(errors, (Error){ |
241 | .type = ERR_TYPE_PARSER, | 270 | .type = ERR_TYPE_PARSER, |