Skip to content

Commit 42e00a8

Browse files
authored
Merge pull request #44 from unlv-evol/dev
[FEAT]: Add boolean and delimiters regex for major programming languages
2 parents e81e0ac + ed6bd02 commit 42e00a8

28 files changed

+1064
-97
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ When you're finished with the changes, create a pull request, also known as a PR
6161

6262
### Your PR is merged!
6363

64-
Congratulations :tada::tada: <br />
64+
Congratulations :tada: :tada: <br />
6565
The PyReprism team thanks you :sparkles:.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[![codecov](https://codecov.io/gh/unlv-evol/PyReprism/graph/badge.svg?token=J2JV31837H)](https://codecov.io/gh/unlv-evol/PyReprism)
1010
![PyPI - Version](https://img.shields.io/pypi/v/pyreprism)
1111
![GitHub last commit (branch)](https://img.shields.io/github/last-commit/unlv-evol/pyreprism/main)
12-
12+
[![SWH](https://archive.softwareheritage.org/badge/origin/https://pypi.org/project/PyReprism//)](https://archive.softwareheritage.org/browse/origin/?origin_url=https://pypi.org/project/PyReprism/)
1313

1414
# PyReprism
1515

dev-requirements.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pytest
2+
flake8
3+
pytest-cov
4+
build
5+
twine
6+
hatchling
7+
hatch-vcs
8+
sphinx
9+
sphinx_rtd_theme

docs/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Minimal makefile for Sphinx documentation
1+
# Minimal makefile for Sphinx documentation
22
#
33

44
# You can set these variables from the command line.

docs/conf.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
# add these directories to sys.path here. If the directory is relative to the
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212
#
13-
# import os
14-
# import sys
15-
# sys.path.insert(0, os.path.abspath('.'))
13+
import os
14+
import sys
15+
sys.path.insert(0, os.path.abspath('../src'))
1616

1717

1818
# -- Project information -----------------------------------------------------
@@ -60,4 +60,4 @@
6060
# Add any paths that contain custom static files (such as style sheets) here,
6161
# relative to this directory. They are copied after the builtin static files,
6262
# so a file named "default.css" will overwrite the builtin "default.css".
63-
html_static_path = ["_static"]
63+
html_static_path = ["_static"]

docs/normalizer.rst

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,18 @@
22

33
============
44
Normalizer
5-
============
5+
============
6+
7+
.. automodule:: PyReprism.utils.normalizer
8+
:members:
9+
:undoc-members:
10+
:show-inheritance:
11+
:special-members:
12+
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__
13+
14+
.. automodule:: PyReprism.utils.extension
15+
:members:
16+
:undoc-members:
17+
:show-inheritance:
18+
:special-members:
19+
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__

docs/reference.rst

+101-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,106 @@ Reference
55
============
66

77
Version
8-
--------
8+
---------
99
.. py:data:: src.PyReprism.__version__
1010
11-
Current PyReprism version.
11+
Current PyReprism version.
12+
13+
Python
14+
-------
15+
.. automodule:: PyReprism.languages.python
16+
:members:
17+
:undoc-members:
18+
:show-inheritance:
19+
:special-members:
20+
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__
21+
22+
Java
23+
-------
24+
.. automodule:: PyReprism.languages.java
25+
:members:
26+
:undoc-members:
27+
:show-inheritance:
28+
:special-members:
29+
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__
30+
31+
C++
32+
-------
33+
.. automodule:: PyReprism.languages.cpp
34+
:members:
35+
:undoc-members:
36+
:show-inheritance:
37+
:special-members:
38+
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__
39+
40+
C
41+
-------
42+
.. automodule:: PyReprism.languages.c
43+
:members:
44+
:undoc-members:
45+
:show-inheritance:
46+
:special-members:
47+
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__
48+
49+
Scala
50+
-------
51+
.. automodule:: PyReprism.languages.scala
52+
:members:
53+
:undoc-members:
54+
:show-inheritance:
55+
:special-members:
56+
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__
57+
58+
Dart
59+
-------
60+
.. automodule:: PyReprism.languages.dart
61+
:members:
62+
:undoc-members:
63+
:show-inheritance:
64+
:special-members:
65+
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__
66+
67+
Rust
68+
-------
69+
.. automodule:: PyReprism.languages.rust
70+
:members:
71+
:undoc-members:
72+
:show-inheritance:
73+
:special-members:
74+
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__
75+
76+
Kotlin
77+
-------
78+
.. automodule:: PyReprism.languages.kotlin
79+
:members:
80+
:undoc-members:
81+
:show-inheritance:
82+
:special-members:
83+
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__
84+
85+
Swift
86+
-------
87+
.. automodule:: PyReprism.languages.swift
88+
:members:
89+
:undoc-members:
90+
:show-inheritance:
91+
:special-members:
92+
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__
93+
94+
JavaScript
95+
----------
96+
.. automodule:: PyReprism.languages.javascript
97+
:members:
98+
:undoc-members:
99+
:show-inheritance:
100+
:special-members:
101+
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__
102+
103+
JSX
104+
-------
105+
.. automodule:: PyReprism.languages.jsx
106+
:members:
107+
:undoc-members:
108+
:show-inheritance:
109+
:special-members:
110+
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "PyReprism"
7-
version = "0.0.3"
7+
version = "0.0.4"
88
authors = [
99
{ name= "UNLV EVOL LAB", email="[email protected]" },
1010
]

requirements.txt

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
pytest
22
flake8
3-
pytest-cov
4-
build
5-
twine
6-
hatchling
7-
hatch-vcs
3+
pytest-cov

src/PyReprism/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.0.4"

src/PyReprism/languages/c.py

+75-5
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,106 @@ def __init__():
88

99
@staticmethod
1010
def file_extension() -> str:
11+
"""
12+
Return the file extension used for C files.
13+
14+
:return: The file extension for C files.
15+
:rtype: str
16+
"""
1117
return extension.c
1218

1319
@staticmethod
1420
def keywords() -> list:
21+
"""
22+
Return a list of C keywords and built-in functions.
23+
24+
:return: A list of C keywords and built-in function names.
25+
:rtype: list
26+
"""
1527
keyword = '_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while|define|defined|elif|else|endif|error|ifdef|ifndef|if|import|include|line|pragma|undef|using|__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|stdin|stdout|stderr'.split('|')
1628
return keyword
1729

1830
@staticmethod
19-
def comment_regex():
31+
def comment_regex() -> re.Pattern:
32+
"""
33+
Compile and return a regular expression pattern to identify different types of comments and non-comment code in C source files.
34+
35+
:return: A compiled regex pattern with named groups to match single-line comments, multiline comments, and non-comment code elements.
36+
:rtype: re.Pattern
37+
"""
2038
pattern = re.compile(r'(?P<comment>//.*?$|/\*[^*]*\*+(?:[^/*][^*]*\*+)*?/)|(?P<noncomment>[^/]+)', re.DOTALL | re.MULTILINE)
2139
return pattern
2240

2341
@staticmethod
24-
def number_regex():
42+
def number_regex() -> re.Pattern:
43+
"""
44+
Compile and return a regular expression pattern to identify numeric literals in C code.
45+
46+
:return: A compiled regex pattern to match C numeric literals, including integers, floats, and complex numbers.
47+
:rtype: re.Pattern
48+
"""
2549
pattern = re.compile(r'(?:\b0x[\da-f]+|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?)[ful]*')
2650
return pattern
2751

2852
@staticmethod
29-
def operator_regex():
53+
def operator_regex() -> re.Pattern:
54+
"""
55+
Compile and return a regular expression pattern to identify C operators.
56+
57+
:return: A compiled regex pattern to match various C operators and logical keywords.
58+
:rtype: re.Pattern
59+
"""
3060
pattern = re.compile(r'-[>-]?|\+\+?|!=?|<<?=?|>>?=?|==?|&&?|\|\|?|[~^%?*\/]')
3161
return pattern
3262

3363
@staticmethod
34-
def keywords_regex():
64+
def keywords_regex() -> re.Pattern:
65+
"""
66+
Compile and return a regular expression pattern to identify C keywords.
67+
68+
:return: A compiled regex pattern to match C keywords.
69+
:rtype: re.Pattern
70+
"""
3571
return re.compile(r'\b(' + '|'.join(C.keywords()) + r')\b')
3672

73+
@staticmethod
74+
def boolean_regex() -> re.Pattern:
75+
"""
76+
Compile and return a regular expression pattern to identify C boolean literals.
77+
78+
:return: A compiled regex pattern to match C boolean literals.
79+
:rtype: re.Pattern
80+
"""
81+
return re.compile(r'\b(?:true|false)\b')
82+
83+
@staticmethod
84+
def delimiters_regex() -> re.Pattern:
85+
"""
86+
Compile and return a regular expression pattern to identify C and C++ delimiters.
87+
88+
:return: A compiled regex pattern to match C and C++ delimiters.
89+
:rtype: re.Pattern
90+
"""
91+
return re.compile(r'[()\[\]{}.,:;@<>*&]')
92+
3793
@staticmethod
3894
def remove_comments(source_code: str) -> str:
95+
"""
96+
Remove comments from the provided C source code string.
97+
98+
:param str source_code: The C source code from which to remove comments.
99+
:return: The source code with all comments removed.
100+
:rtype: str
101+
"""
39102
return C.comment_regex().sub(lambda match: match.group('noncomment') if match.group('noncomment') else '', source_code).strip()
40103

41104
@staticmethod
42-
def remove_keywords(source: str):
105+
def remove_keywords(source: str) -> str:
106+
"""
107+
Remove all C keywords from the provided source code string.
108+
109+
:param str source: The source code string from which to remove C keywords.
110+
:return: The source code string with all C keywords removed.
111+
:rtype: str
112+
"""
43113
return re.sub(re.compile(C.keywords_regex()), '', source)

0 commit comments

Comments
 (0)