Skip to content

Commit

Permalink
Construct group #0 at the AST root for all dialects.
Browse files Browse the repository at this point in the history
My thinking here is that capturing the entire expression is a property of the runtime, regardless of whether a particular dialect offers syntax for group capture for subexpressions. Practically, it seems like a user might want to know what a pattern matched (i.e. ignoring the unanchored prefix and suffix).
  • Loading branch information
katef committed Apr 26, 2024
1 parent d80644a commit 4b8276a
Show file tree
Hide file tree
Showing 13 changed files with 738 additions and 634 deletions.
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 4b8276a

Please sign in to comment.