コード例 #1
0
		public XmlTextReader GetSyntaxModeXmlTextReader(SyntaxMode syntaxMode)
		{
			string syntaxModeFile = Path.Combine(directory, syntaxMode.FileName);
			if (!File.Exists(syntaxModeFile)) {
				MessageBox.Show("Can't load highlighting definition " + syntaxModeFile + " (file not found)!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
				return null;
			}
			return new XmlTextReader(File.OpenRead(syntaxModeFile));
		}
コード例 #2
0
        public XmlTextReader GetSyntaxModeXmlTextReader(SyntaxMode syntaxMode)
        {
            string syntaxModeFile = Path.Combine(directory, syntaxMode.FileName);

            if (!File.Exists(syntaxModeFile))
            {
                MessageBox.Show("Can't load highlighting definition " + syntaxModeFile + " (file not found)!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                return(null);
            }
            return(new XmlTextReader(File.OpenRead(syntaxModeFile)));
        }
コード例 #3
0
        //此函数接收一个syntaxMode对象和一个XmlTextReader对象为参数,分析此xmlTextReader对象所对应的语法模式文件,
        //并返回一个高亮度显示策略对象(DefaultHighlightingStrategy).
        DefaultHighlightingStrategy ParseSyntaxMode(SyntaxMode syntaxMode, XmlTextReader xmlTextReader)
        {
            try
            {
                //XmlValidatingReader validatingReader = new XmlValidatingReader(xmlTextReader);
                //Stream shemaStream = Assembly.GetCallingAssembly().GetManifestResourceStream("Mode.xsd");
                //validatingReader.Schemas.Add("", new XmlTextReader(shemaStream));
                //validatingReader.ValidationType = ValidationType.Schema;
                //validatingReader.ValidationEventHandler += new ValidationEventHandler (ValidationHandler);
                //以上定义了一个XmlValidatingReader对象,用于验证语法模式文件.(如CSharp-Mode.xshd)

                XmlDocument doc = new XmlDocument();
                doc.Load(xmlTextReader);

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

                if (doc.DocumentElement.Attributes["extensions"] != null)
                {
                    highlighter.Extensions = doc.DocumentElement.Attributes["extensions"].InnerText.Split(new char[] { ';', '|' });
                }

                // parse environment color
                XmlElement environment = doc.DocumentElement["Environment"];
                if (environment != null)
                {
                    foreach (XmlNode node in environment.ChildNodes)
                    {
                        if (node is XmlElement)
                        {
                            XmlElement el = (XmlElement)node;
                            highlighter.SetColorForEnvironment(el.Name, new HighlightColor(el));
                        }
                    }
                }

                // parse properties,not all xshd files have
                if (doc.DocumentElement["Properties"] != null)
                {
                    foreach (XmlElement propertyElement in doc.DocumentElement["Properties"].ChildNodes)
                    {
                        highlighter.Properties[propertyElement.Attributes["name"].InnerText] = propertyElement.Attributes["value"].InnerText;
                    }
                }

                // parse digits
                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));
                }

                xmlTextReader.Close();

                if (errors != null)
                {
                    ReportErrors(syntaxMode.FileName);
                    errors = null;
                    return(null);
                }
                else
                {
                    return(highlighter);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("不能加载语法模式文件.\n" + e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return(null);
            }
        }
コード例 #4
0
		//此函数接收一个syntaxMode对象和一个XmlTextReader对象为参数,分析此xmlTextReader对象所对应的语法模式文件,
		//并返回一个高亮度显示策略对象(DefaultHighlightingStrategy).
		DefaultHighlightingStrategy ParseSyntaxMode(SyntaxMode syntaxMode, XmlTextReader xmlTextReader)
		{
			try 
			{
                //XmlValidatingReader validatingReader = new XmlValidatingReader(xmlTextReader);
                //Stream shemaStream = Assembly.GetCallingAssembly().GetManifestResourceStream("Mode.xsd");
                //validatingReader.Schemas.Add("", new XmlTextReader(shemaStream));
                //validatingReader.ValidationType = ValidationType.Schema;
                //validatingReader.ValidationEventHandler += new ValidationEventHandler (ValidationHandler);
				//以上定义了一个XmlValidatingReader对象,用于验证语法模式文件.(如CSharp-Mode.xshd)
				
				XmlDocument doc = new XmlDocument();
                doc.Load(xmlTextReader);
				
				DefaultHighlightingStrategy highlighter = new DefaultHighlightingStrategy(doc.DocumentElement.Attributes["name"].InnerText);
				
				if (doc.DocumentElement.Attributes["extensions"]!= null) 
				{
					highlighter.Extensions = doc.DocumentElement.Attributes["extensions"].InnerText.Split(new char[] { ';', '|' });
				}
				
				// parse environment color
				XmlElement environment = doc.DocumentElement["Environment"];
				if (environment != null) 
				{
					foreach (XmlNode node in environment.ChildNodes) 
					{
						if (node is XmlElement) 
						{
							XmlElement el = (XmlElement)node;
							highlighter.SetColorForEnvironment(el.Name, new HighlightColor(el));
						}
					}
				}
				
				// parse properties,not all xshd files have
				if (doc.DocumentElement["Properties"]!= null) 
				{
					foreach (XmlElement propertyElement in doc.DocumentElement["Properties"].ChildNodes) 
					{
						highlighter.Properties[propertyElement.Attributes["name"].InnerText] =  propertyElement.Attributes["value"].InnerText;
					}
				}
				
				// parse digits
				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));
				}
				
				xmlTextReader.Close();
				
				if(errors!=null) 
				{
					ReportErrors(syntaxMode.FileName);
					errors = null;
					return null;
				} 
				else 
				{
					return highlighter;		
				}
			} 
			catch (Exception e) 
			{
				MessageBox.Show("不能加载语法模式文件.\n" + e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
				return null;
			}
		}