extract args into struct

This commit is contained in:
Roberto Alsina 2023-07-11 21:09:42 -03:00
parent 071393f757
commit 8dad75b6f8

View File

@ -21,14 +21,25 @@
};
argname = alpha+
> mark
% {};
% {
shortcodes[c_sc].argnames[shortcodes[c_sc].argcount].start = mark-start;
shortcodes[c_sc].argnames[shortcodes[c_sc].argcount].len = p-mark;
};
qvalue = ('"' [^"]* '"')
> mark
% {};
% {
shortcodes[c_sc].argvals[shortcodes[c_sc].argcount].start = mark-start;
shortcodes[c_sc].argvals[shortcodes[c_sc].argcount].len = p-mark;
shortcodes[c_sc].argcount++;
};
value = alnum+
> mark
% {};
% {
shortcodes[c_sc].argvals[shortcodes[c_sc].argcount].start = mark-start;
shortcodes[c_sc].argvals[shortcodes[c_sc].argcount].len = p-mark;
shortcodes[c_sc].argcount++;
};
arg = ((argname '=')? (value|qvalue));
@ -77,9 +88,7 @@
printf("opened: %s\n", sc.s);
str_copyb(&sc,start + shortcodes[c_sc].name.start, shortcodes[c_sc].name.len);
printf("closed: %s\n", sc.s);
// Closing the wrong code
// TODO error reporting
return;
return 1;
}
// Reuse this shortcode entry for next one
shortcodes[c_sc].name.start = 0;
@ -107,7 +116,7 @@ struct shortcode {
};
typedef struct shortcode shortcode;
void parse(char *input) {
int parse(char *input) {
%%write data;
char *eof, *ts, *te = 0;
int cs, act = 0;
@ -139,12 +148,21 @@ void parse(char *input) {
str_copyb(&sc, start + shortcodes[i].data.start, shortcodes[i].data.len);
printf("sc_data: %s\n", sc.s);
}
for (int j=0; j< shortcodes[i].argcount; j++) {
str_copyb(&sc, start + shortcodes[i].argnames[j].start, shortcodes[i].argnames[j].len);
printf("argname %d: %s\n", j, sc.s);
str_copyb(&sc, start + shortcodes[i].argvals[j].start, shortcodes[i].argvals[j].len);
printf("argval %d: %s\n", j, sc.s);
}
}
return 0;
}
int main(int argc, char **argv) {
parse(
"bbb{{% sarasa %}}ccc{{< c1 arg2 >}}foobar{{% /c1%}}aaa{{% sarasa %}}");
"bbb{{% sarasa sar1 sar2 \"sar3\" %}}ccc
{{< c1 arg2 >}}foobar{{% /c1%}}aaa{{% sarasa name=pepe %}}");
// if (output == 0) {
// printf("parse error\n");
// return 1;