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;
}
var session = new CUISession();
var session = new CUISession
{
Verbose = argumentParser.IsOptionSpecified(CommandLineOptions.OPTION_VERBOSE)
};
if (argumentParser.IsOptionSpecified(CommandLineOptions.OPTION_OUTPUT_FOLDER))
{
@ -35,7 +38,7 @@ namespace ZoneCodeGenerator.Interface
if (argumentParser.IsOptionSpecified(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)
{
@ -51,7 +54,7 @@ namespace ZoneCodeGenerator.Interface
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;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -57,7 +57,7 @@ namespace ZoneCodeGenerator.Parsing.Testing
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;
matchedEntries.Clear();
@ -65,7 +65,10 @@ namespace ZoneCodeGenerator.Parsing.Testing
ConsumedTokenCount = 0;
tested = true;
var context = new MatchingContext(lexer, taggedMatchers);
var context = new MatchingContext(lexer, taggedMatchers)
{
Verbose = verbose
};
if (context.Verbose)
{

View File

@ -4,6 +4,6 @@
{
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);
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
topBlockNameAssignable.Verify(assignable => assignable.AssignName(It.IsAny<string>()), Times.Never());