From: NeilBrown Date: Sat, 22 Jun 2013 07:39:23 +0000 (+1000) Subject: Record in a code_node whether it was indented or not. X-Git-Tag: draftparser~20 X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=5458aee9c9dc5ef75189107a2d4a1ac565b44a7c Record in a code_node whether it was indented or not. This is needed to correctly adjust for this indent when processing the code. Signed-off-by: NeilBrown --- diff --git a/csrc/mdcode.mdc b/csrc/mdcode.mdc index dc78a12..1b5d48f 100644 --- a/csrc/mdcode.mdc +++ b/csrc/mdcode.mdc @@ -153,6 +153,11 @@ The `code_node` will also have an `indent` depth which eventually gets set to the sum for the indents from all references on the path from the root. +Finally we need to know if the `code_node` was recognised by being +indented or not. If it was, the client of this data will want to +strip of the leading tab or 4 spaces. Hence a `needs_strip` flag is +needed. + ##### exported types struct text { @@ -170,6 +175,7 @@ the root. struct text code; int indent; int line_no; + int needs_strip; struct code_node *next; struct section *child; }; @@ -266,7 +272,7 @@ in a new node. ##### internal functions static void code_add_text(struct psection *where, struct text txt, - int line_no) + int line_no, int needs_strip) { struct code_node *n; if (txt.len == 0) @@ -275,6 +281,7 @@ in a new node. n->code = txt; n->indent = 0; n->line_no = line_no; + n->needs_strip = needs_strip; n->next = NULL; n->child = NULL; if (where->last) @@ -592,7 +599,8 @@ for that. struct text txt; txt.txt = start; txt.len = pos - start; - code_add_text(sect, txt, start_line); + code_add_text(sect, txt, start_line, + marker == NULL); } ref = take_header(t, end); if (ref.len) { @@ -608,7 +616,8 @@ for that. struct text txt; txt.txt = start; txt.len = pos - start; - code_add_text(sect, txt, start_line); + code_add_text(sect, txt, start_line, + marker == NULL); } if (marker) { pos = skip_line(pos, end); @@ -774,18 +783,15 @@ for `Makefiles`. for (; node; node = node->next) { char *c = node->code.txt; int len = node->code.len; - int undent = 0; if (!len) continue; fprintf(out, "#line %d \"%s\"\n", node->line_no, fname); - if (*c == ' ' || *c == '\t') - undent = 1; while (len && *c) { fprintf(out, "%*s", node->indent, ""); - if (undent) { + if (node->needs_strip) { if (*c == '\t' && len > 1) { c++; len--;