~sircmpwn/hare

dd6568fed0473f15e9ff4e387ddab4b8a8476fc7 — Drew DeVault 9 months ago 859d762
hare::parse: remove expression classes
3 files changed, 10 insertions(+), 18 deletions(-)

M hare/parse/decl.ha
M hare/parse/expr.ha
M hare/parse/exprclass.ha
M hare/parse/decl.ha => hare/parse/decl.ha +1 -1
@@ 58,7 58,7 @@ fn decl_global(
			_type.flags |= ast::type_flags::CONST;
		};
		want_btoken(lexer, btoken::EQUAL)?;
		let init = simple_expression(lexer)?;
		let init = expression(lexer)?;
		let btok = try_btoken(lexer, btoken::COMMA)?;
		append(decl, ast::decl_global {
			is_const = tok == btoken::DEF,

M hare/parse/expr.ha => hare/parse/expr.ha +3 -3
@@ 111,7 111,7 @@ fn plain_expression(lexer: *lex::lexer) (ast::expr | error) = {
		btoken::LBRACKET => abort(), // TODO: Array literal
		btoken::STRUCT => abort(), // TODO: Struct literal
		btoken::LPAREN => {
			let ex = complex_expression(lexer);
			let ex = expression(lexer);
			return switch (want_btoken(lexer,
					btoken::RPAREN, btoken::COMMA)?) {
				btoken::RPAREN => ex,


@@ 261,9 261,9 @@ fn expression_list(lexer: *lex::lexer) (ast::expr | error) = {
					more = false;
					control_statement(lexer)?;
				},
				* => scope_expression(lexer)?,
				* => expression(lexer)?,
			},
			* => scope_expression(lexer)?,
			* => expression(lexer)?,
		};
		append(items, alloc(item));
		want_btoken(lexer, btoken::SEMICOLON)?;

M hare/parse/exprclass.ha => hare/parse/exprclass.ha +6 -14
@@ 3,10 3,10 @@ use hare::lex::{btoken};
use hare::lex;
use io;

// Parses a complex-expression.
export fn complex_expression(lexer: *lex::lexer) (ast::expr | error) = {
	// TODO: if, for, switch, match
	return simple_expression(lexer);
// Parses an expression.
export fn expression(lexer: *lex::lexer) (ast::expr | error) = {
	// TODO: if, for, switch, match, etc
	return binarithm(lexer, void, 0);
};

// Parses a compound-expression.


@@ 20,21 20,13 @@ export fn compound_expression(lexer: *lex::lexer) (ast::expr | error) = {
	lex::unlex(lexer, tok);
	let tok = match (tok.0) {
		tok: btoken => tok,
		* => return complex_expression(lexer),
		* => return expression(lexer),
	};

	return switch (tok) {
		btoken::LBRACE => expression_list(lexer),
		btoken::BREAK, btoken::CONTINUE, btoken::RETURN =>
			control_statement(lexer),
		* => complex_expression(lexer),
		* => expression(lexer),
	};
};

fn scope_expression(lexer: *lex::lexer) (ast::expr | error) = {
	return simple_expression(lexer); // TODO
};

// Parses a simple-expression.
export fn simple_expression(lexer: *lex::lexer) (ast::expr | error) =
	binarithm(lexer, void, 0);