public XmlTextReader GetSyntaxModeFile(SyntaxMode syntaxMode)
		{
			string syntaxModeFile = Path.Combine(directory, syntaxMode.FileName);
			if (!File.Exists(syntaxModeFile)) {
				throw new HighlightingDefinitionInvalidException("Can't load highlighting definition " + syntaxModeFile + " (file not found)!");
			}
			return new XmlTextReader(File.OpenRead(syntaxModeFile));
		}
Beispiel #2
0
        public XmlTextReader GetSyntaxModeFile(SyntaxMode syntaxMode)
        {
            string syntaxModeFile = Path.Combine(directory, syntaxMode.FileName);

            if (!File.Exists(syntaxModeFile))
            {
                throw new HighlightingDefinitionInvalidException("Can't load highlighting definition " + syntaxModeFile + " (file not found)!");
            }
            return(new XmlTextReader(File.OpenRead(syntaxModeFile)));
        }
        public ResourceSyntaxModeProvider()
        {
            Assembly assembly         = typeof(SyntaxMode).Assembly;
            Stream   syntaxModeStream = assembly.GetManifestResourceStream("GodLesZ.eAthenaEditor.Library.Resources.SyntaxModes.xml");

            if (syntaxModeStream != null)
            {
                syntaxModes = SyntaxMode.GetSyntaxModes(syntaxModeStream);
            }
            else
            {
                syntaxModes = new List <SyntaxMode>();
            }
        }
Beispiel #4
0
        public void UpdateSyntaxModeList()
        {
            string syntaxModeFile = Path.Combine(directory, "SyntaxModes.xml");

            if (File.Exists(syntaxModeFile))
            {
                Stream s = File.OpenRead(syntaxModeFile);
                syntaxModes = SyntaxMode.GetSyntaxModes(s);
                s.Close();
            }
            else
            {
                syntaxModes = ScanDirectory(directory);
            }
        }
Beispiel #5
0
        public static DefaultHighlightingStrategy Parse(DefaultHighlightingStrategy highlighter, SyntaxMode syntaxMode, XmlReader xmlReader)
        {
            if (syntaxMode == null)
            {
                throw new ArgumentNullException("syntaxMode");
            }
            if (xmlReader == null)
            {
                throw new ArgumentNullException("xmlTextReader");
            }
            try {
                List <ValidationEventArgs> errors   = null;
                XmlReaderSettings          settings = new XmlReaderSettings();
                Stream shemaStream = typeof(HighlightingDefinitionParser).Assembly.GetManifestResourceStream("GodLesZ.eAthenaEditor.Library.Resources.Mode.xsd");
                settings.Schemas.Add("", new XmlTextReader(shemaStream));
                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);

                if (highlighter == null)
                {
                    highlighter = new DefaultHighlightingStrategy(doc.DocumentElement.Attributes["name"].InnerText);
                }

                if (doc.DocumentElement.HasAttribute("extends"))
                {
                    KeyValuePair <SyntaxMode, ISyntaxModeFileProvider> entry = HighlightingManager.Manager.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[] { ';', '|' });
                }

                XmlElement environment = doc.DocumentElement["Environment"];
                if (environment != null)
                {
                    foreach (XmlNode node in environment.ChildNodes)
                    {
                        if (node is XmlElement)
                        {
                            XmlElement el = (XmlElement)node;
                            if (el.Name == "Custom")
                            {
                                highlighter.SetColorFor(el.GetAttribute("name"), el.HasAttribute("bgcolor") ? new HighlightBackground(el) : new HighlightColor(el));
                            }
                            else
                            {
                                highlighter.SetColorFor(el.Name, el.HasAttribute("bgcolor") ? new HighlightBackground(el) : new HighlightColor(el));
                            }
                        }
                    }
                }

                // 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 HighlightingDefinitionInvalidException(msg.ToString());
                }
                else
                {
                    return(highlighter);
                }
            } catch (Exception e) {
                throw new HighlightingDefinitionInvalidException("Could not load mode definition file '" + syntaxMode.FileName + "'.\n", e);
            }
        }
Beispiel #6
0
 public static DefaultHighlightingStrategy Parse(SyntaxMode syntaxMode, XmlReader xmlReader)
 {
     return(Parse(null, syntaxMode, xmlReader));
 }
		public XmlTextReader GetSyntaxModeFile(SyntaxMode syntaxMode)
		{
			Assembly assembly = typeof(SyntaxMode).Assembly;
			return new XmlTextReader(assembly.GetManifestResourceStream("GodLesZ.eAthenaEditor.Library.Resources." + syntaxMode.FileName));
		}
        public XmlTextReader GetSyntaxModeFile(SyntaxMode syntaxMode)
        {
            Assembly assembly = typeof(SyntaxMode).Assembly;

            return(new XmlTextReader(assembly.GetManifestResourceStream("GodLesZ.eAthenaEditor.Library.Resources." + syntaxMode.FileName)));
        }
		public static DefaultHighlightingStrategy Parse(DefaultHighlightingStrategy highlighter, SyntaxMode syntaxMode, XmlReader xmlReader) {
			if (syntaxMode == null)
				throw new ArgumentNullException("syntaxMode");
			if (xmlReader == null)
				throw new ArgumentNullException("xmlTextReader");
			try {
				List<ValidationEventArgs> errors = null;
				XmlReaderSettings settings = new XmlReaderSettings();
				Stream shemaStream = typeof(HighlightingDefinitionParser).Assembly.GetManifestResourceStream("GodLesZ.eAthenaEditor.Library.Resources.Mode.xsd");
				settings.Schemas.Add("", new XmlTextReader(shemaStream));
				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);

				if (highlighter == null)
					highlighter = new DefaultHighlightingStrategy(doc.DocumentElement.Attributes["name"].InnerText);

				if (doc.DocumentElement.HasAttribute("extends")) {
					KeyValuePair<SyntaxMode, ISyntaxModeFileProvider> entry = HighlightingManager.Manager.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[] { ';', '|' });
				}

				XmlElement environment = doc.DocumentElement["Environment"];
				if (environment != null) {
					foreach (XmlNode node in environment.ChildNodes) {
						if (node is XmlElement) {
							XmlElement el = (XmlElement)node;
							if (el.Name == "Custom") {
								highlighter.SetColorFor(el.GetAttribute("name"), el.HasAttribute("bgcolor") ? new HighlightBackground(el) : new HighlightColor(el));
							} else {
								highlighter.SetColorFor(el.Name, el.HasAttribute("bgcolor") ? new HighlightBackground(el) : new HighlightColor(el));
							}
						}
					}
				}

				// 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 HighlightingDefinitionInvalidException(msg.ToString());
				} else {
					return highlighter;
				}
			} catch (Exception e) {
				throw new HighlightingDefinitionInvalidException("Could not load mode definition file '" + syntaxMode.FileName + "'.\n", e);
			}
		}
		public static DefaultHighlightingStrategy Parse(SyntaxMode syntaxMode, XmlReader xmlReader) {
			return Parse(null, syntaxMode, xmlReader);
		}