/// <summary> /// /// </summary> void LoadSyntaxDefs() { string[] files = Directory.GetFiles("SyntaxDefinition"); foreach (string file in files) { if (Path.GetExtension(file).ToLower() == ".xshd") { using (XmlTextReader reader = new XmlTextReader(file)) { HighlightingStrategy highlightingStrategy = HighlightingDefinitionParser.Parse(reader); if (highlightingStrategy != null) { if (highlightingStrategy.Name == "Text") { HighlightingDefinitions[".txt"] = highlightingStrategy; } else { foreach (string ext in highlightingStrategy.Extensions) { HighlightingDefinitions[ext.ToLower()] = highlightingStrategy; } } } } } } // Resolve references. foreach (var val in HighlightingDefinitions.Values) { // val.ResolveReferences(); // Resolve references from Span definitions to RuleSets val.ResolveRuleSetReferences(); } }
public LineManager(Document document, HighlightingStrategy highlightingStrategy) { _document = document; _highlightingStrategy = highlightingStrategy; }
public static HighlightingStrategy Parse(XmlReader xmlReader) { try { List <ValidationEventArgs> errors = null; XmlReaderSettings settings = new XmlReaderSettings(); // was: Stream schemaStream = typeof(HighlightingDefinitionParser).Assembly.GetManifestResourceStream("ICSharpCode.TextEditor.Resources.Mode.xsd"); string schemaStreamFile = Path.Combine("SyntaxDefinition", "Mode.xsd"); Stream schemaStream = File.OpenRead(schemaStreamFile); settings.Schemas.Add("", new XmlTextReader(schemaStream)); settings.Schemas.ValidationEventHandler += delegate(object sender, ValidationEventArgs args) { if (errors == null) { errors = new List <ValidationEventArgs>(); } errors.Add(args); }; settings.ValidationType = ValidationType.Schema; XmlReader validatingReader = XmlReader.Create(xmlReader, settings); XmlDocument doc = new XmlDocument(); doc.Load(validatingReader); HighlightingStrategy highlighter = new HighlightingStrategy(doc.DocumentElement.Attributes["name"].InnerText); //TODOsyntax this is not used right now: //if (doc.DocumentElement.HasAttribute("extends")) //{ // KeyValuePair<SyntaxMode, ISyntaxModeFileProvider> entry = HighlightingManager.Instance.FindHighlighterEntry(doc.DocumentElement.GetAttribute("extends")); // if (entry.Key == null) // { // throw new HighlightingDefinitionInvalidException("Cannot find referenced highlighting source " + doc.DocumentElement.GetAttribute("extends")); // } // else // { // highlighter = Parse(highlighter, entry.Key, entry.Value.GetSyntaxModeFile(entry.Key)); // if (highlighter == null) return null; // } //} if (doc.DocumentElement.HasAttribute("extensions")) { highlighter.Extensions = doc.DocumentElement.GetAttribute("extensions").Split(new char[] { ';', '|' }); } if (doc.DocumentElement.HasAttribute("folding")) { highlighter.Folding = doc.DocumentElement.GetAttribute("folding"); } // parse properties if (doc.DocumentElement["Properties"] != null) { foreach (XmlElement propertyElement in doc.DocumentElement["Properties"].ChildNodes) { highlighter.Properties[propertyElement.Attributes["name"].InnerText] = propertyElement.Attributes["value"].InnerText; } } if (doc.DocumentElement["Digits"] != null) { highlighter.DigitColor = new HighlightColor(doc.DocumentElement["Digits"]); } XmlNodeList nodes = doc.DocumentElement.GetElementsByTagName("RuleSet"); foreach (XmlElement element in nodes) { highlighter.AddRuleSet(new HighlightRuleSet(element)); } xmlReader.Close(); if (errors != null) { StringBuilder msg = new StringBuilder(); foreach (ValidationEventArgs args in errors) { msg.AppendLine(args.Message); } throw new Exception(msg.ToString()); } else { return(highlighter); } } catch (Exception e) { throw new Exception("Could not load mode definition file", e); } }