Exemple #1
0
        /// <summary>
        /// Sets the element's position to the XmlReader's position.
        /// </summary>
        static void SetPosition(XshdElement element, XmlReader reader)
        {
            IXmlLineInfo lineInfo = reader as IXmlLineInfo;

            if (lineInfo != null)
            {
                element.LineNumber   = lineInfo.LineNumber;
                element.ColumnNumber = lineInfo.LinePosition;
            }
        }
Exemple #2
0
 static Exception Error(XshdElement element, string message)
 {
     if (element.LineNumber > 0)
     {
         return(new HighlightingDefinitionInvalidException(
                    "Error at line " + element.LineNumber + ":\n" + message));
     }
     else
     {
         return(new HighlightingDefinitionInvalidException(message));
     }
 }
Exemple #3
0
            IHighlightingDefinition GetDefinition(XshdElement position, string definitionName)
            {
                if (definitionName == null)
                {
                    return(def);
                }
                if (resolver == null)
                {
                    throw Error(position, "Resolving references to other syntax definitions is not possible because the IHighlightingDefinitionReferenceResolver is null.");
                }
                IHighlightingDefinition d = resolver.GetDefinition(definitionName);

                if (d == null)
                {
                    throw Error(position, "Could not find definition with name '" + definitionName + "'.");
                }
                return(d);
            }
Exemple #4
0
 HighlightingRuleSet GetRuleSet(XshdElement position, XshdReference <XshdRuleSet> ruleSetReference)
 {
     if (ruleSetReference.InlineElement != null)
     {
         return((HighlightingRuleSet)ruleSetReference.InlineElement.AcceptVisitor(this));
     }
     else if (ruleSetReference.ReferencedElement != null)
     {
         IHighlightingDefinition definition = GetDefinition(position, ruleSetReference.ReferencedDefinition);
         HighlightingRuleSet     ruleSet    = definition.GetNamedRuleSet(ruleSetReference.ReferencedElement);
         if (ruleSet == null)
         {
             throw Error(position, "Could not find rule set named '" + ruleSetReference.ReferencedElement + "'.");
         }
         return(ruleSet);
     }
     else
     {
         return(null);
     }
 }
Exemple #5
0
 HighlightingColor GetColor(XshdElement position, XshdReference <XshdColor> colorReference)
 {
     if (colorReference.InlineElement != null)
     {
         return((HighlightingColor)colorReference.InlineElement.AcceptVisitor(this));
     }
     else if (colorReference.ReferencedElement != null)
     {
         IHighlightingDefinition definition = GetDefinition(position, colorReference.ReferencedDefinition);
         HighlightingColor       color      = definition.GetNamedColor(colorReference.ReferencedElement);
         if (color == null)
         {
             throw Error(position, "Could not find color named '" + colorReference.ReferencedElement + "'.");
         }
         return(color);
     }
     else
     {
         return(null);
     }
 }
Exemple #6
0
            Regex CreateRegex(XshdElement position, string regex, XshdRegexType regexType)
            {
                if (regex == null)
                {
                    throw Error(position, "Regex missing");
                }
                RegexOptions options = RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture;

                if (regexType == XshdRegexType.IgnorePatternWhitespace)
                {
                    options |= RegexOptions.IgnorePatternWhitespace;
                }
                if (ignoreCase)
                {
                    options |= RegexOptions.IgnoreCase;
                }
                try {
                    return(new Regex(regex, options));
                } catch (ArgumentException ex) {
                    throw Error(position, ex.Message);
                }
            }