Write statements are no longer in ragel_def elements. They appear on their own
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Thu, 1 Feb 2007 02:42:53 +0000 (02:42 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Thu, 1 Feb 2007 02:42:53 +0000 (02:42 +0000)
next to host elements. The ragel_def tag is now used exclusively for defining a
machine.

git-svn-id: http://svn.complang.org/ragel/trunk@46 052ea7fc-9027-0410-9066-f65837a77df0

ragel/ragel.h
ragel/rlscan.rl
rlcodegen/xmlparse.kl

index 81d3f9a..23c8d29 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2003 Adrian Thurston <thurston@cs.queensu.ca>
+ *  Copyright 2001-2007 Adrian Thurston <thurston@cs.queensu.ca>
  */
 
 /*  This file is part of Ragel.
index db2c7ef..0784730 100644 (file)
@@ -68,7 +68,7 @@ struct Scanner
                includeDepth(includeDepth),
                line(1), column(1), lastnl(0), 
                parser(0), active(false), 
-               parserExistsError(false), ragelDefOpen(false),
+               parserExistsError(false),
                whitespaceOn(true)
                {}
 
@@ -91,7 +91,6 @@ struct Scanner
        void updateCol();
        void startSection();
        void endSection();
-       void openRagelDef();
        void do_scan();
        bool parserExists();
        ostream &scan_error();
@@ -121,7 +120,6 @@ struct Scanner
        /* This is set if ragel has already emitted an error stating that
         * no section name has been seen and thus no parser exists. */
        bool parserExistsError;
-       bool ragelDefOpen;
 
        /* This is for inline code. By default it is on. It goes off for
         * statements and values in inline blocks which are parsed. */
@@ -297,7 +295,6 @@ void Scanner::token( int type )
        action write_command
        {
                if ( active ) {
-                       openRagelDef();
                        if ( strcmp( tokdata, "data" ) != 0 &&
                                        strcmp( tokdata, "init" ) != 0 &&
                                        strcmp( tokdata, "exec" ) != 0 &&
@@ -305,7 +302,8 @@ void Scanner::token( int type )
                        {
                                scan_error() << "unknown write command" << endl;
                        }
-                       output << "  <write what=\"" << tokdata << "\">";
+                       output << "<write def_name=\"" << parser->sectionName << 
+                                       "\" what=\"" << tokdata << "\">";
                }
        }
 
@@ -388,7 +386,6 @@ void Scanner::startSection( )
        if ( includeDepth == 0 ) {
                if ( machineSpec == 0 && machineName == 0 )
                        output << "</host>\n";
-               ragelDefOpen = false;
        }
 
        sectionLoc.fileName = fileName;
@@ -396,14 +393,6 @@ void Scanner::startSection( )
        sectionLoc.col = 0;
 }
 
-void Scanner::openRagelDef()
-{
-       if ( ! ragelDefOpen ) {
-               ragelDefOpen = true;
-               output << "<ragel_def name=\"" << parser->sectionName << "\">\n";
-       }
-}
-
 void Scanner::endSection( )
 {
        /* Execute the eof actions for the section parser. */
@@ -423,11 +412,6 @@ void Scanner::endSection( )
        }
 
        if ( includeDepth == 0 ) {
-               if ( ragelDefOpen ) {
-                       output << "</ragel_def>\n";
-                       ragelDefOpen = false;
-               }
-
                if ( machineSpec == 0 && machineName == 0 ) {
                        /* The end section may include a newline on the end, so
                         * we use the last line, which will count the newline. */
index 92d3b6b..386b7df 100644 (file)
@@ -49,7 +49,7 @@ start:
                gblErrorCount += 1;
        };
 
-tag_ragel: tag_ragel_head host_or_def_list '/' TAG_ragel;
+tag_ragel: tag_ragel_head ragel_def_list host_or_write_list '/' TAG_ragel;
 
 tag_ragel_head: TAG_ragel
        final {
@@ -88,13 +88,16 @@ tag_ragel_head: TAG_ragel
                outStream = openOutput( sourceFileName );
        };
 
-host_or_def_list: host_or_def_list host_or_def;
-host_or_def_list: ;
+ragel_def_list: ragel_def_list ragel_def;
+ragel_def_list: ;
 
-host_or_def: host;
-host_or_def: ragel_def;
+host_or_write_list: host_or_write_list host_or_write;
+host_or_write_list: ;
 
-host: 
+host_or_write: tag_host;
+host_or_write: tag_write;
+
+tag_host: 
        TAG_host '/' TAG_host
        final {
                Attribute *lineAttr = $1->tag->findAttr( "line" );
@@ -110,12 +113,7 @@ host:
                        *outStream << $3->tag->content;
        };
 
-ragel_def: 
-       tag_ragel_def_head ragel_def_item_list '/' TAG_ragel_def
-       final {
-               if ( gblErrorCount == 0 )
-                       cgd->generate();
-       };
+ragel_def: tag_ragel_def_head ragel_def_item_list '/' TAG_ragel_def;
 
 tag_ragel_def_head: TAG_ragel_def 
        final {
@@ -136,11 +134,6 @@ tag_ragel_def_head: TAG_ragel_def
                        cgd = makeCodeGen( sourceFileName, fsmName, *outStream, wantComplete );
                }
 
-               cgd->writeOps = 0;
-               cgd->writeData = false;
-               cgd->writeInit = false;
-               cgd->writeExec = false;
-               cgd->writeEOF = false;
                ::keyOps = &cgd->thisKeyOps;
        };
 
@@ -152,7 +145,6 @@ ragel_def_item: tag_getkey_expr;
 ragel_def_item: tag_access_expr;
 ragel_def_item: tag_curstate_expr;
 ragel_def_item: tag_machine;
-ragel_def_item: tag_write;
 
 tag_alph_type: TAG_alphtype '/' TAG_alphtype
        final {
@@ -175,7 +167,7 @@ tag_curstate_expr: TAG_curstate inline_list '/' TAG_curstate
                cgd->curStateExpr = $2->inlineList;
        };
 
-tag_write: TAG_write write_option_list '/' TAG_write
+tag_write: tag_write_head write_option_list '/' TAG_write
        final {
                Attribute *what = $1->tag->findAttr( "what" );
                if ( what == 0 ) {
@@ -190,9 +182,41 @@ tag_write: TAG_write write_option_list '/' TAG_write
                                cgd->writeExec = true;
                        else if ( strcmp( what->value, "eof" ) == 0 )
                                cgd->writeEOF = true;
+
+                       if ( gblErrorCount == 0 )
+                               cgd->generate();
+               }
+       };
+
+nonterm tag_write_head
+{
+       XMLTag *tag;
+       InputLoc loc;
+};
+
+tag_write_head: TAG_write
+       final {
+               Attribute *nameAttr = $1->tag->findAttr( "def_name" );
+               if ( nameAttr == 0 ) {
+                       error($1->loc) << "tag <write> requires a def_name attribute" << endl;
                }
+               else {
+                       CodeGenMapEl *mapEl = codeGenMap.find( nameAttr->value );
+                       assert( mapEl != 0 );
+                       cgd = mapEl->value;
+               }
+
+               cgd->writeData = false;
+               cgd->writeInit = false;
+               cgd->writeExec = false;
+               cgd->writeEOF = false;
+               ::keyOps = &cgd->thisKeyOps;
+
+               $$->tag = $1->tag;
+               $$->loc = $1->loc;
        };
 
+
 write_option_list: write_option_list tag_option;
 write_option_list: ;