00001 #include <iostream>
00002 #include <fstream>
00003 #include <string>
00004 #include <ctype.h>
00005
00006 namespace fbwrap
00007 {
00008
00009 typedef SimList<string> SymList;
00010
00011 class Scanner
00012 {
00013 int line;
00014 int charpos;
00015 std::istream ∈
00016 virtual bool isword(char c)
00017 {
00018 return (isalnum(c) || c=='_' || c=='$');
00019 }
00020 void SkipComent();
00021 char lGet()
00022 {
00023 int c=in.get();
00024 charpos++;
00025 if(c=='\n')
00026 line++;
00027 return (char)c;
00028 }
00029 public:
00030 Scanner(std::istream &pIn)
00031 : in(pIn)
00032 {
00033 line=0;
00034 charpos=0;
00035 }
00036 char Get();
00037 void Putback(char c)
00038 {
00039 in.putback(c);
00040 charpos--;
00041 if(c=='\n')
00042 line--;
00043 }
00044 bool Eof()
00045 {
00046 return in.eof();
00047 }
00048 bool Check(const char *s);
00049 bool SeekChar(char c);
00050 void GetWORD(string &s);
00051 void GetSTRING(string &s);
00052 void SkipSp();
00053 int GetLine()
00054 {
00055 return line;
00056 }
00057 int GetPos()
00058 {
00059 return charpos;
00060 }
00061 void Reset()
00062 {
00063 charpos=line=0;
00064 }
00065 };
00066
00067 class SqlScript : public Scanner
00068 {
00069 public:
00070 enum StateEnum {st_init,st_empty,st_stmt,st_ok,st_error, st_end};
00071 enum TypeEnum {t_none,t_query,t_term,t_autoDDL,t_names,t_transaction,t_connect,t_edit};
00072 private:
00073 string sqlst;
00074 string Var;
00075 StateEnum state;
00076 char endchar;
00077 bool empty;
00078 TypeEnum stmtType;
00079 int linestart;
00080 public:
00081 SymList vars;
00082 SqlScript(std::istream &pIn);
00083 bool ScriptEnd()
00084 {
00085 return state==st_end;
00086 }
00087 string GetSqlText()
00088 {
00089 return sqlst;
00090 }
00091 int GetState()
00092 {
00093 return state;
00094 }
00095 string GetVar()
00096 {
00097 return Var;
00098 }
00099 int GetType()
00100 {
00101 return stmtType;
00102 }
00103 void Scan();
00104 int GetLineStart()
00105 {
00106 return linestart;
00107 }
00108 };
00109
00110 }
00111