From 33b5172256d580b40ee2de3ed0496a72eaa78118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Fri, 26 Apr 2024 12:02:22 +0200 Subject: [PATCH 1/2] Add test cases for bounds with no minimum. --- tests/retest.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/retest.c b/tests/retest.c index 21b1e56..0fba8a7 100644 --- a/tests/retest.c +++ b/tests/retest.c @@ -1480,6 +1480,21 @@ main(int argc, char **argv) test_exec("aaaaa", 0, REG_OK, 0, 5, END); test_exec("aaaaaa", 0, REG_OK, 0, 6, END); test_exec("aaaaaaa", 0, REG_OK, 0, 7, END); + test_comp("a{,}", REG_EXTENDED, REG_OK); + test_exec("", 0, REG_OK, 0, 0, END); + test_exec("aaa", 0, REG_OK, 0, 3, END); + test_comp("a{,0}", REG_EXTENDED, REG_OK); + test_exec("", 0, REG_OK, 0, 0, END); + test_exec("aaa", 0, REG_OK, 0, 0, END); + test_comp("a{,1}", REG_EXTENDED, REG_OK); + test_exec("", 0, REG_OK, 0, 0, END); + test_exec("a", 0, REG_OK, 0, 1, END); + test_exec("aa", 0, REG_OK, 0, 1, END); + test_comp("a{,2}", REG_EXTENDED, REG_OK); + test_exec("", 0, REG_OK, 0, 0, END); + test_exec("a", 0, REG_OK, 0, 1, END); + test_exec("aa", 0, REG_OK, 0, 2, END); + test_exec("aaa", 0, REG_OK, 0, 2, END); test_comp("a{5,10}", REG_EXTENDED, REG_OK); test_comp("a{6,6}", REG_EXTENDED, REG_OK); From 5fa5f0dd3f3e09e42800befb641b19b815b29bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Fri, 26 Apr 2024 12:25:46 +0200 Subject: [PATCH 2/2] Allow the minimum count of a bound to be omitted. --- doc/tre-syntax.html | 15 +++++++++++---- lib/tre-parse.c | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/doc/tre-syntax.html b/doc/tre-syntax.html index 13ccb54..640bb17 100644 --- a/doc/tre-syntax.html +++ b/doc/tre-syntax.html @@ -126,16 +126,23 @@

Repeat operators

  1. {m,n}
  2. +
  3. {,n}
  4. {m,}
  5. {m}
  6. +
  7. {,}

An atom followed by [1] matches a sequence of m through n -(inclusive) matches of the atom. An atom followed by [2] -matches a sequence of m or more matches of the atom. An atom -followed by [3] matches a sequence of exactly m matches of the -atom. +(inclusive) matches of the atom. +An atom followed by [2] matches a sequence of up to n matches +of the atom. +An atom followed by [3] matches a sequence of m or more matches +of the atom. +An atom followed by [4] matches a sequence of exactly m matches +of the atom. +An atom followed by [5] matches a sequence of zero or more matches of +the atom.

diff --git a/lib/tre-parse.c b/lib/tre-parse.c index b62c022..e11af47 100644 --- a/lib/tre-parse.c +++ b/lib/tre-parse.c @@ -635,6 +635,8 @@ tre_parse_bound(tre_parse_ctx_t *ctx, tre_ast_node_t **result) max = min; if (r < ctx->re_end && *r == CHAR_COMMA) { + if (min < 0) + min = 0; r++; DPRINT(("tre_parse: max count: '%.*" STRF "'\n", REST(r))); max = tre_parse_int(&r, ctx->re_end);