From c21aa20df1f4b6994dfac14bd28d16ecd2982cd4 Mon Sep 17 00:00:00 2001 From: Blank Spruce <32396809+BlankSpruce@users.noreply.github.com> Date: Sat, 20 Jun 2020 18:33:17 +0200 Subject: [PATCH] Don't treat missing value of one value keyword as an error Since missing value might lead to StopIteration exception for now let's just allow that value to be missing. Previously it'd stop formating of remaining files in the batch. More details: PEP 479 Although it's an issue with incorrect CMake code rather than parsing/formatting such code nevertheless it'd be more of an annoyance in that case --- CHANGELOG.md | 5 +++++ gersemi/__version__.py | 2 +- .../argument_aware_command_invocation_dumper.py | 6 +++++- ...g_value_for_one_value_keyword_is_not_an_error.in.cmake | 3 +++ ..._value_for_one_value_keyword_is_not_an_error.out.cmake | 8 ++++++++ 5 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/formatter/missing_value_for_one_value_keyword_is_not_an_error.in.cmake create mode 100644 tests/formatter/missing_value_for_one_value_keyword_is_not_an_error.out.cmake diff --git a/CHANGELOG.md b/CHANGELOG.md index b633c0b..73b55bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [0.2.1] 2020-06-20 + +### Fixed +- Missing value for one value keyword no longer leads to stopping formatting of remaining files in the batch + ## [0.2.0] 2020-06-14 ### Added diff --git a/gersemi/__version__.py b/gersemi/__version__.py index eff8a9c..88f56c2 100644 --- a/gersemi/__version__.py +++ b/gersemi/__version__.py @@ -4,4 +4,4 @@ __license__ = "MPL 2.0" __title__ = "gersemi" __url__ = "https://github.com/BlankSpruce/gersemi" -__version__ = "0.2.0" +__version__ = "0.2.1" diff --git a/gersemi/command_invocation_dumpers/argument_aware_command_invocation_dumper.py b/gersemi/command_invocation_dumpers/argument_aware_command_invocation_dumper.py index fa6cf79..7af5785 100644 --- a/gersemi/command_invocation_dumpers/argument_aware_command_invocation_dumper.py +++ b/gersemi/command_invocation_dumpers/argument_aware_command_invocation_dumper.py @@ -67,7 +67,11 @@ def _split_by_keywords(self, arguments: Nodes) -> Tuple[Iterator[Nodes], Nodes]: groups += [[argument]] elif is_one_of_one_value_keywords(argument): groups += [pop_all(accumulator)] - groups += [[argument, next(iterator)]] + next_argument = next(iterator, None) + if next_argument is None: + groups += [[argument]] + else: + groups += [[argument, next_argument]] elif is_one_of_multi_value_keywords(argument): groups += [pop_all(accumulator)] accumulator = [argument] diff --git a/tests/formatter/missing_value_for_one_value_keyword_is_not_an_error.in.cmake b/tests/formatter/missing_value_for_one_value_keyword_is_not_an_error.in.cmake new file mode 100644 index 0000000..66d8aca --- /dev/null +++ b/tests/formatter/missing_value_for_one_value_keyword_is_not_an_error.in.cmake @@ -0,0 +1,3 @@ +try_compile(FOO BAR BAZ OUTPUT_VARIABLE) + +try_compile(FOO__________________________________________________ BAR__________________________________________________ BAZ__________________________________________________ OUTPUT_VARIABLE) diff --git a/tests/formatter/missing_value_for_one_value_keyword_is_not_an_error.out.cmake b/tests/formatter/missing_value_for_one_value_keyword_is_not_an_error.out.cmake new file mode 100644 index 0000000..44c38c0 --- /dev/null +++ b/tests/formatter/missing_value_for_one_value_keyword_is_not_an_error.out.cmake @@ -0,0 +1,8 @@ +try_compile(FOO BAR BAZ OUTPUT_VARIABLE) + +try_compile( + FOO__________________________________________________ + BAR__________________________________________________ + BAZ__________________________________________________ + OUTPUT_VARIABLE +)