minor changes

This commit is contained in:
Roberto Alsina 2023-07-12 17:10:55 -03:00
parent 64053c3f37
commit 89beb7bbbc
3 changed files with 11 additions and 10 deletions

View File

@ -9,8 +9,7 @@ typedef struct chunk chunk;
struct shortcode
{
int start;
int len;
chunk whole;
chunk name;
chunk data;
char matching;

View File

@ -54,10 +54,10 @@
shortcode = (start spc name (sep arg)* spc end)
> {
sc_list[c_sc].start = p-start-1;
sc_list[c_sc].whole.start = p-start-1;
}
@ {
sc_list[c_sc].len = p-start-sc_list[c_sc].start+1;
sc_list[c_sc].whole.len = p-start-sc_list[c_sc].whole.start+1;
data_mark = p+1;
c_sc++;
};
@ -75,7 +75,7 @@
matched_shortcode = (shortcode any* closing_shortcode)
@ {
sc_list[c_sc-1].matching = 1;
sc_list[c_sc-1].len = p-start-sc_list[c_sc-1].start + 1;
sc_list[c_sc-1].whole.len = p-start-sc_list[c_sc-1].whole.start + 1;
if (
sc_list[c_sc-1].name.len != sc_list[c_sc].name.len ||
strncmp(
@ -92,7 +92,8 @@
}
// Reuse this shortcode entry for next one
sc_list[c_sc].name.start = 0;
};
sc_list[c_sc].name.len=0;
};
main := (any* (shortcode | matched_shortcode))*;
}%%

View File

@ -23,17 +23,18 @@ Ensure(parse, empty_string)
Ensure(parse, simple_shortcode)
{
char *input = "{{% shortcode %}}";
char *input = "foobar {{% shortcode %}}blah";
result = parse(input);
chunk_s(input, result[0].name);
// Only 1 shortcode
assert_that(result[1].name.len, is_equal_to(0));
// It's a simple one called shortcode, no args
chunk_s(input, result[0].name);
assert_that(s.s, is_equal_to_string("shortcode"));
assert_that(result[0].matching, is_equal_to(0));
assert_that(result[0].argcount, is_equal_to(0));
chunk_s(input, result[0].whole);
assert_that(s.s, is_equal_to_string("{{% shortcode %}}"));
}
Ensure(parse, matching_shortcode)
@ -43,7 +44,7 @@ Ensure(parse, matching_shortcode)
chunk_s(input, result[0].name);
// Only 1 shortcode
// assert_that(result[1].name.len, is_equal_to(0));
assert_that(result[1].name.len, is_equal_to(0));
// It's a matching one called shortcode, no args
assert_that(s.s, is_equal_to_string("shortcode"));