From 5fd3de16f4a6de8d5c28c7a80e9a4965eede2ab3 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] 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 82004cf..b1d146c 100644 --- a/lib/tre-parse.c +++ b/lib/tre-parse.c @@ -622,6 +622,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);