Skip to content

Commit e4df49a

Browse files
authored
fix: parsing multiline expr (#124)
* fix: list print * fix multiline parser map
1 parent 2370dab commit e4df49a

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/interpreter/parser.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static ArenaLL arguments(Parser *parser);
7878

7979
static void handle_parse_err(Parser *parser, char *msg, ParseErrorType pet);
8080

81-
static ParseError *new_parse_error(Arena *arena, char *msg, Token *failed, ParseErrorType pet)
81+
static ParseError *parse_error_new(Arena *arena, char *msg, Token *failed, ParseErrorType pet)
8282
{
8383
ParseError *error = m_arena_alloc_struct(arena, ParseError);
8484
error->err_type = pet;
@@ -220,7 +220,7 @@ static void handle_parse_err(Parser *parser, char *msg, ParseErrorType pet)
220220
if ((failed->type == t_eof || failed->type == t_newline) && parser->token_pos != 0)
221221
failed = arraylist_get(parser->tokens, parser->token_pos - 1);
222222

223-
ParseError *error = new_parse_error(parser->ast_arena, msg, failed, pet);
223+
ParseError *error = parse_error_new(parser->ast_arena, msg, failed, pet);
224224
if (parser->perr_head == NULL)
225225
parser->perr_head = error;
226226
else
@@ -834,11 +834,10 @@ static Expr *list(Parser *parser)
834834
ListExpr *expr = (ListExpr *)expr_alloc(parser->ast_arena, EXPR_LIST, parser->source_line);
835835

836836
/* if next is not ']', parse list initializer */
837-
if (!match(parser, t_rbracket)) {
837+
if (!match(parser, t_rbracket))
838838
expr->exprs = sequence(parser, t_rbracket);
839-
} else {
839+
else
840840
expr->exprs = NULL;
841-
}
842841

843842
return (Expr *)expr;
844843
}
@@ -858,11 +857,13 @@ static Expr *map(Parser *parser)
858857
do {
859858
KeyValuePair *pair = m_arena_alloc_struct(parser->ast_arena, KeyValuePair);
860859
pair->key = expression(parser);
861-
consume(parser, t_colon, "Expected colon ':' to denote value for key in map expression");
860+
consume(parser, t_colon, "Expected ':' to denote value for key in map expression");
862861
pair->value = expression(parser);
863862
arena_ll_append(expr->key_value_pairs, pair);
863+
ignore(parser, t_newline);
864864
if (!match(parser, t_comma))
865865
break;
866+
ignore(parser, t_newline);
866867
} while (!check(parser, t_rbracket));
867868

868869
consume(parser, t_rbracket, "Expected ']' to terminate map");

src/interpreter/value/slash_value.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ void list_print(Interpreter *interpreter, SlashValue self)
437437
assert(item.T->print != NULL);
438438
item.T->print(interpreter, item);
439439
if (i != underlying->len - 1)
440-
printf(", ");
440+
SLASH_PRINT(&interpreter->stream_ctx, ", ");
441441
}
442442
SLASH_PRINT(&interpreter->stream_ctx, "]");
443443
}

0 commit comments

Comments
 (0)