]> git.mdlowis.com Git - archive/parse-utils.git/commitdiff
Updated lexer interface
authorMike D. Lowis <mike@mdlowis.com>
Fri, 9 Mar 2012 23:44:55 +0000 (18:44 -0500)
committerMike D. Lowis <mike@mdlowis.com>
Fri, 9 Mar 2012 23:44:55 +0000 (18:44 -0500)
source/lexer/ilexer.cpp
source/lexer/ilexer.h

index 25e260f694db0c16163b1ac4d806a87a3a4cf31e..b90320dcde58fcd7d746c32c2d8334362ac41592 100644 (file)
@@ -4,7 +4,7 @@
 
 using namespace std;
 
-ILexer::ILexer() : line(-1), column(-1)
+ILexer::ILexer(istream& in) : line(-1), column(-1), in_stream(in)
 {
 }
 
@@ -12,44 +12,20 @@ ILexer::~ILexer()
 {
 }
 
-void ILexer::setInput(char* in)
-{
-    line = 1;
-    column = 0;
-    input = new istringstream( string( in ) );
-    consume();
-}
-
-void ILexer::setInput(string& in)
-{
-    line = 1;
-    column = 0;
-    input = new istringstream( in );
-    consume();
-}
-
-void ILexer::setInput(istream* in)
-{
-    line = 1;
-    column = 0;
-    input = in;
-    consume();
-}
-
 bool ILexer::eof(void)
 {
-    return ((input == NULL) || (input->eof()));
+    return in_stream.eof();
 }
 
 void ILexer::consume(void)
 {
-    if(input->eof())
+    if(in_stream.eof())
     {
         current = EOF;
     }
     else
     {
-        current = input->get();
+        current = in_stream.get();
         if(current == '\n')
         {
             line++;
index d21768d57a921ced2edd0e4c0569ee062c6a13bf..7ad8198945223d492b7972bec34189ecc44f81c9 100644 (file)
@@ -12,20 +12,14 @@ class ILexer
         int line;
         int column;
         char current;
-        std::istream* input;
+        std::istream& in_stream;
 
     public:
-        ILexer();
+        ILexer(std::istream& in);
         virtual ~ILexer();
-
-        void setInput(char* in);
-        void setInput(std::string& in);
-        void setInput(std::istream* in);
-
         void consume(void);
         void match(char x);
         bool eof(void);
-
         virtual Token next(void) = 0;
 };