From 89beb7bbbc7c73d0612afa24991806d164b25249 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Wed, 12 Jul 2023 17:10:55 -0300 Subject: [PATCH] minor changes --- shortcodes.h | 3 +-- shortcodes.rl | 9 +++++---- tests.c | 9 +++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/shortcodes.h b/shortcodes.h index 1d0a2f6..72fa89f 100644 --- a/shortcodes.h +++ b/shortcodes.h @@ -9,8 +9,7 @@ typedef struct chunk chunk; struct shortcode { - int start; - int len; + chunk whole; chunk name; chunk data; char matching; diff --git a/shortcodes.rl b/shortcodes.rl index d2b2a3d..0f5e13e 100644 --- a/shortcodes.rl +++ b/shortcodes.rl @@ -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))*; }%% diff --git a/tests.c b/tests.c index 7027801..a543310 100755 --- a/tests.c +++ b/tests.c @@ -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"));