2023-07-10 19:39:01 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "bstrlib/bstrlib.h"
|
|
|
|
|
2023-07-10 21:11:54 +00:00
|
|
|
bstring grab_chunk(char *start, char *end) {
|
|
|
|
blk2bstr(start, end-start);
|
|
|
|
}
|
|
|
|
|
2023-07-10 19:39:01 +00:00
|
|
|
%%{
|
|
|
|
machine shortcode;
|
|
|
|
|
2023-07-10 21:11:54 +00:00
|
|
|
action mark {
|
|
|
|
mark = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
spc = space*;
|
|
|
|
sep = space+;
|
2023-07-10 23:36:50 +00:00
|
|
|
path = (alnum | '/' )+;
|
2023-07-10 21:11:54 +00:00
|
|
|
|
2023-07-11 00:55:45 +00:00
|
|
|
name = (alpha+ path?)
|
2023-07-10 21:11:54 +00:00
|
|
|
> mark
|
2023-07-11 00:55:45 +00:00
|
|
|
% {bcatStatic(output, "N ");
|
2023-07-10 23:30:50 +00:00
|
|
|
bcatblk(output, mark, p-mark);
|
2023-07-11 00:55:45 +00:00
|
|
|
bcatStatic(output, "\n");
|
2023-07-10 23:30:50 +00:00
|
|
|
};
|
2023-07-11 00:55:45 +00:00
|
|
|
argname = alpha+
|
2023-07-10 21:17:17 +00:00
|
|
|
> mark
|
2023-07-11 00:55:45 +00:00
|
|
|
% {bcatStatic(output, "A ");
|
2023-07-10 23:30:50 +00:00
|
|
|
bcatblk(output, mark, p-mark);
|
2023-07-11 00:55:45 +00:00
|
|
|
bcatStatic(output, "\n");
|
2023-07-10 23:30:50 +00:00
|
|
|
};
|
|
|
|
qvalue = ('"' [^"]* '"')
|
2023-07-10 21:11:54 +00:00
|
|
|
> mark
|
2023-07-11 00:55:45 +00:00
|
|
|
% {bcatStatic(output, "V ");
|
2023-07-10 23:30:50 +00:00
|
|
|
bcatblk(output, mark+1, p-mark-2);
|
2023-07-11 00:55:45 +00:00
|
|
|
bcatStatic(output, "\n");
|
2023-07-10 23:30:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
value = alnum+
|
|
|
|
> mark
|
2023-07-11 00:55:45 +00:00
|
|
|
% {bcatStatic(output, "V ");
|
2023-07-10 23:30:50 +00:00
|
|
|
bcatblk(output, mark, p-mark);
|
2023-07-11 00:55:45 +00:00
|
|
|
bcatStatic(output, "\n");
|
2023-07-10 23:30:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
arg = ((argname '=')? (value|qvalue));
|
2023-07-10 19:39:01 +00:00
|
|
|
|
2023-07-10 23:30:50 +00:00
|
|
|
start_p = '{{%';
|
|
|
|
end_p = '%}}';
|
2023-07-10 19:39:01 +00:00
|
|
|
|
2023-07-10 23:30:50 +00:00
|
|
|
start_b = '{{<';
|
|
|
|
end_b = '>}}';
|
|
|
|
|
|
|
|
start = start_p | start_b ;
|
|
|
|
end = end_p | end_b ;
|
|
|
|
|
|
|
|
shortcode = (start spc name (sep arg)* spc end)
|
2023-07-11 00:55:45 +00:00
|
|
|
@ {bcatStatic(output, "+++ opening\n");};
|
2023-07-10 23:30:50 +00:00
|
|
|
|
2023-07-11 00:55:45 +00:00
|
|
|
closing_shortcode = (start spc '/' name spc end)
|
|
|
|
@ {bcatStatic(output, "--- closing\n");};
|
2023-07-10 23:36:50 +00:00
|
|
|
|
2023-07-11 00:55:45 +00:00
|
|
|
|
|
|
|
main := (any* (shortcode | closing_shortcode))*;
|
2023-07-10 19:39:01 +00:00
|
|
|
}%%
|
|
|
|
|
2023-07-10 23:30:50 +00:00
|
|
|
bstring parse(char *input) {
|
2023-07-10 19:39:01 +00:00
|
|
|
%%write data;
|
|
|
|
char *eof, *ts, *te = 0;
|
|
|
|
int cs, act = 0;
|
|
|
|
|
2023-07-10 23:30:50 +00:00
|
|
|
char *p = input;
|
|
|
|
char *pe = p + strlen(input);
|
2023-07-10 19:39:01 +00:00
|
|
|
|
2023-07-10 21:11:54 +00:00
|
|
|
char *mark = 0;
|
2023-07-10 23:30:50 +00:00
|
|
|
bstring output = bfromcstr("");
|
2023-07-10 19:39:01 +00:00
|
|
|
%% write init;
|
|
|
|
%% write exec;
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2023-07-11 00:55:45 +00:00
|
|
|
bstring output = parse("
|
|
|
|
{{< o1 arg1 >}}
|
|
|
|
{{% /c1%}}");
|
2023-07-10 19:39:01 +00:00
|
|
|
printf("\n%s\n", output->data);
|
|
|
|
return 0;
|
|
|
|
}
|