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); }
/// <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); }