~emersion/mrsh

f848f5cfe0ea842dc064b899eb8082d6a15efaf4 — emersion 3 years ago e357a7f
Correctly parse simple assignments without command name
3 files changed, 14 insertions(+), 7 deletions(-)

M include/mrsh/ast.h
M parser.c
M shell/shell.c
M include/mrsh/ast.h => include/mrsh/ast.h +1 -1
@@ 40,7 40,7 @@ struct mrsh_command {
 */
struct mrsh_simple_command {
	struct mrsh_command command;
	char *name;
	char *name; // can be NULL if it contains only assignments
	struct mrsh_array arguments; // char *
	struct mrsh_array io_redirects; // struct mrsh_io_redirect *
	struct mrsh_array assignments; // struct mrsh_assignment *

M parser.c => parser.c +8 -6
@@ 584,17 584,19 @@ static bool cmd_suffix(struct mrsh_parser *state,
static struct mrsh_simple_command *simple_command(struct mrsh_parser *state) {
	struct mrsh_simple_command cmd = {0};

	bool has_prefix = false;
	while (cmd_prefix(state, &cmd)) {
		// This space is intentionally left blank
		has_prefix = true;
	}

	// TODO: alias substitution
	cmd.name = word(state, true);
	if (cmd.name == NULL) {
	if (cmd.name == NULL && !has_prefix) {
		return NULL;
	}

	while (cmd_suffix(state, &cmd)) {
		// This space is intentionally left blank
	} else if (cmd.name != NULL) {
		while (cmd_suffix(state, &cmd)) {
			// This space is intentionally left blank
		}
	}

	return mrsh_simple_command_create(cmd.name, &cmd.arguments,

M shell/shell.c => shell/shell.c +5 -0
@@ 6,6 6,11 @@ void mrsh_state_init(struct mrsh_state *state) {
}

static struct task *handle_simple_command(struct mrsh_simple_command *sc) {
	if (sc->name == NULL) {
		// TODO: task that sets variable
		return task_list_create();
	}

	struct task *task = task_builtin_create(sc);
	if (task != NULL) {
		return task;