Skip to content

Commit

Permalink
Merge pull request #463 from katef/kate/is-literal-non-pcre
Browse files Browse the repository at this point in the history
Break a dependency on group #0 for re_is_literal()
  • Loading branch information
katef authored Apr 26, 2024
2 parents d05126a + 4b8276a commit 0ea82df
Show file tree
Hide file tree
Showing 15 changed files with 747 additions and 630 deletions.
2 changes: 1 addition & 1 deletion include/fsm/bool.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fsm_union(struct fsm *a, struct fsm *b,
* starting states and (if used) capture bases.
*
* bases[] is expected to have the same count as fsms[], and
* will be initialized by the function.
* will be initialized by the function. May be NULL.
*
* On success, returns the unioned fsm and updates bases[].
* On failure, returns NULL; all fsms are freed. */
Expand Down
19 changes: 14 additions & 5 deletions src/libfsm/union.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ fsm_union_array(size_t fsm_count,
struct fsm *res = fsms[0];

fsms[0] = NULL;
memset(bases, 0x00, fsm_count * sizeof(bases[0]));
if (bases != NULL) {
memset(bases, 0x00, fsm_count * sizeof(bases[0]));
}

for (i = 1; i < fsm_count; i++) {
struct fsm_combine_info ci;
Expand All @@ -117,9 +119,14 @@ fsm_union_array(size_t fsm_count,
return NULL;
}

res = combined;

if (bases == NULL) {
continue;
}

bases[i].state = ci.base_b;
bases[i].capture = ci.capture_base_b;
res = combined;

/* If the first argument didn't get its states put first
* in the union, then shift the bases for everything
Expand All @@ -134,9 +141,11 @@ fsm_union_array(size_t fsm_count,
}

#if LOG_UNION_ARRAY
for (i = 0; i < fsm_count; i++) {
fprintf(stderr, "union_array: bases %u: %zu, %zu\n",
i, bases[i].state, bases[i].capture);
if (bases != NULL) {
for (i = 0; i < fsm_count; i++) {
fprintf(stderr, "union_array: bases %u: %zu, %zu\n",
i, bases[i].state, bases[i].capture);
}
}
#endif

Expand Down
50 changes: 37 additions & 13 deletions src/libre/dialect/glob/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions src/libre/dialect/glob/parser.sid
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ast_count;
ast_class_id;
!endpoint;
!group_id;
group_id;

%terminals%

Expand Down Expand Up @@ -84,7 +84,7 @@
!<count-one>: () -> (:ast_count);
!<count-range>: (:unsigned, :pos, :unsigned, :pos) -> (:ast_count);

!<make-group-id>: () -> (:group_id);
<make-group-id>: () -> (:group_id);
!<make-literal-cbrak>: () -> (:char);
!<make-literal-cr>: () -> (:char);
!<make-literal-nl>: () -> (:char);
Expand All @@ -97,7 +97,7 @@
<ast-make-concat>: () -> (:ast_expr);
!<ast-make-alt>: () -> (:ast_expr);
<ast-make-piece>: (:ast_expr, :ast_count) -> (:ast_expr);
!<ast-make-group>: (:ast_expr, :group_id) -> (:ast_expr);
<ast-make-group>: (:ast_expr, :group_id) -> (:ast_expr);
!<ast-get-re-flags>: () -> (:re_flags);
!<ast-set-re-flags>: (:re_flags) -> ();
!<ast-mask-re-flags>: (:re_flags, :re_flags) -> ();
Expand Down Expand Up @@ -165,12 +165,14 @@
};

re_glob: () -> (node :ast_expr) = {
id = <make-group-id>;
{
node = <ast-make-concat>;
list-of-atoms(node);
e = <ast-make-concat>;
list-of-atoms(e);
||
node = <ast-make-empty>;
e = <ast-make-empty>;
};
node = <ast-make-group>(e, id);

{
EOF;
Expand Down
50 changes: 37 additions & 13 deletions src/libre/dialect/like/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions src/libre/dialect/like/parser.sid
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ast_count;
ast_class_id;
!endpoint;
!group_id;
group_id;

%terminals%

Expand Down Expand Up @@ -84,7 +84,7 @@
!<count-one>: () -> (:ast_count);
!<count-range>: (:unsigned, :pos, :unsigned, :pos) -> (:ast_count);

!<make-group-id>: () -> (:group_id);
<make-group-id>: () -> (:group_id);
!<make-literal-cbrak>: () -> (:char);
!<make-literal-cr>: () -> (:char);
!<make-literal-nl>: () -> (:char);
Expand All @@ -97,7 +97,7 @@
<ast-make-concat>: () -> (:ast_expr);
!<ast-make-alt>: () -> (:ast_expr);
<ast-make-piece>: (:ast_expr, :ast_count) -> (:ast_expr);
!<ast-make-group>: (:ast_expr, :group_id) -> (:ast_expr);
<ast-make-group>: (:ast_expr, :group_id) -> (:ast_expr);
!<ast-get-re-flags>: () -> (:re_flags);
!<ast-set-re-flags>: (:re_flags) -> ();
!<ast-mask-re-flags>: (:re_flags, :re_flags) -> ();
Expand Down Expand Up @@ -165,12 +165,14 @@
};

re_like: () -> (node :ast_expr) = {
id = <make-group-id>;
{
node = <ast-make-concat>;
list-of-atoms(node);
e = <ast-make-concat>;
list-of-atoms(e);
||
node = <ast-make-empty>;
e = <ast-make-empty>;
};
node = <ast-make-group>(e, id);

{
EOF;
Expand Down
Loading

0 comments on commit 0ea82df

Please sign in to comment.