Source-highlight Library
srchilite::HighlightRule Class Reference

Base class for highlight rules. More...

#include <highlightrule.h>

Inheritance diagram for srchilite::HighlightRule:
Collaboration diagram for srchilite::HighlightRule:

List of all members.

Public Member Functions

 HighlightRule (const std::string &name)
 Creates a rule for the given element (Although each rule can concern more than one program element, we provide only this convenience constructor with only one name: if the rule concerns more than one element one can use addElem method)
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 tryToMatch below).
virtual bool tryToMatch (std::string::const_iterator start, std::string::const_iterator end, HighlightToken &token, const MatchingParameters &params)=0
 Try to match this rule against the passed string.
virtual const std::string toString () const =0
virtual void replaceReferences (const ReplacementList &rep)=0
 Performs replacement of references in this rule.
virtual HighlightRuleclone ()=0
const HighlightStatePtr getNextState () const
void setNextState (HighlightStatePtr _nextState)
void addElem (const std::string &name)
 Adds an element name to the list of this rule.
const ElemListgetElemList () const
int getExitLevel () const
void setExitLevel (int l)
bool isNested () const
void setNested (bool n)
bool getNeedsReferenceReplacement () const
void setNeedsReferenceReplacement (bool b=true)
bool getHasSubexpressions () const
void setHasSubexpressions (bool b=true)
std::string getAdditionalInfo () const
void setAdditionalInfo (const std::string &info)

Private Attributes

ElemList elemList
 the list of program elements detected by this rule
HighlightStatePtr nextState
 if set, it represents the state to enter if this rule matches this class does not delete nextState
std::string additionalInfo
 additional information about this rule
int exitLevel
 how many state must we exit if we match this rule: 0: none, -1: all, otherwise the number of states to exit
bool nested
 tells that if this rule matches we must enter the same state once again
bool needsReferenceReplacement
 whether this rule has dynamic references to be replaced
bool hasSubexpressions
 whether this rule can match subexpressions

Detailed Description

Base class for highlight rules.

This abstracts from the actual implementation for matching.


Constructor & Destructor Documentation

srchilite::HighlightRule::HighlightRule ( const std::string &  name)

Creates a rule for the given element (Although each rule can concern more than one program element, we provide only this convenience constructor with only one name: if the rule concerns more than one element one can use addElem method)

Parameters:
namethe element name of this rule

Member Function Documentation

void srchilite::HighlightRule::addElem ( const std::string &  name)

Adds an element name to the list of this rule.

Parameters:
namethe name to add
virtual HighlightRule* srchilite::HighlightRule::clone ( ) [pure virtual]
Returns:
a copy of this rule.

Implemented in srchilite::RegexHighlightRule.

virtual void srchilite::HighlightRule::replaceReferences ( const ReplacementList rep) [pure virtual]

Performs replacement of references in this rule.

Parameters:
thelist of values for the replacement; the first element is the value for replacing the first dynamic back reference, and so on. (it should contain 9 possibly empty elements)

Implemented in srchilite::RegexHighlightRule.

bool srchilite::HighlightRule::tryToMatch ( const std::string &  s,
HighlightToken token,
const MatchingParameters params 
) [virtual]

Try to match this rule against the passed string (implemented by calling the pure virtual function tryToMatch below).

The passed token is assumed to be reset (i.e., no existing matching information is stored in it when passing it to this method).

Parameters:
sthe string for trying to match the rule
tokenwhere results will be inserted, if the rule matched
paramsadditional arguments for the matching
Returns:
the result of this matching
virtual bool srchilite::HighlightRule::tryToMatch ( std::string::const_iterator  start,
std::string::const_iterator  end,
HighlightToken token,
const MatchingParameters params 
) [pure virtual]

Try to match this rule against the passed string.

Parameters:
startthe beginning of the string for trying to match the rule
endthe beginning of the string for trying to match the rule
tokenwhere results will be inserted, if the rule matched
paramsadditional arguments for the matching
Returns:
the result of this matching

Implemented in srchilite::RegexHighlightRule.


The documentation for this class was generated from the following files: