private bool SkipWhiteSpaces() { int start = _position; //move to next real character for (; _position < _text.Length && char.IsWhiteSpace(_text, _position); _position++) { } //end of file if (_position >= _text.Length) { return(true); } //if the header has already started and we're not in an open region, check if there was more than one NewLine if (_started && _regionStarts.Count == 0) { var firstNewLine = NewLineManager.NextLineEndPositionInformation(_text, start, _position - start); if (firstNewLine != null) { int afterFirstNewLine = firstNewLine.Index + firstNewLine.LineEndLenght; int nextNewLine = NewLineManager.NextLineEndPosition(_text, afterFirstNewLine, _position - afterFirstNewLine); //more than one NewLine (= at least one empty line) if (nextNewLine > 0) { return(true); } } } return(false); }
private EditPoint EndOfHeader(string header, TextPoint start = null) { if (start == null) { start = _document.CreateEditPoint(_document.StartPoint); } var end = _document.CreateEditPoint(start); var headerLengthInCursorSteps = NewLineManager.ReplaceAllLineEnds(header, " ").Length; end.CharRight(headerLengthInCursorSteps); return(end); }
public Document(TextDocument document, Language language, string[] lines, ProjectItem projectItem, IEnumerable <string> keywords = null) { _document = document; _lineEndingInDocument = NewLineManager.DetectMostFrequentLineEnd(GetText()); string inputText = CreateInputText(lines); _header = new DocumentHeader(document, inputText, new DocumentHeaderProperties(projectItem)); _keywords = keywords; _language = language; _commentParser = new CommentParser(language.LineComment, language.BeginComment, language.EndComment, language.BeginRegion, language.EndRegion); }
private bool HandleToken(string token) { if (token == null) { return(false); } if (LineComment != null && token.StartsWith(LineComment)) { SetStarted(); //proceed to end of line _position = NewLineManager.NextLineEndPosition(_text, _position - token.Length + LineComment.Length); UpdatePositionIfEndOfFile(); return(true); } else if (BeginComment != null && token.StartsWith(BeginComment)) { SetStarted(); _position = _text.IndexOf(EndComment, _position - token.Length + BeginComment.Length); if (_position < 0) { throw new ParseException(); } else { _position += EndComment.Length; } return(true); } else if (BeginRegion != null && token == BeginRegion) { SetStarted(); _regionStarts.Push(_position - BeginRegion.Length); _position = NewLineManager.NextLineEndPosition(_text, _position); UpdatePositionIfEndOfFile(); return(true); } else if (EndRegion != null && token == EndRegion) { SetStarted(); if (_regionStarts.Count == 0) { throw new ParseException(); } _regionStarts.Pop(); _position = NewLineManager.NextLineEndPosition(_text, _position); UpdatePositionIfEndOfFile(); return(true); } else if (EndRegion != null && EndRegion.Contains(token)) { SetStarted(); string firstPart = token; token = GetToken(); if ((firstPart + " " + token) == EndRegion) { if (_regionStarts.Count == 0) { throw new ParseException(); } _regionStarts.Pop(); } _position = NewLineManager.NextLineEndPosition(_text, _position); UpdatePositionIfEndOfFile(); return(true); } else { _position -= token.Length; return(false); } }