X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=ragel%2Frlscan.rl;h=3c325c31e193bb3ce3e00b933a6f36c714d1310b;hb=9f3c2baa91083bb5b33b4f3ec07f58d900157e32;hp=bf4cd928d2c724a8724ff9f9b61d96b27b01cd75;hpb=ccdf333e9947f28ebfe79c5fba4b33c6ed5365e5;p=external%2Fragel.git diff --git a/ragel/rlscan.rl b/ragel/rlscan.rl index bf4cd92..3c325c3 100644 --- a/ragel/rlscan.rl +++ b/ragel/rlscan.rl @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 Adrian Thurston + * Copyright 2006-2007 Adrian Thurston */ /* This file is part of Ragel. @@ -25,6 +25,7 @@ #include "ragel.h" #include "rlscan.h" +#include "inputdata.h" //#define LOG_TOKENS @@ -147,7 +148,7 @@ void Scanner::flushImport() } } -void Scanner::directToParser( Parser *toParser, char *tokFileName, int tokLine, +void Scanner::directToParser( Parser *toParser, const char *tokFileName, int tokLine, int tokColumn, int type, char *tokdata, int toklen ) { InputLoc loc; @@ -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 ); } /* @@ -246,11 +247,13 @@ ostream &Scanner::scan_error() return cerr; } -bool Scanner::recursiveInclude( char *inclFileName, char *inclSectionName ) +/* An approximate check for duplicate includes. Due to aliasing of files it's + * possible for duplicates to creep in. */ +bool Scanner::duplicateInclude( char *inclFileName, char *inclSectionName ) { - for ( IncludeStack::Iter si = includeStack; si.lte(); si++ ) { - if ( strcmp( si->fileName, inclFileName ) == 0 && - strcmp( si->sectionName, inclSectionName ) == 0 ) + for ( IncludeHistory::Iter hi = parser->includeHistory; hi.lte(); hi++ ) { + if ( strcmp( hi->fileName, inclFileName ) == 0 && + strcmp( hi->sectionName, inclSectionName ) == 0 ) { return true; } @@ -276,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; @@ -329,21 +333,16 @@ void Scanner::handleInclude() scan_error() << "include: attempted: \"" << *tried++ << '\"' << endl; } else { - /* Check for a recursive include structure. Add the current file/section - * name then check if what we are including is already in the stack. */ - includeStack.append( IncludeStackItem( fileName, parser->sectionName ) ); + /* Don't include anything that's already been included. */ + if ( !duplicateInclude( includeChecks[found], inclSectionName ) ) { + parser->includeHistory.append( IncludeHistoryItem( + includeChecks[found], inclSectionName ) ); - if ( recursiveInclude( includeChecks[found], inclSectionName ) ) - scan_error() << "include: this is a recursive include operation" << endl; - else { - Scanner scanner( includeChecks[found], *inFile, output, parser, + Scanner scanner( id, includeChecks[found], *inFile, parser, inclSectionName, includeDepth+1, false ); scanner.do_scan( ); delete inFile; } - - /* Remove the last element (len-1) */ - includeStack.remove( -1 ); } } } @@ -364,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 ); @@ -412,24 +411,26 @@ void Scanner::handleImport() action write_command { if ( active() && machineSpec == 0 && machineName == 0 ) { - output << "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 << "" << tokdata << ""; + id.inputItems.tail->writeArgs.append( strdup(tokdata) ); } action write_close { if ( active() && machineSpec == 0 && machineName == 0 ) - output << "\n"; + id.inputItems.tail->writeArgs.append( 0 ); } write_stmt = @@ -484,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; @@ -510,14 +510,9 @@ void Scanner::startSection( ) { parserExistsError = false; - if ( includeDepth == 0 ) { - if ( machineSpec == 0 && machineName == 0 ) - output << "\n"; - } - sectionLoc.fileName = fileName; sectionLoc.line = line; - sectionLoc.col = 0; + sectionLoc.col = column; } void Scanner::endSection( ) @@ -530,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 ); } @@ -539,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 << ""; + InputItem *inputItem = new InputItem; + inputItem->type = InputItem::HostData; + inputItem->loc.line = line; + inputItem->loc.col = column; + id.inputItems.append( inputItem ); } } } @@ -553,7 +552,8 @@ bool isAbsolutePath( const char *path ) #endif } -char **Scanner::makeIncludePathChecks( char *thisFileName, char *fileName, int fnlen ) +char **Scanner::makeIncludePathChecks( const char *thisFileName, + const char *fileName, int fnlen ) { char **checks = new char*[2]; long nextCheck = 0; @@ -582,7 +582,7 @@ char **Scanner::makeIncludePathChecks( char *thisFileName, char *fileName, int f } /* 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]; @@ -933,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 ); };