Logo Search packages:      
Sourcecode: highlight version File versions  Download package

void highlight::CodeGenerator::matchRegex ( const string &  line  )  [private]

test for regular expressions

Parameters:
line current input line

Definition at line 375 of file codegenerator.cpp.

References highlight::RegexElement::capturingGroup, Pattern::createMatcher(), highlight::LanguageDefinition::getRegexElements(), highlight::RegexElement::kwClass, langInfo, highlight::RegexElement::open, regexGroups, and highlight::RegexElement::rePattern.

Referenced by getInputChar().

      {

            regexGroups.clear();
            int matchBegin=0;
            int matchLen=0;
            int groupID=0;
            // cycle through all regex, save the start and ending indices to report them later
            for ( unsigned int i=0; i<langInfo.getRegexElements().size(); i++ )
            {
                  RegexElement *regexElem = langInfo.getRegexElements() [i];
                  auto_ptr<Matcher> matcher ( regexElem->rePattern->createMatcher ( line ) );
                  while ( matcher->findNextMatch() )
                  {
                        groupID = ( regexElem->capturingGroup<0 ) ? matcher->getGroupNum()-1 : regexElem->capturingGroup;
                        matchBegin =  matcher->getStartingIndex ( groupID );
                        if ( matchBegin<0 ) continue;
                        matchLen = matcher->getEndingIndex ( groupID ) - matchBegin;
                        /*
                                    std::cerr << "\nmatchBegin="<<1+ matchBegin
                                              << " matchLen old" << ( matcher->getGroup(matcher->getGroupNum()-1).size())
                                              << " matchLen new" << matchLen<<" group: "<<(matcher->getGroup(matcher->getGroupNum()-1))
                                              << " group id= "<<regexElem->groupID<<"\n";
                        */
                        regexGroups.insert (
                            make_pair ( matchBegin+1, ReGroup ( regexElem->open, matchLen, regexElem->kwClass ) ) );
                  }
            }
      }


Generated by  Doxygen 1.6.0   Back to index