diff --git a/src/ZoneCodeGenerator/Interface/CUI.cs b/src/ZoneCodeGenerator/Interface/CUI.cs index 515a7331..286ddb44 100644 --- a/src/ZoneCodeGenerator/Interface/CUI.cs +++ b/src/ZoneCodeGenerator/Interface/CUI.cs @@ -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; } diff --git a/src/ZoneCodeGenerator/Interface/CUISession.cs b/src/ZoneCodeGenerator/Interface/CUISession.cs index 0a4262f6..3addefbd 100644 --- a/src/ZoneCodeGenerator/Interface/CUISession.cs +++ b/src/ZoneCodeGenerator/Interface/CUISession.cs @@ -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; } } } diff --git a/src/ZoneCodeGenerator/Interface/CommandLineOptions.cs b/src/ZoneCodeGenerator/Interface/CommandLineOptions.cs index 85078405..44d5b09b 100644 --- a/src/ZoneCodeGenerator/Interface/CommandLineOptions.cs +++ b/src/ZoneCodeGenerator/Interface/CommandLineOptions.cs @@ -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, diff --git a/src/ZoneCodeGenerator/Parsing/C_Header/HeaderReader.cs b/src/ZoneCodeGenerator/Parsing/C_Header/HeaderReader.cs index 05e112af..cee069b9 100644 --- a/src/ZoneCodeGenerator/Parsing/C_Header/HeaderReader.cs +++ b/src/ZoneCodeGenerator/Parsing/C_Header/HeaderReader.cs @@ -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(state, lexer); - if (!parser.Parse()) + if (!parser.Parse(verbose)) return null; dataRepository = new InMemoryDataRepository(); diff --git a/src/ZoneCodeGenerator/Parsing/CommandFile/CommandFileReader.cs b/src/ZoneCodeGenerator/Parsing/CommandFile/CommandFileReader.cs index d2898b6e..824e0446 100644 --- a/src/ZoneCodeGenerator/Parsing/CommandFile/CommandFileReader.cs +++ b/src/ZoneCodeGenerator/Parsing/CommandFile/CommandFileReader.cs @@ -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(state, lexer); - if (!parser.Parse()) + if (!parser.Parse(verbose)) return false; preprocessorStream.Close(); diff --git a/src/ZoneCodeGenerator/Parsing/Matching/MatchingContext.cs b/src/ZoneCodeGenerator/Parsing/Matching/MatchingContext.cs index 043fd991..8d7c788c 100644 --- a/src/ZoneCodeGenerator/Parsing/Matching/MatchingContext.cs +++ b/src/ZoneCodeGenerator/Parsing/Matching/MatchingContext.cs @@ -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) diff --git a/src/ZoneCodeGenerator/Parsing/Parser.cs b/src/ZoneCodeGenerator/Parsing/Parser.cs index 53f3f6d9..aa7b937d 100644 --- a/src/ZoneCodeGenerator/Parsing/Parser.cs +++ b/src/ZoneCodeGenerator/Parsing/Parser.cs @@ -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); diff --git a/src/ZoneCodeGenerator/Parsing/Testing/AbstractTokenTest.cs b/src/ZoneCodeGenerator/Parsing/Testing/AbstractTokenTest.cs index b65a3538..f9d9d324 100644 --- a/src/ZoneCodeGenerator/Parsing/Testing/AbstractTokenTest.cs +++ b/src/ZoneCodeGenerator/Parsing/Testing/AbstractTokenTest.cs @@ -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) { diff --git a/src/ZoneCodeGenerator/Parsing/Testing/ITokenTest.cs b/src/ZoneCodeGenerator/Parsing/Testing/ITokenTest.cs index 996c89e7..5a0fa110 100644 --- a/src/ZoneCodeGenerator/Parsing/Testing/ITokenTest.cs +++ b/src/ZoneCodeGenerator/Parsing/Testing/ITokenTest.cs @@ -4,6 +4,6 @@ { int ConsumedTokenCount { get; } - TokenTestResult PerformTest(TState state, ILexer lexer); + TokenTestResult PerformTest(TState state, ILexer lexer, bool verbose = false); } } diff --git a/test/ZoneCodeGeneratorTests/Parsing/Testing/Tests/TestCloseBlockTest.cs b/test/ZoneCodeGeneratorTests/Parsing/Testing/Tests/TestCloseBlockTest.cs index 0b59f4d4..207e27ab 100644 --- a/test/ZoneCodeGeneratorTests/Parsing/Testing/Tests/TestCloseBlockTest.cs +++ b/test/ZoneCodeGeneratorTests/Parsing/Testing/Tests/TestCloseBlockTest.cs @@ -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()), Times.Never());