bshell: re-organise build into three separate components
bshell: the front-end binary bshell.runtime: contains the parser, compiler, and classes needed to run bshell scripts bshell.core: contains the builtin commandlets and aliases
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#include "../syntax.h"
|
||||
|
||||
bool parse_block(struct bshell_parse_ctx *ctx, struct bshell_ast_node **out)
|
||||
{
|
||||
if (!parse_symbol(ctx, BSHELL_SYM_LEFT_BRACE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
parse_linefeed(ctx);
|
||||
|
||||
struct bshell_block_ast_node *block
|
||||
= (struct bshell_block_ast_node *)bshell_ast_node_create(
|
||||
BSHELL_AST_BLOCK);
|
||||
|
||||
bool ok = true;
|
||||
while (1) {
|
||||
if (parse_symbol(ctx, BSHELL_SYM_RIGHT_BRACE)) {
|
||||
break;
|
||||
}
|
||||
|
||||
parse_linefeed(ctx);
|
||||
|
||||
struct bshell_ast_node *stmt = NULL;
|
||||
if (!parse_statement(ctx, &stmt)) {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
|
||||
fx_queue_push_back(&block->n_statements, &stmt->n_entry);
|
||||
|
||||
if (parse_symbol(ctx, BSHELL_SYM_RIGHT_BRACE)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!parse_linefeed(ctx)
|
||||
&& !parse_symbol(ctx, BSHELL_SYM_SEMICOLON)) {
|
||||
report_error(
|
||||
ctx,
|
||||
"expected `;`, `}`, or linefeed after "
|
||||
"statement");
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
bshell_ast_node_destroy((struct bshell_ast_node *)block);
|
||||
block = NULL;
|
||||
}
|
||||
|
||||
*out = (struct bshell_ast_node *)block;
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user