hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 198146b7990b34fc5d1b55d01a84500040427d6d
parent 9a17974f1c648d2ad9365e0009306144a83a0b4d
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon,  5 Apr 2021 19:41:10 -0400

hare::parse: move expr classes into exprclass.ha

Diffstat:
Mhare/parse/expr.ha | 46+++++-----------------------------------------
Ahare/parse/exprclass.ha | 40++++++++++++++++++++++++++++++++++++++++
Mscripts/gen-stdlib | 1+
Mstdlib.mk | 2++
4 files changed, 48 insertions(+), 41 deletions(-)

diff --git a/hare/parse/expr.ha b/hare/parse/expr.ha @@ -1,6 +1,6 @@ use hare::ast; -use hare::lex; use hare::lex::{btoken}; +use hare::lex; fn binarithm( lexer: *lex::lexer, @@ -77,6 +77,10 @@ fn cast(lexer: *lex::lexer, lvalue: (ast::expr | void)) (ast::expr | error) = { }); }; +fn control_statement(lexer: *lex::lexer) (ast::expr | error) = { + abort(); // TODO +}; + fn objsel(lexer: *lex::lexer) (ast::expr | error) = { abort(); // TODO }; @@ -199,43 +203,3 @@ fn expression_list(lexer: *lex::lexer) (ast::expr | error) = { 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)?) { - io::EOF => return syntaxerr(mkloc(lexer), - "Unexpected EOF, expected compound expression"), - t: (lex::token, lex::location) => t, - }; - - lex::unlex(lexer, tok); - let tok = match (tok.0) { - tok: btoken => tok, - * => return complex_expression(lexer), - }; - - return switch (tok) { - btoken::LBRACE => expression_list(lexer), - btoken::BREAK, btoken::CONTINUE, btoken::RETURN => - control_statement(lexer), - * => complex_expression(lexer), - }; -}; - -// Parses a simple-expression -export fn simple_expression(lexer: *lex::lexer) (ast::expr | error) = - binarithm(lexer, void, 0); - -// Parses a complex-expression -export fn complex_expression(lexer: *lex::lexer) (ast::expr | error) = { - // TODO: if, for, switch, match - return simple_expression(lexer); -}; - -fn scope_expression(lexer: *lex::lexer) (ast::expr | error) = { - return simple_expression(lexer); // TODO -}; - -fn control_statement(lexer: *lex::lexer) (ast::expr | error) = { - abort(); // TODO -}; diff --git a/hare/parse/exprclass.ha b/hare/parse/exprclass.ha @@ -0,0 +1,40 @@ +use hare::ast; +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 a compound-expression. +export fn compound_expression(lexer: *lex::lexer) (ast::expr | error) = { + let tok = match (lex::lex(lexer)?) { + io::EOF => return syntaxerr(mkloc(lexer), + "Unexpected EOF, expected compound expression"), + t: (lex::token, lex::location) => t, + }; + + lex::unlex(lexer, tok); + let tok = match (tok.0) { + tok: btoken => tok, + * => return complex_expression(lexer), + }; + + return switch (tok) { + btoken::LBRACE => expression_list(lexer), + btoken::BREAK, btoken::CONTINUE, btoken::RETURN => + control_statement(lexer), + * => complex_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); diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib @@ -323,6 +323,7 @@ gensrcs_hare_parse() { gen_srcs hare::parse \ decl.ha \ expr.ha \ + exprclass.ha \ ident.ha \ import.ha \ type.ha \ diff --git a/stdlib.mk b/stdlib.mk @@ -472,6 +472,7 @@ $(HARECACHE)/hare/module/hare_module.ssa: $(stdlib_hare_module_srcs) $(stdlib_rt stdlib_hare_parse_srcs= \ $(STDLIB)/hare/parse/decl.ha \ $(STDLIB)/hare/parse/expr.ha \ + $(STDLIB)/hare/parse/exprclass.ha \ $(STDLIB)/hare/parse/ident.ha \ $(STDLIB)/hare/parse/import.ha \ $(STDLIB)/hare/parse/type.ha \ @@ -1286,6 +1287,7 @@ $(TESTCACHE)/hare/module/hare_module.ssa: $(testlib_hare_module_srcs) $(testlib_ testlib_hare_parse_srcs= \ $(STDLIB)/hare/parse/decl.ha \ $(STDLIB)/hare/parse/expr.ha \ + $(STDLIB)/hare/parse/exprclass.ha \ $(STDLIB)/hare/parse/ident.ha \ $(STDLIB)/hare/parse/import.ha \ $(STDLIB)/hare/parse/type.ha \