From 751316c34465ea77e066c3052729b207f3d62e0c Mon Sep 17 00:00:00 2001 From: Zach White Date: Tue, 26 May 2020 13:05:41 -0700 Subject: [CLI] Add a subcommand for getting information about a keyboard (#8666) You can now use `qmk info` to get information about keyboards and keymaps. Co-authored-by: Erovia --- lib/python/qmk/comment_remover.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/python/qmk/comment_remover.py (limited to 'lib/python/qmk/comment_remover.py') diff --git a/lib/python/qmk/comment_remover.py b/lib/python/qmk/comment_remover.py new file mode 100644 index 0000000000..45a25257f8 --- /dev/null +++ b/lib/python/qmk/comment_remover.py @@ -0,0 +1,20 @@ +"""Removes C/C++ style comments from text. + +Gratefully adapted from https://stackoverflow.com/a/241506 +""" +import re + +comment_pattern = re.compile(r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE) + + +def _comment_stripper(match): + """Removes C/C++ style comments from a regex match. + """ + s = match.group(0) + return ' ' if s.startswith('/') else s + + +def comment_remover(text): + """Remove C/C++ style comments from text. + """ + return re.sub(comment_pattern, _comment_stripper, text) -- cgit v1.2.3