** introduce yylex_init_extra; see the manual for details
+** introduce %option extra-type="your_type *" (resolves bug #1744505)
+
** The flex program now parses multiple short concatenated options (resolves bug
#1619820). Thanks to Petr Machata of Red Hat on this issue.
@example
@verbatim
int yylex_init ( yyscan_t * ptr_yy_globals ) ;
+ int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t * ptr_yy_globals ) ;
int yylex ( yyscan_t yyscanner ) ;
int yylex_destroy ( yyscan_t yyscanner ) ;
@end verbatim
the scanner itself.
By default, @code{YY_EXTRA_TYPE} is defined as type @code{void *}. You
-will have to cast @code{yyextra} and the return value from
-@code{yyget_extra} to the appropriate value each time you access the
-extra data. To avoid casting, you may override the default type by
-defining @code{YY_EXTRA_TYPE} in section 1 of your scanner:
+may redefine this type using @code{%option extra-type="your_type"} in
+the scanner:
@cindex YY_EXTRA_TYPE, defining your own type
@example
%{
#include <sys/stat.h>
#include <unistd.h>
- #define YY_EXTRA_TYPE struct stat*
%}
%option reentrant
+ %option extra-type="struct stat *"
%%
__filesize__ printf( "%ld", yyextra->st_size );
}while(0)
]])
-int yylex_init M4_YY_PARAMS(yyscan_t* scanner);
%endif
#endif
]])
+m4_ifdef( [[M4_EXTRA_TYPE_DEFS]],
+[[
+#define YY_EXTRA_TYPE M4_EXTRA_TYPE_DEFS
+]],
+[[
#ifndef YY_EXTRA_TYPE
#define YY_EXTRA_TYPE void *
#endif
+]]
+)
%if-c-only Reentrant structure and macros (non-C++).
%if-reentrant
]])
]])
+int yylex_init M4_YY_PARAMS(yyscan_t* scanner);
+
+int yylex_init_extra M4_YY_PARAMS( YY_EXTRA_TYPE user_defined, yyscan_t* scanner);
+
%endif
/* Accessor methods to globals.
extern int skel_ind;
extern char *infilename, *outfilename, *headerfilename;
extern int did_outfilename;
-extern char *prefix, *yyclass;
+extern char *prefix, *yyclass, *extra_type;
extern int do_stdinit, use_stdout;
extern char **input_files;
extern int num_input_files;
action_index;
char *infilename = NULL, *outfilename = NULL, *headerfilename = NULL;
int did_outfilename;
-char *prefix, *yyclass;
+char *prefix, *yyclass, *extra_type = NULL;
int do_stdinit, use_stdout;
int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
if (!ansi_func_protos)
buf_m4_define( &m4defs_buf, "M4_YY_NO_ANSI_FUNC_PROTOS", NULL);
+ if (extra_type)
+ buf_m4_define( &m4defs_buf, "M4_EXTRA_TYPE_DEFS", extra_type);
+
if (!use_stdout) {
FILE *prev_stdout;
/* parse.y - parser for flex input */
%token CHAR NUMBER SECTEND SCDECL XSCDECL NAME PREVCCL EOF_OP
-%token OPTION_OP OPT_OUTFILE OPT_PREFIX OPT_YYCLASS OPT_HEADER
+%token OPTION_OP OPT_OUTFILE OPT_PREFIX OPT_YYCLASS OPT_HEADER OPT_EXTRA_TYPE
%token OPT_TABLES
%token CCE_ALNUM CCE_ALPHA CCE_BLANK CCE_CNTRL CCE_DIGIT CCE_GRAPH
outfilename = copy_string( nmstr );
did_outfilename = 1;
}
+ | OPT_EXTRA_TYPE '=' NAME
+ { extra_type = copy_string( nmstr ); }
| OPT_PREFIX '=' NAME
{ prefix = copy_string( nmstr ); }
| OPT_YYCLASS '=' NAME
yyget_lloc ACTION_M4_IFDEF("M4""_YY_NO_GET_LLOC", ! option_sense);
yyset_lloc ACTION_M4_IFDEF("M4""_YY_NO_SET_LLOC", ! option_sense);
+ extra-type return OPT_EXTRA_TYPE;
outfile return OPT_OUTFILE;
prefix return OPT_PREFIX;
yyclass return OPT_YYCLASS;