Пример #1
0
        private void Tokenize()
        {
            string[] tokenStrings = Regex.Split(Input, Constants.DelimiterRegex);

            foreach (var tokenString in tokenStrings)
            {
                var token = new Token(tokenString);
                if (token.TokenType == TokenType.ArgumentPrefix)
                {
                    ++_unresolvedTemplateArgumentCount;
                }

                Tokens.Add(token);
            }
        }
Пример #2
0
        private string ProcessSequence(Token prefixToken, IEnumerator<Token> tokens, SymbolTable symbolTable, Dictionary<string, string> arguments)
        {
            var builder = new StringBuilder();
            while (tokens.MoveNext())
            {
                Token currentToken = tokens.Current;

                if (currentToken.TokenType == TokenType.StringLiteral)
                {
                    builder.Append(currentToken.Text);
                }
                else if (currentToken.IsPrefix)
                {
                    builder.Append(ProcessSequence(currentToken, tokens, symbolTable, arguments));
                }
                else if (currentToken.IsSuffix)
                {
                    if (currentToken.TokenType == prefixToken.ClosingTokenType)
                    {
                        return PeformReplacement(prefixToken, builder.ToString(), symbolTable, arguments);
                    }

                    throw new InvalidOperationException("Unbalance prefix and suffix tokens.");
                }
            }

            if (prefixToken != null)
            {
                throw new InvalidOperationException("Invalid prefix token.");
            }

            return builder.ToString();
        }
Пример #3
0
 private string PeformReplacement(Token prefixToken, string text, SymbolTable symbolTable, Dictionary<string, string> arguments)
 {
     switch (prefixToken.TokenType)
     {
         case TokenType.ArgumentPrefix:
             return ReplaceArgument(text, arguments);
         case TokenType.FunctionPrefix:
             return ReplaceFunction(text);
         case TokenType.SymbolLookupPrefix:
             throw new NotImplementedException("Symbol Table Lookup replacements are not available in this version of the language.");
         case TokenType.VariablePrefix:
             throw new NotImplementedException("Variable replacements are not available in this version of the language.");
         default:
             throw new InvalidOperationException("Unsupported Replacement Token Type.");
     }
 }