Source-highlight Library
srchilite::RegexHighlightRule Class Reference

An implementation of HighlightRule using Boost regex library. More...

#include <regexhighlightrule.h>

Inheritance diagram for srchilite::RegexHighlightRule:
Collaboration diagram for srchilite::RegexHighlightRule:

Public Member Functions

 RegexHighlightRule (const std::string &s)
 
 RegexHighlightRule (const std::string &name, const std::string &s)
 
virtual bool tryToMatch (std::string::const_iterator start, std::string::const_iterator end, HighlightToken &token, const MatchingParameters &params)
 Try to match this rule against the passed string. More...
 
virtual const std::string toString () const
 
virtual void replaceReferences (const ReplacementList &rep)
 Performs replacement of references in this rule. More...
 
virtual HighlightRuleclone ()
 
void setRegExp (const std::string &s)
 
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). More...
 
const HighlightStatePtr getNextState () const
 
void setNextState (HighlightStatePtr _nextState)
 
void addElem (const std::string &name)
 Adds an element name to the list of this rule. More...
 
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

boost::regex regExp
 the regular expression for the rule
 
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

An implementation of HighlightRule using Boost regex library.

Constructor & Destructor Documentation

◆ RegexHighlightRule() [1/2]

srchilite::RegexHighlightRule::RegexHighlightRule ( const std::string &  s)
Parameters
sthe string representing the regular expression

◆ RegexHighlightRule() [2/2]

srchilite::RegexHighlightRule::RegexHighlightRule ( const std::string &  name,
const std::string &  s 
)
Parameters
namethe element name represented by this rule
sthe string representing the regular expression

Member Function Documentation

◆ addElem()

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

Adds an element name to the list of this rule.

Parameters
namethe name to add

◆ clone()

HighlightRule * srchilite::RegexHighlightRule::clone ( )
virtual
Returns
a copy of this rule.

Implements srchilite::HighlightRule.

◆ replaceReferences()

void srchilite::RegexHighlightRule::replaceReferences ( const ReplacementList rep)
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)

Implements srchilite::HighlightRule.

◆ tryToMatch() [1/2]

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

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

◆ tryToMatch() [2/2]

bool srchilite::RegexHighlightRule::tryToMatch ( std::string::const_iterator  start,
std::string::const_iterator  end,
HighlightToken token,
const MatchingParameters params 
)
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

Implements srchilite::HighlightRule.


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