Example #1
0
        /// <summary>
        ///		Sets an Option that was requested from template
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="parserOptions"></param>
        /// <returns></returns>
        public async Promise SetOption(string name, IMorestachioExpression value, ParserOptions parserOptions)
        {
            var val = (await value.GetValue(new ContextObject(parserOptions, ".", null, new object()), new ScopeData()))
                      .Value;

            if (name.Equals("TokenPrefix", StringComparison.InvariantCultureIgnoreCase))
            {
                if (val == null)
                {
                    Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()),
                                                          "SET OPTION", "VALUE", $"The expression returned null for option '{name}' that does not accept a null value"));
                    return;
                }
                PrefixToken = val.ToString();
            }
            if (name.Equals("TokenSuffix", StringComparison.InvariantCultureIgnoreCase))
            {
                if (val == null)
                {
                    Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()),
                                                          "SET OPTION", "VALUE", $"The expression returned null for option '{name}' that does not accept a null value"));
                    return;
                }
                SuffixToken = val.ToString();
            }
        }
Example #2
0
        public async Task TestExpressionRuns(string variation, int width, int depth, int noArguments, int runs)
        {
            var expression = ConstructExpression("", width, depth, noArguments);

            ExpressionParser.ParseExpression("data", TokenzierContext.FromText("data"));

            var data = new Dictionary <string, object>();

            for (int i = 0; i < width; i++)
            {
                data["data"] = new Dictionary <string, object>();
            }


            var totalTime = Stopwatch.StartNew();
            var parseTime = Stopwatch.StartNew();
            IMorestachioExpression morestachioExpression = null;

            for (var i = 0; i < runs; i++)
            {
                morestachioExpression = ExpressionParser.ParseExpression(expression.Item1,
                                                                         TokenzierContext.FromText(expression.Item1));
            }

            parseTime.Stop();
            var executeTime = Stopwatch.StartNew();

            for (int i = 0; i < runs; i++)
            {
                var parserOptions = new ParserOptions("");
                await morestachioExpression.GetValue(new ContextObject(".", null, data)
                {
                }, new ScopeData(parserOptions));
            }
            executeTime.Stop();
            totalTime.Stop();
            PerformanceCounter.PerformanceCounters.Add(new PerformanceCounter.ExpressionPerformanceCounterEntity(variation)
            {
                TimePerRun  = new TimeSpan(parseTime.ElapsedTicks / runs),
                RunOver     = runs,
                Width       = width,
                Depth       = depth,
                NoArguments = noArguments,
                ParseTime   = parseTime.Elapsed,
                TotalTime   = totalTime.Elapsed,
                ExecuteTime = executeTime.Elapsed
            });
        }
Example #3
0
        ///  <summary>
        ///         Sets an Option that was requested from template
        ///  </summary>
        ///  <param name="name"></param>
        ///  <param name="value"></param>
        ///  <param name="parserOptions"></param>
        ///  <returns></returns>
        public async Promise SetOption(string name, IMorestachioExpression value, ParserOptions parserOptions)
        {
            var val = (await value.GetValue(new ContextObject(".", null, new object()), new ScopeData(parserOptions)))
                      .Value;

            if (name.Equals("TrimTailing", StringComparison.OrdinalIgnoreCase))
            {
                if (val == null)
                {
                    Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()),
                                                          "SET OPTION", "VALUE", $"The expression returned null for option '{name}' that does not accept a null value"));
                    return;
                }
                if (!(val is bool valBool))
                {
                    Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()),
                                                          "SET OPTION", "VALUE", $"The expression returned '{val.GetType()}' for option '{name}' but expected and value of type '{typeof(bool)}'"));
                    return;
                }
                TrimTailing = valBool;
            }
            if (name.Equals("TrimLeading", StringComparison.OrdinalIgnoreCase))
            {
                if (val == null)
                {
                    Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()),
                                                          "SET OPTION", "VALUE", $"The expression returned null for option '{name}' that does not accept a null value"));
                    return;
                }
                if (!(val is bool valBool))
                {
                    Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()),
                                                          "SET OPTION", "VALUE", $"The expression returned '{val.GetType()}' for option '{name}' but expected and value of type '{typeof(bool)}'"));
                    return;
                }
                TrimLeading = valBool;
            }
            if (name.Equals("TrimAllTailing", StringComparison.OrdinalIgnoreCase))
            {
                if (val == null)
                {
                    Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()),
                                                          "SET OPTION", "VALUE", $"The expression returned null for option '{name}' that does not accept a null value"));
                    return;
                }
                if (!(val is bool valBool))
                {
                    Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()),
                                                          "SET OPTION", "VALUE", $"The expression returned '{val.GetType()}' for option '{name}' but expected and value of type '{typeof(bool)}'"));
                    return;
                }
                TrimAllTailing = valBool;
            }
            if (name.Equals("TrimAllLeading", StringComparison.OrdinalIgnoreCase))
            {
                if (val == null)
                {
                    Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()),
                                                          "SET OPTION", "VALUE", $"The expression returned null for option '{name}' that does not accept a null value"));
                    return;
                }
                if (!(val is bool valBool))
                {
                    Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()),
                                                          "SET OPTION", "VALUE", $"The expression returned '{val.GetType()}' for option '{name}' but expected and value of type '{typeof(bool)}'"));
                    return;
                }
                TrimAllLeading = valBool;
            }
        }