Exemplo n.º 1
0
        public static MorestachioDocumentInfo ParseWithOptions([NotNull] ParserOptions parsingOptions)
        {
            if (parsingOptions == null)
            {
                throw new ArgumentNullException(nameof(parsingOptions));
            }

            if (parsingOptions.SourceFactory == null)
            {
                throw new ArgumentNullException(nameof(parsingOptions), "The given Stream is null");
            }

            var errors   = new List <IMorestachioError>();
            var profiler = new PerformanceProfiler(parsingOptions.ProfileExecution);
            Queue <TokenPair> tokens;

            using (profiler.Begin("Tokenize"))
            {
                tokens = new Queue <TokenPair>(Tokenizer.Tokenize(parsingOptions, errors, profiler));
            }

            //if there are any errors do not parse the template
            var documentInfo = new MorestachioDocumentInfo(parsingOptions,
                                                           errors.Any() ? null : Parse(tokens), errors);

            documentInfo.Profiler = profiler;
            return(documentInfo);
        }
Exemplo n.º 2
0
        public static MorestachioDocumentInfo ParseWithOptions([NotNull] ParserOptions parsingOptions)
        {
            if (parsingOptions == null)
            {
                throw new ArgumentNullException(nameof(parsingOptions));
            }

            if (parsingOptions.SourceFactory == null)
            {
                throw new ArgumentNullException(nameof(parsingOptions), "The given Stream is null");
            }
            var errors = new List <IMorestachioError>();
            var tokens = new Queue <TokenPair>(Tokenizer.Tokenize(parsingOptions, errors));
            //if there are any errors do not parse the template
            var documentInfo = new MorestachioDocumentInfo(parsingOptions, errors.Any() ? null : Parse(tokens, parsingOptions), errors);

            return(documentInfo);
        }
Exemplo n.º 3
0
        public static async MorestachioDocumentInfoPromise ParseWithOptionsAsync([NotNull] ParserOptions parsingOptions)
        {
            if (parsingOptions == null)
            {
                throw new ArgumentNullException(nameof(parsingOptions));
            }

            parsingOptions.Seal();

            var tokenzierContext = TokenzierContext.FromText(parsingOptions.Template, parsingOptions.CultureInfo);
            var tokenizerResult  = await Tokenizer.Tokenize(parsingOptions, tokenzierContext);

            //if there are any errors do not parse the template
            var documentInfo = new MorestachioDocumentInfo(parsingOptions,
                                                           tokenzierContext.Errors.Any() ? null : Parse(tokenizerResult, parsingOptions), tokenzierContext.Errors);

            return(documentInfo);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Parses the Template with the given options
        /// </summary>
        /// <param name="parsingOptions">a set of options</param>
        /// <returns></returns>
        public static async MorestachioDocumentInfoPromise ParseWithOptionsAsync(ParserOptions parsingOptions)
        {
            if (parsingOptions == null)
            {
                throw new ArgumentNullException(nameof(parsingOptions));
            }

            parsingOptions.Seal();
            parsingOptions.Logger?.LogDebug(LoggingFormatter.ParserEventId, "Parse new Template");

            var tokenzierContext = new TokenzierContext(new List <int>(), parsingOptions.CultureInfo);
            var tokenizerResult  = await Tokenizer.Tokenize(parsingOptions, tokenzierContext);

            parsingOptions.Logger?.LogDebug(LoggingFormatter.ParserEventId, "Template Parsed", new Dictionary <string, object>()
            {
                { "Errors", tokenzierContext.Errors }
            });
            //if there are any errors do not parse the template
            var documentInfo = new MorestachioDocumentInfo(parsingOptions,
                                                           tokenzierContext.Errors.Any() ? null : Parse(tokenizerResult, parsingOptions), tokenzierContext.Errors);

            return(documentInfo);
        }