00001 #ifndef lexer_h
00002 #define lexer_h
00003
00004 #include "file.h"
00005 #include "error.h"
00006
00008
00009 class Lexer
00010 {
00011 private:
00012 File in;
00013 File out;
00014
00015 bool eof_reached;
00016
00017 int line_number;
00018 int cursor_pos;
00019
00020 std::string current_dir;
00021
00022 public:
00023 Lexer( File in, File out, std::string current_dir = "");
00024
00025 void lex();
00026
00027 class Error;
00028
00029 class cannot_open_file;
00030
00031 class cannot_create_file;
00032
00033 private:
00034 std::string read_line();
00035
00037 std::string::size_type find_tag( std::string line, std::string::size_type startpos );
00038
00040 std::string::size_type find_end_of_tag( std::string line, std::string::size_type startpos );
00041
00043 std::string get_tag( std::string line, std::string::size_type startpos );
00044 };
00045
00047 class Lexer::Error : public :: Error
00048 {
00049 public:
00050 template <class T>Error( std::string error_string, T what )
00051 : ::Error( Line(), "Lexer", error_string, what )
00052 {}
00053 };
00054
00056 class Lexer::cannot_open_file : public Lexer::Error
00057 {
00058 public:
00059 template <class T>cannot_open_file( T what )
00060 : Error( _("cannot open file"), what )
00061 {}
00062 };
00063
00065 class Lexer::cannot_create_file : public Lexer::Error
00066 {
00067 public:
00068 template <class T>cannot_create_file( T what )
00069 : Error( _("cannot create file"), what )
00070 {}
00071 };
00072
00073 #endif