Skip to content

Commit

Permalink
Format some things with black
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGross committed Mar 6, 2024
1 parent 2424d99 commit 0b57336
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
21 changes: 12 additions & 9 deletions coq_tools/strip_comments.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__all__ = ['strip_comments']
__all__ = ["strip_comments"]


def strip_comments(contents):
"""Strips the comments from coq code in contents.
Expand All @@ -14,23 +15,25 @@ def strip_comments(contents):
Note that we take some extra care to leave *) untouched when it
does not terminate a comment.
"""
contents = contents.replace('(*', ' (* ').replace('*)', ' *) ')
tokens = contents.split(' ')
contents = contents.replace("(*", " (* ").replace("*)", " *) ")
tokens = contents.split(" ")
rtn = []
is_string = False
comment_level = 0
for token in tokens:
do_append = (comment_level == 0)
do_append = comment_level == 0
if is_string:
if token.count('"') % 2 == 1: # there are an odd number of '"' characters, indicating that we've ended the string
if token.count('"') % 2 == 1:
# there are an odd number of '"' characters, indicating that we've ended the string
is_string = False
elif token.count('"') % 2 == 1: # there are an odd number of '"' characters, so we're starting a string
elif token.count('"') % 2 == 1:
# there are an odd number of '"' characters, so we're starting a string
is_string = True
elif token == '(*':
elif token == "(*":
comment_level += 1
do_append = False
elif comment_level > 0 and token == '*)':
elif comment_level > 0 and token == "*)":
comment_level -= 1
if do_append:
rtn.append(token)
return ' '.join(rtn).replace(' (* ', '(*').replace(' *) ', '*)').strip('\n\t ')
return " ".join(rtn).replace(" (* ", "(*").replace(" *) ", "*)").strip("\n\t ")
13 changes: 7 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
[project]
name = "coq-tools"
version = "0.0.5"
authors = [
{ name="Jason Gross", email="[email protected]" },
]
authors = [{ name = "Jason Gross", email = "[email protected]" }]
description = "Some scripts to help manipulate Coq developments and minimize error-producing Coq code"
readme = "README.md"
requires-python = ">=3.5"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]

[project.urls]
Expand All @@ -20,3 +18,6 @@ classifiers = [
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[tool.black]
line-length = 120

0 comments on commit 0b57336

Please sign in to comment.