]> granicus.if.org Git - flex/commitdiff
make yywrap work with c++ scanners as per sf bug report
authorWill Estes <wlestes@users.sourceforge.net>
Sun, 22 Oct 2006 22:17:38 +0000 (22:17 +0000)
committerWill Estes <wlestes@users.sourceforge.net>
Sun, 22 Oct 2006 22:17:38 +0000 (22:17 +0000)
FlexLexer.h
NEWS
main.c
tests/test-c++-multiple-scanners/scanner-2.l

index 3a1025cf399033319b9d1eb09a257718fc24fe49..892e9e6082a848ee20b449cc59d7d6f032f2da38 100644 (file)
@@ -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 36fd83e876ea26e3ad1253e79b4674a59621a541..990d62e4c8ebfaa30be674699566b207629014ff 100644 (file)
--- 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 5d8a8185e5a16e59ae22983baf4c06faa01fd724..c4e79233bd2699e106535bd45ad9faec45260ec4 100644 (file)
--- 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 <FlexLexer.h>");
 
+               if (!do_yywrap) {
+                       outn("\nint yyFlexLexer::yywrap() { return 1; }");
+               }
+
                if (yyclass) {
                        outn ("int yyFlexLexer::yylex()");
                        outn ("\t{");
index db844022d48d178e72ff81eba5532b89c2a01c7d..15faf26fb33c660f4ce0065ccc22ea59bc784f62 100644 (file)
@@ -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;
 <OFF>.|\n yy_pop_state(); return 7;
 %%
 
+int S2_FlexLexer::yywrap()
+{
+    std::cout << "NOW WRAPPING." << std::endl;
+    return 1;
+}