Skip to content

Commit c897e9d

Browse files
authored
Merge pull request #509 from katef/sv/fix-lx-token-identification
Fix lx token identification
2 parents f6fc836 + 08fd72c commit c897e9d

35 files changed

+447
-274
lines changed

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ SUBDIR += tests/fsm
124124
SUBDIR += tests/glob
125125
SUBDIR += tests/like
126126
SUBDIR += tests/literal
127-
# FIXME: commenting this out for now due to Makefile error
128-
#SUBDIR += tests/lxpos
127+
SUBDIR += tests/lxpos
129128
SUBDIR += tests/minimise
130129
SUBDIR += tests/native
131130
SUBDIR += tests/pcre
@@ -190,6 +189,6 @@ STAGE_BUILD := ${STAGE_BUILD:Nbin/cvtpcre}
190189

191190
.if make(test)
192191
.END::
193-
grep FAIL ${BUILD}/tests/*/res*; [ $$? -ne 0 ]
192+
grep FAIL ${BUILD}/tests/*/*res*; [ $$? -ne 0 ]
194193
.endif
195194

include/fsm/print.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,15 @@ struct fsm_hooks {
7575
void *lang_opaque, void *hook_opaque);
7676

7777
int (*reject)(FILE *, const struct fsm_options *opt,
78+
const struct fsm_state_metadata *state_metadata,
7879
void *lang_opaque, void *hook_opaque);
7980

81+
/* If non-NULL, this will be called to generate code
82+
* in scope immediately after advancing to the
83+
* next character of input. */
84+
int (*advance)(FILE *, const struct fsm_options *opt,
85+
const char *cur_char_var, void *hook_opaque);
86+
8087
int (*comment)(FILE *, const struct fsm_options *opt,
8188
const struct fsm_state_metadata *state_metadata,
8289
void *hook_opaque);

src/libfsm/print.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ int
111111
print_hook_reject(FILE *f,
112112
const struct fsm_options *opt,
113113
const struct fsm_hooks *hooks,
114+
const struct fsm_state_metadata *state_metadata,
114115
int (*default_reject)(FILE *f, const struct fsm_options *opt,
115116
void *lang_opaque, void *hook_opaque),
116117
void *lang_opaque)
@@ -124,7 +125,7 @@ print_hook_reject(FILE *f,
124125
}
125126

126127
if (hooks->reject != NULL) {
127-
return hooks->reject(f, opt,
128+
return hooks->reject(f, opt, state_metadata,
128129
lang_opaque, hooks->hook_opaque);
129130
} else if (default_reject != NULL) {
130131
return default_reject(f, opt,

src/libfsm/print.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ int
4444
print_hook_reject(FILE *f,
4545
const struct fsm_options *opt,
4646
const struct fsm_hooks *hooks,
47+
const struct fsm_state_metadata *state_metadata,
4748
int (*default_reject)(FILE *f, const struct fsm_options *opt,
4849
void *lang_opaque, void *hook_opaque),
4950
void *lang_opaque);

src/libfsm/print/awk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ print_end(FILE *f, const struct dfavm_op_ir *op,
154154
{
155155
switch (end_bits) {
156156
case VM_END_FAIL:
157-
return print_hook_reject(f, opt, hooks, default_reject, NULL);
157+
return print_hook_reject(f, opt, hooks, NULL, default_reject, NULL);
158158

159159
case VM_END_SUCC:;
160160
struct fsm_state_metadata state_metadata = {

src/libfsm/print/c.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ print_groups(FILE *f, const struct fsm_options *opt,
210210
}
211211

212212
static int
213-
print_case(FILE *f, const struct ir *ir,
213+
print_case(FILE *f, const struct ir *ir, fsm_state_t state_id,
214214
const struct fsm_options *opt,
215215
const struct fsm_hooks *hooks,
216216
const char *cp,
@@ -222,10 +222,16 @@ print_case(FILE *f, const struct ir *ir,
222222
assert(f != NULL);
223223
assert(cs != NULL);
224224

225+
assert(state_id < ir->n);
226+
const struct fsm_state_metadata state_metadata = {
227+
.end_ids = ir->states[state_id].endids.ids,
228+
.end_id_count = ir->states[state_id].endids.count,
229+
};
230+
225231
switch (cs->strategy) {
226232
case IR_NONE:
227233
fprintf(f, "\t\t\t");
228-
if (-1 == print_hook_reject(f, opt, hooks, default_reject, NULL)) {
234+
if (-1 == print_hook_reject(f, opt, hooks, &state_metadata, default_reject, NULL)) {
229235
return -1;
230236
}
231237
fprintf(f, "\n");
@@ -254,7 +260,7 @@ print_case(FILE *f, const struct ir *ir,
254260
print_groups(f, opt, ir_indexof(ir, cs), cs->u.partial.groups, cs->u.partial.n);
255261

256262
fprintf(f, "\t\t\tdefault: ");
257-
if (-1 == print_hook_reject(f, opt, hooks, default_reject, NULL)) {
263+
if (-1 == print_hook_reject(f, opt, hooks, &state_metadata, default_reject, NULL)) {
258264
return -1;
259265
}
260266
fprintf(f, "\n");
@@ -285,7 +291,7 @@ print_case(FILE *f, const struct ir *ir,
285291

286292
print_ranges(f, opt, cs->u.error.error.ranges, cs->u.error.error.n);
287293
fprintf(f, " ");
288-
if (-1 == print_hook_reject(f, opt, hooks, default_reject, NULL)) {
294+
if (-1 == print_hook_reject(f, opt, hooks, &state_metadata, default_reject, NULL)) {
289295
return -1;
290296
}
291297
fprintf(f, "\n");
@@ -398,7 +404,7 @@ print_endstates(FILE *f,
398404

399405
/* unexpected EOT */
400406
fprintf(f, "\tdefault: ");
401-
if (-1 == print_hook_reject(f, opt, hooks, default_reject, NULL)) {
407+
if (-1 == print_hook_reject(f, opt, hooks, NULL, default_reject, NULL)) {
402408
return -1;
403409
}
404410
fprintf(f, "\n");
@@ -435,7 +441,7 @@ fsm_print_cfrag(FILE *f, const struct ir *ir,
435441
}
436442
fprintf(f, "\n");
437443

438-
if (-1 == print_case(f, ir, opt, hooks, cp, &ir->states[i])) {
444+
if (-1 == print_case(f, ir, i, opt, hooks, cp, &ir->states[i])) {
439445
return -1;
440446
}
441447

@@ -500,6 +506,12 @@ fsm_print_c_body(FILE *f, const struct ir *ir,
500506
break;
501507
}
502508

509+
if (hooks->advance != NULL) {
510+
if (-1 == hooks->advance(f, opt, cp, hooks->hook_opaque)) {
511+
return -1;
512+
}
513+
}
514+
503515
if (-1 == fsm_print_cfrag(f, ir, opt, hooks, cp)) {
504516
return -1;
505517
}

src/libfsm/print/dot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ print_dotfrag(FILE *f,
226226
if (!opt->anonymous_states) {
227227
fprintf(f, "\t%sS%-2u [ ", prefix, s);
228228

229-
if (-1 == print_hook_reject(f, opt, hooks, default_reject, &s)) {
229+
if (-1 == print_hook_reject(f, opt, hooks, NULL, default_reject, &s)) {
230230
return -1;
231231
}
232232

src/libfsm/print/fsm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ print_state(FILE *f, const struct fsm_options *opt, const struct fsm_hooks *hook
184184
assert(opt != NULL);
185185

186186
if (!fsm_isend(fsm, s)) {
187-
if (-1 == print_hook_reject(f, opt, hooks, NULL, NULL)) {
187+
if (-1 == print_hook_reject(f, opt, hooks, NULL, NULL, NULL)) {
188188
return -1;
189189
}
190190
}

src/libfsm/print/go.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ print_end(FILE *f, const struct dfavm_op_ir *op,
185185

186186
switch (end_bits) {
187187
case VM_END_FAIL:
188-
return print_hook_reject(f, opt, hooks, default_reject, NULL);
188+
return print_hook_reject(f, opt, hooks, NULL, default_reject, NULL);
189189

190190
case VM_END_SUCC:
191191
assert(op->ret >= retlist->a);

src/libfsm/print/ir.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ struct ir_state {
9191
} error;
9292

9393
struct {
94-
/* Note: This is allocated separately, to avoid
95-
* making the union significantly larger. */
96-
struct ir_state_table {
97-
unsigned to[FSM_SIGMA_COUNT];
98-
} *table;
94+
int not_yet_implemented;
9995
} table;
10096
} u;
10197
};

0 commit comments

Comments
 (0)