Beispiel #1
0
        public IEnumerable <IRPElement> ConvertTokens(IEnumerable <RPToken> tokens)
        {
            List <IRPElement> roslynPath = new List <IRPElement>();
            List <RPToken>    tokenList  = tokens.ToList();

            for (int index = 0; index < tokenList.Count; index++)
            {
                _elementBuilder.Clean();

                int tokensConsumed = _elementBuilder.ConvertTokens(tokenList.Skip(index));

                if (_elementBuilder.Element == null || tokensConsumed == 0)
                {
                    throw new Exception($"Unable to convert token {tokenList[index]}");
                }

                roslynPath.Add(_elementBuilder.Element);

                index += tokensConsumed - 1;
            }

            return(roslynPath);
        }
        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);
        }