示例#1
0
            private Regex CreateRegex(XshdElement position, string regex, XshdRegexType regexType)
            {
                if (regex == null)
                {
                    throw Error(position, "Regex missing");
                }
                var 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);
                }
            }
示例#2
0
 /// <summary>
 /// Sets the element's position to the XmlReader's position.
 /// </summary>
 private static void SetPosition(XshdElement element, XmlReader reader)
 {
     if (reader is IXmlLineInfo lineInfo)
     {
         element.LineNumber   = lineInfo.LineNumber;
         element.ColumnNumber = lineInfo.LinePosition;
     }
 }
示例#3
0
 private static Exception Error(XshdElement element, string message)
 {
     if (element.LineNumber > 0)
     {
         return(new HighlightingDefinitionInvalidException(
                    "Error at line " + element.LineNumber + ":\n" + message));
     }
     return(new HighlightingDefinitionInvalidException(message));
 }
示例#4
0
 private HighlightingRuleSet GetRuleSet(XshdElement position, XshdReference <XshdRuleSet> ruleSetReference)
 {
     if (ruleSetReference.InlineElement != null)
     {
         return((HighlightingRuleSet)ruleSetReference.InlineElement.AcceptVisitor(this));
     }
     if (ruleSetReference.ReferencedElement != null)
     {
         var definition = GetDefinition(position, ruleSetReference.ReferencedDefinition);
         var ruleSet    = definition.GetNamedRuleSet(ruleSetReference.ReferencedElement);
         if (ruleSet == null)
         {
             throw Error(position, "Could not find rule set named '" + ruleSetReference.ReferencedElement + "'.");
         }
         return(ruleSet);
     }
     return(null);
 }
示例#5
0
            private 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.");
                }
                var d = _resolver.GetDefinition(definitionName);

                if (d == null)
                {
                    throw Error(position, "Could not find definition with name '" + definitionName + "'.");
                }
                return(d);
            }
示例#6
0
 private HighlightingColor GetColor(XshdElement position, XshdReference <XshdColor> colorReference)
 {
     if (colorReference.InlineElement != null)
     {
         return((HighlightingColor)colorReference.InlineElement.AcceptVisitor(this));
     }
     if (colorReference.ReferencedElement != null)
     {
         var definition = GetDefinition(position, colorReference.ReferencedDefinition);
         var color      = definition.GetNamedColor(colorReference.ReferencedElement);
         if (color == null)
         {
             throw Error(position, "Could not find color named '" + colorReference.ReferencedElement + "'.");
         }
         return(color);
     }
     return(null);
 }