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

State highlight::CodeGenerator::getCurrentState (  )  [private]

return new state

TODO COMMENT ... END 2 eintraege in langdef (ML_COMMENT_START=regex(), ML_COMMENT_END=regex()) weil comment sonst als identifier erkannt wird

Definition at line 436 of file codegenerator.cpp.

References StringTools::change_case(), currentKeywordClass, getInputChar(), getState(), highlight::LanguageDefinition::getSymbolString(), highlight::LanguageDefinition::isIgnoreCase(), highlight::LanguageDefinition::isKeyword(), langInfo, line, lineIndex, regexGroups, and token.

Referenced by processDirectiveState(), processEscapeCharState(), processKeywordState(), processMultiLineCommentState(), processNumberState(), processRootState(), processSingleLineCommentState(), processStringState(), and processSymbolState().

      {

            unsigned char c='\0';

            if ( token.length() ==0 )
            {
                  c=getInputChar();
            }
            else
            {
                  lineIndex-= ( token.length()-1 );
                  c=token[0];
            }
            if ( c=='\n' )
            {
                  return _EOL;   // End of line
            }

            if ( c=='\0' )
            {
                  return _EOF;   // End of file
            }

//  if (iswspace(c)) {
            if ( c==' ' || c=='\t' )
            {
                  token= c;
                  return _WS;
            }

            /** TODO
                COMMENT ... END 2 eintraege in langdef (ML_COMMENT_START=regex(), ML_COMMENT_END=regex())
                weil comment sonst als identifier erkannt wird
            */

            // Test if a regular expression was found at the current position
            if ( !regexGroups.empty() )
            {
                  if ( regexGroups.count ( lineIndex ) )
                  {
                        token = line.substr ( lineIndex-1, regexGroups[lineIndex].length );
                        unsigned int oldIndex= lineIndex;
                        if ( regexGroups[oldIndex].length>1 ) lineIndex+= regexGroups[lineIndex].length-1;

                        if ( regexGroups[oldIndex].state==IDENTIFIER_BEGIN || regexGroups[oldIndex].state==KEYWORD )
                        {
                              string reservedWord= ( langInfo.isIgnoreCase() ) ? StringTools::change_case ( token ) :token;
                              currentKeywordClass=langInfo.isKeyword ( reservedWord );
                              if ( !currentKeywordClass && regexGroups[oldIndex].state==KEYWORD )
                                    currentKeywordClass = regexGroups[oldIndex].kwClass;
                              return ( currentKeywordClass ) ? KEYWORD : STANDARD;
                        }
                        else
                        {
                              return regexGroups[oldIndex].state;
                        }
                  }
            }

            unsigned int symbolLength;
            size_t symbolPos;
            size_t symbolFind;
            string symbols=langInfo.getSymbolString();

            //TODO this while loop kills performance - adjust search algorithm

            symbolPos = symbols.find ( c );
            // search symbols (comment delimiters, directives etc.)
            // before keywords, because alphabetic chars may be part of symbols, too
            while ( symbolPos!= string::npos )
            {
                  symbolFind = symbols.find ( ' ', symbolPos );
                  if ( symbolFind==string::npos ) break;
                  symbolLength=symbolFind-symbolPos;
                  token = symbols.substr ( symbolPos, symbolLength );
                  // Abfrage nach Leerzeichen in SymbolString verhindert falsches
                  // Erkennen von Symbolteilen:
                  if ( lineIndex && token == line.substr ( lineIndex-1, symbolLength )
                          && symbols[symbolPos-1]==' ' )
                  {
                        lineIndex += ( symbolLength-1 );
                        return getState ( symbols, symbolPos );
                  }
                  else
                  {
                        symbolPos = symbols.find_first_not_of ( ' ',symbols.find ( ' ',symbolPos ) );
                  }
            }

            // Character not referring to any state
            token = c;
            return STANDARD;
      }


Generated by  Doxygen 1.6.0   Back to index