Ejemplo 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);
        }
 public static IDisposable BeginSafe(this PerformanceProfiler profiler, string name)
 {
     return(profiler?.Begin(name) ?? _instance);
 }