From 17f30b40f8a2d2ba5a2bea4c7c0cec5af14c04e5 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sun, 11 May 2014 16:58:40 +1000 Subject: [PATCH] pargergen: support $ --- csrc/parsergen.mdc | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/csrc/parsergen.mdc b/csrc/parsergen.mdc index ef01bf3..b3d1cf6 100644 --- a/csrc/parsergen.mdc +++ b/csrc/parsergen.mdc @@ -397,12 +397,15 @@ collected and forms the code-fragment for the production. It must all be in one `code_node` of the literate code. The `}$` must be at the end of a line. -Text in the code fragment will undergo substitutions where `$N` for -some numeric `N` will be replaced with a variable holding the parse -information for the particular symbol in the production. `$0` is the -head of the production, `$1` is the first symbol of the body, etc. -The type of `$N` for a terminal symbol is `struct token`. For -a non-terminal, it is whatever has been declared for that symbol. +Text in the code fragment will undergo substitutions where `$N` or +`$body_size); + int i; + fprintf(f, "\t\t\t"); for (c = p->code.txt; c < p->code.txt + p->code.len; c++) { int n; + int use = 0; if (*c != '$') { fputc(*c, f); if (*c == '\n') @@ -1981,7 +1992,13 @@ to the appropriate type for each access. All this is handling in continue; } c++; + if (*c == '<') { + use = 1; + c++; + } if (*c < '0' || *c > '9') { + if (use) + fputc('<', f); fputc(*c, f); continue; } @@ -2002,13 +2019,23 @@ to the appropriate type for each access. All this is handling in n-1); else if (p->body[n-1]->struct_name.txt == NULL) fprintf(f, "$%d", n); - else + else { fprintf(f, "(*(struct %.*s*%s)body[%d])", p->body[n-1]->struct_name.len, p->body[n-1]->struct_name.txt, p->body[n-1]->isref ? "*":"", n-1); + used[n-1] = use; + } } fputs("\n", f); + for (i = 0; i < p->body_size; i++) { + if (p->body[i]->struct_name.txt && + p->body[i]->isref && + used[i]) + // assume this has been copied out + fprintf(f, "\t\t*(void**)body[%d] = NULL;\n", i); + } + free(used); } ###### functions -- 2.43.0