Skip to content

Commit

Permalink
Merge pull request #98 from dag-erling/des/implicit-min
Browse files Browse the repository at this point in the history
Allow the minimum count of a bound to be omitted
  • Loading branch information
dag-erling authored Jul 30, 2024
2 parents 11a32cb + 5fa5f0d commit 1cff35b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
15 changes: 11 additions & 4 deletions doc/tre-syntax.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,23 @@ <h3>Repeat operators</h3>

<ol>
<li><tt>{</tt><i>m</i><tt>,</tt><i>n</i><tt>}</tt></li>
<li><tt>{,</tt><i>n</i><tt>}</tt></li>
<li><tt>{</tt><i>m</i><tt>,}</tt></li>
<li><tt>{</tt><i>m</i><tt>}</tt></li>
<li><tt>{,}</tt></li>
</ol>

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


Expand Down
2 changes: 2 additions & 0 deletions lib/tre-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,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);
Expand Down
15 changes: 15 additions & 0 deletions tests/retest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1cff35b

Please sign in to comment.