Moved scanner class into a new header rlscan.h.
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Tue, 13 Mar 2007 17:31:39 +0000 (17:31 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Tue, 13 Mar 2007 17:31:39 +0000 (17:31 +0000)
git-svn-id: http://svn.complang.org/ragel/trunk@142 052ea7fc-9027-0410-9066-f65837a77df0

ragel/main.cpp
ragel/ragel.h
ragel/rlscan.h [new file with mode: 0644]
ragel/rlscan.rl

index 1cb43d6..597297c 100644 (file)
@@ -29,6 +29,7 @@
 
 /* Parsing. */
 #include "ragel.h"
+#include "rlscan.h"
 
 /* Parameters and output. */
 #include "pcheck.h"
@@ -297,7 +298,8 @@ int main(int argc, char **argv)
        if ( machineSpec == 0 && machineName == 0 )
                outputBuffer << "<host line=\"1\" col=\"1\">";
 
-       scan( inputFileName, *inStream, outputBuffer );
+       Scanner scanner( inputFileName, *inStream, outputBuffer, 0, 0, 0 );
+       scanner.do_scan();
 
        /* Finished, final check for errors.. */
        if ( gblErrorCount > 0 )
index 3a6ee81..7264135 100644 (file)
@@ -67,7 +67,6 @@ std::ostream &error();
 std::ostream &error( const InputLoc &loc ); 
 std::ostream &warning( const InputLoc &loc ); 
 
-void scan( char *fileName, std::istream &input, std::ostream &output );
 void terminateAllParsers( );
 void writeMachines( std::ostream &out, std::string hostData, char *inputFileName );
 void xmlEscapeHost( std::ostream &out, char *data, int len );
diff --git a/ragel/rlscan.h b/ragel/rlscan.h
new file mode 100644 (file)
index 0000000..b23017e
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ *  Copyright 2007 Adrian Thurston <thurston@cs.queensu.ca>
+ */
+
+/*  This file is part of Ragel.
+ *
+ *  Ragel is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ * 
+ *  Ragel is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ * 
+ *  You should have received a copy of the GNU General Public License
+ *  along with Ragel; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+ */
+
+#ifndef _RLSCAN_H
+#define _RLSCAN_H
+
+#include <iostream>
+#include "rlscan.h"
+#include "vector.h"
+#include "rlparse.h"
+#include "parsedata.h"
+#include "avltree.h"
+#include "vector.h"
+
+using std::istream;
+using std::ostream;
+
+extern char *Parser_lelNames[];
+
+/* This is used for tracking the current stack of include file/machine pairs. It is
+ * is used to detect and recursive include structure. */
+struct IncludeStackItem
+{
+       IncludeStackItem( char *fileName, char *sectionName )
+               : fileName(fileName), sectionName(sectionName) {}
+
+       char *fileName;
+       char *sectionName;
+};
+
+typedef Vector<IncludeStackItem> IncludeStack;
+
+struct Scanner
+{
+       Scanner( char *fileName, istream &input, ostream &output,
+                       Parser *inclToParser, char *inclSectionTarg,
+                       int includeDepth )
+       : 
+               fileName(fileName), input(input), output(output),
+               inclToParser(inclToParser),
+               inclSectionTarg(inclSectionTarg),
+               includeDepth(includeDepth),
+               line(1), column(1), lastnl(0), 
+               parser(0), ignoreSection(false), 
+               parserExistsError(false),
+               whitespaceOn(true),
+               lastToken(0)
+               {}
+
+       bool recursiveInclude( char *inclFileName, char *inclSectionName );
+
+       char *prepareFileName( char *fileName, int len )
+       {
+               bool caseInsensitive;
+               Token tokenFnStr, tokenRes;
+               tokenFnStr.data = fileName;
+               tokenFnStr.length = len;
+               tokenFnStr.prepareLitString( tokenRes, caseInsensitive );
+               return tokenRes.data;
+       }
+
+       void init();
+       void token( int type, char *start, char *end );
+       void token( int type, char c );
+       void token( int type );
+       void updateCol();
+       void startSection();
+       void endSection();
+       void do_scan();
+       bool active();
+       ostream &scan_error();
+
+       char *fileName;
+       istream &input;
+       ostream &output;
+       Parser *inclToParser;
+       char *inclSectionTarg;
+       int includeDepth;
+
+       int cs;
+       int line;
+       char *word, *lit;
+       int word_len, lit_len;
+       InputLoc sectionLoc;
+       char *tokstart, *tokend;
+       int column;
+       char *lastnl;
+
+       /* Set by machine statements, these persist from section to section
+        * allowing for unnamed sections. */
+       Parser *parser;
+       bool ignoreSection;
+       IncludeStack includeStack;
+
+       /* 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;
+
+       /* This is for inline code. By default it is on. It goes off for
+        * statements and values in inline blocks which are parsed. */
+       bool whitespaceOn;
+
+       /* Keeps a record of the previous token sent to the section parser. */
+       int lastToken;
+};
+
+#endif /* _RLSCAN_H */
index ece2a74..cc2fd12 100644 (file)
 #include <string.h>
 
 #include "ragel.h"
-#include "rlparse.h"
-#include "parsedata.h"
-#include "avltree.h"
-#include "vector.h"
+#include "rlscan.h"
 
 using std::ifstream;
 using std::istream;
@@ -36,101 +33,12 @@ using std::cout;
 using std::cerr;
 using std::endl;
 
-extern char *Parser_lelNames[];
-
-/* This is used for tracking the current stack of include file/machine pairs. It is
- * is used to detect and recursive include structure. */
-struct IncludeStackItem
-{
-       IncludeStackItem( char *fileName, char *sectionName )
-               : fileName(fileName), sectionName(sectionName) {}
-
-       char *fileName;
-       char *sectionName;
-};
-
-typedef Vector<IncludeStackItem> IncludeStack;
-
 enum InlineBlockType
 {
        CurlyDelimited,
        SemiTerminated
 };
 
-struct Scanner
-{
-       Scanner( char *fileName, istream &input, ostream &output,
-                       Parser *inclToParser, char *inclSectionTarg,
-                       int includeDepth )
-       : 
-               fileName(fileName), input(input), output(output),
-               inclToParser(inclToParser),
-               inclSectionTarg(inclSectionTarg),
-               includeDepth(includeDepth),
-               line(1), column(1), lastnl(0), 
-               parser(0), ignoreSection(false), 
-               parserExistsError(false),
-               whitespaceOn(true),
-               lastToken(0)
-               {}
-
-       bool recursiveInclude( char *inclFileName, char *inclSectionName );
-
-       char *prepareFileName( char *fileName, int len )
-       {
-               bool caseInsensitive;
-               Token tokenFnStr, tokenRes;
-               tokenFnStr.data = fileName;
-               tokenFnStr.length = len;
-               tokenFnStr.prepareLitString( tokenRes, caseInsensitive );
-               return tokenRes.data;
-       }
-
-       void init();
-       void token( int type, char *start, char *end );
-       void token( int type, char c );
-       void token( int type );
-       void updateCol();
-       void startSection();
-       void endSection();
-       void do_scan();
-       bool active();
-       ostream &scan_error();
-
-       char *fileName;
-       istream &input;
-       ostream &output;
-       Parser *inclToParser;
-       char *inclSectionTarg;
-       int includeDepth;
-
-       int cs;
-       int line;
-       char *word, *lit;
-       int word_len, lit_len;
-       InputLoc sectionLoc;
-       char *tokstart, *tokend;
-       int column;
-       char *lastnl;
-
-       /* Set by machine statements, these persist from section to section
-        * allowing for unnamed sections. */
-       Parser *parser;
-       bool ignoreSection;
-       IncludeStack includeStack;
-
-       /* 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;
-
-       /* This is for inline code. By default it is on. It goes off for
-        * statements and values in inline blocks which are parsed. */
-       bool whitespaceOn;
-
-       /* Keeps a record of the previous token sent to the section parser. */
-       int lastToken;
-};
-
 %%{
        machine section_parse;
        alphtype int;
@@ -282,7 +190,6 @@ void Scanner::token( int type )
 
                                Scanner scanner( inclFileName, *inFile, output, parser,
                                                inclSectionName, includeDepth+1 );
-                               scanner.init();
                                scanner.do_scan( );
                                delete inFile;
                        }
@@ -844,6 +751,8 @@ void Scanner::do_scan()
        bool singleLineSpec = false;
        InlineBlockType inlineBlockType = CurlyDelimited;
 
+       /* Init the section parser and the character scanner. */
+       init();
        %% write init;
 
        while ( execute ) {
@@ -914,12 +823,4 @@ void Scanner::do_scan()
 
 void scan( char *fileName, istream &input, ostream &output )
 {
-       Scanner scanner( fileName, input, output, 0, 0, 0 );
-       scanner.init();
-       scanner.do_scan();
-
-       InputLoc eofLoc;
-       eofLoc.fileName = fileName;
-       eofLoc.col = 1;
-       eofLoc.line = scanner.line;
 }