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); } }
/// <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; } }
/// <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; } }
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); } 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); }
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); }
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); } }