예제 #1
0
        public static Span Read(XmlReader reader)
        {
            Span result = new Span();

            result.Rule      = reader.GetAttribute("rule");
            result.Color     = reader.GetAttribute("color");
            result.TagColor  = reader.GetAttribute("tagColor");
            result.NextColor = reader.GetAttribute("nextColor");

            result.Escape = reader.GetAttribute("escape");

            string stopateol = reader.GetAttribute("stopateol");

            if (!String.IsNullOrEmpty(stopateol))
            {
                result.StopAtEol = Boolean.Parse(stopateol);
            }

            if (reader.LocalName == AltNode)
            {
                AddFlags(result.BeginFlags, reader.GetAttribute("flags"));
                result.Continuation = reader.GetAttribute("continuation");
                result.Begin        = new Regex(reader.ReadElementString());
                result.StopAtEol    = true;
            }
            else
            {
                XmlReadHelper.ReadList(reader, Node, delegate() {
                    switch (reader.LocalName)
                    {
                    case "Begin":
                        AddFlags(result.BeginFlags, reader.GetAttribute("flags"));
                        result.Begin = new Regex(reader.ReadElementString());
                        return(true);

                    case "End":
                        AddFlags(result.EndFlags, reader.GetAttribute("flags"));
                        result.End = new Regex(reader.ReadElementString());
                        return(true);

                    case "Exit":
                        AddFlags(result.ExitFlags, reader.GetAttribute("flags"));
                        result.Exit = new Regex(reader.ReadElementString());
                        return(true);
                    }
                    return(false);
                });
            }
            return(result);
        }
예제 #2
0
        public static SyntaxMode Read(Stream stream)
        {
            var reader         = XmlReader.Create(stream);
            var result         = new SyntaxMode(null);
            var matches        = new List <Match> ();
            var spanList       = new List <Span> ();
            var prevMarkerList = new List <Marker> ();

            XmlReadHelper.ReadList(reader, Node, delegate() {
                if (reader == null)
                {
                    return(true);
                }
                switch (reader.LocalName)
                {
                case Node:
                    string extends = reader.GetAttribute("extends");
                    if (!String.IsNullOrEmpty(extends))
                    {
                        result = (SyntaxMode)SyntaxModeService.GetSyntaxMode(null, extends).MemberwiseClone();
                        spanList.AddRange(result.spans);
                        prevMarkerList.AddRange(result.prevMarker);
                        matches.AddRange(result.matches);
                    }
                    result.Name     = reader.GetAttribute("name");
                    result.MimeType = reader.GetAttribute(MimeTypesAttribute);
                    if (!String.IsNullOrEmpty(reader.GetAttribute("ignorecase")))
                    {
                        result.IgnoreCase = Boolean.Parse(reader.GetAttribute("ignorecase"));
                    }
                    return(true);

                case Rule.Node:
                    result.rules.Add(Rule.Read(result, reader, result.IgnoreCase));
                    return(true);
                }
                return(result.ReadNode(reader, matches, spanList, prevMarkerList));
            });
            result.spans      = spanList.ToArray();
            result.prevMarker = prevMarkerList.ToArray();
            result.matches    = matches.ToArray();
            return(result);
        }
예제 #3
0
파일: Match.cs 프로젝트: nagyistge/NClass
        public static Match Read(XmlReader reader)
        {
            string expression = reader.GetAttribute("expression");

            if (!string.IsNullOrEmpty(expression))
            {
                var result = new Match();

                result.Pattern = "\\G" + expression;
                var ignoreCaseAttr = reader.GetAttribute("ignorecase");
                if (!string.IsNullOrEmpty(ignoreCaseAttr))
                {
                    result.IgnoreCase = Boolean.Parse(ignoreCaseAttr);
                }
                result.regex = new System.Text.RegularExpressions.Regex(result.Pattern, result.IgnoreCase ? RegexOptions.Compiled | RegexOptions.IgnoreCase : RegexOptions.Compiled);

                XmlReadHelper.ReadList(reader, Node, delegate() {
                    switch (reader.LocalName)
                    {
                    case "Group":
                        result.Groups.Add(reader.GetAttribute("color"));
                        return(true);
                    }
                    return(false);
                });

                return(result);
            }

            string color   = reader.GetAttribute("color");
            string pattern = reader.ReadElementString();
            Match  result2 = pattern == "CSharpNumber" ? new CSharpNumberMatch() : new Match();

            result2.Color   = color;
            result2.Pattern = "\\G" + pattern;
            result2.regex   = new System.Text.RegularExpressions.Regex(result2.Pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
            return(result2);
        }