00001 // 00002 // Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2004-2008 00003 // 00004 // Copyright: See COPYING file that comes with this distribution 00005 // 00006 00007 #ifndef HIGHLIGHTRULE_H_ 00008 #define HIGHLIGHTRULE_H_ 00009 00010 #include <string> 00011 #include <boost/shared_ptr.hpp> 00012 00013 #include "highlightstate.h" 00014 00015 namespace srchilite { 00016 00017 struct HighlightToken; 00018 struct MatchingParameters; 00019 00021 typedef std::deque<std::string> ElemList; 00022 00027 class HighlightRule { 00029 ElemList elemList; 00030 00033 HighlightStatePtr nextState; 00034 00036 std::string additionalInfo; 00037 00040 int exitLevel; 00041 00043 bool nested; 00044 00046 bool needsReferenceReplacement; 00047 00049 bool hasSubexpressions; 00050 00051 public: 00052 HighlightRule(); 00060 HighlightRule(const std::string &name); 00061 virtual ~HighlightRule(); 00062 00074 virtual bool tryToMatch(const std::string &s, HighlightToken &token, 00075 const MatchingParameters ¶ms); 00076 00086 virtual bool tryToMatch(std::string::const_iterator start, 00087 std::string::const_iterator end, HighlightToken &token, 00088 const MatchingParameters ¶ms) = 0; 00089 00090 virtual const std::string toString() const = 0; 00091 00098 virtual void replaceReferences(const ReplacementList &rep) = 0; 00099 00103 virtual HighlightRule *clone() = 0; 00104 00105 const HighlightStatePtr getNextState() const { 00106 return nextState; 00107 } 00108 void setNextState(HighlightStatePtr _nextState) { 00109 nextState = _nextState; 00110 } 00111 00116 void addElem(const std::string &name); 00117 00118 const ElemList &getElemList() const { 00119 return elemList; 00120 } 00121 00122 int getExitLevel() const { 00123 return exitLevel; 00124 } 00125 void setExitLevel(int l) { 00126 exitLevel = l; 00127 } 00128 00129 bool isNested() const { 00130 return nested; 00131 } 00132 void setNested(bool n) { 00133 nested = n; 00134 } 00135 00136 bool getNeedsReferenceReplacement() const { 00137 return needsReferenceReplacement; 00138 } 00139 00140 void setNeedsReferenceReplacement(bool b = true) { 00141 needsReferenceReplacement = b; 00142 } 00143 00144 bool getHasSubexpressions() const { 00145 return hasSubexpressions; 00146 } 00147 00148 void setHasSubexpressions(bool b = true) { 00149 hasSubexpressions = b; 00150 } 00151 00152 std::string getAdditionalInfo() const { 00153 return additionalInfo; 00154 } 00155 00156 void setAdditionalInfo(const std::string &info) { 00157 additionalInfo = info; 00158 } 00159 }; 00160 00161 } 00162 00163 #endif /*HIGHLIGHTRULE_H_*/