extract args into struct
This commit is contained in:
parent
071393f757
commit
8dad75b6f8
@ -21,14 +21,25 @@
|
|||||||
};
|
};
|
||||||
argname = alpha+
|
argname = alpha+
|
||||||
> mark
|
> mark
|
||||||
% {};
|
% {
|
||||||
|
shortcodes[c_sc].argnames[shortcodes[c_sc].argcount].start = mark-start;
|
||||||
|
shortcodes[c_sc].argnames[shortcodes[c_sc].argcount].len = p-mark;
|
||||||
|
};
|
||||||
qvalue = ('"' [^"]* '"')
|
qvalue = ('"' [^"]* '"')
|
||||||
> mark
|
> 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+
|
value = alnum+
|
||||||
> mark
|
> 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));
|
arg = ((argname '=')? (value|qvalue));
|
||||||
|
|
||||||
@ -77,9 +88,7 @@
|
|||||||
printf("opened: %s\n", sc.s);
|
printf("opened: %s\n", sc.s);
|
||||||
str_copyb(&sc,start + shortcodes[c_sc].name.start, shortcodes[c_sc].name.len);
|
str_copyb(&sc,start + shortcodes[c_sc].name.start, shortcodes[c_sc].name.len);
|
||||||
printf("closed: %s\n", sc.s);
|
printf("closed: %s\n", sc.s);
|
||||||
// Closing the wrong code
|
return 1;
|
||||||
// TODO error reporting
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// Reuse this shortcode entry for next one
|
// Reuse this shortcode entry for next one
|
||||||
shortcodes[c_sc].name.start = 0;
|
shortcodes[c_sc].name.start = 0;
|
||||||
@ -107,44 +116,53 @@ struct shortcode {
|
|||||||
};
|
};
|
||||||
typedef struct shortcode shortcode;
|
typedef struct shortcode shortcode;
|
||||||
|
|
||||||
void parse(char *input) {
|
int parse(char *input) {
|
||||||
%%write data;
|
%%write data;
|
||||||
char *eof, *ts, *te = 0;
|
char *eof, *ts, *te = 0;
|
||||||
int cs, act = 0;
|
int cs, act = 0;
|
||||||
|
|
||||||
char *start = input;
|
char *start = input;
|
||||||
char *p = input;
|
char *p = input;
|
||||||
char *pe = p + strlen(input);
|
char *pe = p + strlen(input);
|
||||||
|
|
||||||
shortcode shortcodes[1000];
|
shortcode shortcodes[1000];
|
||||||
int c_sc = 0;
|
int c_sc = 0;
|
||||||
|
|
||||||
int sc_start = 0;
|
int sc_start = 0;
|
||||||
int sc_end = 0;
|
int sc_end = 0;
|
||||||
|
|
||||||
char *mark = p;
|
char *mark = p;
|
||||||
char *data_mark = p;
|
char *data_mark = p;
|
||||||
str sc;
|
str sc;
|
||||||
str_init(&sc);
|
str_init(&sc);
|
||||||
|
|
||||||
%% write init;
|
%% write init;
|
||||||
%% write exec;
|
%% write exec;
|
||||||
|
|
||||||
for (int i=0; shortcodes[i].name.start!=0; i++) {
|
for (int i=0; shortcodes[i].name.start!=0; i++) {
|
||||||
str_copyb(&sc, start + shortcodes[i].name.start, shortcodes[i].name.len);
|
str_copyb(&sc, start + shortcodes[i].name.start, shortcodes[i].name.len);
|
||||||
printf("sc_name: %s (%d)\n", sc.s, shortcodes[i].matching );
|
printf("sc_name: %s (%d)\n", sc.s, shortcodes[i].matching );
|
||||||
str_copyb(&sc, start + shortcodes[i].start, shortcodes[i].len);
|
str_copyb(&sc, start + shortcodes[i].start, shortcodes[i].len);
|
||||||
printf("full_sc: %s\n", sc.s);
|
printf("full_sc: %s\n", sc.s);
|
||||||
if (shortcodes[i].matching) {
|
if (shortcodes[i].matching) {
|
||||||
str_copyb(&sc, start + shortcodes[i].data.start, shortcodes[i].data.len);
|
str_copyb(&sc, start + shortcodes[i].data.start, shortcodes[i].data.len);
|
||||||
printf("sc_data: %s\n", sc.s);
|
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) {
|
int main(int argc, char **argv) {
|
||||||
parse(
|
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) {
|
// if (output == 0) {
|
||||||
// printf("parse error\n");
|
// printf("parse error\n");
|
||||||
// return 1;
|
// return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user