Exemple #1
0
        public XmlHighlightingDefinition(XshdSyntaxDefinition xshd, IHighlightingDefinitionReferenceResolver resolver)
        {
            Name = xshd.Name;
            // Create HighlightingRuleSet instances
            var rnev = new RegisterNamedElementsVisitor(this);

            xshd.AcceptElements(rnev);
            // Assign MainRuleSet so that references can be resolved
            foreach (var element in xshd.Elements)
            {
                if (element is XshdRuleSet xrs && xrs.Name == null)
                {
                    if (MainRuleSet != null)
                    {
                        throw Error(element, "Duplicate main RuleSet. There must be only one nameless RuleSet!");
                    }
                    MainRuleSet = rnev.RuleSets[xrs];
                }
            }
            if (MainRuleSet == null)
            {
                throw new HighlightingDefinitionInvalidException("Could not find main RuleSet.");
            }
            // Translate elements within the rulesets (resolving references and processing imports)
            xshd.AcceptElements(new TranslateElementVisitor(this, rnev.RuleSets, resolver));

            foreach (var p in xshd.Elements.OfType <XshdProperty>())
            {
                _propDict.Add(p.Name, p.Value);
            }
        }
Exemple #2
0
        /// <summary>
        /// Writes the specified syntax definition.
        /// </summary>
        public void WriteDefinition(XshdSyntaxDefinition definition)
        {
            if (definition == null)
            {
                throw new ArgumentNullException(nameof(definition));
            }
            _writer.WriteStartElement("SyntaxDefinition", Namespace);
            if (definition.Name != null)
            {
                _writer.WriteAttributeString("name", definition.Name);
            }
            if (definition.Extensions != null)
            {
                _writer.WriteAttributeString("extensions", string.Join(";", definition.Extensions.ToArray()));
            }

            definition.AcceptElements(this);

            _writer.WriteEndElement();
        }