00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(_XRB_DATAFILESCANNER_HPP_)
00012 #define _XRB_DATAFILESCANNER_HPP_
00013
00014 #include "xrb.hpp"
00015
00016 #include <fstream>
00017 #include <string>
00018
00019 #include "xrb_datafileparser.h"
00020
00021 namespace Xrb
00022 {
00023
00024 class DataFileLocation;
00025 class DataFileValue;
00026
00027 class DataFileScanner
00028 {
00029 public:
00030
00031 DataFileScanner ();
00032 ~DataFileScanner ();
00033
00034 inline bool IsOpen () { return m_input.is_open(); }
00035 inline std::string const &InputPath () const { return m_input_path; }
00036 inline Uint32 LineNumber () const { return m_line_number; }
00037 inline bool WereWarningsEncountered () const { return m_were_warnings_encountered; }
00038 inline bool WereErrorsEncountered () const { return m_were_errors_encountered; }
00039
00040 bool Open (std::string const &input_path);
00041 void Close ();
00042
00043 void EmitWarning (std::string const &message);
00044 void EmitWarning (DataFileLocation const &file_location, std::string const &message);
00045
00046 void EmitError (std::string const &message);
00047 void EmitError (DataFileLocation const &file_location, std::string const &message);
00048
00049 DataFileParser::Token::Type Scan (DataFileValue **scanned_token);
00050
00051 private:
00052
00053 DataFileParser::Token::Type ScanIdentifier (DataFileValue **scanned_token);
00054 DataFileParser::Token::Type ScanOperator (DataFileValue **scanned_token);
00055 DataFileParser::Token::Type ScanNumeric (DataFileValue **scanned_token);
00056 DataFileParser::Token::Type ScanBinaryNumeric (DataFileValue **scanned_token, bool is_signed, bool is_positive);
00057 DataFileParser::Token::Type ScanOctalNumeric (DataFileValue **scanned_token, bool is_signed, bool is_positive, char first_char);
00058 DataFileParser::Token::Type ScanDecimalNumeric (DataFileValue **scanned_token, bool is_signed, bool is_positive, char first_char);
00059 DataFileParser::Token::Type ScanHexadecimalNumeric (DataFileValue **scanned_token, bool is_signed, bool is_positive);
00060 DataFileParser::Token::Type ScanFloatingPointNumeric (DataFileValue **scanned_token);
00061 DataFileParser::Token::Type ScanCharacterLiteral (DataFileValue **scanned_token);
00062 DataFileParser::Token::Type ScanStringLiteral (DataFileValue **scanned_token);
00063
00064 void ScanComment ();
00065
00066 inline bool IsNextCharEOF (char *c = NULL)
00067 {
00068 if (c != NULL)
00069 *c = m_input.peek();
00070 return m_input.peek() == EOF;
00071 }
00072
00073 std::string m_input_path;
00074 std::ifstream m_input;
00075 std::string m_text;
00076 Uint32 m_line_number;
00077 bool m_were_warnings_encountered;
00078 bool m_were_errors_encountered;
00079 };
00080
00081 }
00082
00083 #endif // !defined(_XRB_DATAFILESCANNER_HPP_)