1 /* 2 * This file is part of the FortranProject plugin for Code::Blocks IDE 3 * and licensed under the GNU General Public License, version 3 4 * http://www.gnu.org/licenses/gpl-3.0.html 5 */ 6 7 #ifndef FTOKINIZER_H 8 #define FTOKINIZER_H 9 10 #include <sdk.h> 11 #ifndef CB_PRECOMP 12 #include <wx/string.h> 13 14 #include <filemanager.h> 15 #endif 16 #include <vector> 17 18 //bool cbRead(wxFile& file,wxString& st); 19 20 // Writes a wxString to a non-unicode file. File must be open. File is closed automatically. 21 //bool cbWrite(wxFile& file, const wxString& buff); 22 23 bool ReadFileToString(wxFile& file,wxString& st); 24 25 enum FortranSourceForm 26 { 27 fsfFixed=0, 28 fsfFree, 29 }; 30 31 class Tokenizerf 32 { 33 public: 34 Tokenizerf(const wxString& filename = wxEmptyString, FortranSourceForm sourceForm = fsfFree); 35 ~Tokenizerf(); 36 37 bool Init(const wxString& filename, FortranSourceForm sourceForm); 38 bool InitFromBuffer(const wxString& buffer, FortranSourceForm sourceForm); 39 wxString GetToken(); 40 wxString GetTokenSameLine(); 41 wxString GetTokenSameFortranLine(); 42 wxString PeekToken(); 43 wxString PeekTokenSameFortranLine(); GetFilename()44 const wxString& GetFilename(){ return m_Filename; } GetLineNumber()45 unsigned int GetLineNumber(){ return m_LineNumber; } GetPeekedLineNumber()46 unsigned int GetPeekedLineNumber(){ return m_PeekedLineNumber; } GetCurrentIndex()47 unsigned int GetCurrentIndex(){ return m_TokenIndex; } GetLineCount()48 unsigned int GetLineCount(){ return m_LineStartIdx.size(); } IsOK()49 bool IsOK(){ return m_IsOK; } 50 bool SkipToOneOfChars(const char* chars, bool toLineEnd = false); 51 wxArrayString GetTokensToEOL(wxArrayString* arrStrLines = 0); 52 wxArrayString PeekTokensToEOL(); 53 wxString GetCurrentLine(); 54 wxString GetLineFortran(); 55 wxString GetLine(unsigned int nl); 56 unsigned int GetLineStartIndex(unsigned int indexInLine); 57 unsigned int GetLineEndIndex(unsigned int indexInLine); 58 void SetDetailedParsing(bool detPars); 59 void SetFilename(const wxString& filename); 60 void UngetToken(); 61 bool SkipToEOL(); 62 protected: 63 void BaseInit(); 64 wxString DoGetToken(); 65 bool ReadFile(); 66 bool SkipWhiteSpace(); 67 bool SkipToChar(const wxChar& ch, bool toLineEnd = false); 68 bool SkipBlock(const wxChar& ch, int maxLines = 0); 69 bool SkipUnwanted(); // skips comments, assignments, preprocessor etc. IsEOF()70 bool IsEOF(){ return m_TokenIndex >= m_BufferLen; } 71 bool MoveToNextChar(); 72 void AdjustLineNumber(); 73 wxChar CurrentChar(); 74 wxChar NextChar(); 75 wxChar PreviousChar(); 76 bool IsBindTo(); 77 private: 78 bool CharInString(const char ch, const char* chars); 79 wxString m_Filename; 80 wxString m_Buffer; 81 unsigned int m_BufferLen; 82 unsigned int m_TokenIndex; 83 unsigned int m_UndoTokenIndex; 84 unsigned int m_PeekedTokenIndex; 85 unsigned int m_LineNumber; 86 unsigned int m_LineNumberStart; 87 unsigned int m_UndoLineNumber; 88 unsigned int m_UndoLineNumberStart; 89 unsigned int m_PeekedLineNumber; 90 unsigned int m_PeekedLineNumberStart; 91 unsigned int m_Column; 92 unsigned int m_UndoColumn; 93 unsigned int m_PeekedColumn; 94 bool m_WasNextLine; 95 bool m_UndoWasNextLine; 96 bool m_PeekedWasNextLine; 97 bool m_WasPeeked; 98 bool m_IsOK; 99 FortranSourceForm m_SourceForm; 100 wxString m_PeekedToken; 101 bool m_DetailedParsing; 102 std::vector<unsigned int> m_LineStartIdx; 103 }; 104 105 #endif // FTOKINIZER_H 106