|
2 | 2 |
|
3 | 3 | namespace StandardAnchorTags;
|
4 | 4 |
|
| 5 | +/// <summary> |
| 6 | +/// The data storage for the headers of the grammar file |
| 7 | +/// </summary> |
| 8 | +/// <param name="LexicalHeader">The text for the lexical section header</param> |
| 9 | +/// <param name="SyntacticHeader">The text for the syntactic section header</param> |
| 10 | +/// <param name="UnsafeExtensionsHeader">The text for the unsafe extensions header</param> |
| 11 | +/// <param name="GrammarFooter">The footer</param> |
5 | 12 | public record GrammarHeaders(string LexicalHeader,
|
6 | 13 | string SyntacticHeader,
|
7 | 14 | string UnsafeExtensionsHeader,
|
8 | 15 | string GrammarFooter);
|
9 | 16 |
|
| 17 | +/// <summary> |
| 18 | +/// This class generates a grammar file from the ANTLR blocks in the standard |
| 19 | +/// </summary> |
| 20 | +/// <remarks> |
| 21 | +/// The full grammar is in small pieces in each clause of the standard. Then, |
| 22 | +/// its duplicated in an Annex. Rather than copy and paste by hand, generate that |
| 23 | +/// Annex from the other smaller parts. |
| 24 | +/// </remarks> |
10 | 25 | public class GenerateGrammar : IDisposable
|
11 | 26 | {
|
| 27 | + /// <summary> |
| 28 | + /// Read the existing headers from a grammar file |
| 29 | + /// </summary> |
| 30 | + /// <param name="pathToStandard">Path to the standard files (likely ../standard)</param> |
| 31 | + /// <param name="grammarFile">The filename for the grammar annex</param> |
| 32 | + /// <returns>The task that will return the headers when complete.</returns> |
12 | 33 | public static async Task<GrammarHeaders> ReadExistingHeaders(string pathToStandard, string grammarFile)
|
13 | 34 | {
|
14 | 35 | GrammarHeaders headers = new GrammarHeaders("", "", "", "");
|
@@ -50,24 +71,53 @@ public static async Task<GrammarHeaders> ReadExistingHeaders(string pathToStanda
|
50 | 71 | private readonly string pathToStandardFiles;
|
51 | 72 | private readonly StreamWriter grammarStream;
|
52 | 73 |
|
| 74 | + /// <summary> |
| 75 | + /// Construct a new grammar generator |
| 76 | + /// </summary> |
| 77 | + /// <param name="grammarPath">The path to the file</param> |
| 78 | + /// <param name="pathToStandardFiles">The path to the files in the standard</param> |
| 79 | + /// <param name="headers">The header text</param> |
53 | 80 | public GenerateGrammar(string grammarPath, string pathToStandardFiles, GrammarHeaders headers)
|
54 | 81 | {
|
55 | 82 | grammarStream = new StreamWriter(Path.Combine(pathToStandardFiles, grammarPath), false);
|
56 | 83 | this.pathToStandardFiles = pathToStandardFiles;
|
57 | 84 | informativeTextBlocks = headers;
|
58 | 85 | }
|
59 | 86 |
|
| 87 | + /// <summary> |
| 88 | + /// Write the header text that appears before the grammar output. |
| 89 | + /// </summary> |
| 90 | + /// <returns>The task</returns> |
60 | 91 | public async Task WriteHeader() => await grammarStream.WriteAsync(informativeTextBlocks.LexicalHeader);
|
| 92 | + |
| 93 | + /// <summary> |
| 94 | + /// Write the header text for the syntactic section |
| 95 | + /// </summary> |
| 96 | + /// <returns>The task</returns> |
61 | 97 | public async Task WriteSyntaxHeader() => await grammarStream.WriteAsync(informativeTextBlocks.SyntacticHeader);
|
| 98 | + |
| 99 | + /// <summary> |
| 100 | + /// Write the header text for the unsafe extensions section |
| 101 | + /// </summary> |
| 102 | + /// <returns>The task</returns> |
62 | 103 | public async Task WriteUnsafeExtensionHeader() => await grammarStream.WriteAsync(informativeTextBlocks.UnsafeExtensionsHeader);
|
63 | 104 |
|
| 105 | + /// <summary> |
| 106 | + /// Write the footer text that appears after the grammar output. |
| 107 | + /// </summary> |
| 108 | + /// <returns>The task</returns> |
64 | 109 | public async Task WriteGrammarFooter()
|
65 | 110 | {
|
66 | 111 | await grammarStream.WriteAsync(informativeTextBlocks.GrammarFooter);
|
67 | 112 | await grammarStream.FlushAsync();
|
68 | 113 | grammarStream.Close();
|
69 | 114 | }
|
70 | 115 |
|
| 116 | + /// <summary> |
| 117 | + /// Extract the grammar from one file in the standard |
| 118 | + /// </summary> |
| 119 | + /// <param name="inputFileName">The input file from the standard</param> |
| 120 | + /// <returns>The task</returns> |
71 | 121 | public async Task ExtractGrammarFrom(string inputFileName)
|
72 | 122 | {
|
73 | 123 | string inputFilePath = $"{pathToStandardFiles}/{inputFileName}";
|
@@ -106,5 +156,8 @@ public async Task ExtractGrammarFrom(string inputFileName)
|
106 | 156 | }
|
107 | 157 | }
|
108 | 158 |
|
| 159 | + /// <summary> |
| 160 | + /// Dispose of the stream |
| 161 | + /// </summary> |
109 | 162 | public void Dispose() => grammarStream.Dispose();
|
110 | 163 | }
|
0 commit comments