diff options
author | sodabrew <sodabrew> | 2007-09-10 06:16:33 +0000 |
---|---|---|
committer | sodabrew <sodabrew> | 2007-09-10 06:16:33 +0000 |
commit | dd19e9d7f7379ef4bafe29fbc6525f9dc943ea97 (patch) | |
tree | efb9b56d93c2b77629c30e12cc4976c6409e3094 | |
parent | ac31304f600edc8763178aab8b68db7c0931abcc (diff) | |
download | flex-dd19e9d7f7379ef4bafe29fbc6525f9dc943ea97.tar.gz |
Introduce %option extra-type="your_type *" (resolves bug #1744505).
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | doc/flex.texi | 9 | ||||
-rw-r--r-- | flex.skl | 12 | ||||
-rw-r--r-- | flexdef.h | 2 | ||||
-rw-r--r-- | main.c | 5 | ||||
-rw-r--r-- | parse.y | 4 | ||||
-rw-r--r-- | scan.l | 1 |
7 files changed, 26 insertions, 9 deletions
@@ -7,6 +7,8 @@ See the file COPYING for copying conditions. ** 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. diff --git a/doc/flex.texi b/doc/flex.texi index e4a2f3d..f9a9e9e 100644 --- a/doc/flex.texi +++ b/doc/flex.texi @@ -4215,6 +4215,7 @@ after @code{yylex}, respectively. @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 @@ -4359,10 +4360,8 @@ be accessed from within the very first yyalloc, used to allocate 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 @@ -4371,9 +4370,9 @@ defining @code{YY_EXTRA_TYPE} in section 1 of your scanner: %{ #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 ); @@ -332,7 +332,6 @@ m4_define( [[M4_YY_INCR_LINENO]], }while(0) ]]) -int yylex_init M4_YY_PARAMS(yyscan_t* scanner); %endif @@ -780,9 +779,16 @@ m4_ifdef( [[M4_YY_NO_UNISTD_H]],, #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 @@ -882,6 +888,10 @@ m4_ifdef( [[M4_YY_NOT_IN_HEADER]], ]]) ]]) +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. @@ -448,7 +448,7 @@ extern const char *skel[]; 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; @@ -65,7 +65,7 @@ int action_size, defs1_offset, prolog_offset, action_offset, 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; @@ -334,6 +334,9 @@ void check_options () 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; @@ -1,7 +1,7 @@ /* 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 @@ -196,6 +196,8 @@ option : OPT_OUTFILE '=' NAME 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 @@ -420,6 +420,7 @@ M4QEND "]]" 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; |