Ejemplo n.º 1
0
        IHighlightingStrategy LoadDefinition(DictionaryEntry entry)
        {
            SyntaxMode syntaxMode = (SyntaxMode)entry.Key;
            ISyntaxModeFileProvider syntaxModeFileProvider = (ISyntaxModeFileProvider)entry.Value;

            DefaultHighlightingStrategy highlightingStrategy = null;

            try {
                //johnny
                //var reader = syntaxModeFileProvider.GetSyntaxModeFile(syntaxMode);
                System.Xml.XmlTextReader reader = syntaxModeFileProvider.GetSyntaxModeFile(syntaxMode);
                if (reader == null)
                {
                    throw new HighlightingDefinitionInvalidException("Could not get syntax mode file for " + syntaxMode.Name);
                }
                highlightingStrategy = HighlightingDefinitionParser.Parse(syntaxMode, reader);
                if (highlightingStrategy.Name != syntaxMode.Name)
                {
                    throw new HighlightingDefinitionInvalidException("The name specified in the .xshd '" + highlightingStrategy.Name + "' must be equal the syntax mode name '" + syntaxMode.Name + "'");
                }
            } finally {
                if (highlightingStrategy == null)
                {
                    highlightingStrategy = DefaultHighlighting;
                }
                highlightingDefs[syntaxMode.Name] = highlightingStrategy;
                highlightingStrategy.ResolveReferences();
            }
            return(highlightingStrategy);
        }
        IHighlightingStrategy LoadDefinition(Tuple <SyntaxMode, ISyntaxModeFileProvider> entry)
        {
            SyntaxMode syntaxMode = entry.Item1;
            ISyntaxModeFileProvider syntaxModeFileProvider = entry.Item2;

            DefaultHighlightingStrategy highlightingStrategy = null;

            try
            {
                var reader = syntaxModeFileProvider.GetSyntaxModeFile(syntaxMode);
                if (reader == null)
                {
                    throw new HighlightingDefinitionInvalidException("Could not get syntax mode file for " + syntaxMode.Name);
                }
                highlightingStrategy = HighlightingDefinitionParser.Parse(syntaxMode, reader);
                if (highlightingStrategy.Name != syntaxMode.Name)
                {
                    throw new HighlightingDefinitionInvalidException("The name specified in the .xshd '" + highlightingStrategy.Name + "' must be equal the syntax mode name '" + syntaxMode.Name + "'");
                }
            }
            finally
            {
                if (highlightingStrategy == null)
                {
                    highlightingStrategy = DefaultHighlighting;
                }
                HighlightingDefinitions[syntaxMode.Name] = highlightingStrategy;
                highlightingStrategy.ResolveReferences();
            }
            return(highlightingStrategy);
        }
Ejemplo n.º 3
0
        private IHighlightingStrategy LoadDefinition(DictionaryEntry entry)
        {
            SyntaxMode key = (SyntaxMode)entry.Key;
            ISyntaxModeFileProvider     value = (ISyntaxModeFileProvider)entry.Value;
            DefaultHighlightingStrategy defaultHighlighting = null;

            try
            {
                XmlTextReader syntaxModeFile = value.GetSyntaxModeFile(key);
                if (syntaxModeFile == null)
                {
                    throw new HighlightingDefinitionInvalidException(string.Concat("Could not get syntax mode file for ", key.Name));
                }
                defaultHighlighting = HighlightingDefinitionParser.Parse(key, syntaxModeFile);
                if (defaultHighlighting.Name != key.Name)
                {
                    string[] name = new string[] { "The name specified in the .xshd '", defaultHighlighting.Name, "' must be equal the syntax mode name '", key.Name, "'" };
                    throw new HighlightingDefinitionInvalidException(string.Concat(name));
                }
            }
            finally
            {
                if (defaultHighlighting == null)
                {
                    defaultHighlighting = this.DefaultHighlighting;
                }
                this.highlightingDefs[key.Name] = defaultHighlighting;
                defaultHighlighting.ResolveReferences();
            }
            return(defaultHighlighting);
        }
        IHighlightingStrategy LoadDefinition(DictionaryEntry entry)
        {
            SyntaxMode syntaxMode = (SyntaxMode)entry.Key;
            ISyntaxModeFileProvider syntaxModeFileProvider = (ISyntaxModeFileProvider)entry.Value;

            DefaultHighlightingStrategy highlightingStrategy = HighlightingDefinitionParser.Parse(syntaxMode, syntaxModeFileProvider.GetSyntaxModeFile(syntaxMode));

            highlightingDefs[syntaxMode.Name] = highlightingStrategy;
            highlightingStrategy.ResolveReferences();

            return(highlightingStrategy);
        }
Ejemplo n.º 5
0
        public SyntaxMode AddHighlightingStrategy(string syntaxFile)
        {
            DefaultHighlightingStrategy highlightingStrategy = null;
            SyntaxMode syntaxMode = new SyntaxMode(syntaxFile, "", "");

            try
            {
                var reader = new XmlTextReader(File.OpenRead(syntaxFile));
                if (reader == null)
                {
                    throw new HighlightingDefinitionInvalidException("Could not get syntax mode file for " + syntaxFile);
                }

                highlightingStrategy  = HighlightingDefinitionParser.Parse(syntaxMode, reader);
                syntaxMode.Name       = highlightingStrategy.Name;
                syntaxMode.Extensions = highlightingStrategy.Extensions;

                //if (highlightingStrategy.Name != syntaxMode.Name)
                //{
                //    throw new HighlightingDefinitionInvalidException("The name specified in the .xshd '" + highlightingStrategy.Name + "' must be equal the syntax mode name '" + syntaxMode.Name + "'");
                //}

                if (highlightingStrategy == null)
                {
                    highlightingStrategy = DefaultHighlighting;
                }
                highlightingDefs[syntaxMode.Name] = highlightingStrategy;
                highlightingStrategy.ResolveReferences();
                foreach (string extension in highlightingStrategy.Extensions)
                {
                    extensionsToName[extension.ToUpperInvariant()] = highlightingStrategy.Name;
                }

                return(syntaxMode);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message + ex.StackTrace);
                return(null);
            }
        }
        /// <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();
            }
        }
Ejemplo n.º 7
0
        public static DefaultHighlightingStrategy Parse(DefaultHighlightingStrategy highlighter, SyntaxMode syntaxMode, XmlReader xmlReader)
        {
            DefaultHighlightingStrategy defaultHighlightingStrategy;
            HighlightColor highlightBackground;
            HighlightColor highlightColor;

            if (syntaxMode == null)
            {
                throw new ArgumentNullException("syntaxMode");
            }
            if (xmlReader == null)
            {
                throw new ArgumentNullException("xmlTextReader");
            }
            try
            {
                List <ValidationEventArgs> validationEventArgs = null;
                XmlReaderSettings          xmlReaderSetting    = new XmlReaderSettings();
                Stream manifestResourceStream = typeof(HighlightingDefinitionParser).Assembly.GetManifestResourceStream("BigBug.ICSharpCode.TextEditor.xshd.Mode.xsd");
                xmlReaderSetting.Schemas.Add("", new XmlTextReader(manifestResourceStream));
                xmlReaderSetting.Schemas.ValidationEventHandler += new ValidationEventHandler((object sender, ValidationEventArgs args) => {
                    if (validationEventArgs == null)
                    {
                        validationEventArgs = new List <ValidationEventArgs>();
                    }
                    validationEventArgs.Add(args);
                });
                xmlReaderSetting.ValidationType = ValidationType.Schema;
                XmlReader   xmlReader1  = XmlReader.Create(xmlReader, xmlReaderSetting);
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(xmlReader1);
                if (highlighter == null)
                {
                    highlighter = new DefaultHighlightingStrategy(xmlDocument.DocumentElement.Attributes["name"].InnerText);
                }
                if (xmlDocument.DocumentElement.HasAttribute("extends"))
                {
                    KeyValuePair <SyntaxMode, ISyntaxModeFileProvider> keyValuePair = HighlightingManager.Manager.FindHighlighterEntry(xmlDocument.DocumentElement.GetAttribute("extends"));
                    if (keyValuePair.Key == null)
                    {
                        throw new HighlightingDefinitionInvalidException(string.Concat("Cannot find referenced highlighting source ", xmlDocument.DocumentElement.GetAttribute("extends")));
                    }
                    highlighter = HighlightingDefinitionParser.Parse(highlighter, keyValuePair.Key, keyValuePair.Value.GetSyntaxModeFile(keyValuePair.Key));
                    if (highlighter == null)
                    {
                        defaultHighlightingStrategy = null;
                        return(defaultHighlightingStrategy);
                    }
                }
                if (xmlDocument.DocumentElement.HasAttribute("extensions"))
                {
                    string attribute = xmlDocument.DocumentElement.GetAttribute("extensions");
                    char[] chrArray  = new char[] { ';', '|' };
                    highlighter.Extensions = attribute.Split(chrArray);
                }
                XmlElement item = xmlDocument.DocumentElement["Environment"];
                if (item != null)
                {
                    foreach (XmlNode childNode in item.ChildNodes)
                    {
                        if (!(childNode is XmlElement))
                        {
                            continue;
                        }
                        XmlElement xmlElement = (XmlElement)childNode;
                        if (xmlElement.Name != "Custom")
                        {
                            DefaultHighlightingStrategy defaultHighlightingStrategy1 = highlighter;
                            string name = xmlElement.Name;
                            if (xmlElement.HasAttribute("bgcolor"))
                            {
                                highlightBackground = new HighlightBackground(xmlElement);
                            }
                            else
                            {
                                highlightBackground = new HighlightColor(xmlElement);
                            }
                            defaultHighlightingStrategy1.SetColorFor(name, highlightBackground);
                        }
                        else
                        {
                            DefaultHighlightingStrategy defaultHighlightingStrategy2 = highlighter;
                            string str = xmlElement.GetAttribute("name");
                            if (xmlElement.HasAttribute("bgcolor"))
                            {
                                highlightColor = new HighlightBackground(xmlElement);
                            }
                            else
                            {
                                highlightColor = new HighlightColor(xmlElement);
                            }
                            defaultHighlightingStrategy2.SetColorFor(str, highlightColor);
                        }
                    }
                }
                if (xmlDocument.DocumentElement["Properties"] != null)
                {
                    foreach (XmlElement innerText in xmlDocument.DocumentElement["Properties"].ChildNodes)
                    {
                        highlighter.Properties[innerText.Attributes["name"].InnerText] = innerText.Attributes["value"].InnerText;
                    }
                }
                if (xmlDocument.DocumentElement["Digits"] != null)
                {
                    highlighter.DigitColor = new HighlightColor(xmlDocument.DocumentElement["Digits"]);
                }
                foreach (XmlElement elementsByTagName in xmlDocument.DocumentElement.GetElementsByTagName("RuleSet"))
                {
                    highlighter.AddRuleSet(new HighlightRuleSet(elementsByTagName));
                }
                xmlReader.Close();
                if (validationEventArgs != null)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    foreach (ValidationEventArgs validationEventArg in validationEventArgs)
                    {
                        stringBuilder.AppendLine(validationEventArg.Message);
                    }
                    throw new HighlightingDefinitionInvalidException(stringBuilder.ToString());
                }
                defaultHighlightingStrategy = highlighter;
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                throw new HighlightingDefinitionInvalidException(string.Concat("Could not load mode definition file '", syntaxMode.FileName, "'.\n"), exception);
            }
            return(defaultHighlightingStrategy);
        }
Ejemplo n.º 8
0
 public static DefaultHighlightingStrategy Parse(SyntaxMode syntaxMode, XmlReader xmlReader)
 {
     return(HighlightingDefinitionParser.Parse(null, syntaxMode, xmlReader));
 }