@@ -297,6 +297,26 @@ reject_c(FILE *f, const struct fsm_options *opt,
297
297
return 0 ;
298
298
}
299
299
300
+ static int
301
+ advance_c (FILE * f , const struct fsm_options * opt , const char * cur_char_var , void * hook_opaque )
302
+ {
303
+ (void )hook_opaque ;
304
+
305
+ switch (opt -> io ) {
306
+ case FSM_IO_GETC :
307
+ break ;
308
+
309
+ case FSM_IO_STR :
310
+ case FSM_IO_PAIR :
311
+ /* When libfsm's generated code advances a character, update
312
+ * lx's token name buffer and position bookkeeping. */
313
+ fprintf (f , "\t\tif (!%sadvance_end(lx, %s)) { return %sERROR; }\n" ,
314
+ prefix .api , cur_char_var , prefix .tok );
315
+ break ;
316
+ }
317
+ return 0 ;
318
+ }
319
+
300
320
static void
301
321
print_proto (FILE * f , const struct ast * ast , const struct ast_zone * z )
302
322
{
@@ -485,8 +505,7 @@ print_io(FILE *f, const struct fsm_options *opt)
485
505
fprintf (f , "}\n" );
486
506
fprintf (f , "\n" );
487
507
488
- switch (opt -> io ) {
489
- case FSM_IO_GETC :
508
+ if (opt -> io == FSM_IO_GETC ) {
490
509
/* TODO: consider passing char *c, and return int 0/-1 for error */
491
510
if (opt -> comments ) {
492
511
fprintf (f , "/* This wrapper manages one character of lookahead/pushback\n" );
@@ -536,17 +555,6 @@ print_io(FILE *f, const struct fsm_options *opt)
536
555
fprintf (f , "\treturn %sgetc((struct %slx *)getc_opaque);\n" , prefix .api , prefix .lx );
537
556
fprintf (f , "}\n" );
538
557
fprintf (f , "\n" );
539
- break ;
540
-
541
- case FSM_IO_PAIR :
542
- case FSM_IO_STR :
543
- /* When libfsm's generated code advances a character, update
544
- * lx's token name buffer and position bookkeeping. */
545
- fprintf (f , "#ifndef FSM_ADVANCE_HOOK\n" );
546
- fprintf (f , "#define FSM_ADVANCE_HOOK(C) if (!%sadvance_end(lx, C)) { return %sERROR; }\n" , prefix .api , prefix .tok );
547
- fprintf (f , "#endif\n" );
548
- fprintf (f , "\n" );
549
- break ;
550
558
}
551
559
552
560
fprintf (f , "#if __STDC_VERSION__ >= 199901L\n" );
@@ -831,6 +839,7 @@ print_zone(FILE *f, const struct ast *ast, const struct ast_zone *z,
831
839
832
840
hooks .accept = accept_c ;
833
841
hooks .reject = reject_c ;
842
+ hooks .advance = advance_c ;
834
843
hooks .hook_opaque = & hook_env ;
835
844
836
845
fsm_print (f , z -> fsm , opt , & hooks , FSM_PRINT_C );
0 commit comments