Skip to content

Commit

Permalink
Merge pull request katef#471 from katef/kate/ast-pos
Browse files Browse the repository at this point in the history
Remove lexical position annotations for AST nodes
  • Loading branch information
katef authored May 30, 2024
2 parents 073305b + e9d190a commit 80e9311
Show file tree
Hide file tree
Showing 22 changed files with 2,180 additions and 2,593 deletions.
20 changes: 3 additions & 17 deletions src/libre/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,13 @@ ast_free(struct ast *ast)
}

struct ast_count
ast_make_count(unsigned min, const struct ast_pos *start,
unsigned max, const struct ast_pos *end)
ast_make_count(unsigned min, unsigned max)
{
struct ast_count res;

memset(&res, 0x00, sizeof res);

res.min = min;
res.max = max;

if (start != NULL) {
res.start = *start;
}
if (end != NULL) {
res.end = *end;
}

return res;
}

Expand Down Expand Up @@ -794,8 +784,7 @@ ast_make_expr_subtract(struct ast_expr_pool **poolp, enum re_flags re_flags, str

struct ast_expr *
ast_make_expr_range(struct ast_expr_pool **poolp, enum re_flags re_flags,
const struct ast_endpoint *from, struct ast_pos start,
const struct ast_endpoint *to, struct ast_pos end)
const struct ast_endpoint *from, const struct ast_endpoint *to)
{
struct ast_expr *res;

Expand All @@ -810,9 +799,7 @@ ast_make_expr_range(struct ast_expr_pool **poolp, enum re_flags re_flags,
res->type = AST_EXPR_RANGE;
res->re_flags = re_flags;
res->u.range.from = *from;
res->u.range.start = start;
res->u.range.to = *to;
res->u.range.end = end;

return res;
}
Expand Down Expand Up @@ -852,7 +839,6 @@ ast_make_expr_named(struct ast_expr_pool **poolp, enum re_flags re_flags, const
}
} else {
struct ast_endpoint from, to;
struct ast_pos pos = { 0, 0, 0 }; /* XXX: pass in pos */

from.type = AST_ENDPOINT_LITERAL;
if (class->ranges[i].a <= UCHAR_MAX) {
Expand All @@ -868,7 +854,7 @@ ast_make_expr_named(struct ast_expr_pool **poolp, enum re_flags re_flags, const
to.u.codepoint.u = class->ranges[i].b;
}

res->u.alt.n[i] = ast_make_expr_range(poolp, re_flags, &from, pos, &to, pos);
res->u.alt.n[i] = ast_make_expr_range(poolp, re_flags, &from, &to);
if (res->u.alt.n[i] == NULL) {
goto error;
}
Expand Down
22 changes: 2 additions & 20 deletions src/libre/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@
#ifndef RE_AST_H
#define RE_AST_H

/*
* This is a duplicate of struct lx_pos, but since we're linking to
* code with several distinct lexers, there isn't a clear lexer.h
* to include here. The parser sees both definitions, and will
* build a `struct ast_pos` in the appropriate places.
*/
struct ast_pos {
unsigned byte;
unsigned line;
unsigned col;
};

enum ast_expr_type {
/* Reserve one value (0) indicating a freed expression. This value is
* intentionally unnamed: code that switches on n->type should be able
Expand All @@ -40,9 +28,7 @@ enum ast_expr_type {
#define AST_COUNT_UNBOUNDED ((unsigned)-1)
struct ast_count {
unsigned min;
struct ast_pos start;
unsigned max;
struct ast_pos end;
};

enum ast_anchor_type {
Expand Down Expand Up @@ -206,9 +192,7 @@ struct ast_expr {

struct {
struct ast_endpoint from;
struct ast_pos start;
struct ast_endpoint to;
struct ast_pos end;
} range;

struct {
Expand Down Expand Up @@ -265,8 +249,7 @@ void
ast_free(struct ast *ast);

struct ast_count
ast_make_count(unsigned min, const struct ast_pos *start,
unsigned max, const struct ast_pos *end);
ast_make_count(unsigned min, unsigned max);

/*
* Expressions
Expand Down Expand Up @@ -322,8 +305,7 @@ ast_add_expr_concat(struct ast_expr *cat, struct ast_expr *node);

struct ast_expr *
ast_make_expr_range(struct ast_expr_pool **poolp, enum re_flags re_flags,
const struct ast_endpoint *from, struct ast_pos start,
const struct ast_endpoint *to, struct ast_pos end);
const struct ast_endpoint *from, const struct ast_endpoint *to);

struct ast_expr *
ast_make_expr_named(struct ast_expr_pool **poolp, enum re_flags re_flags, const struct class *class);
Expand Down
5 changes: 3 additions & 2 deletions src/libre/ast_new_from_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ remove_state(struct ast_expr_pool **poolp, struct rese *state)
return 0;
}
rep = ast_make_expr_repeat(poolp, 0, tmp,
ast_make_count(0, NULL, AST_COUNT_UNBOUNDED, NULL));
ast_make_count(0, AST_COUNT_UNBOUNDED));
if (!rep) {
ast_expr_free(*poolp, tmp);
ast_expr_free(*poolp, cat);
Expand Down Expand Up @@ -453,7 +453,8 @@ ast_expr_new_from_fsm(struct ast_expr_pool **poolp, const struct fsm *fsm)
}

rep = ast_make_expr_repeat(
poolp, 0, restart->expr, ast_make_count(0, NULL, AST_COUNT_UNBOUNDED, NULL));
poolp, 0, restart->expr,
ast_make_count(0, AST_COUNT_UNBOUNDED));
if (!rep) {
ast_expr_free(*poolp, cat);
free_restates(*poolp, restates, numstates + 1);
Expand Down
Loading

0 comments on commit 80e9311

Please sign in to comment.