Source-highlight Library
highlightrule.h
1 //
2 // Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2004-2008
3 //
4 // Copyright: See COPYING file that comes with this distribution
5 //
6 
7 #ifndef HIGHLIGHTRULE_H_
8 #define HIGHLIGHTRULE_H_
9 
10 #include <string>
11 #include <boost/shared_ptr.hpp>
12 
13 #include "highlightstate.h"
14 
15 namespace srchilite {
16 
17 struct HighlightToken;
19 
21 typedef std::deque<std::string> ElemList;
22 
29  ElemList elemList;
30 
34 
36  std::string additionalInfo;
37 
40  int exitLevel;
41 
43  bool nested;
44 
47 
50 
51 public:
52  HighlightRule();
60  HighlightRule(const std::string &name);
61  virtual ~HighlightRule();
62 
74  virtual bool tryToMatch(const std::string &s, HighlightToken &token,
75  const MatchingParameters &params);
76 
86  virtual bool tryToMatch(std::string::const_iterator start,
87  std::string::const_iterator end, HighlightToken &token,
88  const MatchingParameters &params) = 0;
89 
90  virtual const std::string toString() const = 0;
91 
98  virtual void replaceReferences(const ReplacementList &rep) = 0;
99 
103  virtual HighlightRule *clone() = 0;
104 
105  const HighlightStatePtr getNextState() const {
106  return nextState;
107  }
108  void setNextState(HighlightStatePtr _nextState) {
109  nextState = _nextState;
110  }
111 
116  void addElem(const std::string &name);
117 
118  const ElemList &getElemList() const {
119  return elemList;
120  }
121 
122  int getExitLevel() const {
123  return exitLevel;
124  }
125  void setExitLevel(int l) {
126  exitLevel = l;
127  }
128 
129  bool isNested() const {
130  return nested;
131  }
132  void setNested(bool n) {
133  nested = n;
134  }
135 
136  bool getNeedsReferenceReplacement() const {
138  }
139 
140  void setNeedsReferenceReplacement(bool b = true) {
141  needsReferenceReplacement = b;
142  }
143 
144  bool getHasSubexpressions() const {
145  return hasSubexpressions;
146  }
147 
148  void setHasSubexpressions(bool b = true) {
149  hasSubexpressions = b;
150  }
151 
152  std::string getAdditionalInfo() const {
153  return additionalInfo;
154  }
155 
156  void setAdditionalInfo(const std::string &info) {
157  additionalInfo = info;
158  }
159 };
160 
161 }
162 
163 #endif /*HIGHLIGHTRULE_H_*/
virtual void replaceReferences(const ReplacementList &rep)=0
Performs replacement of references in this rule.
std::string additionalInfo
additional information about this rule
Definition: highlightrule.h:36
Structure for passing parameters to the matching algorithm, for instance, "not beginning of line"...
Definition: matchingparameters.h:16
bool nested
tells that if this rule matches we must enter the same state once again
Definition: highlightrule.h:43
HighlightStatePtr nextState
if set, it represents the state to enter if this rule matches this class does not delete nextState ...
Definition: highlightrule.h:33
virtual bool tryToMatch(const std::string &s, HighlightToken &token, const MatchingParameters &params)
Try to match this rule against the passed string (implemented by calling the pure virtual function tr...
Definition: highlightrule.cpp:34
C++ class: doctemplate.h.
Definition: bufferedoutput.cpp:13
void addElem(const std::string &name)
Adds an element name to the list of this rule.
Definition: highlightrule.cpp:30
ElemList elemList
the list of program elements detected by this rule
Definition: highlightrule.h:29
Base class for highlight rules.
Definition: highlightrule.h:27
int exitLevel
how many state must we exit if we match this rule: 0: none, -1: all, otherwise the number of states t...
Definition: highlightrule.h:40
boost::shared_ptr< HighlightState > HighlightStatePtr
the reference to an HighlightState
Definition: highlightstate.h:38
std::vector< std::string > ReplacementList
the values for replacing references (it should contain 9 possibly empty elements, because 9 is usuall...
Definition: highlightstate.h:36
Token containing information for performing the highlight.
Definition: highlighttoken.h:33
std::deque< std::string > ElemList
list representing the names of parts of a program
Definition: highlightrule.h:18
virtual HighlightRule * clone()=0
bool needsReferenceReplacement
whether this rule has dynamic references to be replaced
Definition: highlightrule.h:46
bool hasSubexpressions
whether this rule can match subexpressions
Definition: highlightrule.h:49