Skip to content

Commit

Permalink
Merge pull request #44 from unlv-evol/dev
Browse files Browse the repository at this point in the history
[FEAT]: Add boolean and delimiters regex for major programming languages
  • Loading branch information
danielogen authored Aug 12, 2024
2 parents e81e0ac + ed6bd02 commit 42e00a8
Show file tree
Hide file tree
Showing 28 changed files with 1,064 additions and 97 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ When you're finished with the changes, create a pull request, also known as a PR

### Your PR is merged!

Congratulations :tada::tada: <br />
Congratulations :tada: :tada: <br />
The PyReprism team thanks you :sparkles:.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![codecov](https://codecov.io/gh/unlv-evol/PyReprism/graph/badge.svg?token=J2JV31837H)](https://codecov.io/gh/unlv-evol/PyReprism)
![PyPI - Version](https://img.shields.io/pypi/v/pyreprism)
![GitHub last commit (branch)](https://img.shields.io/github/last-commit/unlv-evol/pyreprism/main)

[![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/)

# PyReprism

Expand Down
9 changes: 9 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pytest
flake8
pytest-cov
build
twine
hatchling
hatch-vcs
sphinx
sphinx_rtd_theme
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Minimal makefile for Sphinx documentation
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
Expand Down
8 changes: 4 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
import os
import sys
sys.path.insert(0, os.path.abspath('../src'))


# -- Project information -----------------------------------------------------
Expand Down Expand Up @@ -60,4 +60,4 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
html_static_path = ["_static"]
16 changes: 15 additions & 1 deletion docs/normalizer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@

============
Normalizer
============
============

.. automodule:: PyReprism.utils.normalizer
:members:
:undoc-members:
:show-inheritance:
:special-members:
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__

.. automodule:: PyReprism.utils.extension
:members:
:undoc-members:
:show-inheritance:
:special-members:
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__
103 changes: 101 additions & 2 deletions docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,106 @@ Reference
============

Version
--------
---------
.. py:data:: src.PyReprism.__version__
Current PyReprism version.
Current PyReprism version.

Python
-------
.. automodule:: PyReprism.languages.python
:members:
:undoc-members:
:show-inheritance:
:special-members:
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__

Java
-------
.. automodule:: PyReprism.languages.java
:members:
:undoc-members:
:show-inheritance:
:special-members:
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__

C++
-------
.. automodule:: PyReprism.languages.cpp
:members:
:undoc-members:
:show-inheritance:
:special-members:
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__

C
-------
.. automodule:: PyReprism.languages.c
:members:
:undoc-members:
:show-inheritance:
:special-members:
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__

Scala
-------
.. automodule:: PyReprism.languages.scala
:members:
:undoc-members:
:show-inheritance:
:special-members:
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__

Dart
-------
.. automodule:: PyReprism.languages.dart
:members:
:undoc-members:
:show-inheritance:
:special-members:
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__

Rust
-------
.. automodule:: PyReprism.languages.rust
:members:
:undoc-members:
:show-inheritance:
:special-members:
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__

Kotlin
-------
.. automodule:: PyReprism.languages.kotlin
:members:
:undoc-members:
:show-inheritance:
:special-members:
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__

Swift
-------
.. automodule:: PyReprism.languages.swift
:members:
:undoc-members:
:show-inheritance:
:special-members:
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__

JavaScript
----------
.. automodule:: PyReprism.languages.javascript
:members:
:undoc-members:
:show-inheritance:
:special-members:
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__

JSX
-------
.. automodule:: PyReprism.languages.jsx
:members:
:undoc-members:
:show-inheritance:
:special-members:
:exclude-members: __dict__, __weakref__, __eq__, __str__, __hash__
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "PyReprism"
version = "0.0.3"
version = "0.0.4"
authors = [
{ name= "UNLV EVOL LAB", email="ogenrwot@unlv.nevada.edu" },
]
Expand Down
6 changes: 1 addition & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
pytest
flake8
pytest-cov
build
twine
hatchling
hatch-vcs
pytest-cov
1 change: 1 addition & 0 deletions src/PyReprism/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.0.4"
80 changes: 75 additions & 5 deletions src/PyReprism/languages/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,106 @@ def __init__():

@staticmethod
def file_extension() -> str:
"""
Return the file extension used for C files.
:return: The file extension for C files.
:rtype: str
"""
return extension.c

@staticmethod
def keywords() -> list:
"""
Return a list of C keywords and built-in functions.
:return: A list of C keywords and built-in function names.
:rtype: list
"""
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('|')
return keyword

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

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

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

@staticmethod
def keywords_regex():
def keywords_regex() -> re.Pattern:
"""
Compile and return a regular expression pattern to identify C keywords.
:return: A compiled regex pattern to match C keywords.
:rtype: re.Pattern
"""
return re.compile(r'\b(' + '|'.join(C.keywords()) + r')\b')

@staticmethod
def boolean_regex() -> re.Pattern:
"""
Compile and return a regular expression pattern to identify C boolean literals.
:return: A compiled regex pattern to match C boolean literals.
:rtype: re.Pattern
"""
return re.compile(r'\b(?:true|false)\b')

@staticmethod
def delimiters_regex() -> re.Pattern:
"""
Compile and return a regular expression pattern to identify C and C++ delimiters.
:return: A compiled regex pattern to match C and C++ delimiters.
:rtype: re.Pattern
"""
return re.compile(r'[()\[\]{}.,:;@<>*&]')

@staticmethod
def remove_comments(source_code: str) -> str:
"""
Remove comments from the provided C source code string.
:param str source_code: The C source code from which to remove comments.
:return: The source code with all comments removed.
:rtype: str
"""
return C.comment_regex().sub(lambda match: match.group('noncomment') if match.group('noncomment') else '', source_code).strip()

@staticmethod
def remove_keywords(source: str):
def remove_keywords(source: str) -> str:
"""
Remove all C keywords from the provided source code string.
:param str source: The source code string from which to remove C keywords.
:return: The source code string with all C keywords removed.
:rtype: str
"""
return re.sub(re.compile(C.keywords_regex()), '', source)
Loading

0 comments on commit 42e00a8

Please sign in to comment.