From b72890d44ed1adc459b6d78fba33aa7b224878d1 Mon Sep 17 00:00:00 2001 From: Miguel Lechon Date: Thu, 4 Mar 2021 15:18:42 +0100 Subject: [PATCH] before_comment fix. When two or more comments are followed by a node, use the closest comment as the before_comment. Prior to the fix, this combination left node unbefore_commented: // comment1 \n // comment2 \n node --- source/md.h | 1 - source/md_impl.c | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source/md.h b/source/md.h index d62e2ee..52a5bce 100644 --- a/source/md.h +++ b/source/md.h @@ -11,7 +11,6 @@ // - Outputting anything to MD or C code ideally would do something // smart with auto-indentation, since some people have wanted readable // layout (if they aren't using 4coder with virtual whitespace basically) -// - Building with Clang // - Split out C-related stuff into helper language layers // - Helpers for parsing NodeFlags, figuring out which nodes in a set are // separated by a semicolon, something like MD_SeekNodeWithFlags(node) -> node ? diff --git a/source/md_impl.c b/source/md_impl.c index c353cdd..a122605 100644 --- a/source/md_impl.c +++ b/source/md_impl.c @@ -1461,7 +1461,11 @@ _MD_ParseOneNode(MD_ParseCtx *ctx) else if(token.kind == MD_TokenKind_Newline) { MD_Parse_Bump(ctx, token); - if(MD_Parse_RequireKind(ctx, MD_TokenKind_Newline, 0)) + if(MD_Parse_RequireKind(ctx, MD_TokenKind_Comment, &comment_token)) + { + // NOTE(mal): If more than one comment, use the last comment + } + else if(MD_Parse_RequireKind(ctx, MD_TokenKind_Newline, 0)) { _MD_MemoryZero(&comment_token, sizeof(comment_token)); }