shortcode/shortcodes.rl

64 lines
1.2 KiB
Plaintext
Raw Normal View History

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 21:17:17 +00:00
name = alpha+
2023-07-10 21:11:54 +00:00
> mark
2023-07-10 21:17:17 +00:00
% {printf("name: '%s'\n", grab_chunk(mark, p)->data);};
argname = alpha+
> mark
% {printf("argname: '%s'\n", grab_chunk(mark, p)->data);};
2023-07-10 21:11:54 +00:00
value = (('"' [^"]* '"') | alnum+)
> mark
% {printf("value: '%s'\n", grab_chunk(mark, p)->data);};
2023-07-10 21:17:17 +00:00
arg = (argname '=' value)
2023-07-10 21:11:54 +00:00
> mark
% {printf("arg: '%s'\n", grab_chunk(mark, p)->data);};
2023-07-10 19:39:01 +00:00
2023-07-10 21:11:54 +00:00
start = '{{';
end = '}}';
2023-07-10 19:39:01 +00:00
2023-07-10 21:17:17 +00:00
main := (start spc name (sep (arg | value))* spc end);
2023-07-10 19:39:01 +00:00
}%%
bstring parse(char *_input) {
%%write data;
char *eof, *ts, *te = 0;
int cs, act = 0;
bstring output = bfromcstr("out");
bstring input = bfromcstr(_input);
char *p = input->data;
char *pe = p + blength(input);
2023-07-10 21:11:54 +00:00
char *mark = 0;
bstring label;
2023-07-10 19:39:01 +00:00
%% write init;
%% write exec;
2023-07-10 21:11:54 +00:00
printf("\nLabel is: '%s'\n", label->data);
2023-07-10 19:39:01 +00:00
return output;
}
int main(int argc, char **argv) {
2023-07-10 21:17:17 +00:00
bstring output = parse("{{ thename \"onearg\" another arg=\"val3\" }}");
2023-07-10 19:39:01 +00:00
printf("\n%s\n", output->data);
return 0;
}