Exemple #1
0
//---------------------------------------------------------------------------
bool __fastcall Parser::Execute(bool paint)
{
  //parse lists
  tasklist.sort();
  tasklistprior.sort();
  upperbound = parent->GetActLine() + PARSEINADVANCE;

  bool painted = false;

  int parsed = 0;
  bool endValid = false;
  while(tasklistprior.size() > 0 || (tasklist.size() > 0 && (tasklist.front().linenum < upperbound || tasklist.front().line->parserState.parseid != currentparseid)) )
  {
    ParseTask pt;
    if(tasklistprior.size() > 0)
    {
      pt = tasklistprior.front();
    }
    else
    {
      pt = tasklist.front();
    }
    linenum = parent->GetLineNum(pt.line);
    bool first = true;
    painted = linenum >= 0 | painted;
    Iter * itr = new Iter(pt.line, linenum >= 0 ? parent->itrLine.linenum+linenum : pt.linenum, 0, parent->buffer);
    state = itr->line->parserState;

    if(itr->linenum == 1)
      state.parseid = currentparseid;
    else if(itr->line != NULL && itr->line->prevline != NULL)
      state.parseid = itr->line->prevline->parserState.parseid;

    if(linenum >= 0)
    {
      ReconstructMarkup();
      actIMarkup = itr->ReconstructIMarkFontStyle();
      actMarkupCombined = actMarkup;
      actMarkupCombined += actIMarkup;
      itr->UpdateNextImark();
    }

    if(state.searchStateStack.top == NULL)
      state.searchStateStack.Push(langdef->GetDefSC(0));
    //LanguageDefinition::SearchIter * searchiter = &state.searchStateStack.top->data;  //now passed directly - no need to keep it
    actFormat = *state.searchStateStack.top->data.base->format;

    tasklistprior.remove(pt);
    tasklist.remove(pt);



    while(itr->word->next && (first || itr->line->parserState != this->state || tasklistprior.front().line == itr->line))
    {
      //take care of record from list
      newline = true;
      first = false;
      //take care of line
      if(itr->line->prevline != NULL) //otherwise sets a format to the first line -> changing langdef will never iterate change in buffer
        itr->line->parserState = this->state;

      tasklistprior.remove(pt);
      tasklist.remove(pt);

      // parent->Log(String("parsing line ")+String(itr->linenum));
      ParseLine(itr, &state.searchStateStack.top->data, linenum >= 0);

      endValid = itr->GoChar();
      if(linenum >= 0)
      {
        //FlushAll();
        painted = true;
        linenum = parent->GetLineNum(itr->line);
      }
      else if(parent->IsLineFirstVisible(itr->line))
      {
        itr->linenum = parent->GetActLine();
        ReconstructMarkup();
        actIMarkup = itr->ReconstructIMarkFontStyle();
        actMarkupCombined = actMarkup;
        actMarkupCombined += actIMarkup;
        itr->UpdateNextImark();

        linenum = 0;
      }
      pt.linenum++;
      pt.line = itr->line;
      parsed++;

      //if(!(linenum >= 0 && linenum <= parent->GetVisLineCount() && itr->line->parserState != this->state) && tasklistprior.size() > 0 )
      if(linenum < 0 && (tasklistprior.size() > 0 || itr->linenum > upperbound || parsed > PARSEINONEGO))
      {
        if(itr->word->next != NULL && itr->line->parserState != this->state)
        {
          this->tasklist.push_front(ParseTask(itr->line, itr->linenum));
        }
        itr->line->parserState = this->state;
        break;
      }
    }
    if(!itr->word->next && linenum >= 0)
    {
      if(first)  //means line has not been either parsed or flushed, because iter was already on nextline (empty line) //well I no longer understand purpose of this, but let's consider, that the tail of buffer has to be explicitly flushed to the drawer
        FlushAll();
      SendEof();
    }

    if(itr->word->next == NULL && endValid) //when last line is empty line, then parseline would not get assigned
      itr->line->parserState = this->state;  //beware - you do not want to assign state into wrong line (when iter could go no further

    //parent->Log(String("parsed to line ")+String(itr->linenum));
    delete itr;

    if((painted || parsed > PARSEINONEGO) && tasklistprior.size() == 0)
    {
      if(painted && paint)
      {
        drawer->Paint();
      }
      if(parsed > PARSEINONEGO)
      {
        if(!onidleset)
        {
          oldidle = Application->OnIdle;
          Application->OnIdle = OnIdle;
          onidleset = true;
        }
        return false;
      }
      parsed = 0;
    }
  }

  return true;
}