/// <summary> /// Implements the visitor for the <see cref="XshtdSyntaxDefinition"/> object. /// </summary> /// <param name="syntax"></param> /// <returns></returns> public object VisitSyntaxDefinition(XshtdSyntaxDefinition syntax) { SyntaxDefinition c; if (syntax.Name != null) { c = def.syntaxDefDict[syntax.Name]; } else { if (syntax.Extensions == null) { return(null); } else { c = new SyntaxDefinition(syntax.Name); } } // Copy extensions to highlighting theme object foreach (var item in syntax.Extensions) { c.Extensions.Add(item); } syntax.AcceptElements(this); return(c); }
/// <summary> /// Implements the visitor for a named color (<see cref="XshtdColor"/> object) /// that is contained in a <see cref="XshtdSyntaxDefinition"/> object. /// /// Method checks if given color name is unique and adds the color into the internal /// collection of inique colors if it is. /// </summary> /// <param name="syntax"></param> /// <param name="color"></param> /// <returns>Always returns null. Throws a <see cref="HighlightingDefinitionInvalidException"/> /// if color name is a duplicate.</returns> public object VisitColor(XshtdSyntaxDefinition syntax, XshtdColor color) { if (color.Name != null) { if (color.Name.Length == 0) { throw Error(color, "Name must not be the empty string"); } if (syntax == null) { throw Error(syntax, "Syntax Definition for theme must not be null"); } SyntaxDefinition synDef; if (def.syntaxDefDict.TryGetValue(syntax.Name, out synDef) == false) { throw Error(syntax, "Themed Syntax Definition does not exist '" + syntax.Name + "'."); } if (synDef.ColorGet(color.Name) == null) { synDef.ColorAdd(new HighlightingColor() { Name = color.Name }); } else { throw Error(color, "Duplicate color name '" + color.Name + "'."); } } return(null); }
/// <summary> /// Implements the visitor for a named color (<see cref="XshtdColor"/> object) /// that is contained in a <see cref="XshtdSyntaxDefinition"/> object. /// </summary> /// <param name="syntax"></param> /// <param name="color"></param> /// <returns></returns> public object VisitColor(XshtdSyntaxDefinition syntax, XshtdColor color) { if (color.Name == null) { throw Error(color, "Name must not be null"); } if (color.Name.Length == 0) { throw Error(color, "Name must not be the empty string"); } if (syntax == null) { throw Error(syntax, "Syntax Definition for theme must not be null"); } SyntaxDefinition synDef; HighlightingColor highColor; if (def.syntaxDefDict.TryGetValue(syntax.Name, out synDef) == false) { throw Error(syntax, "Themed Syntax Definition does not exist '" + syntax.Name + "'."); } highColor = synDef.ColorGet(color.Name); if (highColor == null) { highColor = new HighlightingColor() { Name = color.Name }; synDef.ColorAdd(highColor); } highColor.Foreground = color.Foreground; highColor.Background = color.Background; highColor.Underline = color.Underline; highColor.FontStyle = color.FontStyle; highColor.FontWeight = color.FontWeight; return(highColor); }
/// <summary> /// Implements the visitor for the <see cref="XshtdSyntaxDefinition"/> object. /// </summary> /// <param name="syntax"></param> /// <returns></returns> public object VisitSyntaxDefinition(XshtdSyntaxDefinition syntax) { if (syntax.Name != null) { if (syntax.Name.Length == 0) { throw Error(syntax, "Name must not be the empty string"); } if (def.syntaxDefDict.ContainsKey(syntax.Name)) { throw Error(syntax, "Duplicate syntax definition name '" + syntax.Name + "'."); } def.syntaxDefDict.Add(syntax.Name, new SyntaxDefinition()); } syntax.AcceptElements(this); return(null); }
/// <summary> /// Creates a new XshdColor instance that is part of a <see cref="XshtdSyntaxDefinition"/>. /// </summary> public XshtdColor(XshtdSyntaxDefinition syntax) { _syntax = syntax; }