diff --git a/wpiformat/wpiformat/cidentlist.py b/wpiformat/wpiformat/cidentlist.py index 8557b42..b79bb65 100644 --- a/wpiformat/wpiformat/cidentlist.py +++ b/wpiformat/wpiformat/cidentlist.py @@ -46,6 +46,7 @@ def run_pipeline(self, config_file, name, lines): comment_str = r"/\*|\*/|//|" + linesep + r"|" string_str = r"\\\\|\\\"|\"|" char_str = r"\\'|'|" + digits_str = r"(?P\d+)|" extern_str = r"(?Pextern \"C(\+\+)?\")\s+(?P\{)?|" braces_str = r"\{|\}|;|def\s+\w+|\w+\**\s+\w+\s*(?P\(\))" postfix_str = r"(?=\s*(;|\{))" @@ -54,6 +55,7 @@ def run_pipeline(self, config_file, name, lines): + comment_str + string_str + char_str + + digits_str + extern_str + braces_str + postfix_str @@ -74,6 +76,7 @@ def run_pipeline(self, config_file, name, lines): in_singlecomment = False in_string = False in_char = False + last_digit_end = -1 for match in token_regex.finditer(lines): token = match.group() @@ -114,7 +117,7 @@ def run_pipeline(self, config_file, name, lines): elif token == "\\'": continue elif token == "'": - if not in_string: + if not in_string and match.start() != last_digit_end: in_char = not in_char elif in_string or in_char: # Tokens processed after this branch are ignored if they are in @@ -165,6 +168,8 @@ def run_pipeline(self, config_file, name, lines): # Replaces () with (void) output += lines[pos : match.span("paren")[0]] + "(void)" pos = match.span("paren")[0] + len("()") + elif match.group("digits"): + last_digit_end = match.end() # Write rest of file if it wasn't all processed if pos < len(lines): diff --git a/wpiformat/wpiformat/test/test_cidentlist.py b/wpiformat/wpiformat/test/test_cidentlist.py index 39fa775..4dbebfa 100644 --- a/wpiformat/wpiformat/test/test_cidentlist.py +++ b/wpiformat/wpiformat/test/test_cidentlist.py @@ -494,4 +494,12 @@ def test_cidentlist(): True, ) + # Ensure single quotes in numeric literals are ignored + test.add_input("./Test.cpp", "void func() { int x = 1'000; }") + test.add_latest_input_as_output(True) + + # Ensure single quotes after numeric literals are not ignored + test.add_input("./Test.cpp", "void func() { std::cout << 1 << '0'; }") + test.add_latest_input_as_output(True) + test.run(OutputType.FILE)