cmark

My personal build of CMark ✏️

Commit
c351c72220406d3e934049808ecd09e599487a85
Parent
6182bc78cc0531a735a0ffc452f2922485af05c1
Author
John MacFarlane <jgm@berkeley.edu>
Date

Added partially_consumed_tab to parser.

This keeps track of when we have gotten partway through a tab when consuming initial indentation.

Diffstat

2 files changed, 6 insertions, 2 deletions

Status File Name N° Changes Insertions Deletions
Modified src/blocks.c 7 5 2
Modified src/parser.h 1 1 0
diff --git a/src/blocks.c b/src/blocks.c
@@ -70,6 +70,7 @@ cmark_parser *cmark_parser_new(int options) {
   parser->first_nonspace_column = 0;
   parser->indent = 0;
   parser->blank = false;
+  parser->partially_consumed_tab = false;
   parser->curline = line;
   parser->last_line_length = 0;
   parser->linebuf = buf;
@@ -574,11 +575,13 @@ static void S_advance_offset(cmark_parser *parser, cmark_chunk *input,
   while (count > 0 && (c = peek_at(input, parser->offset))) {
     if (c == '\t') {
       chars_to_tab = TAB_STOP - (parser->column % TAB_STOP);
-      chars_to_advance = chars_to_tab > count ? count : chars_to_tab;
+      parser->partially_consumed_tab = chars_to_tab > count;
+      chars_to_advance = parser->partially_consumed_tab ? count : chars_to_tab;
       parser->column += chars_to_advance;
-      parser->offset += chars_to_advance < chars_to_tab ? 0 : 1;
+      parser->offset += parser->partially_consumed_tab ? 0 : 1;
       count -= (columns ? chars_to_advance : 1);
     } else {
+      parser->partially_consumed_tab = false;
       parser->offset += 1;
       parser->column += 1; // assume ascii; block starts are ascii
       count -= 1;
diff --git a/src/parser.h b/src/parser.h
@@ -22,6 +22,7 @@ struct cmark_parser {
   bufsize_t first_nonspace_column;
   int indent;
   bool blank;
+  bool partially_consumed_tab;
   cmark_strbuf *curline;
   bufsize_t last_line_length;
   cmark_strbuf *linebuf;