minor changes
This commit is contained in:
parent
64053c3f37
commit
89beb7bbbc
@ -9,8 +9,7 @@ typedef struct chunk chunk;
|
|||||||
|
|
||||||
struct shortcode
|
struct shortcode
|
||||||
{
|
{
|
||||||
int start;
|
chunk whole;
|
||||||
int len;
|
|
||||||
chunk name;
|
chunk name;
|
||||||
chunk data;
|
chunk data;
|
||||||
char matching;
|
char matching;
|
||||||
|
@ -54,10 +54,10 @@
|
|||||||
|
|
||||||
shortcode = (start spc name (sep arg)* spc end)
|
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;
|
data_mark = p+1;
|
||||||
c_sc++;
|
c_sc++;
|
||||||
};
|
};
|
||||||
@ -75,7 +75,7 @@
|
|||||||
matched_shortcode = (shortcode any* closing_shortcode)
|
matched_shortcode = (shortcode any* closing_shortcode)
|
||||||
@ {
|
@ {
|
||||||
sc_list[c_sc-1].matching = 1;
|
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 (
|
if (
|
||||||
sc_list[c_sc-1].name.len != sc_list[c_sc].name.len ||
|
sc_list[c_sc-1].name.len != sc_list[c_sc].name.len ||
|
||||||
strncmp(
|
strncmp(
|
||||||
@ -92,6 +92,7 @@
|
|||||||
}
|
}
|
||||||
// Reuse this shortcode entry for next one
|
// Reuse this shortcode entry for next one
|
||||||
sc_list[c_sc].name.start = 0;
|
sc_list[c_sc].name.start = 0;
|
||||||
|
sc_list[c_sc].name.len=0;
|
||||||
};
|
};
|
||||||
|
|
||||||
main := (any* (shortcode | matched_shortcode))*;
|
main := (any* (shortcode | matched_shortcode))*;
|
||||||
|
9
tests.c
9
tests.c
@ -23,17 +23,18 @@ Ensure(parse, empty_string)
|
|||||||
|
|
||||||
Ensure(parse, simple_shortcode)
|
Ensure(parse, simple_shortcode)
|
||||||
{
|
{
|
||||||
char *input = "{{% shortcode %}}";
|
char *input = "foobar {{% shortcode %}}blah";
|
||||||
result = parse(input);
|
result = parse(input);
|
||||||
chunk_s(input, result[0].name);
|
|
||||||
|
|
||||||
// Only 1 shortcode
|
// 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 simple one called shortcode, no args
|
// 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(s.s, is_equal_to_string("shortcode"));
|
||||||
assert_that(result[0].matching, is_equal_to(0));
|
assert_that(result[0].matching, is_equal_to(0));
|
||||||
assert_that(result[0].argcount, 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)
|
Ensure(parse, matching_shortcode)
|
||||||
@ -43,7 +44,7 @@ Ensure(parse, matching_shortcode)
|
|||||||
chunk_s(input, result[0].name);
|
chunk_s(input, result[0].name);
|
||||||
|
|
||||||
// Only 1 shortcode
|
// 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
|
// It's a matching one called shortcode, no args
|
||||||
assert_that(s.s, is_equal_to_string("shortcode"));
|
assert_that(s.s, is_equal_to_string("shortcode"));
|
||||||
|
Loading…
Reference in New Issue
Block a user