Exemple #1
0
        /// <summary>
        /// Initializes a new <see cref="BBTagNode" /> with the provided <paramref name="name" /> and
        /// <paramref name="value" />.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="children"></param>
        /// <returns></returns>
        public static BBTagNode Tag(string name, string value, params BBNode[] children)
        {
            var tag = new BBTagNode(false, name, value);

            foreach (var child in children)
            {
                tag.AddChild(child);
            }
            return(tag);
        }
Exemple #2
0
        private void ParseOpeningTag(BBToken nameToken)
        {
            var    selfClosing = false;
            var    name        = nameToken.Value !;
            string?value       = null;

            if (nameToken.Type != BBTokenType.Text)
            {
                throw new FormatException($"Expected tag name but got {nameToken.Type}.");
            }

            var rbracket = GetNextToken();

            if (rbracket?.Type == BBTokenType.Equals)
            {
                var valueToken = GetNextToken();
                if (valueToken?.Type != BBTokenType.Text)
                {
                    throw new FormatException("Value must come after the equals sign.");
                }
                value = valueToken.Value.Value;

                rbracket = GetNextToken();
            }
            if (rbracket?.Type == BBTokenType.Slash)
            {
                selfClosing = true;
                rbracket    = GetNextToken();
            }
            if (rbracket?.Type != BBTokenType.RBracket)
            {
                throw new FormatException($"Unfinished tag '{name}'.");
            }

            var node = new BBTagNode(selfClosing, name, value);

            _nodeStack.Peek().AddChild(node);
            if (!selfClosing)
            {
                _nodeStack.Push(node);
            }
        }