| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #ifndef __PFILE_PARSER_H__ | ||
| 8 | #define __PFILE_PARSER_H__ | ||
| 9 | |||
| 10 | #include <iostream> | ||
| 11 | #include <vector> | ||
| 12 | #include <map> | ||
| 13 | |||
| 14 | #include "PPath.h" | ||
| 15 | |||
| 16 | #include "PParseSeqDef.h" | ||
| 17 | #include "PLocation.h" | ||
| 18 | |||
| 19 | ///@brief classe qui permet de parser des fichiers texte en renvoyant les tokens les uns après les autres | ||
| 20 | class PFileParser{ | ||
| 21 | public: | ||
| 22 | PFileParser(); | ||
| 23 | virtual ~PFileParser(); | ||
| 24 | |||
| 25 | bool open(const PPath & fileName); | ||
| 26 | |||
| 27 | void setWhiteSpace(const PString & whiteSpace); | ||
| 28 | void setSeparator(const PString & separator); | ||
| 29 | void setFileContent(const PString & fileContent); | ||
| 30 | void setEscapeChar(char escapeChar); | ||
| 31 | void setLocation(const PLocation & location); | ||
| 32 | void setCurrentCharIdx(size_t index); | ||
| 33 | void setLine(size_t currentLine); | ||
| 34 | void setColumn(size_t currentCol); | ||
| 35 | bool isEndOfFile() const; | ||
| 36 | |||
| 37 | void pushPosition(); | ||
| 38 | void popPosition(); | ||
| 39 | void clearPosition(); | ||
| 40 | |||
| 41 | bool isChSpace() const; | ||
| 42 | bool isChSeparator() const; | ||
| 43 | char getEscapeChar() const; | ||
| 44 | |||
| 45 | PPath getFileName() const; | ||
| 46 | PString getNextToken(); | ||
| 47 | PString getNextToken(PString & skippedStr); | ||
| 48 | |||
| 49 | char getNextChar(); | ||
| 50 | |||
| 51 | PString getUntilKey(const PString & patern); | ||
| 52 | PString getUntilKeyWithoutPatern(const PString & patern); | ||
| 53 | PString getUntilKeyWithoutPaternExclude(const PString & patern, const PString & strNotBeforeEndPatern); | ||
| 54 | PString getUntilKeyWithoutPaternRecurse(const PString & patern, const PString & beginPatern, const PString & allowedCharAfterBegin); | ||
| 55 | PString getUntilKeyWithoutPaternRecurseExclude(const PString & patern, const PString & beginPatern, | ||
| 56 | const PString & echapExpr); | ||
| 57 | PString getUntilKeyWithoutPaternRecurse(const PString & patern, const PString & beginPatern); | ||
| 58 | PString getStrComposedOf(const PString & charset); | ||
| 59 | PString getCurrentRow() const; | ||
| 60 | |||
| 61 | bool isMatch(const PString & patern); | ||
| 62 | bool isMatchRewind(const PString & patern); | ||
| 63 | bool isMatchSeq(const PVecString & patern, bool alwaysPopBack = false); | ||
| 64 | bool isMatch(const PString & patern, const PString & forbiddenCharBefore); | ||
| 65 | bool isMatchToken(const PString & patern); | ||
| 66 | PString isMatch(const PVecString & patern); | ||
| 67 | PString isMatchToken(const PVecString & patern); | ||
| 68 | |||
| 69 | template<typename T> | ||
| 70 | bool isMatchToken(PString & matchKey, T & matchValue, const std::map<PString, T> & patern); | ||
| 71 | |||
| 72 | PString isMatch(const std::vector<PVecString > & patern); | ||
| 73 | PString isMatch(const PParseSeq & seq); | ||
| 74 | |||
| 75 | bool isWhiteSpace(); | ||
| 76 | void skipWhiteSpace(); | ||
| 77 | void skipChars(const PString & chToSkip); | ||
| 78 | PString getWhiteSpace() const; | ||
| 79 | PString getSeparator() const; | ||
| 80 | char getCurrentCh() const; | ||
| 81 | char getPrevCh() const; | ||
| 82 | char getChar(size_t index) const; | ||
| 83 | size_t getLine() const; | ||
| 84 | size_t getColumn() const; | ||
| 85 | |||
| 86 | size_t getNbTotalChar() const; | ||
| 87 | size_t getCurrentCharIdx() const; | ||
| 88 | size_t getLineIndentation(); | ||
| 89 | |||
| 90 | PLocation getLocation() const; | ||
| 91 | |||
| 92 | friend std::ostream & operator << (std::ostream & out, const PFileParser & other); | ||
| 93 | |||
| 94 | void incrementCurrentChar(size_t nbChar = 1lu); | ||
| 95 | private: | ||
| 96 | void initialisationPFileParser(); | ||
| 97 | void incrementCurrentLine(); | ||
| 98 | ///Nom du fichier que l'on veut parser | ||
| 99 | PPath p_fileName; | ||
| 100 | ///Contenu du fichier de configuration | ||
| 101 | PString p_fileContent; | ||
| 102 | ///Numéro du caractère courant | ||
| 103 | size_t p_currentChar; | ||
| 104 | ///Nombre de caractères total | ||
| 105 | size_t p_nbTotalChar; | ||
| 106 | ///Numéro de la ligne courante | ||
| 107 | size_t p_currentLine; | ||
| 108 | ///Number of the first column caracter of the current line | ||
| 109 | size_t p_currentLineFirstColumn; | ||
| 110 | ///liste des espaces blancs | ||
| 111 | PString p_listWhiteSpace; | ||
| 112 | ///liste des séparateurs | ||
| 113 | PString p_listSeparator; | ||
| 114 | ///Echap caracter | ||
| 115 | char p_echapChar; | ||
| 116 | ///Vector of all the checkpoint positions in the text file (added with pushPosition() and removed with popPosition() or clear() | ||
| 117 | std::vector<size_t> p_vecPosition; | ||
| 118 | ///Vector of all the checkpoint rows in the text file (added with pushPosition() and removed with popPosition() or clear() | ||
| 119 | std::vector<size_t> p_vecLine; | ||
| 120 | ///Say if we don't want to skip the spaces | ||
| 121 | bool p_dontSkipSpace; | ||
| 122 | ///True if the current char is escaped | ||
| 123 | bool p_currentCharEchaped; | ||
| 124 | }; | ||
| 125 | |||
| 126 | #include "PFileParser_impl.h" | ||
| 127 | |||
| 128 | #endif | ||
| 129 |