object IXshdVisitor.VisitKeywords(XshdKeywords keywords) { writer.WriteStartElement("Keywords", Namespace); WriteColorReference(keywords.ColorReference); foreach (string word in keywords.Words) { writer.WriteElementString("Word", Namespace, word); } writer.WriteEndElement(); return null; }
XshdRuleSet ImportRuleSet(XmlElement element) { XshdRuleSet ruleSet = new XshdRuleSet(); ruleSet.Name = element.GetAttributeOrNull("name"); if (element.HasAttribute("escapecharacter")) { ruleSetEscapeCharacter = element.GetAttribute("escapecharacter")[0]; } else { ruleSetEscapeCharacter = '\0'; } if (element.HasAttribute("reference")) { ruleSet.Elements.Add( new XshdImport { RuleSetReference = new XshdReference<XshdRuleSet>( element.GetAttribute("reference"), string.Empty ) }); } ruleSet.IgnoreCase = element.GetBoolAttribute("ignorecase"); foreach (XmlElement el in element.GetElementsByTagName("KeyWords")) { XshdKeywords keywords = new XshdKeywords(); keywords.ColorReference = GetColorReference(el); // we have to handle old syntax highlighting definitions that contain // empty keywords or empty keyword groups foreach (XmlElement node in el.GetElementsByTagName("Key")) { string word = node.GetAttribute("word"); if (!string.IsNullOrEmpty(word)) keywords.Words.Add(word); } if (keywords.Words.Count > 0) { ruleSet.Elements.Add(keywords); } } foreach (XmlElement el in element.GetElementsByTagName("Span")) { ruleSet.Elements.Add(ImportSpan(el)); } foreach (XmlElement el in element.GetElementsByTagName("MarkPrevious")) { ruleSet.Elements.Add(ImportMarkPrevNext(el, false)); } foreach (XmlElement el in element.GetElementsByTagName("MarkFollowing")) { ruleSet.Elements.Add(ImportMarkPrevNext(el, true)); } return ruleSet; }
public object VisitKeywords(XshdKeywords keywords) { return keywords.ColorReference.AcceptVisitor(this); }
static XshdKeywords ParseKeywords(XmlReader reader) { XshdKeywords keywords = new XshdKeywords(); SetPosition(keywords, reader); keywords.ColorReference = ParseColorReference(reader); reader.Read(); while (reader.NodeType != XmlNodeType.EndElement) { Debug.Assert(reader.NodeType == XmlNodeType.Element); keywords.Words.Add(reader.ReadElementString()); } return keywords; }
public object VisitKeywords(XshdKeywords keywords) { if (keywords.Words.Count == 0) return Error(keywords, "Keyword group must not be empty."); foreach (string keyword in keywords.Words) { if (string.IsNullOrEmpty(keyword)) throw Error(keywords, "Cannot use empty string as keyword"); } StringBuilder keyWordRegex = new StringBuilder(); // We can use "\b" only where the keyword starts/ends with a letter or digit, otherwise we don't // highlight correctly. (example: ILAsm-Mode.xshd with ".maxstack" keyword) if (keywords.Words.All(IsSimpleWord)) { keyWordRegex.Append(@"\b(?>"); // (?> = atomic group // atomic groups increase matching performance, but we // must ensure that the keywords are sorted correctly. // "\b(?>in|int)\b" does not match "int" because the atomic group captures "in". // To solve this, we are sorting the keywords by descending length. int i = 0; foreach (string keyword in keywords.Words.OrderByDescending(w=>w.Length)) { if (i++ > 0) keyWordRegex.Append('|'); keyWordRegex.Append(Regex.Escape(keyword)); } keyWordRegex.Append(@")\b"); } else { keyWordRegex.Append('('); int i = 0; foreach (string keyword in keywords.Words) { if (i++ > 0) keyWordRegex.Append('|'); if (char.IsLetterOrDigit(keyword[0])) keyWordRegex.Append(@"\b"); keyWordRegex.Append(Regex.Escape(keyword)); if (char.IsLetterOrDigit(keyword[keyword.Length - 1])) keyWordRegex.Append(@"\b"); } keyWordRegex.Append(')'); } return new HighlightingRule { Color = GetColor(keywords, keywords.ColorReference), Regex = CreateRegex(keywords, keyWordRegex.ToString(), XshdRegexType.Default) }; }
public object VisitKeywords(XshdKeywords keywords) { if (keywords.Words.Count == 0) return Error(keywords, "Keyword group must not be empty."); foreach (string keyword in keywords.Words) { if (string.IsNullOrEmpty(keyword)) throw Error(keywords, "Cannot use empty string as keyword"); } StringBuilder keyWordRegex = new StringBuilder(@"\b(?>"); // (?> = atomic group // atomic groups increase matching performance, but we // must ensure that the keywords are sorted correctly. // "\b(?>in|int)\b" does not match "int" because the atomic group captures "in". // To solve this, we are sorting the keywords by descending length. int i = 0; foreach (string keyword in keywords.Words.OrderByDescending(w=>w.Length)) { if (i++ > 0) keyWordRegex.Append('|'); keyWordRegex.Append(Regex.Escape(keyword)); } keyWordRegex.Append(@")\b"); return new HighlightingRule { Color = GetColor(keywords, keywords.ColorReference), Regex = CreateRegex(keywords, keyWordRegex.ToString(), XshdRegexType.Default) }; }
private void updateStandardWordList(int i) { OptionsWindow _ow = new OptionsWindow(); XshdKeywords newKeyWords = new XshdKeywords(); XshdSpan newSpan = new XshdSpan(); XshdSpan otherNewSpan = new XshdSpan(); XshdSpan thirdNewSpan = new XshdSpan(); XshdSpan thNewSpan = new XshdSpan(); XshdRule rule = new XshdRule(); XshdRuleSet mainRuleSet = xshd.Elements.OfType<XshdRuleSet>().Where(o => string.IsNullOrEmpty(o.Name)).First(); if(i==0) { for(int ii=0;ii<_ow.commands.Count;ii++) { newKeyWords.Words.Add(_ow.commands[ii].Commnd); } XshdColor xcol = xshd.Elements.OfType<XshdColor>().Where(xc => string.Equals(xc.Name, (_ow.words[i].color+_ow.words[i].fontstyle), StringComparison.CurrentCultureIgnoreCase)).First(); newKeyWords.ColorReference = new XshdReference<XshdColor>(null, xcol.Name); mainRuleSet.Elements.Add(newKeyWords); } if(i==1) { for(int ii=0;ii<_ow.subs.Count;ii++) { newKeyWords.Words.Add(_ow.subs[ii].Sub); } XshdColor xcol = xshd.Elements.OfType<XshdColor>().Where(xc => string.Equals(xc.Name, (_ow.words[i].color+_ow.words[i].fontstyle), StringComparison.CurrentCultureIgnoreCase)).First(); newKeyWords.ColorReference = new XshdReference<XshdColor>(null, xcol.Name); mainRuleSet.Elements.Add(newKeyWords); } if(i==2) { XshdColor xcol = xshd.Elements.OfType<XshdColor>().Where(xc => string.Equals(xc.Name, (_ow.words[i].color+_ow.words[i].fontstyle), StringComparison.CurrentCultureIgnoreCase)).First(); newSpan.SpanColorReference = new XshdReference<XshdColor>(null, xcol.Name); newSpan.BeginRegex = @"[//]{2,3}"; otherNewSpan.SpanColorReference = new XshdReference<XshdColor>(null, xcol.Name); otherNewSpan.BeginRegex = @";."; mainRuleSet.Elements.Add(newSpan); mainRuleSet.Elements.Add(otherNewSpan); } if(i==3) { XshdColor xcol = xshd.Elements.OfType<XshdColor>().Where(xc => string.Equals(xc.Name, (_ow.words[i].color+_ow.words[i].fontstyle), StringComparison.CurrentCultureIgnoreCase)).First(); rule.ColorReference = new XshdReference<XshdColor>(null, xcol.Name); rule.Regex = @"\b0[xX][0-9a-fA-F]+|\b(\d+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?"; mainRuleSet.Elements.Add(rule); } if(i==4) { XshdColor xcol = xshd.Elements.OfType<XshdColor>().Where(xc => string.Equals(xc.Name, (_ow.words[i].color+_ow.words[i].fontstyle), StringComparison.CurrentCultureIgnoreCase)).First(); thNewSpan.SpanColorReference = new XshdReference<XshdColor>(null, xcol.Name); thNewSpan.BeginRegex = "\""; thNewSpan.EndRegex = "\""; mainRuleSet.Elements.Add(thNewSpan); } if(i==5) { for(int ii=0;ii<_ow.oc_alias.Count;ii++) { newKeyWords.Words.Add(_ow.oc_alias[ii].Alias); } XshdColor xcol = xshd.Elements.OfType<XshdColor>().Where(xc => string.Equals(xc.Name, (_ow.words[i].color+_ow.words[i].fontstyle), StringComparison.CurrentCultureIgnoreCase)).First(); newKeyWords.ColorReference = new XshdReference<XshdColor>(null, xcol.Name); mainRuleSet.Elements.Add(newKeyWords); } }
private void updateWordList(int i) { OptionsWindow _ow = new OptionsWindow(); XshdKeywords newKeyWords = new XshdKeywords(); XshdRuleSet mainRuleSet = xshd.Elements.OfType<XshdRuleSet>().Where(o => string.IsNullOrEmpty(o.Name)).First(); newKeyWords.Words.Add(_ow.words[i].Word); XshdColor xcol = xshd.Elements.OfType<XshdColor>().Where(xc => string.Equals(xc.Name, (_ow.words[i].color+_ow.words[i].fontstyle), StringComparison.CurrentCultureIgnoreCase)).First(); newKeyWords.ColorReference = new XshdReference<XshdColor>(null, xcol.Name); mainRuleSet.Elements.Add(newKeyWords); }
public object VisitKeywords(XshdKeywords keywords) { if (keywords.Words.Count == 0) { return(Error(keywords, "Keyword group must not be empty.")); } foreach (string keyword in keywords.Words) { if (string.IsNullOrEmpty(keyword)) { throw Error(keywords, "Cannot use empty string as keyword"); } } StringBuilder keyWordRegex = new StringBuilder(); // We can use "\b" only where the keyword starts/ends with a letter or digit, otherwise we don't // highlight correctly. (example: ILAsm-Mode.xshd with ".maxstack" keyword) if (keywords.Words.All(IsSimpleWord)) { keyWordRegex.Append(@"\b(?>"); // (?> = atomic group // atomic groups increase matching performance, but we // must ensure that the keywords are sorted correctly. // "\b(?>in|int)\b" does not match "int" because the atomic group captures "in". // To solve this, we are sorting the keywords by descending length. int i = 0; foreach (string keyword in keywords.Words.OrderByDescending(w => w.Length)) { if (i++ > 0) { keyWordRegex.Append('|'); } keyWordRegex.Append(Regex.Escape(keyword)); } keyWordRegex.Append(@")\b"); } else { keyWordRegex.Append('('); int i = 0; foreach (string keyword in keywords.Words) { if (i++ > 0) { keyWordRegex.Append('|'); } if (char.IsLetterOrDigit(keyword[0])) { keyWordRegex.Append(@"\b"); } keyWordRegex.Append(Regex.Escape(keyword)); if (char.IsLetterOrDigit(keyword[keyword.Length - 1])) { keyWordRegex.Append(@"\b"); } } keyWordRegex.Append(')'); } return(new HighlightingRule { Color = GetColor(keywords, keywords.ColorReference), Regex = CreateRegex(keywords, keyWordRegex.ToString(), XshdRegexType.Default) }); }
public object VisitKeywords(XshdKeywords keywords) { return(keywords.ColorReference.AcceptVisitor(this)); }
XshdRuleSet ImportRuleSet(XmlElement element) { XshdRuleSet ruleSet = new XshdRuleSet(); ruleSet.Name = element.GetAttributeOrNull("name"); if (element.HasAttribute("escapecharacter")) { ruleSetEscapeCharacter = element.GetAttribute("escapecharacter")[0]; } else { ruleSetEscapeCharacter = '\0'; } if (element.HasAttribute("reference")) { ruleSet.Elements.Add( new XshdImport { RuleSetReference = new XshdReference <XshdRuleSet>( element.GetAttribute("reference"), string.Empty ) }); } ruleSet.IgnoreCase = element.GetBoolAttribute("ignorecase"); foreach (XmlElement el in element.GetElementsByTagName("KeyWords")) { XshdKeywords keywords = new XshdKeywords(); keywords.ColorReference = GetColorReference(el); // we have to handle old syntax highlighting definitions that contain // empty keywords or empty keyword groups foreach (XmlElement node in el.GetElementsByTagName("Key")) { string word = node.GetAttribute("word"); if (!string.IsNullOrEmpty(word)) { keywords.Words.Add(word); } } if (keywords.Words.Count > 0) { ruleSet.Elements.Add(keywords); } } foreach (XmlElement el in element.GetElementsByTagName("Span")) { ruleSet.Elements.Add(ImportSpan(el)); } foreach (XmlElement el in element.GetElementsByTagName("MarkPrevious")) { ruleSet.Elements.Add(ImportMarkPrevNext(el, false)); } foreach (XmlElement el in element.GetElementsByTagName("MarkFollowing")) { ruleSet.Elements.Add(ImportMarkPrevNext(el, true)); } return(ruleSet); }