コード例 #1
0
ファイル: LexSpice.cpp プロジェクト: 6qat/robomongo
static void ColouriseWord(StyleContext& sc, WordList& keywords, WordList& keywords2, WordList& keywords3, bool& apostropheStartsAttribute) {
    apostropheStartsAttribute = true;
    sc.SetState(SCE_SPICE_IDENTIFIER);
    std::string word;
    while (!sc.atLineEnd && !IsSeparatorOrDelimiterCharacter(sc.ch)) {
        word += static_cast<char>(tolower(sc.ch));
        sc.Forward();
    }
    if (keywords.InList(word.c_str())) {
        sc.ChangeState(SCE_SPICE_KEYWORD);
        if (word != "all") {
            apostropheStartsAttribute = false;
        }
    }
    else if (keywords2.InList(word.c_str())) {
        sc.ChangeState(SCE_SPICE_KEYWORD2);
        if (word != "all") {
            apostropheStartsAttribute = false;
        }
    }
    else if (keywords3.InList(word.c_str())) {
        sc.ChangeState(SCE_SPICE_KEYWORD3);
        if (word != "all") {
            apostropheStartsAttribute = false;
        }
    }
    sc.SetState(SCE_SPICE_DEFAULT);
}
コード例 #2
0
ファイル: LexAda.cpp プロジェクト: 6VV/NewTeachingBox
static void ColouriseLabel(StyleContext& sc, WordList& keywords, bool& apostropheStartsAttribute) {
	apostropheStartsAttribute = false;

	sc.SetState(SCE_ADA_LABEL);

	// Skip "<<"
	sc.Forward();
	sc.Forward();

	std::string identifier;

	while (!sc.atLineEnd && !IsSeparatorOrDelimiterCharacter(sc.ch)) {
		identifier += static_cast<char>(tolower(sc.ch));
		sc.Forward();
	}

	// Skip ">>"
	if (sc.Match('>', '>')) {
		sc.Forward();
		sc.Forward();
	} else {
		sc.ChangeState(SCE_ADA_ILLEGAL);
	}

	// If the name is an invalid identifier or a keyword, then make it invalid label
	if (!IsValidIdentifier(identifier) || keywords.InList(identifier.c_str())) {
		sc.ChangeState(SCE_ADA_ILLEGAL);
	}

	sc.SetState(SCE_ADA_DEFAULT);

}
コード例 #3
0
static int classifyWordBullant(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler) {
  char s[100];
  s[0] = '\0';
  for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
    s[i] = static_cast<char>(tolower(styler[start + i]));
    s[i + 1] = '\0';
  }
  int lev= 0;
  char chAttr = SCE_C_IDENTIFIER;
  if (isdigit(s[0]) || (s[0] == '.')){
    chAttr = SCE_C_NUMBER;
  }
  else {
    if (keywords.InList(s)) {
      chAttr = SCE_C_WORD;
      if (strcmp(s, "end") == 0)
        lev = -1;
      else if (strcmp(s, "method") == 0 ||
        strcmp(s, "case") == 0 ||
        strcmp(s, "class") == 0 ||
        strcmp(s, "debug") == 0 ||
        strcmp(s, "test") == 0 ||
        strcmp(s, "if") == 0 ||
        strcmp(s, "lock") == 0 ||
        strcmp(s, "transaction") == 0 ||
        strcmp(s, "trap") == 0 ||
        strcmp(s, "until") == 0 ||
        strcmp(s, "while") == 0)
        lev = 1;
    }
  }
  styler.ColourTo(end, chAttr);
  return lev;
}
コード例 #4
0
ファイル: LexMagik.cpp プロジェクト: Snake174/PipmakAssistant
/**
 * This function detects keywords which are able to have a body. Note that it
 * uses the Fold Containers word description, not the containers description. It
 * only works when the style at that particular position is set on Containers
 * or Flow (number 3 or 4).
 *
 * \param  keywordslist The list of keywords that are scanned, they should only
 *         contain the start keywords, not the end keywords
 * \param  The actual keyword
 * \return 1 if it is a folding start-keyword, -1 if it is a folding end-keyword
 *         0 otherwise
 */
static inline int IsFoldingContainer(WordList &keywordslist, char * keyword) {
    if(
        strlen(keyword) > 3 &&
        keyword[0] == 'e' && keyword[1] == 'n' && keyword[2] == 'd') {
        if (keywordslist.InList(keyword + 3)) {
            return -1;
        }

    } else {
        if(keywordslist.InList(keyword)) {
            return 1;
        }
    }

    return 0;
}
コード例 #5
0
ファイル: LexScriptol.cpp プロジェクト: JowC9V/CLL-Synergie
static void ClassifyWordSol(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler, char *prevWord)
{
    char s[100];
    bool wordIsNumber = isdigit(styler[start]) != 0;
    for (unsigned int i = 0; i < end - start + 1 && i < 30; i++)
     {
           s[i] = styler[start + i];
           s[i + 1] = '\0';
     }
    char chAttr = SCE_SCRIPTOL_IDENTIFIER;
    if (0 == strcmp(prevWord, "class"))       chAttr = SCE_SCRIPTOL_CLASSNAME;
    else if (wordIsNumber)                    chAttr = SCE_SCRIPTOL_NUMBER;
    else if (keywords.InList(s))              chAttr = SCE_SCRIPTOL_KEYWORD;
    else for (unsigned int i = 0; i < end - start + 1; i++)  // test dotted idents
    {
        if (styler[start + i] == '.')
        {
            styler.ColourTo(start + i - 1, chAttr);
            styler.ColourTo(start + i, SCE_SCRIPTOL_OPERATOR);
        }
    }
    styler.ColourTo(end, chAttr);
    strcpy(prevWord, s);
}
コード例 #6
0
ファイル: LexYAML.cpp プロジェクト: JowC9V/CLL-Synergie
static void ColouriseYAMLLine(
	char *lineBuffer,
	unsigned int currentLine,
	unsigned int lengthLine,
	unsigned int startLine,
	unsigned int endPos,
	WordList &keywords,
	Accessor &styler) {

	unsigned int i = 0;
	bool bInQuotes = false;
	unsigned int indentAmount = SpaceCount(lineBuffer);

	if (currentLine > 0) {
		int parentLineState = styler.GetLineState(currentLine - 1);

		if ((parentLineState&YAML_STATE_MASK) == YAML_STATE_TEXT || (parentLineState&YAML_STATE_MASK) == YAML_STATE_TEXT_PARENT) {
			unsigned int parentIndentAmount = parentLineState&(~YAML_STATE_MASK);
			if (indentAmount > parentIndentAmount) {
				styler.SetLineState(currentLine, YAML_STATE_TEXT | parentIndentAmount);
				styler.ColourTo(endPos, SCE_YAML_TEXT);
				return;
			}
		}
	}
	styler.SetLineState(currentLine, 0);
	if (strncmp(lineBuffer, "---", 3) == 0) {	// Document marker
		styler.SetLineState(currentLine, YAML_STATE_DOCUMENT);
		styler.ColourTo(endPos, SCE_YAML_DOCUMENT);
		return;
	}
	// Skip initial spaces
	while ((i < lengthLine) && lineBuffer[i] == ' ') { // YAML always uses space, never TABS or anything else
		i++;
	}
	if (lineBuffer[i] == '\t') { // if we skipped all spaces, and we are NOT inside a text block, this is wrong
		styler.ColourTo(endPos, SCE_YAML_ERROR);
		return;
	}
	if (lineBuffer[i] == '#') {	// Comment
		styler.SetLineState(currentLine, YAML_STATE_COMMENT);
		styler.ColourTo(endPos, SCE_YAML_COMMENT);
		return;
	}
	while (i < lengthLine) {
		if (lineBuffer[i] == '\'' || lineBuffer[i] == '\"') {
			bInQuotes = !bInQuotes;
		} else if (lineBuffer[i] == ':' && !bInQuotes) {
			styler.ColourTo(startLine + i - 1, SCE_YAML_IDENTIFIER);
			styler.ColourTo(startLine + i, SCE_YAML_OPERATOR);
			// Non-folding scalar
			i++;
			while ((i < lengthLine) && isspacechar(lineBuffer[i]))
				i++;
			unsigned int endValue = lengthLine - 1;
			while ((endValue >= i) && isspacechar(lineBuffer[endValue]))
				endValue--;
			lineBuffer[endValue + 1] = '\0';
			if (lineBuffer[i] == '|' || lineBuffer[i] == '>') {
				i++;
				if (lineBuffer[i] == '+' || lineBuffer[i] == '-')
					i++;
				while ((i < lengthLine) && isspacechar(lineBuffer[i]))
					i++;
				if (lineBuffer[i] == '\0') {
					styler.SetLineState(currentLine, YAML_STATE_TEXT_PARENT | indentAmount);
					styler.ColourTo(endPos, SCE_YAML_DEFAULT);
					return;
				} else if (lineBuffer[i] == '#') {
					styler.SetLineState(currentLine, YAML_STATE_TEXT_PARENT | indentAmount);
					styler.ColourTo(startLine + i - 1, SCE_YAML_DEFAULT);
					styler.ColourTo(endPos, SCE_YAML_COMMENT);
					return;
				} else {
					styler.ColourTo(endPos, SCE_YAML_ERROR);
					return;
				}
			} else if (lineBuffer[i] == '#') {
				styler.ColourTo(startLine + i - 1, SCE_YAML_DEFAULT);
				styler.ColourTo(endPos, SCE_YAML_COMMENT);
				return;
			}
			styler.SetLineState(currentLine, YAML_STATE_VALUE);
			if (lineBuffer[i] == '&' || lineBuffer[i] == '*') {
				styler.ColourTo(endPos, SCE_YAML_REFERENCE);
				return;
			}
			if (keywords.InList(&lineBuffer[i])) { // Convertible value (true/false, etc.)
				styler.ColourTo(endPos, SCE_YAML_KEYWORD);
				return;
			} else {
				unsigned int i2 = i;
				while ((i < lengthLine) && lineBuffer[i]) {
					if (!(isascii(lineBuffer[i]) && isdigit(lineBuffer[i])) && lineBuffer[i] != '-' && lineBuffer[i] != '.' && lineBuffer[i] != ',') {
						styler.ColourTo(endPos, SCE_YAML_DEFAULT);
						return;
					}
					i++;
				}
				if (i > i2) {
					styler.ColourTo(endPos, SCE_YAML_NUMBER);
					return;
				}
			}
			break; // shouldn't get here, but just in case, the rest of the line is coloured the default
		}
		i++;
	}
	styler.ColourTo(endPos, SCE_YAML_DEFAULT);
}
コード例 #7
0
ファイル: LexVHDL.cpp プロジェクト: 6VV/NewTeachingBox
//=============================================================================
// Folding the code
static void FoldNoBoxVHDLDoc(
  unsigned int startPos,
  int length,
  int,
  Accessor &styler)
{
  // Decided it would be smarter to have the lexer have all keywords included. Therefore I
  // don't check if the style for the keywords that I use to adjust the levels.
  char words[] =
    "architecture begin block case component else elsif end entity generate loop package process record then "
    "procedure function when";
  WordList keywords;
  keywords.Set(words);

  bool foldComment      = styler.GetPropertyInt("fold.comment", 1) != 0;
  bool foldCompact      = styler.GetPropertyInt("fold.compact", 1) != 0;
  bool foldAtElse       = styler.GetPropertyInt("fold.at.else", 1) != 0;
  bool foldAtBegin      = styler.GetPropertyInt("fold.at.Begin", 1) != 0;
  bool foldAtParenthese = styler.GetPropertyInt("fold.at.Parenthese", 1) != 0;
  //bool foldAtWhen       = styler.GetPropertyInt("fold.at.When", 1) != 0;  //< fold at when in case statements

  int  visibleChars     = 0;
  unsigned int endPos   = startPos + length;

  int lineCurrent       = styler.GetLine(startPos);
  int levelCurrent      = SC_FOLDLEVELBASE;
  if(lineCurrent > 0)
    levelCurrent        = styler.LevelAt(lineCurrent-1) >> 16;
  //int levelMinCurrent   = levelCurrent;
  int levelMinCurrentElse = levelCurrent;   //< Used for folding at 'else'
  int levelMinCurrentBegin = levelCurrent;  //< Used for folding at 'begin'
  int levelNext         = levelCurrent;

  /***************************************/
  int lastStart         = 0;
  char prevWord[32]     = "";

  /***************************************/
  // Find prev word
  // The logic for going up or down a level depends on a the previous keyword
  // This code could be cleaned up.
  int end = 0;
  unsigned int j;
  for(j = startPos; j>0; j--)
  {
    char ch       = styler.SafeGetCharAt(j);
    char chPrev   = styler.SafeGetCharAt(j-1);
    int style     = styler.StyleAt(j);
    int stylePrev = styler.StyleAt(j-1);
    if ((!IsCommentStyle(style)) && (stylePrev != SCE_VHDL_STRING))
    {
      if(IsAWordChar(chPrev) && !IsAWordChar(ch))
      {
        end = j-1;
      }
    }
    if ((!IsCommentStyle(style)) && (style != SCE_VHDL_STRING))
    {
      if(!IsAWordChar(chPrev) && IsAWordStart(ch) && (end != 0))
      {
        char s[32];
        unsigned int k;
        for(k=0; (k<31 ) && (k<end-j+1 ); k++) {
          s[k] = static_cast<char>(tolower(styler[j+k]));
        }
        s[k] = '\0';

        if(keywords.InList(s)) {
          strcpy(prevWord, s);
          break;
        }
      }
    }
  }
  for(j=j+static_cast<unsigned int>(strlen(prevWord)); j<endPos; j++)
  {
    char ch       = styler.SafeGetCharAt(j);
    int style     = styler.StyleAt(j);
    if ((!IsCommentStyle(style)) && (style != SCE_VHDL_STRING))
    {
      if((ch == ';') && (strcmp(prevWord, "end") == 0))
      {
        strcpy(prevWord, ";");
      }
    }
  }

  char  chNext          = styler[startPos];
  char  chPrev          = '\0';
  char  chNextNonBlank;
  int   styleNext       = styler.StyleAt(startPos);
  //Platform::DebugPrintf("Line[%04d] Prev[%20s] ************************* Level[%x]\n", lineCurrent+1, prevWord, levelCurrent);

  /***************************************/
  for (unsigned int i = startPos; i < endPos; i++)
  {
    char ch         = chNext;
    chNext          = styler.SafeGetCharAt(i + 1);
    chPrev          = styler.SafeGetCharAt(i - 1);
    chNextNonBlank  = chNext;
    unsigned int j  = i+1;
    while(IsABlank(chNextNonBlank) && j<endPos)
    {
      j ++ ;
      chNextNonBlank = styler.SafeGetCharAt(j);
    }
    int style           = styleNext;
    styleNext       = styler.StyleAt(i + 1);
    bool atEOL      = (ch == '\r' && chNext != '\n') || (ch == '\n');

    if (foldComment && atEOL)
    {
      if(IsCommentLine(lineCurrent, styler))
      {
        if(!IsCommentLine(lineCurrent-1, styler) && IsCommentLine(lineCurrent+1, styler))
        {
          levelNext++;
        }
        else if(IsCommentLine(lineCurrent-1, styler) && !IsCommentLine(lineCurrent+1, styler))
        {
          levelNext--;
        }
      }
      else
      {
        if (IsCommentBlockStart(lineCurrent, styler) && !IsCommentBlockEnd(lineCurrent, styler))
        {
          levelNext++;
        }
        else if (IsCommentBlockEnd(lineCurrent, styler) && !IsCommentBlockStart(lineCurrent, styler))
        {
          levelNext--;
        }
      }
    }

    if ((style == SCE_VHDL_OPERATOR) && foldAtParenthese)
    {
      if(ch == '(') {
        levelNext++;
      } else if (ch == ')') {
        levelNext--;
      }
    }

    if ((!IsCommentStyle(style)) && (style != SCE_VHDL_STRING))
    {
      if((ch == ';') && (strcmp(prevWord, "end") == 0))
      {
        strcpy(prevWord, ";");
      }

      if(!IsAWordChar(chPrev) && IsAWordStart(ch))
      {
        lastStart = i;
      }

      if(IsAWordChar(ch) && !IsAWordChar(chNext)) {
        char s[32];
        unsigned int k;
        for(k=0; (k<31 ) && (k<i-lastStart+1 ); k++) {
          s[k] = static_cast<char>(tolower(styler[lastStart+k]));
        }
        s[k] = '\0';

        if(keywords.InList(s))
        {
          if (
            strcmp(s, "architecture") == 0  ||
            strcmp(s, "case") == 0          ||
            strcmp(s, "generate") == 0      ||
            strcmp(s, "block") == 0         ||
            strcmp(s, "loop") == 0          ||
            strcmp(s, "package") ==0        ||
            strcmp(s, "process") == 0       ||
            strcmp(s, "record") == 0        ||
            strcmp(s, "then") == 0)
          {
            if (strcmp(prevWord, "end") != 0)
            {
              if (levelMinCurrentElse > levelNext) {
                levelMinCurrentElse = levelNext;
              }
              levelNext++;
            }
          } else if (
            strcmp(s, "component") == 0      ||
            strcmp(s, "entity") == 0         ||
            strcmp(s, "configuration") == 0 )
          {
            if (strcmp(prevWord, "end") != 0 && lastStart)
            { // check for instantiated unit by backward searching for the colon.
              unsigned pos = lastStart;
              char chAtPos, styleAtPos;
              do{// skip white spaces
                pos--;
                styleAtPos = styler.StyleAt(pos);
                chAtPos = styler.SafeGetCharAt(pos);
              }while(pos>0 &&
                     (chAtPos == ' ' || chAtPos == '\t' ||
                      chAtPos == '\n' || chAtPos == '\r' ||
                      IsCommentStyle(styleAtPos)));

              // check for a colon (':') before the instantiated units "entity", "component" or "configuration". Don't fold thereafter.
              if (chAtPos != ':')
              {
                if (levelMinCurrentElse > levelNext) {
                  levelMinCurrentElse = levelNext;
                }
                levelNext++;
              }
            }
          } else if (
            strcmp(s, "procedure") == 0     ||
            strcmp(s, "function") == 0)
          {
            if (strcmp(prevWord, "end") != 0) // check for "end procedure" etc.
            { // This code checks to see if the procedure / function is a definition within a "package"
              // rather than the actual code in the body.
              int BracketLevel = 0;
              for(int pos=i+1; pos<styler.Length(); pos++)
              {
                int styleAtPos = styler.StyleAt(pos);
                char chAtPos = styler.SafeGetCharAt(pos);
                if(chAtPos == '(') BracketLevel++;
                if(chAtPos == ')') BracketLevel--;
                if(
                  (BracketLevel == 0) &&
                  (!IsCommentStyle(styleAtPos)) &&
                  (styleAtPos != SCE_VHDL_STRING) &&
                  !iswordchar(styler.SafeGetCharAt(pos-1)) &&
                  styler.Match(pos, "is") &&
                  !iswordchar(styler.SafeGetCharAt(pos+2)))
                {
                  if (levelMinCurrentElse > levelNext) {
                    levelMinCurrentElse = levelNext;
                  }
                  levelNext++;
                  break;
                }
                if((BracketLevel == 0) && (chAtPos == ';'))
                {
                  break;
                }
              }
            }

          } else if (strcmp(s, "end") == 0) {
            levelNext--;
          }  else if(strcmp(s, "elsif") == 0) { // elsif is followed by then so folding occurs correctly
            levelNext--;
          } else if (strcmp(s, "else") == 0) {
            if(strcmp(prevWord, "when") != 0)  // ignore a <= x when y else z;
            {
              levelMinCurrentElse = levelNext - 1;  // VHDL else is all on its own so just dec. the min level
            }
          } else if(
            ((strcmp(s, "begin") == 0) && (strcmp(prevWord, "architecture") == 0)) ||
            ((strcmp(s, "begin") == 0) && (strcmp(prevWord, "function") == 0)) ||
            ((strcmp(s, "begin") == 0) && (strcmp(prevWord, "procedure") == 0)))
          {
            levelMinCurrentBegin = levelNext - 1;
          }
          //Platform::DebugPrintf("Line[%04d] Prev[%20s] Cur[%20s] Level[%x]\n", lineCurrent+1, prevWord, s, levelCurrent);
          strcpy(prevWord, s);
        }
      }
    }
    if (atEOL) {
      int levelUse = levelCurrent;

      if (foldAtElse && (levelMinCurrentElse < levelUse)) {
        levelUse = levelMinCurrentElse;
      }
      if (foldAtBegin && (levelMinCurrentBegin < levelUse)) {
        levelUse = levelMinCurrentBegin;
      }
      int lev = levelUse | levelNext << 16;
      if (visibleChars == 0 && foldCompact)
        lev |= SC_FOLDLEVELWHITEFLAG;

      if (levelUse < levelNext)
        lev |= SC_FOLDLEVELHEADERFLAG;
      if (lev != styler.LevelAt(lineCurrent)) {
        styler.SetLevel(lineCurrent, lev);
      }
      //Platform::DebugPrintf("Line[%04d] ---------------------------------------------------- Level[%x]\n", lineCurrent+1, levelCurrent);
      lineCurrent++;
      levelCurrent = levelNext;
      //levelMinCurrent = levelCurrent;
      levelMinCurrentElse = levelCurrent;
      levelMinCurrentBegin = levelCurrent;
      visibleChars = 0;
    }
    /***************************************/
    if (!isspacechar(ch)) visibleChars++;
  }

  /***************************************/
//  Platform::DebugPrintf("Line[%04d] ---------------------------------------------------- Level[%x]\n", lineCurrent+1, levelCurrent);
}
コード例 #8
0
ファイル: model_edit.cpp プロジェクト: Nikitaterm/rdo_studio
void Model::onEditCompleteWord()
{
	if (!static_cast<ModelStyle*>(m_pStyle)->autoComplete.useAutoComplete)
		return;

	setFocus();
	std::string primaryKwList = getAllKW();
	WordList fullWordList;
	fullWordList.Set(primaryKwList.c_str());
	fullWordList.InList("");
	primaryKwList = "";

	typedef std::vector<std::string> string_list;

	class compareStringScintilla {
	public:
		bool operator()(std::string A, std::string B) {
			return CompareNCaseInsensitive(A.c_str(), B.c_str(), A.length()) < 0;
		}
	};

	compareStringScintilla functor;

	WordListUtil getList(fullWordList);
	string_list basicList = getList.getNearestWords(std::string());
	std::sort(basicList.begin(), basicList.end(), functor);
	for (string_list::const_iterator it = basicList.begin(); it != basicList.end(); ++it)
	{
		primaryKwList += *it;
		if (it != basicList.end() - 1)
		{
			primaryKwList += " ";
		}
	}
	char currentLine[8000];
	int line = getCurrentLineNumber();
	sendEditor(SCI_GETLINE, line, reinterpret_cast<long>(currentLine));

	int currentPos = getCurrentPos() - getPositionFromLine(line);
	currentLine[currentPos] = '\0';

	int startPos = currentPos;
	int identifierLength = 0;
	std::wstring wCurrentLine = rdo::locale::convertToWStr(currentLine);
	std::wstring::const_reverse_iterator wCharIt = wCurrentLine.rbegin();
	while (wCharIt != wCurrentLine.rend())
	{
		if (!rdo::gui::lexer::isIdentifier(*wCharIt))
			break;
		++identifierLength;
		++wCharIt;
	}
	startPos -= rdo::locale::convertFromWStr(wCurrentLine.substr(wCurrentLine.length() - identifierLength)).length();

	const char*  userPattern = currentLine + startPos;
	unsigned int userPatternLength = currentPos - startPos;

	string_list prioritySortedKwList = getList.getNearestWords(userPattern);
	if (prioritySortedKwList.empty())
	{
		prioritySortedKwList = basicList;
	}

	string_list::const_iterator it = prioritySortedKwList.begin();
	std::string stWord = *it;
	std::sort(prioritySortedKwList.begin(), prioritySortedKwList.end(), functor);

	std::string foundKeyWords = "";
	for (string_list::const_iterator it = prioritySortedKwList.begin(); it != prioritySortedKwList.end(); ++it) 
	{
		foundKeyWords += (*it);
		if (it != prioritySortedKwList.end() - 1)
		{
			foundKeyWords += " ";
		}
	}
	const char* list;

	if (static_cast<ModelStyle*>(m_pStyle)->autoComplete.showFullList)
	{
		list = primaryKwList.c_str();
	}
	else
	{
		list = foundKeyWords.c_str();
		if (!list)
		{
			list = primaryKwList.c_str();
		}
	}

	if (list) 
	{
		std::string startKeyWord       = "";
		std::string startKeyWordScroll = stWord;
		bool useReplace = false;
		if (foundKeyWords.c_str())
		{
			fullWordList.Clear();
			fullWordList.Set(foundKeyWords.c_str());
			fullWordList.InList("");
			startKeyWord = stWord;
			if (prioritySortedKwList.size() == 1 && userPatternLength <= startKeyWord.length() && boost::ifind_first(startKeyWord, userPattern).begin() == startKeyWord.begin())
			{
				useReplace = true;
			}
		}

		while (startKeyWord.find('?') != std::string::npos)
		{
			std::string::size_type pos1 = startKeyWord.find('?');
			std::string::size_type pos2 = startKeyWord.find(' ', pos1);
			startKeyWord.erase(pos1, pos2 - pos1);
		}
		while (startKeyWordScroll.find('?') != std::string::npos)
		{
			std::string::size_type pos1 = startKeyWordScroll.find('?');
			std::string::size_type pos2 = startKeyWordScroll.find(' ', pos1);
			startKeyWordScroll.erase(pos1, pos2 - pos1);
		}

		if (useReplace)
		{
			setSelection  (getCurrentPos(), getCurrentPos() - userPatternLength);
			replaceCurrent(QString::fromStdString(startKeyWord));
		}
		else
		{
			sendEditor      (SCI_AUTOCSHOW,   userPatternLength, (long)list);
			sendEditorString(SCI_AUTOCSELECT, 0, startKeyWord.c_str());
		}
	}
}
コード例 #9
0
//=============================================================================
// 折叠代码
static void FoldNoBoxMAXScriptDoc(
  unsigned int startPos,
  int length,
  int,
  Accessor &styler)
{
	char words[] =
		"begin case else if end undefined unsupplied then local global level with"
		"function fn when while at in to time animate exit do on off for about as"
		"where continue try catch set undo and or not true false for by";
	WordList keywords;
	keywords.Set(words);

	bool foldComment      = styler.GetPropertyInt("fold.comment", 1) != 0;
	bool foldCompact      = styler.GetPropertyInt("fold.compact", 1) != 0;
	bool foldAtElse       = styler.GetPropertyInt("fold.at.else", 1) != 0;
	bool foldAtBegin      = styler.GetPropertyInt("fold.at.Begin", 1) != 0;
	bool foldAtParenthese = styler.GetPropertyInt("fold.at.Parenthese", 1) != 0;
  
	int  visibleChars     = 0;
	unsigned int endPos   = startPos + length;

	int lineCurrent       = styler.GetLine(startPos);
	int levelCurrent      = SC_FOLDLEVELBASE;
	if(lineCurrent > 0)
		levelCurrent        = styler.LevelAt(lineCurrent-1) >> 16;
	//int levelMinCurrent   = levelCurrent;
	int levelMinCurrentElse = levelCurrent;   //< Used for folding at 'else'
	int levelMinCurrentBegin = levelCurrent;  //< Used for folding at 'begin'
	int levelNext         = levelCurrent;
  
    /***************************************/
	int lastStart         = 0;
	char prevWord[32]     = "";
	/***************************************/
	// Find prev word
	// The logic for going up or down a level depends on a the previous keyword
	// This code could be cleaned up.
	int end = 0;
	unsigned int j;
	for(j = startPos; j>0; j--)
	{
		char ch       = styler.SafeGetCharAt(j);
		char chPrev   = styler.SafeGetCharAt(j-1);
		int style     = styler.StyleAt(j);
		int stylePrev = styler.StyleAt(j-1);
		if ((stylePrev != SCE_MAXSCRIPT_COMMENT) && (stylePrev != SCE_MAXSCRIPT_STRING))
		{
			if(IsAWordChar(chPrev) && !IsAWordChar(ch))
			{
				end = j-1;
			}
		}
		if ((style != SCE_MAXSCRIPT_COMMENT) && (style != SCE_MAXSCRIPT_STRING))
		{
			if(!IsAWordChar(chPrev) && IsAWordStart(ch) && (end != 0))
			{
				char s[32];
				unsigned int k;
				for(k=0; (k<31 ) && (k<end-j+1 ); k++)
				{
					s[k] = static_cast<char>(tolower(styler[j+k]));
				}
				s[k] = '\0';

				if(keywords.InList(s))
				{
					strcpy(prevWord, s);
					break;
				}
			}
		}
	}
	for(j=j+static_cast<unsigned int>(strlen(prevWord)); j<endPos; j++)
	{
		char ch       = styler.SafeGetCharAt(j);
		int style     = styler.StyleAt(j);
		if ((style != SCE_VHDL_COMMENT) && (style != SCE_VHDL_STRING))
		{
			if((ch == ';') && (strcmp(prevWord, "end") == 0))
			{
				strcpy(prevWord, ";");
			}
		}
	}

	
	char  chNext          = styler[startPos];
	char  chPrev          = '\0';
	char  chNextNonBlank;
	int   styleNext       = styler.StyleAt(startPos);
	
  /***************************************/
	for (unsigned int i = startPos; i < endPos; i++)
	{
		char ch         = chNext;
		chNext          = styler.SafeGetCharAt(i + 1);
		chPrev          = styler.SafeGetCharAt(i - 1);
		chNextNonBlank  = chNext;
		unsigned int j  = i+1;
		while(IsABlank(chNextNonBlank) && j<endPos)
		{
			j ++ ;
			chNextNonBlank = styler.SafeGetCharAt(j);
		}
		int style           = styleNext;
		styleNext       = styler.StyleAt(i + 1);
		bool atEOL      = (ch == '\r' && chNext != '\n') || (ch == '\n');

		if (foldComment && atEOL && IsCommentLine(lineCurrent, styler))
		{
			if(!IsCommentLine(lineCurrent-1, styler) && IsCommentLine(lineCurrent+1, styler))
			{		
				levelNext++;
			}
			else if(IsCommentLine(lineCurrent-1, styler) && !IsCommentLine(lineCurrent+1, styler))
			{
				levelNext--;
			}
		}

		if ((style == SCE_VHDL_OPERATOR) && foldAtParenthese)
		{
			if(ch == '(')
			{
				levelNext++;
			}
			else if (ch == ')')
			{
				levelNext--;
			}
		}

		if ((style != SCE_VHDL_COMMENT) && (style != SCE_VHDL_STRING))
		{
			if((ch == ';') && (strcmp(prevWord, "end") == 0))
			{
				strcpy(prevWord, ";");
			}

			if(!IsAWordChar(chPrev) && IsAWordStart(ch))
			{
				lastStart = i;
			}

		  if(iswordchar(ch) && !iswordchar(chNext))
		  {
			char s[32];
			unsigned int k;
			for(k=0; (k<31 ) && (k<i-lastStart+1 ); k++)
			{
				s[k] = static_cast<char>(tolower(styler[lastStart+k]));
			}
			s[k] = '\0';

			if(keywords.InList(s))
			{
				if (
					strcmp(s, "architecture") == 0  ||
					strcmp(s, "case") == 0          ||
					strcmp(s, "component") == 0     ||
					strcmp(s, "entity") == 0        ||
					strcmp(s, "generate") == 0      ||
					strcmp(s, "loop") == 0          ||
					strcmp(s, "package") ==0        ||
					strcmp(s, "process") == 0       ||
					strcmp(s, "record") == 0        ||
					strcmp(s, "then") == 0)
				{
					if (strcmp(prevWord, "end") != 0)
					{
						if (levelMinCurrentElse > levelNext)
						{
							levelMinCurrentElse = levelNext;
						}
						levelNext++;
					}
				}
				else if (strcmp(s, "procedure") == 0 || strcmp(s, "function") == 0)
				{		
					if (strcmp(prevWord, "end") != 0) // check for "end procedure" etc.
					{ 	// This code checks to see if the procedure / function is a definition within a "package"
						// rather than the actual code in the body.
						int BracketLevel = 0;
						for(int j=i+1; j<styler.Length(); j++)
						{
							int LocalStyle = styler.StyleAt(j);
							char LocalCh = styler.SafeGetCharAt(j);
							if(LocalCh == '(') BracketLevel++;
							if(LocalCh == ')') BracketLevel--;
							if( (BracketLevel == 0) &&
								(LocalStyle != SCE_VHDL_COMMENT) &&
								(LocalStyle != SCE_VHDL_STRING) &&
								!iswordchar(styler.SafeGetCharAt(j-1)) &&
								styler.Match(j, "is") &&
								!iswordchar(styler.SafeGetCharAt(j+2)))
							{	
								if (levelMinCurrentElse > levelNext)
								{
									levelMinCurrentElse = levelNext;
								}
								levelNext++;
								break;
							}
							if((BracketLevel == 0) && (LocalCh == ';'))
							{
								break;
							}
						}
					}

				}
				else if (strcmp(s, "end") == 0)
				{
					levelNext--;
				}
				else if(strcmp(s, "elsif") == 0)
				{ // elsif is followed by then so folding occurs correctly
					levelNext--;
				}
				else if (strcmp(s, "else") == 0)
				{
					if(strcmp(prevWord, "when") != 0)  // ignore a <= x when y else z;
					{
					  levelMinCurrentElse = levelNext - 1;  // VHDL else is all on its own so just dec. the min level
					}
				 }
				 else if(
					((strcmp(s, "begin") == 0) && (strcmp(prevWord, "architecture") == 0)) ||
					((strcmp(s, "begin") == 0) && (strcmp(prevWord, "function") == 0)) ||
					((strcmp(s, "begin") == 0) && (strcmp(prevWord, "procedure") == 0)))
				{
					levelMinCurrentBegin = levelNext - 1;
				}
				  //Platform::DebugPrintf("Line[%04d] Prev[%20s] Cur[%20s] Level[%x]\n", lineCurrent+1, prevWord, s, levelCurrent);
				  strcpy(prevWord, s);
				}
			}
		}
		if (atEOL)
		{
			int levelUse = levelCurrent;

			if (foldAtElse && (levelMinCurrentElse < levelUse))
			{
				levelUse = levelMinCurrentElse;
			}
			if (foldAtBegin && (levelMinCurrentBegin < levelUse))
			{
				levelUse = levelMinCurrentBegin;
			}
			int lev = levelUse | levelNext << 16;
			if (visibleChars == 0 && foldCompact)
			lev |= SC_FOLDLEVELWHITEFLAG;

			if (levelUse < levelNext)
			lev |= SC_FOLDLEVELHEADERFLAG;
			if (lev != styler.LevelAt(lineCurrent))
			{
				styler.SetLevel(lineCurrent, lev);
			}
			//Platform::DebugPrintf("Line[%04d] ---------------------------------------------------- Level[%x]\n", lineCurrent+1, levelCurrent);
			lineCurrent++;
			levelCurrent = levelNext;
			//levelMinCurrent = levelCurrent;
			levelMinCurrentElse = levelCurrent;
			levelMinCurrentBegin = levelCurrent;
			visibleChars = 0;
		}
		/***************************************/
		if (!isspacechar(ch)) visibleChars++;
	} 	// end for
}