/// <summary> /// Pushes a new char into the current state which calculates the new /// indentation level. /// </summary> /// <param name="ch"> /// A new character. /// </param> public void Push(char ch) { CurrentState.Push(CurrentChar = ch); if (!TextEditorOptions.EolMarker.Contains(ch)) { IsLineStart &= char.IsWhiteSpace(ch); if (IsLineStart) { CurrentIndent.Append(ch); } if (ch == '\t') { var nextTabStop = (column - 1 + TextEditorOptions.IndentSize) / TextEditorOptions.IndentSize; column = 1 + nextTabStop * TextEditorOptions.IndentSize; } else { column++; } } else { if (ch != NewLineChar) { // there can be more than one chars that determine the EOL, // the engine uses only one of them defined with NewLineChar return; } CurrentIndent.Length = 0; IsLineStart = true; column = 1; line++; } offset++; // ignore whitespace and newline chars if (!char.IsWhiteSpace(CurrentChar) && !TextEditorOptions.EolMarker.Contains(CurrentChar)) { PreviousChar = CurrentChar; } }
/// <inheritdoc /> public void Push(char ch) { // append this char to the wordbuf if it can form a valid keyword, otherwise check // if the last sequence of chars form a valid keyword and reset the wordbuf. if ((wordToken.Length == 0 ? char.IsLetter(ch) : char.IsLetterOrDigit(ch)) || ch == '_') { wordToken.Append(ch); } else if (wordToken.Length > 0) { currentState.CheckKeyword(wordToken.ToString()); previousKeyword = wordToken.ToString(); wordToken.Length = 0; isLineStartBeforeWordToken = false; } var isNewLine = NewLine.IsNewLine(ch); if (!isNewLine) { currentState.Push(currentChar = ch); offset++; previousNewline = '\0'; // ignore whitespace and newline chars var isWhitespace = currentChar == ' ' || currentChar == '\t'; if (!isWhitespace) { previousChar = currentChar; isLineStart = false; } if (isLineStart) { currentIndent.Append(ch); } if (ch == '\t') { var nextTabStop = (column - 1 + textEditorOptions.IndentSize) / textEditorOptions.IndentSize; column = 1 + nextTabStop * textEditorOptions.IndentSize; } else { column++; } } else { if (ch == NewLine.LF && previousNewline == NewLine.CR) { offset++; return; } currentState.Push(currentChar = newLineChar); offset++; previousNewline = ch; // there can be more than one chars that determine the EOL, // the engine uses only one of them defined with newLineChar if (currentChar != newLineChar) { return; } currentIndent.Length = 0; isLineStart = true; isLineStartBeforeWordToken = true; column = 1; line++; lineBeganInsideMultiLineComment = IsInsideMultiLineComment; lineBeganInsideVerbatimString = IsInsideVerbatimString; } }