예제 #1
0
        public static SyntaxLanguage GetDynamicLanguage(string name, float windowBrightness)
        {
            SyntaxLanguage language2;
            string         key = name + windowBrightness;

            if (_dynamicLanguages.ContainsKey(key))
            {
                return(_dynamicLanguages[key]);
            }
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("LINQPad.Lexers." + name + ".xml"))
            {
                language2 = DynamicSyntaxLanguage.LoadFromXml(stream, 0);
            }
            foreach (HighlightingStyle style in language2.get_HighlightingStyles())
            {
                if ((style.get_ForeColor().GetBrightness() < 0.2f) && (windowBrightness < 0.4f))
                {
                    style.set_ForeColor(Color.White);
                }
                else if ((windowBrightness < 0.4f) && (style.get_ForeColor() == Color.Blue))
                {
                    style.set_ForeColor(Color.FromArgb(130, 170, 0xff));
                }
                else if ((windowBrightness < 0.4f) && ((style.get_ForeColor() == Color.Red) || (style.get_ForeColor() == Color.FromArgb(220, 20, 20))))
                {
                    style.set_ForeColor(Color.FromArgb(210, 90, 90));
                }
                else if ((windowBrightness < 0.4f) && (style.get_ForeColor() == Color.Green))
                {
                    style.set_ForeColor(Color.FromArgb(100, 200, 110));
                }
            }
            _dynamicLanguages[key] = language2;
            return(language2);
        }
예제 #2
0
        /// <summary>
        /// Loads two languages and creates a state transition from XML to C# within ASP-style directives.
        /// </summary>
        private void CreateDirectiveXmlToCSharpLanguage()
        {
            string outputSyntaxFilePath = Slyce.Common.SyntaxEditorHelper.GetLanguageFileName(TemplateContentLanguage.PlainText);
            string scriptSyntaxFilePath = Slyce.Common.SyntaxEditorHelper.GetLanguageFileName(TemplateContentLanguage.CSharp);

            if (!File.Exists(outputSyntaxFilePath))
            {
                MessageBox.Show(this, "Language syntax file could not be loaded: " + outputSyntaxFilePath);
                return;
            }
            if (!File.Exists(scriptSyntaxFilePath))
            {
                MessageBox.Show(this, "Language syntax file could not be loaded: " + scriptSyntaxFilePath);
                return;
            }
            DynamicSyntaxLanguage language       = DynamicSyntaxLanguage.LoadFromXml(outputSyntaxFilePath, 0);
            DynamicSyntaxLanguage cSharpLanguage = DynamicSyntaxLanguage.LoadFromXml(scriptSyntaxFilePath, 0);

            cSharpLanguage.DefaultLexicalState.DefaultHighlightingStyle.ForeColor = Color.Red;

            language.Tag       = "TemplateLanguage";
            cSharpLanguage.Tag = "ScriptLanguage";

            // Mark that updating is starting
            language.IsUpdating       = true;
            cSharpLanguage.IsUpdating = true;

            // Add a highlighting style
            language.HighlightingStyles.Add(new HighlightingStyle("ASPDirectiveDelimiterStyle", null, Color.Black, Color.Yellow));

            // Create a new lexical state
            DynamicLexicalState lexicalState = new DynamicLexicalState(0, "ASPDirectiveState");

            lexicalState.DefaultTokenKey                    = "ASPDirectiveDefaultToken";
            lexicalState.DefaultHighlightingStyle           = language.HighlightingStyles["DefaultStyle"];
            lexicalState.LexicalStateTransitionLexicalState = cSharpLanguage.LexicalStates["DefaultState"];
            language.LexicalStates.Add(lexicalState);

            // Add the new lexical state at the beginning of the child states...
            // Remember that with an NFA regular expression, the first match is taken...
            // So since a < scope pattern is already in place, we must insert the new one before it
            language.LexicalStates["DefaultState"].ChildLexicalStates.Insert(0, lexicalState);

            // Create a lexical scope with a lexical state transition
            DynamicLexicalScope lexicalScope = new DynamicLexicalScope();

            lexicalState.LexicalScopes.Add(lexicalScope);
            lexicalScope.StartLexicalPatternGroup = new LexicalPatternGroup(LexicalPatternType.Explicit, "ASPDirectiveStartToken", language.HighlightingStyles["ASPDirectiveDelimiterStyle"], "#");
            lexicalScope.EndLexicalPatternGroup   = new LexicalPatternGroup(LexicalPatternType.Explicit, "ASPDirectiveEndToken", language.HighlightingStyles["ASPDirectiveDelimiterStyle"], "#");

            // Mark that updating is complete (since linking is complete, the flag setting
            // will filter from the XML language into the C# language)
            language.IsUpdating = false;
            syntaxEditorFilename.Document.Language = language;
        }
예제 #3
0
        public SyntaxLanguage GetSyntaxLanguage(string file)
        {
            string documentType = this.GetDocumentType(file);

            if (documentType == "text.C#")
            {
                if (CodeProjectService.csharpSyntaxLanguage == null)
                {
                    CodeProjectService.csharpSyntaxLanguage = new CSharpSyntaxLanguage();
                }
                return((SyntaxLanguage)CodeProjectService.csharpSyntaxLanguage);
            }
            if (documentType == "text.VB")
            {
                if (CodeProjectService.vbSyntaxLanguage == null)
                {
                    CodeProjectService.vbSyntaxLanguage = new VBSyntaxLanguage();
                }
                return((SyntaxLanguage)CodeProjectService.vbSyntaxLanguage);
            }
            if (documentType == "text.JS")
            {
                if (CodeProjectService.jsSyntaxLanguage == null)
                {
                    using (Stream stream = (Stream) new MemoryStream(Microsoft.Expression.Code.FileTable.GetByteArray("Resources\\Actipro.JS.xml")))
                        CodeProjectService.jsSyntaxLanguage = DynamicSyntaxLanguage.LoadFromXml(stream, 0);
                }
                return((SyntaxLanguage)CodeProjectService.jsSyntaxLanguage);
            }
            if (documentType == "text.C++")
            {
                if (CodeProjectService.cppSyntaxLanguage == null)
                {
                    using (Stream stream = (Stream) new MemoryStream(Microsoft.Expression.Code.FileTable.GetByteArray("Resources\\Actipro.CPP.xml")))
                    {
                        try
                        {
                            CodeProjectService.cppSyntaxLanguage = DynamicSyntaxLanguage.LoadFromXml(stream, 0);
                        }
                        catch (Exception ex)
                        {
                            throw;
                        }
                    }
                }
                return((SyntaxLanguage)CodeProjectService.cppSyntaxLanguage);
            }
            if (documentType == "text")
            {
                return(SyntaxLanguage.PlainText);
            }
            return((SyntaxLanguage)null);
        }
예제 #4
0
        /// <summary>
        /// Gets a DynamicSyntaxLanguage instance given a Languages enum.
        /// </summary>
        /// <param name="language"></param>
        /// <returns></returns>
        public static DynamicSyntaxLanguage GetDynamicLanguage(TemplateContentLanguage language)
        {
            string outputSyntaxFilePath = GetLanguageFileName(language);
            //if (!File.Exists(outputSyntaxFilePath))
            //{
            //    throw new Exception("Language syntax file could not be loaded: " + outputSyntaxFilePath);
            //}
            string filename = Path.GetFileName(outputSyntaxFilePath);

            //Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format("Slyce.Common.SyntaxFiles.{0}", filename));
            return(DynamicSyntaxLanguage.LoadFromXml(outputSyntaxFilePath, 0));
            //return DynamicSyntaxLanguage.LoadFromXml(stream, 0);
        }