Rule DeepCopy(TextDocument doc, SyntaxMode mode, Rule rule) { var newRule = new Rule(); newRule.spans = new Span[rule.Spans.Length]; for (int i = 0; i < rule.Spans.Length; i++) { newRule.spans [i] = rule.Spans [i].Clone(); } if (rule.HasDelimiter) { newRule.SetDelimiter(rule.GetDelimiter(null)); } newRule.IgnoreCase = rule.IgnoreCase; newRule.Name = rule.Name; newRule.DefaultColor = rule.DefaultColor; newRule.matches = rule.Matches; newRule.prevMarker = rule.PrevMarker; newRule.keywords = rule.keywords; newRule.keywordTable = rule.keywordTable; newRule.keywordTableIgnoreCase = rule.keywordTableIgnoreCase; foreach (var pair in rule.Properties) { newRule.Properties.Add(pair.Key, pair.Value); } return(newRule); }
public void ParseChar(ref int i, char ch) { Rule cur = spanParser.CurRule; bool isWordPart = cur.GetDelimiter(mode).IndexOf(ch) < 0; if (inWord && !isWordPart || !inWord && isWordPart) { AddChunk(ref curChunk, 0, curChunk.Style = GetStyle(curChunk) ?? GetSpanStyle()); } inWord = isWordPart; if (cur.HasMatches && (i - curChunk.Offset == 0 || string.IsNullOrEmpty(cur.GetDelimiter(mode)))) { Match foundMatch = null; var foundMatchLength = new int[0]; int textOffset = i - spanParser.StartOffset; foreach (Match ruleMatch in cur.Matches) { var matchLength = ruleMatch.TryMatch(spanParser.CurText, textOffset); if (foundMatchLength.Length < matchLength.Length) { foundMatch = ruleMatch; foundMatchLength = matchLength; } } if (foundMatch != null) { if (foundMatch.IsGroupMatch) { for (int j = 1; j < foundMatchLength.Length; j++) { var len = foundMatchLength [j]; if (len > 0) { AddChunk(ref curChunk, len, GetChunkStyleColor(foundMatch.Groups [j - 1])); i += len - 1; curChunk.Length = 0; } } return; } if (foundMatchLength[0] > 0) { AddChunk(ref curChunk, foundMatchLength[0], GetChunkStyleColor(foundMatch.Color)); i += foundMatchLength[0] - 1; curChunk.Length = 0; return; } } } wordbuilder.Append(ch); curChunk.Length = i - curChunk.Offset + 1; if (!isWordPart) { AddChunk(ref curChunk, 0, curChunk.Style = GetStyle(curChunk) ?? GetSpanStyle()); } }
Rule DeepCopy (TextDocument doc, SyntaxMode mode, Rule rule) { var newRule = new Rule (); newRule.spans = new Span[rule.Spans.Length]; for (int i = 0; i < rule.Spans.Length; i++) { newRule.spans [i] = rule.Spans [i].Clone (); } if (rule.HasDelimiter) newRule.SetDelimiter (rule.GetDelimiter (null)); newRule.IgnoreCase = rule.IgnoreCase; newRule.Name = rule.Name; newRule.DefaultColor = rule.DefaultColor; newRule.matches = rule.Matches; newRule.prevMarker = rule.PrevMarker; newRule.keywords = rule.keywords; newRule.keywordTable = rule.keywordTable; newRule.keywordTableIgnoreCase = rule.keywordTableIgnoreCase; foreach (var pair in rule.Properties) newRule.Properties.Add (pair.Key, pair.Value); return newRule; }