Line directives need to use the fileName stored in the InputLoc stuctures from
[external/ragel.git] / ragel / rlscan.rl
index 9c96ef1..3c325c3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2006-2007 Adrian Thurston <thurston@cs.queensu.ca>
+ *  Copyright 2006-2007 Adrian Thurston <thurston@complang.org>
  */
 
 /*  This file is part of Ragel.
@@ -25,6 +25,7 @@
 
 #include "ragel.h"
 #include "rlscan.h"
+#include "inputdata.h"
 
 //#define LOG_TOKENS
 
@@ -202,7 +203,7 @@ void Scanner::pass()
        /* If no errors and we are at the bottom of the include stack (the
         * source file listed on the command line) then write out the data. */
        if ( includeDepth == 0 && machineSpec == 0 && machineName == 0 )
-               xmlEscapeHost( output, ts, te-ts );
+               id.inputItems.tail->data.write( ts, te-ts );
 }
 
 /*
@@ -278,12 +279,13 @@ void Scanner::handleMachine()
        if ( !importMachines && inclSectionTarg == 0 ) {
                ignoreSection = false;
 
-               ParserDictEl *pdEl = parserDict.find( machine );
+               ParserDictEl *pdEl = id.parserDict.find( machine );
                if ( pdEl == 0 ) {
                        pdEl = new ParserDictEl( machine );
                        pdEl->value = new Parser( fileName, machine, sectionLoc );
                        pdEl->value->init();
-                       parserDict.insert( pdEl );
+                       id.parserDict.insert( pdEl );
+                       id.parserList.append( pdEl->value );
                }
 
                parser = pdEl->value;
@@ -336,7 +338,7 @@ void Scanner::handleInclude()
                                parser->includeHistory.append( IncludeHistoryItem( 
                                                includeChecks[found], inclSectionName ) );
 
-                               Scanner scanner( includeChecks[found], *inFile, output, parser,
+                               Scanner scanner( id, includeChecks[found], *inFile, parser,
                                                inclSectionName, includeDepth+1, false );
                                scanner.do_scan( );
                                delete inFile;
@@ -361,7 +363,7 @@ void Scanner::handleImport()
                                scan_error() << "import: attempted: \"" << *tried++ << '\"' << endl;
                }
 
-               Scanner scanner( importChecks[found], *inFile, output, parser,
+               Scanner scanner( id, importChecks[found], *inFile, parser,
                                0, includeDepth+1, true );
                scanner.do_scan( );
                scanner.importToken( 0, 0, 0 );
@@ -409,24 +411,26 @@ void Scanner::handleImport()
        action write_command
        {
                if ( active() && machineSpec == 0 && machineName == 0 ) {
-                       output << "<write"
-                                       " def_name=\"" << parser->sectionName << "\""
-                                       " line=\"" << line << "\""
-                                       " col=\"" << column << "\""
-                                       ">";
+                       InputItem *inputItem = new InputItem;
+                       inputItem->type = InputItem::Write;
+                       inputItem->loc.line = line;
+                       inputItem->loc.col = column;
+                       inputItem->name = parser->sectionName;
+                       inputItem->pd = parser->pd;
+                       id.inputItems.append( inputItem );
                }
        }
 
        action write_arg
        {
                if ( active() && machineSpec == 0 && machineName == 0 )
-                       output << "<arg>" << tokdata << "</arg>";
+                       id.inputItems.tail->writeArgs.append( strdup(tokdata) );
        }
 
        action write_close
        {
                if ( active() && machineSpec == 0 && machineName == 0 )
-                       output << "</write>\n";
+                       id.inputItems.tail->writeArgs.append( 0 );
        }
 
        write_stmt =
@@ -481,7 +485,6 @@ void Scanner::token( int type, char *start, char *end )
 void Scanner::processToken( int type, char *tokdata, int toklen )
 {
        int *p, *pe, *eof;
-       
 
        if ( type < 0 )
                p = pe = eof = 0;
@@ -507,14 +510,9 @@ void Scanner::startSection( )
 {
        parserExistsError = false;
 
-       if ( includeDepth == 0 ) {
-               if ( machineSpec == 0 && machineName == 0 )
-                       output << "</host>\n";
-       }
-
        sectionLoc.fileName = fileName;
        sectionLoc.line = line;
-       sectionLoc.col = 0;
+       sectionLoc.col = column;
 }
 
 void Scanner::endSection( )
@@ -527,7 +525,7 @@ void Scanner::endSection( )
                InputLoc loc;
                loc.fileName = fileName;
                loc.line = line;
-               loc.col = 0;
+               loc.col = column;
 
                parser->token( loc, TK_EndSection, 0, 0 );
        }
@@ -536,7 +534,11 @@ void Scanner::endSection( )
                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. */
-                       output << "<host line=\"" << line << "\">";
+                       InputItem *inputItem = new InputItem;
+                       inputItem->type = InputItem::HostData;
+                       inputItem->loc.line = line;
+                       inputItem->loc.col = column;
+                       id.inputItems.append( inputItem );
                }
        }
 }
@@ -580,7 +582,7 @@ char **Scanner::makeIncludePathChecks( const char *thisFileName,
                }
 
                /* Search from the include paths given on the command line. */
-               for ( ArgsVector::Iter incp = includePaths; incp.lte(); incp++ ) {
+               for ( ArgsVector::Iter incp = id.includePaths; incp.lte(); incp++ ) {
                        long pathLen = strlen( *incp );
                        long checkLen = pathLen + 1 + length;
                        char *check = new char[checkLen+1];
@@ -931,6 +933,7 @@ ifstream *Scanner::tryOpenInclude( char **pathChecks, long &found )
 
        # Parser definitions. 
        parser_def := |*
+               'length_cond' => { token( KW_Length ); };
                'machine' => { token( KW_Machine ); };
                'include' => { token( KW_Include ); };
                'import' => { token( KW_Import ); };