aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk/comment_remover.py
diff options
context:
space:
mode:
authorZach White <skullydazed@users.noreply.github.com>2020-05-26 13:05:41 -0700
committerGitHub <noreply@github.com>2020-05-26 13:05:41 -0700
commit751316c34465ea77e066c3052729b207f3d62e0c (patch)
treecb99656b93c156757e2fd7c84fe716f9c300ca89 /lib/python/qmk/comment_remover.py
parent5d3bf8a050f3c0beb1f91147dc1ab54de36cbb05 (diff)
downloadqmk_firmware-751316c34465ea77e066c3052729b207f3d62e0c.tar.gz
qmk_firmware-751316c34465ea77e066c3052729b207f3d62e0c.zip
[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 <Erovia@users.noreply.github.com>
Diffstat (limited to 'lib/python/qmk/comment_remover.py')
-rw-r--r--lib/python/qmk/comment_remover.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/python/qmk/comment_remover.py b/lib/python/qmk/comment_remover.py
new file mode 100644
index 000000000..45a25257f
--- /dev/null
+++ b/lib/python/qmk/comment_remover.py
@@ -0,0 +1,20 @@
1"""Removes C/C++ style comments from text.
2
3Gratefully adapted from https://stackoverflow.com/a/241506
4"""
5import re
6
7comment_pattern = re.compile(r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE)
8
9
10def _comment_stripper(match):
11 """Removes C/C++ style comments from a regex match.
12 """
13 s = match.group(0)
14 return ' ' if s.startswith('/') else s
15
16
17def comment_remover(text):
18 """Remove C/C++ style comments from text.
19 """
20 return re.sub(comment_pattern, _comment_stripper, text)