/// <summary> /// Initializes a new instance of the <see cref="ParserContext"/> class. /// </summary> /// <param name="source">The source.</param> /// <param name="parser">The parser.</param> /// <param name="errorSink">The error sink.</param> /// <param name="providers">The set of tag providers.</param> public ParserContext(ITextDocument source, ParserBase parser, ParserErrorSink errorSink, TagProvidersCollection providers) { Source = new TextDocumentReader(source); Parser = parser; _errorSink = errorSink; TagProviders = providers; }
/// <summary> /// Initializes a new instance of the <see cref="ParserContext"/> class. /// </summary> /// <param name="source">The source.</param> /// <param name="parser">The parser.</param> /// <param name="errorSink">The error sink.</param> public ParserContext(ITextDocument source, ParserBase parser, ParserErrorSink errorSink, TagProvidersCollection providers) { Source = new TextDocumentReader(source); Parser = parser; _errorSink = errorSink; TagProviders = providers; }
/// <summary> /// Creates a document <see cref="Block"/> from the given template. /// </summary> /// <param name="template">The template.</param> /// <returns>The document <see cref="Block"/></returns> private Block CreateDocument(string template) { using (var reader = new StringReader(template)) { using (var source = new SeekableTextReader(reader)) { var errors = new ParserErrorSink(); var parser = new HandlebarsParser(); var context = new ParserContext(source, parser, errors, TagProviders); parser.Context = context; parser.ParseDocument(); var results = context.CompleteParse(); if (results.Success) { return results.Document; } throw new InvalidOperationException( string.Join("\n", results.Errors.Select(e => string.Format("{0}: {1}", e.Location, e.Message)))); } } }
private void ParserTest(string content, Block document, TagProvidersCollection providers = null) { providers = providers ?? TagProvidersCollection.Default; var output = new StringBuilder(); using (var reader = new StringReader(content)) { using (var source = new SeekableTextReader(reader)) { var errors = new ParserErrorSink(); var parser = new HandlebarsParser(); var context = new ParserContext(source, parser, errors, providers); parser.Context = context; parser.ParseDocument(); var results = context.CompleteParse(); var comparer = new EquivalanceComparer(output, 0); Assert.True(comparer.Equals(document, results.Document), output.ToString()); } } }