From a4fa510851cb409efe296caf2abf17c613baaff9 Mon Sep 17 00:00:00 2001 From: Will Estes Date: Sun, 22 Oct 2006 22:17:38 +0000 Subject: [PATCH] make yywrap work with c++ scanners as per sf bug report --- FlexLexer.h | 15 ++++++++------- NEWS | 4 +++- main.c | 8 +++++++- tests/test-c++-multiple-scanners/scanner-2.l | 7 ++++++- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/FlexLexer.h b/FlexLexer.h index 3a1025c..892e9e6 100644 --- a/FlexLexer.h +++ b/FlexLexer.h @@ -122,11 +122,12 @@ public: void yy_delete_buffer( struct yy_buffer_state* b ); void yyrestart( FLEX_STD istream* s ); - void yypush_buffer_state( struct yy_buffer_state* new_buffer ); - void yypop_buffer_state(void); + void yypush_buffer_state( struct yy_buffer_state* new_buffer ); + void yypop_buffer_state(); virtual int yylex(); - virtual void switch_streams( FLEX_STD istream* new_in, FLEX_STD ostream* new_out ); + virtual void switch_streams( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 ); + virtual int yywrap(); protected: virtual int LexerInput( char* buf, int max_size ); @@ -172,10 +173,10 @@ protected: int yy_did_buffer_switch_on_eof; - size_t yy_buffer_stack_top; /**< index of top of stack. */ - size_t yy_buffer_stack_max; /**< capacity of stack. */ - struct yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */ - void yyensure_buffer_stack(void); + size_t yy_buffer_stack_top; /**< index of top of stack. */ + size_t yy_buffer_stack_max; /**< capacity of stack. */ + struct yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */ + void yyensure_buffer_stack(void); // The following are not always needed, but may be depending // on use of certain flex features (like REJECT or yymore()). diff --git a/NEWS b/NEWS index 36fd83e..990d62e 100644 --- a/NEWS +++ b/NEWS @@ -6,7 +6,9 @@ See the file COPYING for copying conditions. * after version 2.5.33 ** memory leaks removed from the C++ scanner (but the C++ scanner is -still experimental and may change radically without notice) + still experimental and may change radically without notice) + +** c++ scanners can now use yywrap ** added new unit test for c++ and yywrap diff --git a/main.c b/main.c index 5d8a818..c4e7923 100644 --- a/main.c +++ b/main.c @@ -1571,7 +1571,9 @@ void readin () } if (!do_yywrap) { - outn ("\n#define yywrap(n) 1"); + if (!C_plus_plus) { + outn ("\n#define yywrap(n) 1"); + } outn ("#define YY_SKIP_YYWRAP"); } @@ -1644,6 +1646,10 @@ void readin () if (C_plus_plus) { outn ("\n#include "); + if (!do_yywrap) { + outn("\nint yyFlexLexer::yywrap() { return 1; }"); + } + if (yyclass) { outn ("int yyFlexLexer::yylex()"); outn ("\t{"); diff --git a/tests/test-c++-multiple-scanners/scanner-2.l b/tests/test-c++-multiple-scanners/scanner-2.l index db84402..15faf26 100644 --- a/tests/test-c++-multiple-scanners/scanner-2.l +++ b/tests/test-c++-multiple-scanners/scanner-2.l @@ -25,7 +25,7 @@ %} %option 8bit outfile="scanner-2.cpp" prefix="S2_" -%option nounput nomain noyywrap +%option nounput nomain %option warn stack noyy_top_state %x OFF @@ -41,3 +41,8 @@ off yy_push_state(OFF); return 4; .|\n yy_pop_state(); return 7; %% +int S2_FlexLexer::yywrap() +{ + std::cout << "NOW WRAPPING." << std::endl; + return 1; +} -- 2.40.0