commit 5d450b1a647e0aeeb1e49e28e0d16af11358e12c
parent 5f490faead1af543eca2a29277454cbc63aba9d5
Author: Drew DeVault <sir@cmpwn.com>
Date: Mon, 5 Apr 2021 09:38:06 -0400
hare::parse: move expression_list
Trying to group the expression classes towards the bottom and leave the
top of the file for the more interesting parsers.
Diffstat:
1 file changed, 31 insertions(+), 31 deletions(-)
diff --git a/hare/parse/expr.ha b/hare/parse/expr.ha
@@ -117,6 +117,37 @@ fn precedence(tok: (lex::token, lex::location)) int = {
};
};
+fn expression_list(lexer: *lex::lexer) (ast::expr | error) = {
+ let items: ast::list_expr = [];
+
+ for (let more = true; more) {
+ let tok = match (lex::lex(lexer)?) {
+ io::EOF => return syntaxerr(mkloc(lexer),
+ "Unexpected EOF, expected scope or control expression"),
+ t: (lex::token, lex::location) => t,
+ };
+ lex::unlex(lexer, tok);
+ let item = match (tok.0) {
+ tok: btoken => switch (tok) {
+ btoken::RBRACE => break,
+ btoken::BREAK,
+ btoken::CONTINUE,
+ btoken::RETURN => {
+ more = false;
+ control_statement(lexer)?;
+ },
+ * => scope_expression(lexer)?,
+ },
+ * => scope_expression(lexer)?,
+ };
+ append(items, alloc(item));
+ want_btoken(lexer, btoken::SEMICOLON)?;
+ };
+
+ want_btoken(lexer, btoken::RBRACE)?;
+ return items;
+};
+
// Parses a compound-expression
export fn compound_expression(lexer: *lex::lexer) (ast::expr | error) = {
let tok = match (lex::lex(lexer)?) {
@@ -149,37 +180,6 @@ export fn complex_expression(lexer: *lex::lexer) (ast::expr | error) = {
return simple_expression(lexer);
};
-fn expression_list(lexer: *lex::lexer) (ast::expr | error) = {
- let items: ast::list_expr = [];
-
- for (let more = true; more) {
- let tok = match (lex::lex(lexer)?) {
- io::EOF => return syntaxerr(mkloc(lexer),
- "Unexpected EOF, expected scope or control expression"),
- t: (lex::token, lex::location) => t,
- };
- lex::unlex(lexer, tok);
- let item = match (tok.0) {
- tok: btoken => switch (tok) {
- btoken::RBRACE => break,
- btoken::BREAK,
- btoken::CONTINUE,
- btoken::RETURN => {
- more = false;
- control_statement(lexer)?;
- },
- * => scope_expression(lexer)?,
- },
- * => scope_expression(lexer)?,
- };
- append(items, alloc(item));
- want_btoken(lexer, btoken::SEMICOLON)?;
- };
-
- want_btoken(lexer, btoken::RBRACE)?;
- return items;
-};
-
fn scope_expression(lexer: *lex::lexer) (ast::expr | error) = {
return simple_expression(lexer); // TODO
};