using System; using System.Collections.Generic; using System.IO; using System.Text; using NTERA.Engine.Compiler; namespace NTERA.Compiler { public class HTMLWriter { protected virtual string ReportFooter { get; } = " \r\n"; public long TotalFileSize { get; set; } public int TotalFileCount { get; set; } public int FunctionCount { get; set; } public IList> Errors { get; set; } public IList> Warnings { get; set; } public void WriteReportToFile(Stream outputStream) { string ReportHeader = $@" NTERA Compilation Report "; using (StreamWriter writer = new StreamWriter(outputStream, Encoding.UTF8, 4096, true)) { writer.WriteLine(ReportHeader); EmitSummary(writer); writer.Write(ReportFooter); } } protected virtual string GetCSSStyle() { return @" body { font-family: sans-serif; } table { height: 98px; width: 100% } .message { width: 33.33% } .symbol { width: 66.67% }"; } protected virtual void EmitSummary(StreamWriter streamWriter) { string fileSizeStr = (TotalFileSize / 1048576D).ToString("0.0"); streamWriter.WriteLine($@"

NTERA Compilation report


NTERA v0.X

Processed {fileSizeStr} MB in {TotalFileCount} files
Processed {FunctionCount} functions

{Errors.Count} errors, {Warnings.Count} warnings

"); streamWriter.WriteLine(@"

Warnings

"); foreach (var warning in Warnings) { EmitError(streamWriter, warning.Item1, warning.Item2); } streamWriter.WriteLine(@"

"); streamWriter.WriteLine(@"

Errors

"); foreach (var error in Errors) { EmitError(streamWriter, error.Item1, error.Item2); } streamWriter.WriteLine(" \r\n
"); } protected virtual void EmitError(StreamWriter streamWriter, ParserError error, string message) { streamWriter.WriteLine($@" {message} {error.SymbolMarker} : {error.ErrorMessage} "); } } }