Skip to content

Commit

Permalink
parser: Accept #-space-% to allow writing PEP8-compliant Python code (#…
Browse files Browse the repository at this point in the history
…1446)

Accept '# %' in parser script header definition because '#%' is against PEP8
(each line of a block comment starts with a # and a single space).
Only minimal changes to achieve this support are included.

'#%' is still supported fully supported and remains in documentation.
The full switch to '# %' is left for v8.

Partial backport of 6352241 (#1287).
  • Loading branch information
wenzeslaus committed Mar 16, 2021
1 parent d0bb19b commit b7caccb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions general/g.parser/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ int main(int argc, char *argv[])
for (ctx.line = 1;; ctx.line++) {
char buff[4096];
char *cmd, *arg;
size_t line_size;

if (!fgets(buff, sizeof(buff), ctx.fp))
break;
Expand All @@ -102,10 +103,19 @@ int main(int argc, char *argv[])
}
*arg = '\0';

if (buff[0] != '#' || buff[1] != '%')
line_size = strlen(buff);
if (line_size > 2 && buff[0] == '#') {
if (buff[1] == '%')
cmd = buff + 2;
else if (line_size > 3 && buff[1] == ' ' && buff[2] == '%')
cmd = buff + 3;
else
continue;
}
else {
continue;
}

cmd = buff + 2;
G_chop(cmd);

arg = strchr(cmd, ':');
Expand Down

0 comments on commit b7caccb

Please sign in to comment.