feat: 将LR分析表生成到代码中 (#27)

Reviewed-on: PostGuard/Canon#27
This commit is contained in:
2024-04-08 19:46:24 +08:00
parent 5e3ea6303e
commit 1690187c0a
14 changed files with 1125 additions and 22 deletions

View File

@@ -0,0 +1,29 @@
using System.Text;
using Canon.Core.Abstractions;
using Canon.Core.Enums;
using Canon.Core.GrammarParser;
namespace Canon.Generator.GrammarGenerator;
public class GenerateCommand
{
private readonly GrammarBuilder _builder = new()
{
Generators = PascalGrammar.Grammar, Begin = new NonTerminator(NonTerminatorType.StartNonTerminator)
};
private readonly GeneratedGrammarParser _parser;
public GenerateCommand()
{
Grammar grammar = _builder.Build();
_parser = grammar.ToGeneratedGrammarParser();
}
public async Task GenerateCode(Stream output, string namespaceValue)
{
string code = _parser.GenerateCode(namespaceValue);
byte[] bytes = Encoding.UTF8.GetBytes(code);
await output.WriteAsync(bytes);
}
}