public override int ConvertTokens(IEnumerable <RPToken> tokens)
        {
            if (Element == null || !(Element is RPSyntaxKindElement syntaxKindElement))
            {
                throw new Exception("An RPSyntaxKindRegexPairTokenType must be preceeded by an RPSyntaxKindTokenType.");
            }

            RPToken token = tokens.ElementAtOrDefault(1);

            if (token == null || !(token.TokenType == typeof(RPRegexTokenType)))
            {
                throw new Exception("The RPSyntaxKindRegexPairTokenType must be followed by an RPRegexTokenType.");
            }

            string regex = token.Value;

            Element = new RPSyntaxKindRegexPairElement(syntaxKindElement.SyntaxKind, RPRegexFactory.Create(regex), syntaxKindElement.ScanType);

            return(base.ConvertTokens(tokens.Skip(2)) + 2);
        }
        public virtual int ConvertTokens(IEnumerable <RPToken> tokens)
        {
            RPToken token = tokens.First();

            if (!_rpTokenTypeRPElementBuilderPairs.ContainsKey(token.TokenType))
            {
                throw new Exception($"{token.TokenType} does not have an associated RPElementBuilder");
            }

            Type rpElementBuilderType = _rpTokenTypeRPElementBuilderPairs[token.TokenType];

            if (rpElementBuilderType.GetMethod("ConvertTokens").DeclaringType == typeof(RPElementBuilder))
            {
                throw new Exception($"{rpElementBuilderType} does not implement the ConvertTokens method.");
            }

            IRPElementBuilder elementBuilder = (IRPElementBuilder)Activator.CreateInstance(rpElementBuilderType, new object[] { Options, Element });

            int tokensConsumed = elementBuilder.ConvertTokens(tokens);

            Element = elementBuilder.Element;

            return(tokensConsumed);
        }