~emersion/mrsh

69713863e96fdcb6640d7985be34d4501317faa0 — Simon Ser 5 months ago 0804d1d
parser: parse here-documents after newline separator

Fixes part of [1].

[1]: https://lists.sr.ht/~emersion/mrsh-dev/%3CC10JME71VSUQ.2ZCBK3RDD2XXW%40homura%3E
1 files changed, 18 insertions(+), 0 deletions(-)

M parser/program.c
M parser/program.c => parser/program.c +18 -0
@@ 362,6 362,9 @@ static int separator(struct mrsh_parser *parser) {

static struct mrsh_and_or_list *and_or(struct mrsh_parser *parser);

static bool expect_here_document(struct mrsh_parser *parser,
	struct mrsh_io_redirect *redir, const char *delim);

static struct mrsh_command_list *term(struct mrsh_parser *parser) {
	struct mrsh_and_or_list *and_or_list = and_or(parser);
	if (and_or_list == NULL) {


@@ 380,6 383,21 @@ static struct mrsh_command_list *term(struct mrsh_parser *parser) {
		cmd->separator_pos = separator_pos;
	}

	if (sep == '\n' && parser->here_documents.len > 0) {
		for (size_t i = 0; i < parser->here_documents.len; ++i) {
			struct mrsh_io_redirect *redir = parser->here_documents.data[i];

			char *delim = mrsh_word_str(redir->name);
			bool ok = expect_here_document(parser, redir, delim);
			free(delim);
			if (!ok) {
				return false;
			}
		}

		parser->here_documents.len = 0;
	}

	return cmd;
}