Shortcodes with {{% and {{< , more than one

This commit is contained in:
Roberto Alsina 2023-07-10 20:30:50 -03:00
parent 3fa44de352
commit 326d13839a
2 changed files with 544 additions and 192 deletions

View File

@ -3,85 +3,115 @@
#include <stdio.h> #include <stdio.h>
#include "bstrlib/bstrlib.h" #include "bstrlib/bstrlib.h"
bstring grab_chunk(char *start, char *end) { bstring grab_chunk(char *start, char *end) {
blk2bstr(start, end-start); blk2bstr(start, end-start);
} }
#line 37 "shortcodes.rl" #line 60 "shortcodes.rl"
bstring parse(char *_input) { bstring parse(char *input) {
#line 19 "shortcodes.c" #line 17 "shortcodes.c"
static const int shortcode_start = 1; static const int shortcode_start = 24;
static const int shortcode_first_final = 15; static const int shortcode_first_final = 24;
static const int shortcode_error = 0; static const int shortcode_error = -1;
static const int shortcode_en_main = 1; static const int shortcode_en_main = 24;
#line 41 "shortcodes.rl" #line 64 "shortcodes.rl"
char *eof, *ts, *te = 0; char *eof, *ts, *te = 0;
int cs, act = 0; int cs, act = 0;
bstring output = bfromcstr("out"); char *p = input;
char *pe = p + strlen(input);
bstring input = bfromcstr(_input);
char *p = input->data;
char *pe = p + blength(input);
char *mark = 0; char *mark = 0;
bstring label; bstring output = bfromcstr("");
#line 35 "shortcodes.c"
#line 42 "shortcodes.c"
{ {
cs = shortcode_start; cs = shortcode_start;
} }
#line 55 "shortcodes.rl" #line 73 "shortcodes.rl"
#line 49 "shortcodes.c" #line 42 "shortcodes.c"
{ {
if ( p == pe ) if ( p == pe )
goto _test_eof; goto _test_eof;
switch ( cs ) switch ( cs )
{ {
case 1: case 24:
if ( (*p) == 123 ) if ( (*p) == 123 )
goto st2; goto tr1;
goto st0;
tr45:
#line 57 "shortcodes.rl"
{bcatcstr(output, "\n");}
goto st0; goto st0;
st0: st0:
cs = 0; if ( ++p == pe )
goto _out; goto _test_eof0;
case 0:
#line 60 "shortcodes.c"
if ( (*p) == 123 )
goto tr1;
goto st0;
tr1:
#line 56 "shortcodes.rl"
{bcatcstr(output, "---\n");}
goto st1;
tr46:
#line 56 "shortcodes.rl"
{bcatcstr(output, "---\n");}
#line 57 "shortcodes.rl"
{bcatcstr(output, "\n");}
goto st1;
st1:
if ( ++p == pe )
goto _test_eof1;
case 1:
#line 78 "shortcodes.c"
if ( (*p) == 123 )
goto tr2;
goto st0;
tr2:
#line 56 "shortcodes.rl"
{bcatcstr(output, "---\n");}
goto st2;
st2: st2:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof2; goto _test_eof2;
case 2: case 2:
if ( (*p) == 123 ) #line 90 "shortcodes.c"
goto st3; switch( (*p) ) {
case 37: goto st3;
case 60: goto st3;
case 123: goto tr2;
}
goto st0; goto st0;
st3: st3:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof3; goto _test_eof3;
case 3: case 3:
if ( (*p) == 32 ) switch( (*p) ) {
goto st3; case 32: goto st3;
case 123: goto tr1;
}
if ( (*p) < 65 ) { if ( (*p) < 65 ) {
if ( 9 <= (*p) && (*p) <= 13 ) if ( 9 <= (*p) && (*p) <= 13 )
goto st3; goto st3;
} else if ( (*p) > 90 ) { } else if ( (*p) > 90 ) {
if ( 97 <= (*p) && (*p) <= 122 ) if ( 97 <= (*p) && (*p) <= 122 )
goto tr3; goto tr4;
} else } else
goto tr3; goto tr4;
goto st0; goto st0;
tr3: tr4:
#line 13 "shortcodes.rl" #line 11 "shortcodes.rl"
{ {
mark = p; mark = p;
} }
@ -90,43 +120,54 @@ st4:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof4; goto _test_eof4;
case 4: case 4:
#line 94 "shortcodes.c" #line 124 "shortcodes.c"
switch( (*p) ) { switch( (*p) ) {
case 32: goto tr4; case 32: goto tr5;
case 125: goto tr6; case 37: goto tr6;
case 62: goto tr6;
case 123: goto tr1;
} }
if ( (*p) < 65 ) { if ( (*p) < 65 ) {
if ( 9 <= (*p) && (*p) <= 13 ) if ( 9 <= (*p) && (*p) <= 13 )
goto tr4; goto tr5;
} else if ( (*p) > 90 ) { } else if ( (*p) > 90 ) {
if ( 97 <= (*p) && (*p) <= 122 ) if ( 97 <= (*p) && (*p) <= 122 )
goto st4; goto st4;
} else } else
goto st4; goto st4;
goto st0; goto st0;
tr4: tr5:
#line 22 "shortcodes.rl" #line 20 "shortcodes.rl"
{printf("name: '%s'\n", grab_chunk(mark, p)->data);} {bcatcstr(output, "N");
bcatblk(output, mark, p-mark);
bcatcstr(output, "\n");
}
goto st5; goto st5;
tr14: tr16:
#line 28 "shortcodes.rl" #line 32 "shortcodes.rl"
{printf("value: '%s'\n", grab_chunk(mark, p)->data);} {bcatcstr(output, "V");
bcatblk(output, mark+1, p-mark-2);
bcatcstr(output, "\n");
}
goto st5; goto st5;
tr24: tr40:
#line 28 "shortcodes.rl" #line 39 "shortcodes.rl"
{printf("value: '%s'\n", grab_chunk(mark, p)->data);} {bcatcstr(output, "V");
#line 31 "shortcodes.rl" bcatblk(output, mark, p-mark);
{printf("arg: '%s'\n", grab_chunk(mark, p)->data);} bcatcstr(output, "\n");
}
goto st5; goto st5;
st5: st5:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof5; goto _test_eof5;
case 5: case 5:
#line 126 "shortcodes.c" #line 165 "shortcodes.c"
switch( (*p) ) { switch( (*p) ) {
case 32: goto st5; case 32: goto st5;
case 34: goto tr8; case 34: goto tr9;
case 125: goto st8; case 37: goto st8;
case 62: goto st8;
case 123: goto tr1;
} }
if ( (*p) < 48 ) { if ( (*p) < 48 ) {
if ( 9 <= (*p) && (*p) <= 13 ) if ( 9 <= (*p) && (*p) <= 13 )
@ -134,192 +175,468 @@ case 5:
} else if ( (*p) > 57 ) { } else if ( (*p) > 57 ) {
if ( (*p) > 90 ) { if ( (*p) > 90 ) {
if ( 97 <= (*p) && (*p) <= 122 ) if ( 97 <= (*p) && (*p) <= 122 )
goto tr10; goto tr12;
} else if ( (*p) >= 65 ) } else if ( (*p) >= 65 )
goto tr10; goto tr12;
} else } else
goto tr9; goto tr11;
goto st0; goto st0;
tr8: tr9:
#line 13 "shortcodes.rl" #line 11 "shortcodes.rl"
{ {
mark = p; mark = p;
} }
goto st6; goto st6;
tr47:
#line 57 "shortcodes.rl"
{bcatcstr(output, "\n");}
goto st6;
st6: st6:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof6; goto _test_eof6;
case 6: case 6:
#line 154 "shortcodes.c" #line 199 "shortcodes.c"
if ( (*p) == 34 ) switch( (*p) ) {
goto st7; case 34: goto st7;
case 123: goto tr15;
}
goto st6; goto st6;
tr48:
#line 57 "shortcodes.rl"
{bcatcstr(output, "\n");}
goto st7;
st7: st7:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof7; goto _test_eof7;
case 7: case 7:
#line 213 "shortcodes.c"
switch( (*p) ) { switch( (*p) ) {
case 32: goto tr14; case 32: goto tr16;
case 125: goto tr15; case 37: goto tr17;
case 62: goto tr17;
case 123: goto tr1;
} }
if ( 9 <= (*p) && (*p) <= 13 ) if ( 9 <= (*p) && (*p) <= 13 )
goto tr14; goto tr16;
goto st0; goto st0;
tr6: tr6:
#line 22 "shortcodes.rl" #line 20 "shortcodes.rl"
{printf("name: '%s'\n", grab_chunk(mark, p)->data);} {bcatcstr(output, "N");
bcatblk(output, mark, p-mark);
bcatcstr(output, "\n");
}
goto st8; goto st8;
tr15: tr17:
#line 28 "shortcodes.rl" #line 32 "shortcodes.rl"
{printf("value: '%s'\n", grab_chunk(mark, p)->data);} {bcatcstr(output, "V");
bcatblk(output, mark+1, p-mark-2);
bcatcstr(output, "\n");
}
goto st8; goto st8;
tr25: tr41:
#line 28 "shortcodes.rl" #line 39 "shortcodes.rl"
{printf("value: '%s'\n", grab_chunk(mark, p)->data);} {bcatcstr(output, "V");
#line 31 "shortcodes.rl" bcatblk(output, mark, p-mark);
{printf("arg: '%s'\n", grab_chunk(mark, p)->data);} bcatcstr(output, "\n");
}
goto st8; goto st8;
st8: st8:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof8; goto _test_eof8;
case 8: case 8:
#line 187 "shortcodes.c" #line 248 "shortcodes.c"
if ( (*p) == 125 ) switch( (*p) ) {
goto st15; case 123: goto tr1;
goto st0; case 125: goto st9;
st15:
if ( ++p == pe )
goto _test_eof15;
case 15:
goto st0;
tr9:
#line 13 "shortcodes.rl"
{
mark = p;
} }
goto st9; goto st0;
st9: st9:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof9; goto _test_eof9;
case 9: case 9:
#line 206 "shortcodes.c"
switch( (*p) ) { switch( (*p) ) {
case 32: goto tr14; case 123: goto tr1;
case 125: goto tr15; case 125: goto st25;
} }
if ( (*p) < 48 ) {
if ( 9 <= (*p) && (*p) <= 13 )
goto tr14;
} else if ( (*p) > 57 ) {
if ( (*p) > 90 ) {
if ( 97 <= (*p) && (*p) <= 122 )
goto st9;
} else if ( (*p) >= 65 )
goto st9;
} else
goto st9;
goto st0; goto st0;
tr10: st25:
#line 13 "shortcodes.rl" if ( ++p == pe )
{ goto _test_eof25;
mark = p; case 25:
} if ( (*p) == 123 )
goto tr46;
goto tr45;
tr15:
#line 56 "shortcodes.rl"
{bcatcstr(output, "---\n");}
goto st10;
tr49:
#line 56 "shortcodes.rl"
{bcatcstr(output, "---\n");}
#line 57 "shortcodes.rl"
{bcatcstr(output, "\n");}
goto st10; goto st10;
st10: st10:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof10; goto _test_eof10;
case 10: case 10:
#line 233 "shortcodes.c" #line 284 "shortcodes.c"
switch( (*p) ) { switch( (*p) ) {
case 32: goto tr14; case 34: goto st7;
case 61: goto tr18; case 123: goto tr20;
case 125: goto tr15;
} }
if ( (*p) < 48 ) { goto st6;
if ( 9 <= (*p) && (*p) <= 13 ) tr20:
goto tr14; #line 56 "shortcodes.rl"
} else if ( (*p) > 57 ) { {bcatcstr(output, "---\n");}
if ( (*p) > 90 ) {
if ( 97 <= (*p) && (*p) <= 122 )
goto st10;
} else if ( (*p) >= 65 )
goto st10;
} else
goto st9;
goto st0;
tr18:
#line 25 "shortcodes.rl"
{printf("argname: '%s'\n", grab_chunk(mark, p)->data);}
goto st11; goto st11;
st11: st11:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof11; goto _test_eof11;
case 11: case 11:
#line 259 "shortcodes.c" #line 298 "shortcodes.c"
if ( (*p) == 34 ) switch( (*p) ) {
goto tr20; case 34: goto st7;
if ( (*p) < 65 ) { case 37: goto st12;
if ( 48 <= (*p) && (*p) <= 57 ) case 60: goto st12;
goto tr21; case 123: goto tr20;
} else if ( (*p) > 90 ) {
if ( 97 <= (*p) && (*p) <= 122 )
goto tr21;
} else
goto tr21;
goto st0;
tr20:
#line 13 "shortcodes.rl"
{
mark = p;
} }
goto st12; goto st6;
st12: st12:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof12; goto _test_eof12;
case 12: case 12:
#line 281 "shortcodes.c" switch( (*p) ) {
if ( (*p) == 34 ) case 32: goto st12;
goto st13; case 34: goto st7;
case 123: goto tr15;
}
if ( (*p) < 65 ) {
if ( 9 <= (*p) && (*p) <= 13 )
goto st12; goto st12;
} else if ( (*p) > 90 ) {
if ( 97 <= (*p) && (*p) <= 122 )
goto tr22;
} else
goto tr22;
goto st6;
tr22:
#line 11 "shortcodes.rl"
{
mark = p;
}
goto st13;
st13: st13:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof13; goto _test_eof13;
case 13: case 13:
#line 334 "shortcodes.c"
switch( (*p) ) { switch( (*p) ) {
case 32: goto tr24; case 32: goto tr23;
case 125: goto tr25; case 34: goto st7;
case 37: goto tr24;
case 62: goto tr24;
case 123: goto tr15;
} }
if ( (*p) < 65 ) {
if ( 9 <= (*p) && (*p) <= 13 ) if ( 9 <= (*p) && (*p) <= 13 )
goto tr24; goto tr23;
goto st0; } else if ( (*p) > 90 ) {
tr21: if ( 97 <= (*p) && (*p) <= 122 )
#line 13 "shortcodes.rl" goto st13;
{ } else
mark = p; goto st13;
goto st6;
tr23:
#line 20 "shortcodes.rl"
{bcatcstr(output, "N");
bcatblk(output, mark, p-mark);
bcatcstr(output, "\n");
}
goto st14;
tr31:
#line 32 "shortcodes.rl"
{bcatcstr(output, "V");
bcatblk(output, mark+1, p-mark-2);
bcatcstr(output, "\n");
}
goto st14;
tr35:
#line 39 "shortcodes.rl"
{bcatcstr(output, "V");
bcatblk(output, mark, p-mark);
bcatcstr(output, "\n");
} }
goto st14; goto st14;
st14: st14:
if ( ++p == pe ) if ( ++p == pe )
goto _test_eof14; goto _test_eof14;
case 14: case 14:
#line 306 "shortcodes.c" #line 376 "shortcodes.c"
switch( (*p) ) { switch( (*p) ) {
case 32: goto tr24; case 32: goto st14;
case 125: goto tr25; case 34: goto tr27;
case 37: goto st16;
case 62: goto st16;
case 123: goto tr15;
} }
if ( (*p) < 48 ) { if ( (*p) < 48 ) {
if ( 9 <= (*p) && (*p) <= 13 ) if ( 9 <= (*p) && (*p) <= 13 )
goto tr24; goto st14;
} else if ( (*p) > 57 ) { } else if ( (*p) > 57 ) {
if ( (*p) > 90 ) { if ( (*p) > 90 ) {
if ( 97 <= (*p) && (*p) <= 122 ) if ( 97 <= (*p) && (*p) <= 122 )
goto st14; goto tr30;
} else if ( (*p) >= 65 ) } else if ( (*p) >= 65 )
goto st14; goto tr30;
} else } else
goto st14; goto tr29;
goto st6;
tr27:
#line 11 "shortcodes.rl"
{
mark = p;
}
goto st15;
st15:
if ( ++p == pe )
goto _test_eof15;
case 15:
#line 406 "shortcodes.c"
switch( (*p) ) {
case 32: goto tr31;
case 34: goto st7;
case 37: goto tr32;
case 62: goto tr32;
case 123: goto tr15;
}
if ( 9 <= (*p) && (*p) <= 13 )
goto tr31;
goto st6;
tr24:
#line 20 "shortcodes.rl"
{bcatcstr(output, "N");
bcatblk(output, mark, p-mark);
bcatcstr(output, "\n");
}
goto st16;
tr32:
#line 32 "shortcodes.rl"
{bcatcstr(output, "V");
bcatblk(output, mark+1, p-mark-2);
bcatcstr(output, "\n");
}
goto st16;
tr36:
#line 39 "shortcodes.rl"
{bcatcstr(output, "V");
bcatblk(output, mark, p-mark);
bcatcstr(output, "\n");
}
goto st16;
st16:
if ( ++p == pe )
goto _test_eof16;
case 16:
#line 442 "shortcodes.c"
switch( (*p) ) {
case 34: goto st7;
case 123: goto tr15;
case 125: goto st17;
}
goto st6;
st17:
if ( ++p == pe )
goto _test_eof17;
case 17:
switch( (*p) ) {
case 34: goto st7;
case 123: goto tr15;
case 125: goto st26;
}
goto st6;
st26:
if ( ++p == pe )
goto _test_eof26;
case 26:
switch( (*p) ) {
case 34: goto tr48;
case 123: goto tr49;
}
goto tr47;
tr29:
#line 11 "shortcodes.rl"
{
mark = p;
}
goto st18;
st18:
if ( ++p == pe )
goto _test_eof18;
case 18:
#line 478 "shortcodes.c"
switch( (*p) ) {
case 32: goto tr35;
case 34: goto st7;
case 37: goto tr36;
case 62: goto tr36;
case 123: goto tr15;
}
if ( (*p) < 48 ) {
if ( 9 <= (*p) && (*p) <= 13 )
goto tr35;
} else if ( (*p) > 57 ) {
if ( (*p) > 90 ) {
if ( 97 <= (*p) && (*p) <= 122 )
goto st18;
} else if ( (*p) >= 65 )
goto st18;
} else
goto st18;
goto st6;
tr30:
#line 11 "shortcodes.rl"
{
mark = p;
}
goto st19;
st19:
if ( ++p == pe )
goto _test_eof19;
case 19:
#line 508 "shortcodes.c"
switch( (*p) ) {
case 32: goto tr35;
case 34: goto st7;
case 37: goto tr36;
case 61: goto tr38;
case 62: goto tr36;
case 123: goto tr15;
}
if ( (*p) < 48 ) {
if ( 9 <= (*p) && (*p) <= 13 )
goto tr35;
} else if ( (*p) > 57 ) {
if ( (*p) > 90 ) {
if ( 97 <= (*p) && (*p) <= 122 )
goto st19;
} else if ( (*p) >= 65 )
goto st19;
} else
goto st18;
goto st6;
tr38:
#line 26 "shortcodes.rl"
{bcatcstr(output, "A");
bcatblk(output, mark, p-mark);
bcatcstr(output, "\n");
}
goto st20;
st20:
if ( ++p == pe )
goto _test_eof20;
case 20:
#line 540 "shortcodes.c"
switch( (*p) ) {
case 34: goto tr27;
case 123: goto tr15;
}
if ( (*p) < 65 ) {
if ( 48 <= (*p) && (*p) <= 57 )
goto tr29;
} else if ( (*p) > 90 ) {
if ( 97 <= (*p) && (*p) <= 122 )
goto tr29;
} else
goto tr29;
goto st6;
tr11:
#line 11 "shortcodes.rl"
{
mark = p;
}
goto st21;
st21:
if ( ++p == pe )
goto _test_eof21;
case 21:
#line 564 "shortcodes.c"
switch( (*p) ) {
case 32: goto tr40;
case 37: goto tr41;
case 62: goto tr41;
case 123: goto tr1;
}
if ( (*p) < 48 ) {
if ( 9 <= (*p) && (*p) <= 13 )
goto tr40;
} else if ( (*p) > 57 ) {
if ( (*p) > 90 ) {
if ( 97 <= (*p) && (*p) <= 122 )
goto st21;
} else if ( (*p) >= 65 )
goto st21;
} else
goto st21;
goto st0;
tr12:
#line 11 "shortcodes.rl"
{
mark = p;
}
goto st22;
st22:
if ( ++p == pe )
goto _test_eof22;
case 22:
#line 593 "shortcodes.c"
switch( (*p) ) {
case 32: goto tr40;
case 37: goto tr41;
case 61: goto tr43;
case 62: goto tr41;
case 123: goto tr1;
}
if ( (*p) < 48 ) {
if ( 9 <= (*p) && (*p) <= 13 )
goto tr40;
} else if ( (*p) > 57 ) {
if ( (*p) > 90 ) {
if ( 97 <= (*p) && (*p) <= 122 )
goto st22;
} else if ( (*p) >= 65 )
goto st22;
} else
goto st21;
goto st0;
tr43:
#line 26 "shortcodes.rl"
{bcatcstr(output, "A");
bcatblk(output, mark, p-mark);
bcatcstr(output, "\n");
}
goto st23;
st23:
if ( ++p == pe )
goto _test_eof23;
case 23:
#line 624 "shortcodes.c"
switch( (*p) ) {
case 34: goto tr9;
case 123: goto tr1;
}
if ( (*p) < 65 ) {
if ( 48 <= (*p) && (*p) <= 57 )
goto tr11;
} else if ( (*p) > 90 ) {
if ( 97 <= (*p) && (*p) <= 122 )
goto tr11;
} else
goto tr11;
goto st0; goto st0;
} }
_test_eof0: cs = 0; goto _test_eof;
_test_eof1: cs = 1; goto _test_eof;
_test_eof2: cs = 2; goto _test_eof; _test_eof2: cs = 2; goto _test_eof;
_test_eof3: cs = 3; goto _test_eof; _test_eof3: cs = 3; goto _test_eof;
_test_eof4: cs = 4; goto _test_eof; _test_eof4: cs = 4; goto _test_eof;
@ -327,26 +644,45 @@ case 14:
_test_eof6: cs = 6; goto _test_eof; _test_eof6: cs = 6; goto _test_eof;
_test_eof7: cs = 7; goto _test_eof; _test_eof7: cs = 7; goto _test_eof;
_test_eof8: cs = 8; goto _test_eof; _test_eof8: cs = 8; goto _test_eof;
_test_eof15: cs = 15; goto _test_eof;
_test_eof9: cs = 9; goto _test_eof; _test_eof9: cs = 9; goto _test_eof;
_test_eof25: cs = 25; goto _test_eof;
_test_eof10: cs = 10; goto _test_eof; _test_eof10: cs = 10; goto _test_eof;
_test_eof11: cs = 11; goto _test_eof; _test_eof11: cs = 11; goto _test_eof;
_test_eof12: cs = 12; goto _test_eof; _test_eof12: cs = 12; goto _test_eof;
_test_eof13: cs = 13; goto _test_eof; _test_eof13: cs = 13; goto _test_eof;
_test_eof14: cs = 14; goto _test_eof; _test_eof14: cs = 14; goto _test_eof;
_test_eof15: cs = 15; goto _test_eof;
_test_eof16: cs = 16; goto _test_eof;
_test_eof17: cs = 17; goto _test_eof;
_test_eof26: cs = 26; goto _test_eof;
_test_eof18: cs = 18; goto _test_eof;
_test_eof19: cs = 19; goto _test_eof;
_test_eof20: cs = 20; goto _test_eof;
_test_eof21: cs = 21; goto _test_eof;
_test_eof22: cs = 22; goto _test_eof;
_test_eof23: cs = 23; goto _test_eof;
_test_eof: {} _test_eof: {}
_out: {} if ( p == eof )
{
switch ( cs ) {
case 25:
case 26:
#line 57 "shortcodes.rl"
{bcatcstr(output, "\n");}
break;
#line 675 "shortcodes.c"
}
} }
#line 56 "shortcodes.rl" }
printf("\nLabel is: '%s'\n", label->data); #line 74 "shortcodes.rl"
return output; return output;
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
bstring output = parse("{{ thename \"onearg\" another arg=\"val3\" }}"); bstring output = parse("{{< thename \"onearg\">}} {{% another argname=\"val3\" %}}");
printf("\n%s\n", output->data); printf("\n%s\n", output->data);
return 0; return 0;
} }

View File

@ -1,8 +1,6 @@
#include <stdio.h> #include <stdio.h>
#include "bstrlib/bstrlib.h" #include "bstrlib/bstrlib.h"
bstring grab_chunk(char *start, char *end) { bstring grab_chunk(char *start, char *end) {
blk2bstr(start, end-start); blk2bstr(start, end-start);
} }
@ -19,47 +17,65 @@ bstring grab_chunk(char *start, char *end) {
name = alpha+ name = alpha+
> mark > mark
% {printf("name: '%s'\n", grab_chunk(mark, p)->data);}; % {bcatcstr(output, "N");
bcatblk(output, mark, p-mark);
bcatcstr(output, "\n");
};
argname = alpha+ argname = alpha+
> mark > mark
% {printf("argname: '%s'\n", grab_chunk(mark, p)->data);}; % {bcatcstr(output, "A");
value = (('"' [^"]* '"') | alnum+) bcatblk(output, mark, p-mark);
bcatcstr(output, "\n");
};
qvalue = ('"' [^"]* '"')
> mark > mark
% {printf("value: '%s'\n", grab_chunk(mark, p)->data);}; % {bcatcstr(output, "V");
arg = (argname '=' value) bcatblk(output, mark+1, p-mark-2);
bcatcstr(output, "\n");
};
value = alnum+
> mark > mark
% {printf("arg: '%s'\n", grab_chunk(mark, p)->data);}; % {bcatcstr(output, "V");
bcatblk(output, mark, p-mark);
bcatcstr(output, "\n");
};
start = '{{'; arg = ((argname '=')? (value|qvalue));
end = '}}';
main := (start spc name (sep (arg | value))* spc end); start_p = '{{%';
end_p = '%}}';
start_b = '{{<';
end_b = '>}}';
start = start_p | start_b ;
end = end_p | end_b ;
shortcode = (start spc name (sep arg)* spc end)
> {bcatcstr(output, "---\n");}
% {bcatcstr(output, "\n");};
main := (any* shortcode)*;
}%% }%%
bstring parse(char *_input) { bstring 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;
bstring output = bfromcstr("out"); char *p = input;
char *pe = p + strlen(input);
bstring input = bfromcstr(_input);
char *p = input->data;
char *pe = p + blength(input);
char *mark = 0; char *mark = 0;
bstring label; bstring output = bfromcstr("");
%% write init; %% write init;
%% write exec; %% write exec;
printf("\nLabel is: '%s'\n", label->data);
return output; return output;
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
bstring output = parse("{{ thename \"onearg\" another arg=\"val3\" }}"); bstring output = parse("{{< thename \"onearg\">}} {{% another argname=\"val3\" %}}");
printf("\n%s\n", output->data); printf("\n%s\n", output->data);
return 0; return 0;
} }