public static List <IOperationProvider> ConfigureFromJObject(JObject rawConfiguration)
        {
            string startToken = rawConfiguration.ToString("startToken");
            string endToken   = rawConfiguration.ToString("endToken");

            if (string.IsNullOrWhiteSpace(startToken))
            {
                throw new TemplateAuthoringException($"Template authoring error. StartToken must be defined", "StartToken");
            }
            else if (string.IsNullOrWhiteSpace(endToken))
            {
                throw new TemplateAuthoringException($"Template authoring error. EndToken must be defined", "EndToken");
            }

            string pseudoEndToken = rawConfiguration.ToString("pseudoEndToken");

            ConditionalKeywords         keywords = ConditionalKeywords.FromJObject(rawConfiguration);
            ConditionalOperationOptions options  = ConditionalOperationOptions.FromJObject(rawConfiguration);

            if (string.IsNullOrWhiteSpace(pseudoEndToken))
            {
                return(GenerateConditionalSetup(startToken, endToken, keywords, options));
            }
            else
            {
                return(GenerateConditionalSetup(startToken, endToken, pseudoEndToken, keywords, options));
            }
        }
示例#2
0
        public static List <IOperationProvider> ConfigureFromJObject(JObject rawConfiguration)
        {
            string token = rawConfiguration.ToString("token");

            if (string.IsNullOrWhiteSpace(token))
            {   // this is the only required data, all the rest is optional
                throw new TemplateAuthoringException("Template authoring error. Token must be defined", "token");
            }

            ConditionalKeywords         keywords = ConditionalKeywords.FromJObject(rawConfiguration);
            ConditionalOperationOptions options  = ConditionalOperationOptions.FromJObject(rawConfiguration);

            return(GenerateConditionalSetup(token, keywords, options));
        }
示例#3
0
        public static ConditionalOperationOptions FromJObject(JObject rawConfiguration)
        {
            ConditionalOperationOptions options = new ConditionalOperationOptions();

            string evaluatorType = rawConfiguration.ToString("evaluator");

            if (!string.IsNullOrWhiteSpace(evaluatorType))
            {
                options.EvaluatorType = evaluatorType;
            }

            options.TrimWhitespace = rawConfiguration.ToBool("trim", true);
            options.WholeLine      = rawConfiguration.ToBool("wholeLine", true);

            string id = rawConfiguration.ToString("id");

            if (!string.IsNullOrWhiteSpace(id))
            {
                options.Id = id;
            }

            return(options);
        }
示例#4
0
        public static List <IOperationProvider> GenerateConditionalSetup(string token, ConditionalKeywords keywords, ConditionalOperationOptions options)
        {
            string             uncommentOperationId     = $"Uncomment (line): {token} -> ()";
            string             reduceCommentOperationId = $"Reduce comment (line): ({token}{token}) -> ({token})";
            IOperationProvider uncomment     = new Replacement(token.TokenConfig(), string.Empty, uncommentOperationId, options.OnByDefault);
            IOperationProvider reduceComment = new Replacement($"{token}{token}".TokenConfig(), token, reduceCommentOperationId, options.OnByDefault);

            List <ITokenConfig> ifTokens           = new List <ITokenConfig>();
            List <ITokenConfig> actionableIfTokens = new List <ITokenConfig>();

            foreach (string ifKeyword in keywords.IfKeywords)
            {
                ifTokens.Add($"{token}{keywords.KeywordPrefix}{ifKeyword}".TokenConfig());
                actionableIfTokens.Add($"{token}{token}{keywords.KeywordPrefix}{ifKeyword}".TokenConfig());
            }

            List <ITokenConfig> elseTokens           = new List <ITokenConfig>();
            List <ITokenConfig> actionableElseTokens = new List <ITokenConfig>();

            foreach (string elseKeyword in keywords.ElseKeywords)
            {
                elseTokens.Add($"{token}{keywords.KeywordPrefix}{elseKeyword}".TokenConfig());
                actionableElseTokens.Add($"{token}{token}{keywords.KeywordPrefix}{elseKeyword}".TokenConfig());
            }

            List <ITokenConfig> elseIfTokens         = new List <ITokenConfig>();
            List <ITokenConfig> actionalElseIfTokens = new List <ITokenConfig>();

            foreach (string elseIfKeyword in keywords.ElseIfKeywords)
            {
                elseIfTokens.Add($"{token}{keywords.KeywordPrefix}{elseIfKeyword}".TokenConfig());
                actionalElseIfTokens.Add($"{token}{token}{keywords.KeywordPrefix}{elseIfKeyword}".TokenConfig());
            }

            List <ITokenConfig> endIfTokens = new List <ITokenConfig>();

            foreach (string endIfKeyword in keywords.EndIfKeywords)
            {
                endIfTokens.Add($"{token}{keywords.KeywordPrefix}{endIfKeyword}".TokenConfig());
                endIfTokens.Add($"{token}{token}{keywords.KeywordPrefix}{endIfKeyword}".TokenConfig());
            }

            ConditionalTokens conditionalTokens = new ConditionalTokens
            {
                IfTokens               = ifTokens,
                ElseTokens             = elseTokens,
                ElseIfTokens           = elseIfTokens,
                EndIfTokens            = endIfTokens,
                ActionableIfTokens     = actionableIfTokens,
                ActionableElseTokens   = actionableElseTokens,
                ActionableElseIfTokens = actionalElseIfTokens,
                ActionableOperations   = new[] { uncommentOperationId, reduceCommentOperationId }
            };

            ConditionEvaluator evaluator   = EvaluatorSelector.Select(options.EvaluatorType);
            IOperationProvider conditional = new Conditional(conditionalTokens, options.WholeLine, options.TrimWhitespace, evaluator, options.Id, options.OnByDefault);

            return(new List <IOperationProvider>()
            {
                conditional,
                reduceComment,
                uncomment
            });
        }
        public static List <IOperationProvider> GenerateConditionalSetup(string startToken, string endToken, string pseudoEndToken, ConditionalKeywords keywords, ConditionalOperationOptions options)
        {
            ConditionEvaluator evaluator = EvaluatorSelector.Select(options.EvaluatorType);

            ConditionalTokens tokens = new ConditionalTokens
            {
                EndIfTokens            = new[] { $"{keywords.KeywordPrefix}{keywords.EndIfKeyword}".TokenConfig(), $"{startToken}{keywords.KeywordPrefix}{keywords.EndIfKeyword}".TokenConfig() },
                ActionableIfTokens     = new[] { $"{startToken}{keywords.KeywordPrefix}{keywords.IfKeyword}".TokenConfig() },
                ActionableElseTokens   = new[] { $"{keywords.KeywordPrefix}{keywords.ElseKeyword}".TokenConfig(), $"{startToken}{keywords.KeywordPrefix}{keywords.ElseKeyword}".TokenConfig() },
                ActionableElseIfTokens = new[] { $"{keywords.KeywordPrefix}{keywords.ElseIfKeyword}".TokenConfig(), $"{startToken}{keywords.KeywordPrefix}{keywords.ElseIfKeyword}".TokenConfig() },
            };

            if (!string.IsNullOrWhiteSpace(pseudoEndToken))
            {
                Guid   operationIdGuid       = new Guid();
                string commentFixOperationId = $"Fix pseudo tokens ({pseudoEndToken} {operationIdGuid})";
                string commentFixResetId     = $"Reset pseudo token fixer ({pseudoEndToken} {operationIdGuid})";

                tokens.ActionableOperations = new[] { commentFixOperationId, commentFixResetId };

                IOperationProvider balancedComments = new BalancedNesting(startToken.TokenConfig(), endToken.TokenConfig(), pseudoEndToken.TokenConfig(), commentFixOperationId, commentFixResetId, options.OnByDefault);
                IOperationProvider conditional      = new Conditional(tokens, options.WholeLine, options.TrimWhitespace, evaluator, options.Id, options.OnByDefault);

                return(new List <IOperationProvider>()
                {
                    conditional,
                    balancedComments
                });
            }
            else
            {
                IOperationProvider conditional = new Conditional(tokens, options.WholeLine, options.TrimWhitespace, evaluator, options.Id, options.OnByDefault);
                return(new List <IOperationProvider>()
                {
                    conditional
                });
            }
        }
        public static List <IOperationProvider> GenerateConditionalSetup(string startToken, string endToken, ConditionalKeywords keywords, ConditionalOperationOptions options)
        {
            string pseudoEndComment;

            if (endToken.Length < 2)
            {   // end comment must be at least two characters to have a programmatically determined pseudo-comment
                pseudoEndComment = null;
            }
            else
            {
                // add a space just before the final character of the end comment
                pseudoEndComment = endToken.Substring(0, endToken.Length - 1) + " " + endToken.Substring(endToken.Length - 1);
            }

            return(GenerateConditionalSetup(startToken, endToken, pseudoEndComment, keywords, options));
        }
示例#7
0
        public static List <IOperationProvider> GenerateConditionalSetup(string token, ConditionalKeywords keywords, ConditionalOperationOptions options)
        {
            string             uncommentOperationId     = $"Uncomment (line): {token} -> ()";
            string             reduceCommentOperationId = $"Reduce comment (line): ({token}{token}) -> ({token})";
            IOperationProvider uncomment     = new Replacement(token, string.Empty, uncommentOperationId);
            IOperationProvider reduceComment = new Replacement($"{token}{token}", token, reduceCommentOperationId);

            ConditionalTokens conditionalTokens = new ConditionalTokens
            {
                IfTokens               = new[] { $"{token}{keywords.KeywordPrefix}{keywords.IfKeyword}" },
                ElseTokens             = new[] { $"{token}{keywords.KeywordPrefix}{keywords.ElseKeyword}" },
                ElseIfTokens           = new[] { $"{token}{keywords.KeywordPrefix}{keywords.ElseIfKeyword}" },
                EndIfTokens            = new[] { $"{token}{keywords.KeywordPrefix}{keywords.EndIfKeyword}", $"{token}{token}{keywords.KeywordPrefix}{keywords.EndIfKeyword}" },
                ActionableIfTokens     = new[] { $"{token}{token}{keywords.KeywordPrefix}{keywords.IfKeyword}" },
                ActionableElseTokens   = new[] { $"{token}{token}{keywords.KeywordPrefix}{keywords.ElseKeyword}" },
                ActionableElseIfTokens = new[] { $"{token}{token}{keywords.KeywordPrefix}{keywords.ElseIfKeyword}" },
                ActionableOperations   = new[] { uncommentOperationId, reduceCommentOperationId }
            };

            ConditionEvaluator evaluator   = EvaluatorSelector.Select(options.EvaluatorType);
            IOperationProvider conditional = new Conditional(conditionalTokens, options.WholeLine, options.TrimWhitespace, evaluator, options.Id);

            return(new List <IOperationProvider>()
            {
                conditional,
                reduceComment,
                uncomment
            });
        }