Пример #1
0
            private 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);
                }
            }
Пример #2
0
 /// <summary>
 /// Sets the element's position to the XmlReader's position.
 /// </summary>
 static void SetPosition(XshdElement element, XmlReader reader)
 {
     if (reader is IXmlLineInfo lineInfo)
     {
         element.LineNumber   = lineInfo.LineNumber;
         element.ColumnNumber = lineInfo.LinePosition;
     }
 }
Пример #3
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);
 }
Пример #4
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;
            }
        }
Пример #5
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;
 }
Пример #6
0
            IHighlightingDefinition GetDefinition(XshdElement position, string definitionName)
            {
                if (definitionName == null)
                {
                    return(def);
                }
                IHighlightingDefinition d = resolver.GetDefinition(definitionName);

                if (d == null)
                {
                    throw Error(position, "Could not find definition with name '" + definitionName + "'.");
                }
                return(d);
            }
Пример #7
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;
     }
 }
Пример #8
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;
     }
 }
Пример #9
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;
			}
		}
Пример #10
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;
     }
 }
Пример #11
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;
 }
Пример #12
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;
     }
 }
Пример #13
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);
     }
 }
Пример #14
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);
 }
			IHighlightingDefinition GetDefinition(XshdElement position, string definitionName)
			{
				if (definitionName == null)
					return def;
				IHighlightingDefinition d = resolver.GetDefinition(definitionName);
				if (d == null)
					throw Error(position, "Could not find definition with name '" + definitionName + "'.");
				return d;
			}