Exemple #1
0
 public GlslLayoutLexer(int nextStyle, XmlNode xml, BaseLexer parentLexer)
     : base(nextStyle, xml, parentLexer) { }
Exemple #2
0
 public GlslStructLexer(int nextStyle, XmlNode xml, BaseLexer parentLexer)
     : base(nextStyle, xml, parentLexer, '}') { }
Exemple #3
0
 public CommandLexer(int nextStyle, XmlNode xml, BaseLexer parentLexer)
     : base(nextStyle, xml, parentLexer) { }
Exemple #4
0
 public DefaultLexer(int nextStyle, XmlNode xml, BaseLexer parentLexer)
     : base(nextStyle, xml, parentLexer) { }
Exemple #5
0
        public BaseLexer(int firstFreeStyle, XmlNode lexerNode, BaseLexer parent)
        {
            parentLexer = parent;
            defaultLexer = GetType().Name == "DefaultLexer" ? null
                : new DefaultLexer(firstFreeStyle, null, this);

            // get style and state ranges
            var stateValues = Enum.GetValues(StateType);
            int styleCount = stateValues.Length;
            int firstState = styleCount > 0 ? ((int[])stateValues).Min() : 0;

            // adjust style ranges if they fall into the Scintilla styles
            firstStyle = firstFreeStyle;
            if (SciStyle.Default <= firstStyle + styleCount && firstStyle <= SciStyle.CallTip)
                firstStyle = SciStyle.CallTip + 1;
            lastStyle = firstStyle + styleCount - 1;
            firstFreeStyle = lastStyle + 1;

            if (StateType.IsEquivalentTo(typeof(BaseState)))
            {
                firstBaseStyle = firstStyle;
                lastBaseStyle = lastStyle;
            }

            // allocate arrays for styles
            styles = Enumerable.Range(firstStyle, styleCount)
                .Select(x => new ScintillaNET.Lexing.Style {
                    id = x, fore = Theme.ForeColor, back = Theme.Workspace
                }).ToArray();
            keywords = new Trie<Keyword>[styleCount];

            // SET TO DEFAULT LEXER
            if (lexerNode == null)
            {
                lexerType = "default";
                lexer = new BaseLexer[0];
                return;
            }

            // get lexer type
            lexerType = lexerNode.GetAttributeValue("type");

            // get style colors
            var styleList = lexerNode.SelectNodes("Style");
            foreach (XmlNode style in styleList)
            {
                if (style.HasAttributeValue("theme") && style.GetAttributeValue("theme").ToLower() != Theme.Name.ToLower())
                    continue;
                var id = (int)Enum.Parse(StateType, style.GetAttributeValue("name"), true);
                var idx = id - firstState;
                if (style.HasAttributeValue("fore"))
                    styles[idx].fore = ColorTranslator.FromHtml(style.GetAttributeValue("fore"));
                if (style.HasAttributeValue("back"))
                    styles[idx].back = ColorTranslator.FromHtml(style.GetAttributeValue("back"));
            }

            // get keyword definitions
            var keywordList = lexerNode.SelectNodes("Keyword");
            foreach (XmlNode keyword in keywordList)
            {
                var id = (int)Enum.Parse(StateType, keyword.GetAttributeValue("style_name"), true);
                var idx = id - firstState;
                var name = keyword.GetAttributeValue("name");
                var hint = keyword.GetAttributeValue("hint");
                if (hint != null && hint.IndexOf('\\') >= 0)
                    hint = regexHint.Replace(hint, "\n");
                if (keywords[idx] == null)
                    keywords[idx] = new Trie<Keyword>();
                keywords[idx].Add(name, new Keyword { word = name, hint = hint });
            }

            // instantiate sub-lexers
            var lexerList = lexerNode.SelectNodes("Lexer");
            lexer = new BaseLexer[lexerList.Count];
            var assembly = typeof(BaseLexer).FullName.Substring(0,
                typeof(BaseLexer).FullName.Length - typeof(BaseLexer).Name.Length);
            for (int i = 0; i < lexerList.Count; i++)
            {
                var type = lexerList[i].GetAttributeValue("lexer");
                var param = new object[] { firstFreeStyle, lexerList[i], this };
                var t = Type.GetType($"{assembly}{type}");
                lexer[i] = (BaseLexer)Activator.CreateInstance(t, param);
                firstFreeStyle = lexer[i].MaxStyle + 1;
            }
        }
Exemple #6
0
 public TechBodyLexer(int nextStyle, XmlNode xml, BaseLexer parentLexer)
     : base(nextStyle, xml, parentLexer) { }
Exemple #7
0
 public GlslFunctionBodyLexer(int nextStyle, XmlNode xml, BaseLexer parentLexer)
     : base(nextStyle, xml, parentLexer) { }
Exemple #8
0
 public GlslStructFuncArgLexer(int nextStyle, XmlNode xml, BaseLexer parentLexer, char closingBrace)
     : base(nextStyle, xml, parentLexer)
 {
     this.closingBrace = closingBrace;
 }
Exemple #9
0
 public GlslFunctionArgLexer(int nextStyle, XmlNode xml, BaseLexer parentLexer)
     : base(nextStyle, xml, parentLexer, ')') { }