public object VisitSpan(XshdSpan span)
 {
     span.BeginColorReference.AcceptVisitor(this);
     span.SpanColorReference.AcceptVisitor(this);
     span.EndColorReference.AcceptVisitor(this);
     return(span.RuleSetReference.AcceptVisitor(this));
 }
Exemple #2
0
        static XshdSpan ParseSpan(XmlReader reader)
        {
            XshdSpan span = new XshdSpan();

            SetPosition(span, reader);
            span.BeginRegex         = reader.GetAttribute("begin");
            span.EndRegex           = reader.GetAttribute("end");
            span.Multiline          = reader.GetBoolAttribute("multiline") ?? false;
            span.SpanColorReference = ParseColorReference(reader);
            span.RuleSetReference   = ParseRuleSetReference(reader);
            if (!reader.IsEmptyElement)
            {
                reader.Read();
                while (reader.NodeType != XmlNodeType.EndElement)
                {
                    Debug.Assert(reader.NodeType == XmlNodeType.Element);
                    switch (reader.Name)
                    {
                    case "Begin":
                        if (span.BeginRegex != null)
                        {
                            throw Error(reader, "Duplicate Begin regex");
                        }
                        span.BeginColorReference = ParseColorReference(reader);
                        span.BeginRegex          = reader.ReadElementString();
                        span.BeginRegexType      = XshdRegexType.IgnorePatternWhitespace;
                        break;

                    case "End":
                        if (span.EndRegex != null)
                        {
                            throw Error(reader, "Duplicate End regex");
                        }
                        span.EndColorReference = ParseColorReference(reader);
                        span.EndRegex          = reader.ReadElementString();
                        span.EndRegexType      = XshdRegexType.IgnorePatternWhitespace;
                        break;

                    case "RuleSet":
                        if (span.RuleSetReference.ReferencedElement != null)
                        {
                            throw Error(reader, "Cannot specify both inline RuleSet and RuleSet reference");
                        }
                        span.RuleSetReference = new XshdReference <XshdRuleSet>(ParseRuleSet(reader));
                        reader.Read();
                        break;

                    default:
                        throw new NotSupportedException("Unknown element " + reader.Name);
                    }
                }
            }
            return(span);
        }
            public object VisitSpan(XshdSpan span)
            {
                if (span.RuleSetReference.InlineElement != null)
                {
                    return(span.RuleSetReference.AcceptVisitor(this));
                }
                XshdSyntaxDefinition definition = allSyntaxDefinitions.SingleOrDefault(def => def.Name == span.RuleSetReference.ReferencedDefinition);

                if (definition != null && visitedDefinitons.Add(definition))
                {
                    foundColors.AddRange(definition.Elements.OfType <XshdColor>());
                }
                return(null);
            }
            public object VisitSpan(XshdSpan span)
            {
                string endRegex = span.EndRegex;

                if (string.IsNullOrEmpty(span.BeginRegex) && string.IsNullOrEmpty(span.EndRegex))
                {
                    throw Error(span, "Span has no start/end regex.");
                }
                if (!span.Multiline)
                {
                    if (endRegex == null)
                    {
                        endRegex = "$";
                    }
                    else if (span.EndRegexType == XshdRegexType.IgnorePatternWhitespace)
                    {
                        endRegex = "($|" + endRegex + "\n)";
                    }
                    else
                    {
                        endRegex = "($|" + endRegex + ")";
                    }
                }
                HighlightingColor wholeSpanColor = GetColor(span, span.SpanColorReference);

                return(new HighlightingSpan
                {
                    StartExpression = CreateRegex(span, span.BeginRegex, span.BeginRegexType),
                    EndExpression = CreateRegex(span, endRegex, span.EndRegexType),
                    RuleSet = GetRuleSet(span, span.RuleSetReference),
                    StartColor = GetColor(span, span.BeginColorReference),
                    SpanColor = wholeSpanColor,
                    EndColor = GetColor(span, span.EndColorReference),
                    SpanColorIncludesStart = true,
                    SpanColorIncludesEnd = true
                });
            }