Add verbose parameter to ZoneCodeGenerator instead of always being verbose in debug mode

This commit is contained in:
Jan 2019-09-27 22:57:58 +02:00
parent f9b7fa57c8
commit 49dfff1efe
10 changed files with 28 additions and 18 deletions

View File

@ -25,7 +25,10 @@ namespace ZoneCodeGenerator.Interface
return true; return true;
} }
var session = new CUISession(); var session = new CUISession
{
Verbose = argumentParser.IsOptionSpecified(CommandLineOptions.OPTION_VERBOSE)
};
if (argumentParser.IsOptionSpecified(CommandLineOptions.OPTION_OUTPUT_FOLDER)) if (argumentParser.IsOptionSpecified(CommandLineOptions.OPTION_OUTPUT_FOLDER))
{ {
@ -35,7 +38,7 @@ namespace ZoneCodeGenerator.Interface
if (argumentParser.IsOptionSpecified(CommandLineOptions.OPTION_CREATE)) if (argumentParser.IsOptionSpecified(CommandLineOptions.OPTION_CREATE))
{ {
session.SourceFilePath = argumentParser.GetValueForOption(CommandLineOptions.OPTION_CREATE); session.SourceFilePath = argumentParser.GetValueForOption(CommandLineOptions.OPTION_CREATE);
session.Repository = HeaderReader.ReadFile(session.SourceFilePath); session.Repository = HeaderReader.ReadFile(session.SourceFilePath, session.Verbose);
if (session.Repository == null) if (session.Repository == null)
{ {
@ -51,7 +54,7 @@ namespace ZoneCodeGenerator.Interface
if (argumentParser.IsOptionSpecified(CommandLineOptions.OPTION_EDITING_COMMANDS)) if (argumentParser.IsOptionSpecified(CommandLineOptions.OPTION_EDITING_COMMANDS))
{ {
if (!CommandFileReader.ReadFile(argumentParser.GetValueForOption(CommandLineOptions.OPTION_EDITING_COMMANDS), session)) if (!CommandFileReader.ReadFile(argumentParser.GetValueForOption(CommandLineOptions.OPTION_EDITING_COMMANDS), session, session.Verbose))
{ {
return false; return false;
} }

View File

@ -8,11 +8,13 @@ namespace ZoneCodeGenerator.Interface
public IDataRepository Repository { get; set; } public IDataRepository Repository { get; set; }
public string GeneratorOutputPath { get; set; } public string GeneratorOutputPath { get; set; }
public string SourceFilePath { get; set; } public string SourceFilePath { get; set; }
public bool Verbose { get; set; }
public CUISession() public CUISession()
{ {
Repository = null; Repository = null;
GeneratorOutputPath = "."; GeneratorOutputPath = ".";
Verbose = false;
} }
} }
} }

View File

@ -15,6 +15,12 @@ namespace ZoneCodeGenerator.Interface
.WithDescription("Show usage.") .WithDescription("Show usage.")
.Build(); .Build();
public static readonly CommandLineOption OPTION_VERBOSE = CommandLineOption.CommandLineOptionBuilder.Create()
.WithShortName("v")
.WithLongName("verbose")
.WithDescription("Gives a lot and detailed output.")
.Build();
// ------ // ------
// INPUT // INPUT
// ------ // ------
@ -75,6 +81,7 @@ namespace ZoneCodeGenerator.Interface
{ {
// GENERAL // GENERAL
OPTION_HELP, OPTION_HELP,
OPTION_VERBOSE,
// INPUT // INPUT
OPTION_CREATE, OPTION_CREATE,

View File

@ -15,7 +15,7 @@ namespace ZoneCodeGenerator.Parsing.C_Header
new PostProcessorUsages(), new PostProcessorUsages(),
}; };
public static IDataRepository ReadFile(string path) public static IDataRepository ReadFile(string path, bool verbose = false)
{ {
try try
{ {
@ -29,7 +29,7 @@ namespace ZoneCodeGenerator.Parsing.C_Header
var lexer = new Lexer(preprocessorStream); var lexer = new Lexer(preprocessorStream);
var parser = new Parser<HeaderParserState>(state, lexer); var parser = new Parser<HeaderParserState>(state, lexer);
if (!parser.Parse()) if (!parser.Parse(verbose))
return null; return null;
dataRepository = new InMemoryDataRepository(); dataRepository = new InMemoryDataRepository();

View File

@ -16,7 +16,7 @@ namespace ZoneCodeGenerator.Parsing.CommandFile
new PostProcessorDefaultBlock(), new PostProcessorDefaultBlock(),
}; };
public static bool ReadFile(string path, CUISession session) public static bool ReadFile(string path, CUISession session, bool verbose = false)
{ {
try try
{ {
@ -29,7 +29,7 @@ namespace ZoneCodeGenerator.Parsing.CommandFile
var lexer = new Lexer(preprocessorStream); var lexer = new Lexer(preprocessorStream);
var parser = new Parser<ICommandParserState>(state, lexer); var parser = new Parser<ICommandParserState>(state, lexer);
if (!parser.Parse()) if (!parser.Parse(verbose))
return false; return false;
preprocessorStream.Close(); preprocessorStream.Close();

View File

@ -17,12 +17,7 @@ namespace ZoneCodeGenerator.Parsing.Matching
{ {
Lexer = lexer; Lexer = lexer;
this.taggedMatchers = taggedMatchers; this.taggedMatchers = taggedMatchers;
#if DEBUG
Verbose = true;
#else
Verbose = false; Verbose = false;
#endif
} }
public TokenMatcher GetMatcherByTag(string tag) public TokenMatcher GetMatcherByTag(string tag)

View File

@ -17,7 +17,7 @@ namespace ZoneCodeGenerator.Parsing
this.lexer = lexer; this.lexer = lexer;
} }
public bool Parse() public bool Parse(bool verbose = false)
{ {
while (!lexer.IsEndOfStream) while (!lexer.IsEndOfStream)
{ {
@ -27,7 +27,7 @@ namespace ZoneCodeGenerator.Parsing
{ {
foreach (var test in state.GetTests()) foreach (var test in state.GetTests())
{ {
switch (test.PerformTest(state, lexer)) switch (test.PerformTest(state, lexer, verbose))
{ {
case TokenTestResult.Match: case TokenTestResult.Match:
lexer.SkipTokens(test.ConsumedTokenCount); lexer.SkipTokens(test.ConsumedTokenCount);

View File

@ -57,7 +57,7 @@ namespace ZoneCodeGenerator.Parsing.Testing
protected abstract void ProcessMatch(TState state); protected abstract void ProcessMatch(TState state);
public TokenTestResult PerformTest(TState state, ILexer lexer) public TokenTestResult PerformTest(TState state, ILexer lexer, bool verbose = false)
{ {
var tokenOffset = 0; var tokenOffset = 0;
matchedEntries.Clear(); matchedEntries.Clear();
@ -65,7 +65,10 @@ namespace ZoneCodeGenerator.Parsing.Testing
ConsumedTokenCount = 0; ConsumedTokenCount = 0;
tested = true; tested = true;
var context = new MatchingContext(lexer, taggedMatchers); var context = new MatchingContext(lexer, taggedMatchers)
{
Verbose = verbose
};
if (context.Verbose) if (context.Verbose)
{ {

View File

@ -4,6 +4,6 @@
{ {
int ConsumedTokenCount { get; } int ConsumedTokenCount { get; }
TokenTestResult PerformTest(TState state, ILexer lexer); TokenTestResult PerformTest(TState state, ILexer lexer, bool verbose = false);
} }
} }

View File

@ -52,7 +52,7 @@ namespace ZoneCodeGeneratorTests.Parsing.Testing.Tests
var test = new TestCloseBlock(false); var test = new TestCloseBlock(false);
Assert.AreEqual(TokenTestResult.Match, test.PerformTest(parserStateMock.Object, lexerMock.Object)); Assert.AreEqual(TokenTestResult.Match, test.PerformTest(parserStateMock.Object, lexerMock.Object, true));
// Be sure there was no name assigned // Be sure there was no name assigned
topBlockNameAssignable.Verify(assignable => assignable.AssignName(It.IsAny<string>()), Times.Never()); topBlockNameAssignable.Verify(assignable => assignable.AssignName(It.IsAny<string>()), Times.Never());