Ejemplo n.º 1
0
    void LmdbLexer::styleText(int start, int end)
    {
        if(!editor()){
            return;
        }

        char *data = new char[end - start + 1];
        editor()->SendScintilla(QsciScintilla::SCI_GETTEXTRANGE, start, end, data);
        QString source(data);
        delete [] data;

        if(source.isEmpty()){
            return;
        }

        paintCommands(source, start);

        int index = 0;
        int begin = 0;
        while( (begin = source.indexOf(help, index, Qt::CaseInsensitive)) != -1){
            index = begin + help.length();

            startStyling(start + begin);
            setStyling(help.length(), HelpKeyword);
            startStyling(start + begin);
        }
    }
Ejemplo n.º 2
0
    void LeveldbLexer::paintCommands(const QString& source, int start)
    {
        for(int i = 0; i < SIZEOFMASS(leveldbCommandsKeywords); ++i){
            QString word = leveldbCommandsKeywords[i];
            int index = 0;
            int begin = 0;
            while( (begin = source.indexOf(word, index, Qt::CaseInsensitive)) != -1){
                index = begin + word.length();

                startStyling(start + begin);
                setStyling(word.length(), Command);
                startStyling(start + begin);
            }
        }
    }
Ejemplo n.º 3
0
void BaseQsciLexerCommandHolder::paintCommands(const QString& source, int start) {
  for (size_t i = 0; i < commands_.size(); ++i) {
    core::CommandInfo cmd = commands_[i];
    QString word = common::ConvertFromString<QString>(cmd.name);
    int index = 0;
    int begin = 0;
    while ((begin = source.indexOf(word, index, Qt::CaseInsensitive)) != -1) {
      index = begin + word.length();

      startStyling(start + begin);
      setStyling(word.length(), Command);
      startStyling(start + begin);
    }
  }
}
Ejemplo n.º 4
0
    void RedisLexer::paintSentinelCommands(const QString& source, int start)
    {
        for(std::vector<QString>::const_iterator it = redisSentinelKeywords.begin(); it != redisSentinelKeywords.end(); ++it){
            QString word = *it;
            int index = 0;
            int begin = 0;
            while( (begin = source.indexOf(word, index, Qt::CaseInsensitive)) != -1){
                index = begin + word.length();

                startStyling(start + begin);
                setStyling(word.length(), Sentinel);
                startStyling(start + begin);
            }
        }
    }
Ejemplo n.º 5
0
    void LmdbLexer::paintCommands(const QString& source, int start)
    {
        for(int i = 0; i < SIZEOFMASS(lmdbCommands); ++i){
            CommandInfo cmd = lmdbCommands[i];
            QString word = common::convertFromString<QString>(cmd.name_);
            int index = 0;
            int begin = 0;
            while( (begin = source.indexOf(word, index, Qt::CaseInsensitive)) != -1){
                index = begin + word.length();

                startStyling(start + begin);
                setStyling(word.length(), Command);
                startStyling(start + begin);
            }
        }
    }
Ejemplo n.º 6
0
void BaseCommandsQsciLexer::paintCommands(const QString& source, int start) {
  for (size_t i = 0; i < commands_.size(); ++i) {
    core::CommandInfo cmd = commands_[i];
    QString word;
    if (common::ConvertFromString(cmd.name, &word)) {
      int index = 0;
      int begin = 0;

      int st = cmd.type == core::CommandInfo::Native ? Command : ExCommand;
      while ((begin = source.indexOf(word, index, Qt::CaseInsensitive)) != -1) {
        index = begin + word.length();

        startStyling(start + begin);
        setStyling(word.length(), st);
        startStyling(start + begin);
      }
    }
  }
}
Ejemplo n.º 7
0
void QsciLexerBin::styleText(int start, int end)
{
   // Reset line styling.
   startStyling(start,0xFF);
   setStyling(end-start,Bin_Default);
}
Ejemplo n.º 8
0
void QsciLexerDefault::styleText(int start, int end)
{
   startStyling(start,0xFF);
   setStyling(end-start,Default_Default);
}
Ejemplo n.º 9
0
void LatexLexer::styleText(int start,int end)
{
    // Ajouter support verbatim
    // Colorier les erreurs de syntaxe
    if (!editor())
        return;

    char *lineChars = new char[end - start+1];
    editor()->SendScintilla(QsciScintilla::SCI_GETTEXTRANGE, start, end, lineChars);
    QString source = QString(lineChars);
    free(lineChars);

    startStyling(start,0xFF);
    QStringList list=source.split('\n');
    int lineIndex=editor()->SendScintilla(QsciScintilla::SCI_LINEFROMPOSITION, start);

    int style=Default,nextStyle=Default;
    if(lineIndex>0){
        int pos = editor()->SendScintilla(QsciScintilla::SCI_GETLINEENDPOSITION, lineIndex-1 );
        if(pos>0){
            int s = editor()->SendScintilla(QsciScintilla::SCI_GETSTYLEAT, pos);
            if(s==MathInline || s==MathDisplay || s==Environment){
                style=s;
                nextStyle=s;
            }
        }
    }

    int level=QsciScintilla::SC_FOLDLEVELBASE;
    if(lineIndex>0){
        QString previousLine = getLine(lineIndex-1);
        level=(editor()->SendScintilla(QsciScintilla::SCI_GETFOLDLEVEL,lineIndex-1)&QsciScintilla::SC_FOLDLEVELNUMBERMASK)+getDiffLevel(previousLine);
    }

    int nbCharsToStyle;
    int styleBeforeMathDisplay=Default,styleBeforeMathInline=Default,styleInBrace=Default,styleBeforeBrace=Default;
    for (int i = 0; i < list.size(); i++) {
        QString line=list.at(i);
        int lineLength=line.size();
        if(style!=MathInline && style!=MathDisplay && style!=Environment){
            style=Default;
            nextStyle=Default;
        }
        int j=0;
        while(j<lineLength){
            QString l=line.mid(j);
            if(l.startsWith("\\%")){
                nbCharsToStyle=2;
                nextStyle=style;
                style=Command;
            }
            else if(l.startsWith("%")){
                nbCharsToStyle=lineLength-j;
                style=Comment;
                nextStyle=Comment;
            }
            else if(l.startsWith("\\[")){
                nbCharsToStyle=2;
                styleBeforeMathDisplay=style;
                style=Command;
                nextStyle=MathDisplay;
            }
            else if(l.startsWith("\\]")){
                nbCharsToStyle=2;
                style=Command;
                nextStyle=styleBeforeMathDisplay;
            }
            else if(l.startsWith("\\(")){
                nbCharsToStyle=2;
                styleBeforeMathInline=style;
                style=Command;
                nextStyle=MathInline;
            }
            else if(l.startsWith("\\)")){
                nbCharsToStyle=2;
                style=Command;
                nextStyle=styleBeforeMathInline;
            }
            else if(l.startsWith("\\$") || l.startsWith("\\{") || l.startsWith("\\}")){
                nbCharsToStyle=2;
                nextStyle=style;
                style=Command;
            }
            else if(l.startsWith("\\")){
                nbCharsToStyle=1;
                nextStyle=style;
                while(nbCharsToStyle<l.size() && l.at(nbCharsToStyle).isLetter()){
                    nbCharsToStyle++;
                }
                QString s=l.left(nbCharsToStyle);
                if(s=="\\begin" || s=="\\end"){
                    styleInBrace=Environment;
                }
                else if(s=="\\part"){
                    styleInBrace=Part;
                }
                else if(s=="\\chapter"){
                    styleInBrace=Chapter;
                }
                else if(s=="\\section"){
                    styleInBrace=Section;
                }
                else if(s=="\\subsection"){
                    styleInBrace=SubSection;
                }
                else if(s=="\\subsubsection"){
                    styleInBrace=SubSubSection;
                }
                else if(s=="\\paragraph"){
                    styleInBrace=Paragraph;
                }
                else if(s=="\\subparagraph"){
                    styleInBrace=SubParagraph;
                }
                style=Command;
            }
            else if(l.startsWith("$")){
                nbCharsToStyle=1;
                if(style==MathInline){
                    nextStyle=styleBeforeMathInline;
                }
                else{
                    styleBeforeMathInline=style;
                    nextStyle=MathInline;
                }
                style=SpecialChar;
            }
            else if(l.at(0).isDigit()){
                bool isNumber=true;
                nbCharsToStyle=1;
                nextStyle=style;
                while(isNumber && nbCharsToStyle<l.size()){
                    nbCharsToStyle++;
                    l.left(nbCharsToStyle).toFloat(&isNumber);
                }
                if(!isNumber){
                    nbCharsToStyle--;
                }
                style=Digit;
            }
            else if(l.startsWith("(")||l.startsWith(")")||l.startsWith("[")||l.startsWith("]")||l.startsWith("&")||l.startsWith("#")){
                nbCharsToStyle=1;
                nextStyle=style;
                style=SpecialChar;
            }
            else if(l.startsWith("{")){
                nbCharsToStyle=1;
                styleBeforeBrace=style;
                nextStyle=styleInBrace;
                style=SpecialChar;
            }
            else if(l.startsWith("}")){
                nbCharsToStyle=1;
                nextStyle=styleBeforeBrace;
                style=SpecialChar;
                styleInBrace=Default;
            }
            else{
                nbCharsToStyle=1;
                if(l.at(0)!=' '){
                    styleInBrace=style;
                }
            }
            setStyling(nbCharsToStyle,defaultStyle(style));
            style=nextStyle;
            j+=nbCharsToStyle;

        }
        setStyling(1,defaultStyle(style));


        QString s=trimComment(line);
        if(s.contains("\\part")){
            level=2000;

        }
        else if(s.contains("\\chapter")){
            level=2001;

        }
        else if(s.contains("\\section")){
            level=2002;

        }
        else if(s.contains("\\subsection")){
            level=2003;

        }
        else if(s.contains("\\subsubsection")){
            level=2004;

        }
        else if(s.contains("\\paragraph")){
            level=2005;

        }
        else if(s.contains("\\subparagraph")){
            level=2006;

        }
        if(isHeaderLine(s)){
            editor()->SendScintilla(QsciScintilla::SCI_SETFOLDLEVEL,lineIndex,level|QsciScintilla::SC_FOLDLEVELHEADERFLAG);
        }
        /*
        else if(line.trimmed().isEmpty()){
            editor()->SendScintilla(QsciScintilla::SCI_SETFOLDLEVEL,lineIndex,level|QsciScintilla::SC_FOLDLEVELWHITEFLAG);
        }
        */
        else{
            editor()->SendScintilla(QsciScintilla::SCI_SETFOLDLEVEL,lineIndex,level);

        }
        level+=getDiffLevel(s);

        lineIndex++;
    }
}
Ejemplo n.º 10
0
void QsciLexerCA65::styleText(int start, int end)
{
   QByteArray   chars;
   QString      text;
   QStringList  lines;
   int          pos;
   int          lineLength;
   int          lineNum;
   int          index;

   // Reset line styling.
   startStyling(start,0xFF);
   setStyling(end-start,CA65_Default);

   // Get the text that is being styled.
   chars.reserve((end-start)+1);
   editor()->SendScintilla(QsciScintilla::SCI_GETTEXTRANGE,start,end,chars.data());

   // Get the starting line index from the position.
   editor()->lineIndexFromPosition(start,&lineNum,&index);

   // Break the text into line chunks.
   text = chars.constData();
   lines = text.split(QRegExp("(\r|\n)"));

   // Style the lines.
   foreach ( const QString& line, lines )
   {
      // Get current line length.
      lineLength = editor()->lineLength(lineNum);

      if ( lineLength )
      {
         // Look for opcodes.
         pos = line.indexOf(opcodeRegex);
         if ( pos != -1 )
         {
            startStyling(start+pos,0xFF);
            setStyling(3,CA65_Opcode);
         }

         // Look for numbers.
         pos = 0;
         do
         {
            pos = line.indexOf(numberRegex,pos);
            if ( pos != -1 )
            {
               startStyling(start+pos,0xFF);
               setStyling(numberRegex.matchedLength(),CA65_Number);
               pos = pos+numberRegex.matchedLength();
            }
         } while ( pos != -1 );

         // Look for labels.
         pos = 0;
         do
         {
            pos = line.indexOf(labelRegex,pos);
            if ( pos != -1 )
            {
               QString leading_space = labelRegex.cap( 1 );
               QString label         = labelRegex.cap( 2 );
               startStyling(start+pos+leading_space.length(),0xFF);
               setStyling(label.length(),CA65_Label);
               pos = pos+labelRegex.matchedLength();

            }
         } while ( pos != -1 );

         // Look for quoted strings.
         pos = 0;
         do
         {
            pos = line.indexOf(QRegExp("\\\".*\\\""),pos);
            if ( pos != -1 )
            {
               startStyling(start+pos,0xFF);
               setStyling(line.indexOf('\"',pos+1)-pos+1,CA65_QuotedString);
               pos = line.indexOf('\"',pos+1)+1;
            }
         } while ( pos != -1 );
         pos = 0;
         do
         {
            pos = line.indexOf(QRegExp("\\\'.*\\\'"),pos);
            if ( pos != -1 )
            {
               startStyling(start+pos,0xFF);
               setStyling(line.indexOf('\'',pos+1)-pos+1,CA65_QuotedString);
               pos = line.indexOf('\'',pos+1)+1;
            }
         } while ( pos != -1 );

         // Look for keywords.
         pos = line.indexOf(keywordRegex);
         if ( pos != -1 )
         {
            startStyling(start+pos,0xFF);
            setStyling(keywordRegex.matchedLength(),CA65_Keyword);
         }

         // Look for comments. (Wash styling of comment over any previously applied).
         pos = line.indexOf(';');
         if ( pos != -1 )
         {
            startStyling(start+pos,0xFF);
            setStyling(lineLength-pos,CA65_Comment);
         }
      }

      start += lineLength;
      lineNum++;
   }