Ejemplo n.º 1
0
static void Colourise_Doc(unsigned int startPos, int length, int, WordList *keywordLists[], Accessor &styler)
{
    int state = sID::DEFAULT;
    char chNext = styler[startPos];
    int lengthDoc = startPos + length;
    // create a buffer large enough to take the largest chunk...
    char *buffer = new char[length];
    int bufferCount = 0;

    // this assumes that we have 2 keyword list in conf.properties
    WordList &directives = *keywordLists[0];
    WordList &params = *keywordLists[1];
    WordList &USERDEF = *keywordLists[2];

    // go through all provided text segment
    // using the hand-written state machine shown below
    styler.StartAt(startPos);
    styler.StartSegment(startPos);
    for (int i = startPos; i < lengthDoc; i++) {
        char ch = chNext;
        chNext = styler.SafeGetCharAt(i + 1);

        if (styler.IsLeadByte(ch)) {
            chNext = styler.SafeGetCharAt(i + 2);
            i++;
            continue;
        }
        switch(state) {
        case sID::DEFAULT:
            if( ch == '\n' || ch == '\r' || ch == '\t' || ch == ' ') {
                // whitespace is simply ignored here...
                styler.ColourTo(i,sID::DEFAULT);
                break;
            } else if( ch == '#' ) {
                // signals the start of a comment...
                state = sID::COMMENT;
                styler.ColourTo(i,sID::COMMENT);
            } else if( ch == '.' /*|| ch == '/'*/) {
                // signals the start of a file...
                state = sID::EXTENSION;
                styler.ColourTo(i,sID::EXTENSION);
            } else if( ch == '"') {
                state = sID::STRING;
                styler.ColourTo(i,sID::STRING);
            } else if( ispunct(ch) ) {
                // signals an operator...
                // no state jump necessary for this
                // simple case...
                styler.ColourTo(i,sID::OPERATOR);
            } else if( isalpha(ch) ) {
                // signals the start of an identifier
                bufferCount = 0;
                buffer[bufferCount++] = static_cast<char>(tolower(ch));
                state = sID::IDENTIFIER;
            } else if( isdigit(ch) ) {
                // signals the start of a number
                bufferCount = 0;
                buffer[bufferCount++] = ch;
                //styler.ColourTo(i,sID::NUMBER);
                state = sID::NUMBER;
            } else {
                // style it the default style..
                styler.ColourTo(i,sID::DEFAULT);
            }
            break;

        case sID::COMMENT:
            // if we find a newline here,
            // we simply go to default state
            // else continue to work on it...
            if( ch == '\n' || ch == '\r' ) {
                state = sID::DEFAULT;
            } else {
                styler.ColourTo(i,sID::COMMENT);
            }
            break;

        case sID::EXTENSION:
            // if we find a non-alphanumeric char,
            // we simply go to default state
            // else we're still dealing with an extension...
            if( isalnum(ch) || (ch == '_') ||
                    (ch == '-') || (ch == '$') ||
                    (ch == '/') || (ch == '.') || (ch == '*') )
            {
                styler.ColourTo(i,sID::EXTENSION);
            } else {
                state = sID::DEFAULT;
                chNext = styler[i--];
            }
            break;

        case sID::STRING:
            // if we find the end of a string char, we simply go to default state
            // else we're still dealing with an string...
            if( (ch == '"' && styler.SafeGetCharAt(i-1)!='\\') || (ch == '\n') || (ch == '\r') ) {
                state = sID::DEFAULT;
            }
            styler.ColourTo(i,sID::STRING);
            break;

        case sID::IDENTIFIER:
            // stay  in CONF_IDENTIFIER state until we find a non-alphanumeric
            if( isalnum(ch) || (ch == '_') || (ch == '-') || (ch == '/') || (ch == '$') || (ch == '.') || (ch == '*')) {
                buffer[bufferCount++] = static_cast<char>(tolower(ch));
            } else {
                state = sID::DEFAULT;
                buffer[bufferCount] = '\0';

                // check if the buffer contains a keyword, and highlight it if it is a keyword...
                if(directives.InList(buffer)) {
                    styler.ColourTo(i-1,sID::DIRECTIVE );
                } else if(params.InList(buffer)) {
                    styler.ColourTo(i-1,sID::PARAMETER );
                } else if(USERDEF.InList(buffer)) {
                    styler.ColourTo(i-1,sID::USERDEF );
                } else if(strchr(buffer,'/') || strchr(buffer,'.')) {
                    styler.ColourTo(i-1,sID::EXTENSION);
                } else {
                    styler.ColourTo(i-1,sID::DEFAULT);
                }

                // push back the faulty character
                chNext = styler[i--];

            }
            break;

        case sID::NUMBER:
            // stay  in CONF_NUMBER state until we find a non-numeric
            if( isdigit(ch) || ch == '.') {
                buffer[bufferCount++] = ch;
            } else {
                state = sID::DEFAULT;
                buffer[bufferCount] = '\0';

                // Colourize here...
                if( strchr(buffer,'.') ) {
                    // it is an IP address...
                    styler.ColourTo(i-1,sID::IP);
                } else {
                    // normal number
                    styler.ColourTo(i-1,sID::NUMBER);
                }

                // push back a character
                chNext = styler[i--];
            }
            break;

        }
    }
    delete []buffer;
}
Ejemplo n.º 2
0
static void ColouriseBullantDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
  Accessor &styler) {
  WordList &keywords = *keywordlists[0];

  styler.StartAt(startPos);

  bool fold = styler.GetPropertyInt("fold") != 0;
  int lineCurrent = styler.GetLine(startPos);
  int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
  int levelCurrent = levelPrev;

  int state = initStyle;
  if (state == SCE_C_STRINGEOL)	// Does not leak onto next line
    state = SCE_C_DEFAULT;
  char chPrev = ' ';
  char chNext = styler[startPos];
  unsigned int lengthDoc = startPos + length;
  int visibleChars = 0;
  styler.StartSegment(startPos);
  int endFoundThisLine = 0;
  for (unsigned int i = startPos; i < lengthDoc; i++) {
    char ch = chNext;
    chNext = styler.SafeGetCharAt(i + 1);

    if ((ch == '\r' && chNext != '\n') || (ch == '\n')) {
      // Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win) or on LF alone (Unix)
      // Avoid triggering two times on Dos/Win
      // End of line
      endFoundThisLine = 0;
      if (state == SCE_C_STRINGEOL) {
        styler.ColourTo(i, state);
        state = SCE_C_DEFAULT;
      }
      if (fold) {
        int lev = levelPrev;
        if (visibleChars == 0)
          lev |= SC_FOLDLEVELWHITEFLAG;
        if ((levelCurrent > levelPrev) && (visibleChars > 0))
          lev |= SC_FOLDLEVELHEADERFLAG;
        styler.SetLevel(lineCurrent, lev);
        lineCurrent++;
        levelPrev = levelCurrent;
      }
      visibleChars = 0;

/*			int indentBlock = GetLineIndentation(lineCurrent);
      if (blockChange==1){
        lineCurrent++;
        int pos=SetLineIndentation(lineCurrent, indentBlock + indentSize);
      } else if (blockChange==-1) {
        indentBlock -= indentSize;
        if (indentBlock < 0)
          indentBlock = 0;
        SetLineIndentation(lineCurrent, indentBlock);
        lineCurrent++;
      }
      blockChange=0;
*/		}
    if (!(IsASCII(ch) && isspace(ch)))
      visibleChars++;

    if (styler.IsLeadByte(ch)) {
      chNext = styler.SafeGetCharAt(i + 2);
      chPrev = ' ';
      i += 1;
      continue;
    }

    if (state == SCE_C_DEFAULT) {
      if (iswordstart(ch)) {
        styler.ColourTo(i-1, state);
          state = SCE_C_IDENTIFIER;
      } else if (ch == '@' && chNext == 'o') {
        if ((styler.SafeGetCharAt(i+2) =='f') && (styler.SafeGetCharAt(i+3) == 'f')) {
          styler.ColourTo(i-1, state);
          state = SCE_C_COMMENT;
        }
      } else if (ch == '#') {
        styler.ColourTo(i-1, state);
        state = SCE_C_COMMENTLINE;
      } else if (ch == '\"') {
        styler.ColourTo(i-1, state);
        state = SCE_C_STRING;
      } else if (ch == '\'') {
        styler.ColourTo(i-1, state);
        state = SCE_C_CHARACTER;
      } else if (isoperator(ch)) {
        styler.ColourTo(i-1, state);
        styler.ColourTo(i, SCE_C_OPERATOR);
      }
    } else if (state == SCE_C_IDENTIFIER) {
      if (!iswordchar(ch)) {
        int levelChange = classifyWordBullant(styler.GetStartSegment(), i - 1, keywords, styler);
        state = SCE_C_DEFAULT;
        chNext = styler.SafeGetCharAt(i + 1);
        if (ch == '#') {
          state = SCE_C_COMMENTLINE;
        } else if (ch == '\"') {
          state = SCE_C_STRING;
        } else if (ch == '\'') {
          state = SCE_C_CHARACTER;
        } else if (isoperator(ch)) {
          styler.ColourTo(i, SCE_C_OPERATOR);
        }
        if (endFoundThisLine == 0)
          levelCurrent+=levelChange;
        if (levelChange == -1)
          endFoundThisLine=1;
      }
    } else if (state == SCE_C_COMMENT) {
      if (ch == '@' && chNext == 'o') {
        if (styler.SafeGetCharAt(i+2) == 'n') {
          styler.ColourTo(i+2, state);
          state = SCE_C_DEFAULT;
          i+=2;
        }
      }
    } else if (state == SCE_C_COMMENTLINE) {
      if (ch == '\r' || ch == '\n') {
        endFoundThisLine = 0;
        styler.ColourTo(i-1, state);
        state = SCE_C_DEFAULT;
      }
    } else if (state == SCE_C_STRING) {
      if (ch == '\\') {
        if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
          i++;
          ch = chNext;
          chNext = styler.SafeGetCharAt(i + 1);
        }
      } else if (ch == '\"') {
        styler.ColourTo(i, state);
        state = SCE_C_DEFAULT;
      } else if (chNext == '\r' || chNext == '\n') {
        endFoundThisLine = 0;
        styler.ColourTo(i-1, SCE_C_STRINGEOL);
        state = SCE_C_STRINGEOL;
      }
    } else if (state == SCE_C_CHARACTER) {
      if ((ch == '\r' || ch == '\n') && (chPrev != '\\')) {
        endFoundThisLine = 0;
        styler.ColourTo(i-1, SCE_C_STRINGEOL);
        state = SCE_C_STRINGEOL;
      } else if (ch == '\\') {
        if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
          i++;
          ch = chNext;
          chNext = styler.SafeGetCharAt(i + 1);
        }
      } else if (ch == '\'') {
        styler.ColourTo(i, state);
        state = SCE_C_DEFAULT;
      }
    }
    chPrev = ch;
  }
  styler.ColourTo(lengthDoc - 1, state);

  // Fill in the real level of the next line, keeping the current flags as they will be filled in later
  if (fold) {
    int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
    //styler.SetLevel(lineCurrent, levelCurrent | flagsNext);
    styler.SetLevel(lineCurrent, levelPrev | flagsNext);

  }
}
Ejemplo n.º 3
0
static void ColouriseNncrontabDoc(Sci_PositionU startPos, Sci_Position length, int, WordList
*keywordLists[], Accessor &styler)
{
	int state = SCE_NNCRONTAB_DEFAULT;
	char chNext = styler[startPos];
	Sci_Position lengthDoc = startPos + length;
	// create a buffer large enough to take the largest chunk...
	char *buffer = new char[length+1];
	Sci_Position bufferCount = 0;
	// used when highliting environment variables inside quoted string:
	bool insideString = false;

	// this assumes that we have 3 keyword list in conf.properties
	WordList &section = *keywordLists[0];
	WordList &keyword = *keywordLists[1];
	WordList &modifier = *keywordLists[2];

	// go through all provided text segment
	// using the hand-written state machine shown below
	styler.StartAt(startPos);
	styler.StartSegment(startPos);
	for (Sci_Position i = startPos; i < lengthDoc; i++) {
		char ch = chNext;
		chNext = styler.SafeGetCharAt(i + 1);

		if (styler.IsLeadByte(ch)) {
			chNext = styler.SafeGetCharAt(i + 2);
			i++;
			continue;
		}
		switch(state) {
			case SCE_NNCRONTAB_DEFAULT:
				if( ch == '\n' || ch == '\r' || ch == '\t' || ch == ' ') {
					// whitespace is simply ignored here...
					styler.ColourTo(i,SCE_NNCRONTAB_DEFAULT);
					break;
				} else if( ch == '#' && styler.SafeGetCharAt(i+1) == '(') {
					// signals the start of a task...
					state = SCE_NNCRONTAB_TASK;
					styler.ColourTo(i,SCE_NNCRONTAB_TASK);
				}
				  else if( ch == '\\' && (styler.SafeGetCharAt(i+1) == ' ' ||
										 styler.SafeGetCharAt(i+1) == '\t')) {
					// signals the start of an extended comment...
					state = SCE_NNCRONTAB_COMMENT;
					styler.ColourTo(i,SCE_NNCRONTAB_COMMENT);
				} else if( ch == '#' ) {
					// signals the start of a plain comment...
					state = SCE_NNCRONTAB_COMMENT;
					styler.ColourTo(i,SCE_NNCRONTAB_COMMENT);
				} else if( ch == ')' && styler.SafeGetCharAt(i+1) == '#') {
					// signals the end of a task...
					state = SCE_NNCRONTAB_TASK;
					styler.ColourTo(i,SCE_NNCRONTAB_TASK);
				} else if( ch == '"') {
					state = SCE_NNCRONTAB_STRING;
					styler.ColourTo(i,SCE_NNCRONTAB_STRING);
				} else if( ch == '%') {
					// signals environment variables
					state = SCE_NNCRONTAB_ENVIRONMENT;
					styler.ColourTo(i,SCE_NNCRONTAB_ENVIRONMENT);
				} else if( ch == '<' && styler.SafeGetCharAt(i+1) == '%') {
					// signals environment variables
					state = SCE_NNCRONTAB_ENVIRONMENT;
					styler.ColourTo(i,SCE_NNCRONTAB_ENVIRONMENT);
				} else if( ch == '*' ) {
					// signals an asterisk
					// no state jump necessary for this simple case...
					styler.ColourTo(i,SCE_NNCRONTAB_ASTERISK);
				} else if( (IsASCII(ch) && isalpha(ch)) || ch == '<' ) {
					// signals the start of an identifier
					bufferCount = 0;
					buffer[bufferCount++] = ch;
					state = SCE_NNCRONTAB_IDENTIFIER;
				} else if( IsASCII(ch) && isdigit(ch) ) {
					// signals the start of a number
					bufferCount = 0;
					buffer[bufferCount++] = ch;
					state = SCE_NNCRONTAB_NUMBER;
				} else {
					// style it the default style..
					styler.ColourTo(i,SCE_NNCRONTAB_DEFAULT);
				}
				break;

			case SCE_NNCRONTAB_COMMENT:
				// if we find a newline here,
				// we simply go to default state
				// else continue to work on it...
				if( ch == '\n' || ch == '\r' ) {
					state = SCE_NNCRONTAB_DEFAULT;
				} else {
					styler.ColourTo(i,SCE_NNCRONTAB_COMMENT);
				}
				break;

			case SCE_NNCRONTAB_TASK:
				// if we find a newline here,
				// we simply go to default state
				// else continue to work on it...
				if( ch == '\n' || ch == '\r' ) {
					state = SCE_NNCRONTAB_DEFAULT;
				} else {
					styler.ColourTo(i,SCE_NNCRONTAB_TASK);
				}
				break;

			case SCE_NNCRONTAB_STRING:
				if( ch == '%' ) {
					state = SCE_NNCRONTAB_ENVIRONMENT;
					insideString = true;
					styler.ColourTo(i-1,SCE_NNCRONTAB_STRING);
					break;
				}
				// if we find the end of a string char, we simply go to default state
				// else we're still dealing with an string...
				if( (ch == '"' && styler.SafeGetCharAt(i-1)!='\\') ||
					(ch == '\n') || (ch == '\r') ) {
					state = SCE_NNCRONTAB_DEFAULT;
				}
				styler.ColourTo(i,SCE_NNCRONTAB_STRING);
				break;

			case SCE_NNCRONTAB_ENVIRONMENT:
				// if we find the end of a string char, we simply go to default state
				// else we're still dealing with an string...
				if( ch == '%' && insideString ) {
					state = SCE_NNCRONTAB_STRING;
					insideString = false;
					break;
				}
				if( (ch == '%' && styler.SafeGetCharAt(i-1)!='\\')
					|| (ch == '\n') || (ch == '\r') || (ch == '>') ) {
					state = SCE_NNCRONTAB_DEFAULT;
					styler.ColourTo(i,SCE_NNCRONTAB_ENVIRONMENT);
					break;
				}
				styler.ColourTo(i+1,SCE_NNCRONTAB_ENVIRONMENT);
				break;

			case SCE_NNCRONTAB_IDENTIFIER:
				// stay  in CONF_IDENTIFIER state until we find a non-alphanumeric
				if( (IsASCII(ch) && isalnum(ch)) || (ch == '_') || (ch == '-') || (ch == '/') ||
					(ch == '$') || (ch == '.') || (ch == '<') || (ch == '>') ||
					(ch == '@') ) {
					buffer[bufferCount++] = ch;
				} else {
					state = SCE_NNCRONTAB_DEFAULT;
					buffer[bufferCount] = '\0';

					// check if the buffer contains a keyword,
					// and highlight it if it is a keyword...
					if(section.InList(buffer)) {
						styler.ColourTo(i,SCE_NNCRONTAB_SECTION );
					} else if(keyword.InList(buffer)) {
						styler.ColourTo(i-1,SCE_NNCRONTAB_KEYWORD );
					} // else if(strchr(buffer,'/') || strchr(buffer,'.')) {
					//	styler.ColourTo(i-1,SCE_NNCRONTAB_EXTENSION);
					// }
					  else if(modifier.InList(buffer)) {
						styler.ColourTo(i-1,SCE_NNCRONTAB_MODIFIER );
					  }	else {
						styler.ColourTo(i-1,SCE_NNCRONTAB_DEFAULT);
					}
					// push back the faulty character
					chNext = styler[i--];
				}
				break;

			case SCE_NNCRONTAB_NUMBER:
				// stay  in CONF_NUMBER state until we find a non-numeric
				if( IsASCII(ch) && isdigit(ch) /* || ch == '.' */ ) {
					buffer[bufferCount++] = ch;
				} else {
					state = SCE_NNCRONTAB_DEFAULT;
					buffer[bufferCount] = '\0';
					// Colourize here... (normal number)
					styler.ColourTo(i-1,SCE_NNCRONTAB_NUMBER);
					// push back a character
					chNext = styler[i--];
				}
				break;
		}
	}
	delete []buffer;
}
Ejemplo n.º 4
0
static void ColouriseTALDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
	Accessor &styler) {

	styler.StartAt(startPos);

	int state = initStyle;
	if (state == SCE_C_CHARACTER)	// Does not leak onto next line
		state = SCE_C_DEFAULT;
	char chPrev = ' ';
	char chNext = styler[startPos];
	unsigned int lengthDoc = startPos + length;

	bool bInClassDefinition;

	int currentLine = styler.GetLine(startPos);
	if (currentLine > 0) {
		styler.SetLineState(currentLine, styler.GetLineState(currentLine-1));
		bInClassDefinition = (styler.GetLineState(currentLine) == 1);
	} else {
		styler.SetLineState(currentLine, 0);
		bInClassDefinition = false;
	}

	bool bInAsm = (state == SCE_C_REGEX);
	if (bInAsm)
		state = SCE_C_DEFAULT;

	styler.StartSegment(startPos);
	int visibleChars = 0;
	for (unsigned int i = startPos; i < lengthDoc; i++) {
		char ch = chNext;

		chNext = styler.SafeGetCharAt(i + 1);

		if ((ch == '\r' && chNext != '\n') || (ch == '\n')) {
			// Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win) or on LF alone (Unix)
			// Avoid triggering two times on Dos/Win
			// End of line
			if (state == SCE_C_CHARACTER) {
				ColourTo(styler, i, state, bInAsm);
				state = SCE_C_DEFAULT;
			}
			visibleChars = 0;
			currentLine++;
			styler.SetLineState(currentLine, (bInClassDefinition ? 1 : 0));
		}

		if (styler.IsLeadByte(ch)) {
			chNext = styler.SafeGetCharAt(i + 2);
			chPrev = ' ';
			i += 1;
			continue;
		}

		if (state == SCE_C_DEFAULT) {
			if (isTALwordstart(ch)) {
				ColourTo(styler, i-1, state, bInAsm);
				state = SCE_C_IDENTIFIER;
			} else if (ch == '!' && chNext != '*') {
				ColourTo(styler, i-1, state, bInAsm);
				state = SCE_C_COMMENT;
			} else if (ch == '!' && chNext == '*') {
				ColourTo(styler, i-1, state, bInAsm);
				state = SCE_C_COMMENTDOC;
			} else if (ch == '-' && chNext == '-') {
				ColourTo(styler, i-1, state, bInAsm);
				state = SCE_C_COMMENTLINE;
			} else if (ch == '"') {
				ColourTo(styler, i-1, state, bInAsm);
				state = SCE_C_STRING;
			} else if (ch == '?' && visibleChars == 0) {
				ColourTo(styler, i-1, state, bInAsm);
				state = SCE_C_PREPROCESSOR;
			} else if (isTALoperator(ch)) {
				ColourTo(styler, i-1, state, bInAsm);
				ColourTo(styler, i, SCE_C_OPERATOR, bInAsm);
			}
		} else if (state == SCE_C_IDENTIFIER) {
			if (!isTALwordchar(ch)) {
				int lStateChange = classifyWordTAL(styler.GetStartSegment(), i - 1, keywordlists, styler, bInAsm);

				if(lStateChange == 1) {
					styler.SetLineState(currentLine, 1);
					bInClassDefinition = true;
				} else if(lStateChange == 2) {
					bInAsm = true;
				} else if(lStateChange == -1) {
					styler.SetLineState(currentLine, 0);
					bInClassDefinition = false;
					bInAsm = false;
				}

				state = SCE_C_DEFAULT;
				chNext = styler.SafeGetCharAt(i + 1);
				if (ch == '!' && chNext != '*') {
					state = SCE_C_COMMENT;
				} else if (ch == '!' && chNext == '*') {
					ColourTo(styler, i-1, state, bInAsm);
					state = SCE_C_COMMENTDOC;
				} else if (ch == '-' && chNext == '-') {
					state = SCE_C_COMMENTLINE;
				} else if (ch == '"') {
					state = SCE_C_STRING;
				} else if (isTALoperator(ch)) {
					ColourTo(styler, i, SCE_C_OPERATOR, bInAsm);
				}
			}
		} else {
			if (state == SCE_C_PREPROCESSOR) {
				if ((ch == '\r' || ch == '\n') && !(chPrev == '\\' || chPrev == '\r')) {
					ColourTo(styler, i-1, state, bInAsm);
					state = SCE_C_DEFAULT;
				}
			} else if (state == SCE_C_COMMENT) {
				if (ch == '!' || (ch == '\r' || ch == '\n') ) {
					ColourTo(styler, i, state, bInAsm);
					state = SCE_C_DEFAULT;
				}
			} else if (state == SCE_C_COMMENTDOC) {
				if (ch == '!' || (ch == '\r' || ch == '\n')) {
					if (((i > styler.GetStartSegment() + 2) || (
						(initStyle == SCE_C_COMMENTDOC) &&
						(styler.GetStartSegment() == static_cast<unsigned int>(startPos))))) {
							ColourTo(styler, i, state, bInAsm);
							state = SCE_C_DEFAULT;
					}
				}
			} else if (state == SCE_C_COMMENTLINE) {
				if (ch == '\r' || ch == '\n') {
					ColourTo(styler, i-1, state, bInAsm);
					state = SCE_C_DEFAULT;
				}
			} else if (state == SCE_C_STRING) {
				if (ch == '"') {
					ColourTo(styler, i, state, bInAsm);
					state = SCE_C_DEFAULT;
				}
			}
		}
        if (!isspacechar(ch))
            visibleChars++;
		chPrev = ch;
	}
	ColourTo(styler, lengthDoc - 1, state, bInAsm);
}
Ejemplo n.º 5
0
static void ColouriseInnoDoc(unsigned int startPos, int length, int, WordList *keywordLists[], Accessor &styler) {
	int state = SCE_INNO_DEFAULT;
	char chPrev;
	char ch = 0;
	char chNext = styler[startPos];
	int lengthDoc = startPos + length;
	char *buffer = new char[length];
	int bufferCount = 0;
	bool isBOL, isEOL, isWS, isBOLWS = 0;
	bool isCode = false;
	bool isCStyleComment = false;

	WordList &sectionKeywords = *keywordLists[0];
	WordList &standardKeywords = *keywordLists[1];
	WordList &parameterKeywords = *keywordLists[2];
	WordList &preprocessorKeywords = *keywordLists[3];
	WordList &pascalKeywords = *keywordLists[4];
	WordList &userKeywords = *keywordLists[5];

	// Go through all provided text segment
	// using the hand-written state machine shown below
	styler.StartAt(startPos);
	styler.StartSegment(startPos);
	for (int i = startPos; i < lengthDoc; i++) {
		chPrev = ch;
		ch = chNext;
		chNext = styler.SafeGetCharAt(i + 1);

		if (styler.IsLeadByte(ch)) {
			chNext = styler.SafeGetCharAt(i + 2);
			i++;
			continue;
		}

		isBOL = (chPrev == 0) || (chPrev == '\n') || (chPrev == '\r' && ch != '\n');
		isBOLWS = (isBOL) ? 1 : (isBOLWS && (chPrev == ' ' || chPrev == '\t'));
		isEOL = (ch == '\n' || ch == '\r');
		isWS = (ch == ' ' || ch == '\t');

		switch(state) {
			case SCE_INNO_DEFAULT:
				if (!isCode && ch == ';' && isBOLWS) {
					// Start of a comment
					state = SCE_INNO_COMMENT;
				} else if (ch == '[' && isBOLWS) {
					// Start of a section name
					bufferCount = 0;
					state = SCE_INNO_SECTION;
				} else if (ch == '#' && isBOLWS) {
					// Start of a preprocessor directive
					state = SCE_INNO_PREPROC;
				} else if (!isCode && ch == '{' && chNext != '{' && chPrev != '{') {
					// Start of an inline expansion
					state = SCE_INNO_INLINE_EXPANSION;
				} else if (isCode && (ch == '{' || (ch == '(' && chNext == '*'))) {
					// Start of a Pascal comment
					state = SCE_INNO_COMMENT_PASCAL;
					isCStyleComment = false;
				} else if (isCode && ch == '/' && chNext == '/') {
					// Apparently, C-style comments are legal, too
					state = SCE_INNO_COMMENT_PASCAL;
					isCStyleComment = true;
				} else if (ch == '"') {
					// Start of a double-quote string
					state = SCE_INNO_STRING_DOUBLE;
				} else if (ch == '\'') {
					// Start of a single-quote string
					state = SCE_INNO_STRING_SINGLE;
				} else if (isascii(ch) && (isalpha(ch) || (ch == '_'))) {
					// Start of an identifier
					bufferCount = 0;
					buffer[bufferCount++] = static_cast<char>(tolower(ch));
					state = SCE_INNO_IDENTIFIER;
				} else {
					// Style it the default style
					styler.ColourTo(i,SCE_INNO_DEFAULT);
				}
				break;

			case SCE_INNO_COMMENT:
				if (isEOL) {
					state = SCE_INNO_DEFAULT;
					styler.ColourTo(i,SCE_INNO_COMMENT);
				}
				break;

			case SCE_INNO_IDENTIFIER:
				if (isascii(ch) && (isalnum(ch) || (ch == '_'))) {
					buffer[bufferCount++] = static_cast<char>(tolower(ch));
				} else {
					state = SCE_INNO_DEFAULT;
					buffer[bufferCount] = '\0';

					// Check if the buffer contains a keyword
					if (!isCode && standardKeywords.InList(buffer)) {
						styler.ColourTo(i-1,SCE_INNO_KEYWORD);
					} else if (!isCode && parameterKeywords.InList(buffer)) {
						styler.ColourTo(i-1,SCE_INNO_PARAMETER);
					} else if (isCode && pascalKeywords.InList(buffer)) {
						styler.ColourTo(i-1,SCE_INNO_KEYWORD_PASCAL);
					} else if (!isCode && userKeywords.InList(buffer)) {
						styler.ColourTo(i-1,SCE_INNO_KEYWORD_USER);
					} else {
						styler.ColourTo(i-1,SCE_INNO_DEFAULT);
					}

					// Push back the faulty character
					chNext = styler[i--];
					ch = chPrev;
				}
				break;

			case SCE_INNO_SECTION:
				if (ch == ']') {
					state = SCE_INNO_DEFAULT;
					buffer[bufferCount] = '\0';

					// Check if the buffer contains a section name
					if (sectionKeywords.InList(buffer)) {
						styler.ColourTo(i,SCE_INNO_SECTION);
						isCode = !CompareCaseInsensitive(buffer, "code");
					} else {
						styler.ColourTo(i,SCE_INNO_DEFAULT);
					}
				} else if (isascii(ch) && (isalnum(ch) || (ch == '_'))) {
					buffer[bufferCount++] = static_cast<char>(tolower(ch));
				} else {
					state = SCE_INNO_DEFAULT;
					styler.ColourTo(i,SCE_INNO_DEFAULT);
				}
				break;

			case SCE_INNO_PREPROC:
				if (isWS || isEOL) {
					if (isascii(chPrev) && isalpha(chPrev)) {
						state = SCE_INNO_DEFAULT;
						buffer[bufferCount] = '\0';

						// Check if the buffer contains a preprocessor directive
						if (preprocessorKeywords.InList(buffer)) {
							styler.ColourTo(i-1,SCE_INNO_PREPROC);
						} else {
							styler.ColourTo(i-1,SCE_INNO_DEFAULT);
						}

						// Push back the faulty character
						chNext = styler[i--];
						ch = chPrev;
					}
				} else if (isascii(ch) && isalpha(ch)) {
					if (chPrev == '#' || chPrev == ' ' || chPrev == '\t')
						bufferCount = 0;
					buffer[bufferCount++] = static_cast<char>(tolower(ch));
				}
				break;

			case SCE_INNO_STRING_DOUBLE:
				if (ch == '"' || isEOL) {
					state = SCE_INNO_DEFAULT;
					styler.ColourTo(i,SCE_INNO_STRING_DOUBLE);
				}
				break;

			case SCE_INNO_STRING_SINGLE:
				if (ch == '\'' || isEOL) {
					state = SCE_INNO_DEFAULT;
					styler.ColourTo(i,SCE_INNO_STRING_SINGLE);
				}
				break;

			case SCE_INNO_INLINE_EXPANSION:
				if (ch == '}') {
					state = SCE_INNO_DEFAULT;
					styler.ColourTo(i,SCE_INNO_INLINE_EXPANSION);
				} else if (isEOL) {
					state = SCE_INNO_DEFAULT;
					styler.ColourTo(i,SCE_INNO_DEFAULT);
				}
				break;

			case SCE_INNO_COMMENT_PASCAL:
				if (isCStyleComment) {
					if (isEOL) {
						state = SCE_INNO_DEFAULT;
						styler.ColourTo(i,SCE_INNO_COMMENT_PASCAL);
					}
				} else {
					if (ch == '}' || (ch == ')' && chPrev == '*')) {
						state = SCE_INNO_DEFAULT;
						styler.ColourTo(i,SCE_INNO_COMMENT_PASCAL);
					} else if (isEOL) {
						state = SCE_INNO_DEFAULT;
						styler.ColourTo(i,SCE_INNO_DEFAULT);
					}
				}
				break;

		}
	}
	delete []buffer;
}
Ejemplo n.º 6
0
static void ColouriseMSSQLDoc(unsigned int startPos, int length,
                              int initStyle, WordList *keywordlists[], Accessor &styler) {


  styler.StartAt(startPos);

  bool fold = styler.GetPropertyInt("fold") != 0;
  int lineCurrent = styler.GetLine(startPos);
  int spaceFlags = 0;

  int state = initStyle;
  int prevState = initStyle;
  char chPrev = ' ';
  char chNext = styler[startPos];
  styler.StartSegment(startPos);
  unsigned int lengthDoc = startPos + length;
  for (unsigned int i = startPos; i < lengthDoc; i++) {
    char ch = chNext;
    chNext = styler.SafeGetCharAt(i + 1);

    if ((ch == '\r' && chNext != '\n') || (ch == '\n')) {
      int indentCurrent = styler.IndentAmount(lineCurrent, &spaceFlags);
      int lev = indentCurrent;
      if (!(indentCurrent & SC_FOLDLEVELWHITEFLAG)) {
        // Only non whitespace lines can be headers
        int indentNext = styler.IndentAmount(lineCurrent + 1, &spaceFlags);
        if (indentCurrent < (indentNext & ~SC_FOLDLEVELWHITEFLAG)) {
          lev |= SC_FOLDLEVELHEADERFLAG;
        }
      }
      if (fold) {
        styler.SetLevel(lineCurrent, lev);
      }
    }

    if (styler.IsLeadByte(ch)) {
      chNext = styler.SafeGetCharAt(i + 2);
      chPrev = ' ';
      i += 1;
      continue;
    }

    // When the last char isn't part of the state (have to deal with it too)...
    if ( (state == SCE_MSSQL_IDENTIFIER) ||
                    (state == SCE_MSSQL_STORED_PROCEDURE) ||
                    (state == SCE_MSSQL_DATATYPE) ||
                    //~ (state == SCE_MSSQL_COLUMN_NAME) ||
                    (state == SCE_MSSQL_FUNCTION) ||
                    //~ (state == SCE_MSSQL_GLOBAL_VARIABLE) ||
                    (state == SCE_MSSQL_VARIABLE)) {
      if (!iswordchar(ch)) {
        int stateTmp;

                if ((state == SCE_MSSQL_VARIABLE) || (state == SCE_MSSQL_COLUMN_NAME)) {
                    styler.ColourTo(i - 1, state);
          stateTmp = state;
                } else
                    stateTmp = classifyWordSQL(styler.GetStartSegment(), i - 1, keywordlists, styler, state, prevState);

        prevState = state;

        if (stateTmp == SCE_MSSQL_IDENTIFIER || stateTmp == SCE_MSSQL_VARIABLE)
          state = SCE_MSSQL_DEFAULT_PREF_DATATYPE;
        else
          state = SCE_MSSQL_DEFAULT;
      }
    } else if (state == SCE_MSSQL_LINE_COMMENT) {
      if (ch == '\r' || ch == '\n') {
        styler.ColourTo(i - 1, state);
        prevState = state;
        state = SCE_MSSQL_DEFAULT;
      }
    } else if (state == SCE_MSSQL_GLOBAL_VARIABLE) {
      if ((ch != '@') && !iswordchar(ch)) {
        classifyWordSQL(styler.GetStartSegment(), i - 1, keywordlists, styler, state, prevState);
        prevState = state;
        state = SCE_MSSQL_DEFAULT;
      }
    }

    // If is the default or one of the above succeeded
    if (state == SCE_MSSQL_DEFAULT || state == SCE_MSSQL_DEFAULT_PREF_DATATYPE) {
      if (iswordstart(ch)) {
        styler.ColourTo(i - 1, SCE_MSSQL_DEFAULT);
        prevState = state;
        state = SCE_MSSQL_IDENTIFIER;
      } else if (ch == '/' && chNext == '*') {
        styler.ColourTo(i - 1, SCE_MSSQL_DEFAULT);
        prevState = state;
        state = SCE_MSSQL_COMMENT;
      } else if (ch == '-' && chNext == '-') {
        styler.ColourTo(i - 1, SCE_MSSQL_DEFAULT);
        prevState = state;
        state = SCE_MSSQL_LINE_COMMENT;
      } else if (ch == '\'') {
        styler.ColourTo(i - 1, SCE_MSSQL_DEFAULT);
        prevState = state;
        state = SCE_MSSQL_STRING;
      } else if (ch == '"') {
        styler.ColourTo(i - 1, SCE_MSSQL_DEFAULT);
        prevState = state;
        state = SCE_MSSQL_COLUMN_NAME;
      } else if (ch == '[') {
        styler.ColourTo(i - 1, SCE_MSSQL_DEFAULT);
        prevState = state;
        state = SCE_MSSQL_COLUMN_NAME_2;
      } else if (isoperator(ch)) {
        styler.ColourTo(i - 1, SCE_MSSQL_DEFAULT);
        styler.ColourTo(i, SCE_MSSQL_OPERATOR);
                //~ style = SCE_MSSQL_DEFAULT;
        prevState = state;
        state = SCE_MSSQL_DEFAULT;
      } else if (ch == '@') {
                styler.ColourTo(i - 1, SCE_MSSQL_DEFAULT);
        prevState = state;
                if (chNext == '@') {
                    state = SCE_MSSQL_GLOBAL_VARIABLE;
//                    i += 2;
                } else
                    state = SCE_MSSQL_VARIABLE;
            }


    // When the last char is part of the state...
    } else if (state == SCE_MSSQL_COMMENT) {
        if (ch == '/' && chPrev == '*') {
          if (((i > (styler.GetStartSegment() + 2)) || ((initStyle == SCE_MSSQL_COMMENT) &&
              (styler.GetStartSegment() == startPos)))) {
            styler.ColourTo(i, state);
            //~ state = SCE_MSSQL_COMMENT;
          prevState = state;
                        state = SCE_MSSQL_DEFAULT;
          }
        }
      } else if (state == SCE_MSSQL_STRING) {
        if (ch == '\'') {
          if ( chNext == '\'' ) {
            i++;
          ch = chNext;
          chNext = styler.SafeGetCharAt(i + 1);
          } else {
            styler.ColourTo(i, state);
          prevState = state;
            state = SCE_MSSQL_DEFAULT;
          //i++;
          }
        //ch = chNext;
        //chNext = styler.SafeGetCharAt(i + 1);
        }
      } else if (state == SCE_MSSQL_COLUMN_NAME) {
        if (ch == '"') {
          if (chNext == '"') {
            i++;
          ch = chNext;
          chNext = styler.SafeGetCharAt(i + 1);
        } else {
                    styler.ColourTo(i, state);
          prevState = state;
          state = SCE_MSSQL_DEFAULT_PREF_DATATYPE;
          //i++;
                }
                }
    } else if (state == SCE_MSSQL_COLUMN_NAME_2) {
      if (ch == ']') {
                styler.ColourTo(i, state);
        prevState = state;
                state = SCE_MSSQL_DEFAULT_PREF_DATATYPE;
                //i++;
      }
    }

    chPrev = ch;
  }
  styler.ColourTo(lengthDoc - 1, state);
}
Ejemplo n.º 7
0
static void ColouriseSolDoc(unsigned int startPos, int length, int initStyle,
                            WordList *keywordlists[], Accessor &styler)
 {

	int lengthDoc = startPos + length;
        char stringType = '\"';

	if (startPos > 0)
        {
            int lineCurrent = styler.GetLine(startPos);
            if (lineCurrent > 0)
            {
              startPos = styler.LineStart(lineCurrent-1);
              if (startPos == 0) initStyle = SCE_SCRIPTOL_DEFAULT;
              else               initStyle = styler.StyleAt(startPos-1);
            }
	}

	styler.StartAt(startPos, 127);

	WordList &keywords = *keywordlists[0];

	int whingeLevel = styler.GetPropertyInt("tab.timmy.whinge.level");
	char prevWord[200];
	prevWord[0] = '\0';
        if (length == 0)  return;

	int state = initStyle & 31;

	int nextIndex = 0;
        char chPrev  = ' ';
        char chPrev2 = ' ';
        char chNext  = styler[startPos];
	styler.StartSegment(startPos);
	bool atStartLine = true;
	int spaceFlags = 0;
	for (int i = startPos; i < lengthDoc; i++)
        {

         if (atStartLine)
         {
         char chBad = static_cast<char>(64);
         char chGood = static_cast<char>(0);
         char chFlags = chGood;

         if (whingeLevel == 1)
         {
             chFlags = (spaceFlags & wsInconsistent) ? chBad : chGood;
         }
         else if (whingeLevel == 2)
         {
             chFlags = (spaceFlags & wsSpaceTab) ? chBad : chGood;
         }
         else if (whingeLevel == 3)
         {
             chFlags = (spaceFlags & wsSpace) ? chBad : chGood;
         }
         else if (whingeLevel == 4)
         {
              chFlags = (spaceFlags & wsTab) ? chBad : chGood;
         }
         styler.SetFlags(chFlags, static_cast<char>(state));
         atStartLine = false;
       }

       char ch = chNext;
       chNext = styler.SafeGetCharAt(i + 1);

       if ((ch == '\r' && chNext != '\n') || (ch == '\n') || (i == lengthDoc))
       {
          if ((state == SCE_SCRIPTOL_DEFAULT) ||
              (state == SCE_SCRIPTOL_TRIPLE) ||
              (state == SCE_SCRIPTOL_COMMENTBLOCK))
          {
              styler.ColourTo(i, state);
          }
          atStartLine = true;
        }

        if (styler.IsLeadByte(ch))
         {
             chNext = styler.SafeGetCharAt(i + 2);
             chPrev  = ' ';
             chPrev2 = ' ';
             i += 1;
             continue;
         }

        if (state == SCE_SCRIPTOL_STRINGEOL)
         {
             if (ch != '\r' && ch != '\n')
             {
                    styler.ColourTo(i - 1, state);
                    state = SCE_SCRIPTOL_DEFAULT;
             }
         }

        if (state == SCE_SCRIPTOL_DEFAULT)
         {
            if (IsSolWordStart(ch))
            {
                 styler.ColourTo(i - 1, state);
                 state = SCE_SCRIPTOL_KEYWORD;
            }
            else if (ch == '`')
            {
                styler.ColourTo(i - 1, state);
                state = SCE_SCRIPTOL_COMMENTLINE;
            }
            else if (ch == '/')
            {
                styler.ColourTo(i - 1, state);
                if(chNext == '/') state = SCE_SCRIPTOL_CSTYLE;
                if(chNext == '*') state = SCE_SCRIPTOL_COMMENTBLOCK;
            }

            else if (IsSolStringStart(ch))
            {
               styler.ColourTo(i - 1, state);
               state = GetSolStringState(styler, i, &nextIndex);
               if(state == SCE_SCRIPTOL_STRING)
               {
                 stringType = ch;
               }
               if (nextIndex != i + 1)
               {
                   i = nextIndex - 1;
                   ch = ' ';
                   chPrev = ' ';
                   chNext = styler.SafeGetCharAt(i + 1);
               }
           }
            else if (isoperator(ch))
            {
                 styler.ColourTo(i - 1, state);
                 styler.ColourTo(i, SCE_SCRIPTOL_OPERATOR);
            }
          }
          else if (state == SCE_SCRIPTOL_KEYWORD)
          {
              if (!iswordchar(ch))
              {
                 ClassifyWordSol(styler.GetStartSegment(), i - 1, keywords, styler, prevWord);
                 state = SCE_SCRIPTOL_DEFAULT;
                 if (ch == '`')
                 {
                     state = chNext == '`' ? SCE_SCRIPTOL_PERSISTENT : SCE_SCRIPTOL_COMMENTLINE;
                 }
                 else if (IsSolStringStart(ch))
                 {
                    styler.ColourTo(i - 1, state);
                    state = GetSolStringState(styler, i, &nextIndex);
                    if (nextIndex != i + 1)
                    {
                       i = nextIndex - 1;
                       ch = ' ';
                       chPrev = ' ';
                       chNext = styler.SafeGetCharAt(i + 1);
                     }
                 }
                 else if (isoperator(ch))
                 {
                     styler.ColourTo(i, SCE_SCRIPTOL_OPERATOR);
                 }
             }
          }
          else
          {
            if (state == SCE_SCRIPTOL_COMMENTLINE ||
                state == SCE_SCRIPTOL_PERSISTENT ||
                state == SCE_SCRIPTOL_CSTYLE)
            {
                 if (ch == '\r' || ch == '\n')
                 {
                     styler.ColourTo(i - 1, state);
                     state = SCE_SCRIPTOL_DEFAULT;
                 }
            }
            else if(state == SCE_SCRIPTOL_COMMENTBLOCK)
            {
              if(chPrev == '*' && ch == '/')
              {
                styler.ColourTo(i, state);
                state = SCE_SCRIPTOL_DEFAULT;
              }
            }
            else if ((state == SCE_SCRIPTOL_STRING) ||
                     (state == SCE_SCRIPTOL_CHARACTER))
            {
               if ((ch == '\r' || ch == '\n') && (chPrev != '\\'))
                {
                    styler.ColourTo(i - 1, state);
                    state = SCE_SCRIPTOL_STRINGEOL;
                }
                else if (ch == '\\')
                {
                   if (chNext == '\"' || chNext == '\'' || chNext == '\\')
                   {
                        i++;
                        ch = chNext;
                        chNext = styler.SafeGetCharAt(i + 1);
                   }
                 }
                else if ((ch == '\"') || (ch == '\''))
                {
                    // must match the entered quote type
                    if(ch == stringType)
                    {
                      styler.ColourTo(i, state);
                      state = SCE_SCRIPTOL_DEFAULT;
                    }
                 }
             }
             else if (state == SCE_SCRIPTOL_TRIPLE)
             {
                if ((ch == '\'' && chPrev == '\'' && chPrev2 == '\'') ||
                    (ch == '\"' && chPrev == '\"' && chPrev2 == '\"'))
                 {
                    styler.ColourTo(i, state);
                    state = SCE_SCRIPTOL_DEFAULT;
                 }
             }

           }
          chPrev2 = chPrev;
          chPrev = ch;
	}
        if (state == SCE_SCRIPTOL_KEYWORD)
        {
            ClassifyWordSol(styler.GetStartSegment(),
                 lengthDoc-1, keywords, styler, prevWord);
	}
        else
        {
            styler.ColourTo(lengthDoc-1, state);
	}
}