using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using NTERA.Interpreter.Compiler;
namespace NTERA.Compiler
{
public class HTMLWriter
{
protected virtual string ReportHeader { get; } =
@"
";
protected virtual string ReportFooter { get; } =
@"
";
public long TotalFileSize { get; set; }
public int TotalFileCount { get; set; }
public int FunctionCount { get; set; }
public IList> Errors { get; set; }
public void WriteReportToFile(Stream outputStream)
{
using (StreamWriter writer = new StreamWriter(outputStream, Encoding.UTF8, 4096, true))
{
writer.WriteLine(ReportHeader);
EmitSummary(writer);
writer.Write(ReportFooter);
}
}
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
");
foreach (var error in Errors)
{
EmitError(streamWriter, error.Item1, error.Item2);
}
streamWriter.WriteLine($@"
");
}
protected virtual void EmitError(StreamWriter streamWriter, ParserError error, string message)
{
streamWriter.WriteLine($@"
{message} |
{error.SymbolMarker} : {error.ErrorMessage} |
");
}
}
}