1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- 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; } =
- @"<!DOCTYPE html>
- <html lang=""en"" xmlns=""http://www.w3.org/1999/xhtml"">
- <head>
- <meta charset=""utf-8""/>
- <title></title>
- </head>
- <body style=""font-family: sans-serif"">";
- protected virtual string ReportFooter { get; } =
- @" </body>
- </html>";
- public long TotalFileSize { get; set; }
- public int TotalFileCount { get; set; }
- public int FunctionCount { get; set; }
- public IList<Tuple<ParserError, string>> 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($@" <h3>NTERA Compilation report</h3>
- <hr />
- <p>NTERA v0.X</p>
- <p>Processed {fileSizeStr} MB in {TotalFileCount} files<br />
- Processed {FunctionCount} functions
- </p>
- <p>{Errors.Count} errors</p>
- <table style=""height: 98px;"" width=""100%"">
- <tbody>");
- foreach (var error in Errors)
- {
- EmitError(streamWriter, error.Item1, error.Item2);
- }
-
- streamWriter.WriteLine($@" </tbody>
- </table>");
- }
- protected virtual void EmitError(StreamWriter streamWriter, ParserError error, string message)
- {
- streamWriter.WriteLine($@" <tr>
- <td style=""width: 30.6667%;"">{message}</td>
- <td style=""width: 66.3333%;"">{error.SymbolMarker} : {error.ErrorMessage}</td>
- </tr>");
- }
- }
- }
|