Skip to content

Commit

Permalink
bump to v1.5.4
Browse files Browse the repository at this point in the history
- Updated docs.
- Merged "ZeroArgumentsException" and "LessThanTwoArgumentsException" into "NotEnoughArgumentsException".
- Merged "NegativeArgumentException", "NonPositiveArgumentException" and "MinGreaterThanMaxException" into "InvalidArgumentValueException".
- Merged "NeitherStringNorPregexException", "NeitherCharNorTokenException", "NonStringArgumentException" and "NonIntegerArgumentException" into "InvalidArgumentTypeException".
- Added "EmptyNegativeAssertionException" which is thrown whenever an "Empty" class instance is provided as a negative assertion pattern.
- Updated parameter names of lookaround-assertion class constructors.
- Modified existing tests and added some more.
  • Loading branch information
manoss96 committed Aug 16, 2022
1 parent e7c5915 commit 0edc98f
Show file tree
Hide file tree
Showing 19 changed files with 495 additions and 437 deletions.
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pregex==1.5.3
pregex==1.5.4
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Manos Stoumpos'

# The full version, including alpha/beta/rc tags
release = '1.5.3'
release = '1.5.4'


# -- General configuration ---------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/source/docstring/modules.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
+++++++
#########
pregex
+++++++
#########

In this page you can learn about each one of pregex's core modules
and how to effectively use them in order to build complex RegEx patterns.
Expand Down
41 changes: 27 additions & 14 deletions docs/source/docstring/pregex.rst
Original file line number Diff line number Diff line change
@@ -1,53 +1,66 @@
*********************
pregex.pre
-----------------
*********************
.. automodule:: pregex.pre
:members:
:undoc-members:

-----------------
============================


*********************
pregex.assertions
------------------------
*********************
.. automodule:: pregex.assertions
:members:
:undoc-members:

------------------------
============================


*********************
pregex.classes
---------------------
*********************
.. automodule:: pregex.classes
:members:
:undoc-members:

------------------------
============================


*********************
pregex.groups
------------------------
*********************
.. automodule:: pregex.groups
:members:
:undoc-members:

------------------------
============================


*********************
pregex.operators
-----------------------
*********************
.. automodule:: pregex.operators
:members:
:undoc-members:

------------------------
============================


*********************
pregex.quantifiers
-------------------------
*********************
.. automodule:: pregex.quantifiers
:members:
:undoc-members:

------------------------
============================


*********************
pregex.tokens
--------------------
*********************
.. automodule:: pregex.tokens
:members:
:undoc-members:
:undoc-members:
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pregex"
version = "1.5.3"
version = "1.5.4"
authors = [
{email = "[email protected]"},
{name = "Manos Stoumpos"}
Expand Down
199 changes: 115 additions & 84 deletions src/pregex/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
quantifier.
Classes & methods
===========================================
-------------------------------------------
Below are listed all classes within :py:mod:`pregex.assertions`
along with any possible methods they may possess.
Expand Down Expand Up @@ -58,51 +58,62 @@ class __PositiveLookaround(__Assertion):
Constitutes the base class for classes ``FollowedBy`` and ``PrecededBy`` \
that are part of this module.
:param Pregex | str pre1: A Pregex instance or string representing the `match` pattern.
:param Pregex | str pre2: A Pregex instance or string representing the `assertion` pattern.
:param Pregex | str match: A Pregex instance or string representing the `match` pattern.
:param Pregex | str assertion: A Pregex instance or string representing the `assertion` pattern.
:param (Pregex, Pregex => str) transform: A `transform` function for the provided patterns.
'''
def __init__(self, pre1: _pre.Pregex or str, pre2: _pre.Pregex or str, transform):
def __init__(self, match: _pre.Pregex or str, assertion: _pre.Pregex or str, transform):
'''
Constitutes the base class for classes ``FollowedBy`` and ``PrecededBy`` \
that are part of this module.
:param Pregex | str pre1: A Pregex instance or string representing the `match` pattern.
:param Pregex | str pre2: A Pregex instance or string representing the `assertion` pattern.
:param Pregex | str match: A Pregex instance or string representing the `match` pattern.
:param Pregex | str assertion: A Pregex instance or string representing the `assertion` pattern.
:param (Pregex, Pregex => str) transform: A `transform` function for the provided patterns.
'''
pre1 = __class__._to_pregex(pre1)
pre2 = __class__._to_pregex(pre2)
super().__init__(transform(pre1, pre2))
match = __class__._to_pregex(match)
assertion = __class__._to_pregex(assertion)
result = match if assertion._get_type() == _pre._Type.Empty \
else transform(match, assertion)
super().__init__(str(result))


class __NegativeLookaround(__Assertion):
'''
Constitutes the base class for classes ``NotFollowedBy`` and ``NotPrecededBy`` \
that are part of this module.
:param Pregex | str pre1: A Pregex instance or string representing the `match` pattern.
:param Pregex | str *pres: One or more Pregex instances or strings representing the `assertion` patterns.
:param Pregex | str *pres: Two or more Pregex instances, the first of which always \
represents the `match` pattern, while the rest constitute `assertion` patterns.
:param (tuple[Pregex | str] => str) transform: A `transform` function for the provided patterns.
:raises LessThanTwoArgumentsException: Less than two arguments are provided.
:raises NotEnoughArgumentsException: No assertion patterns were provided.
:raises EmptyNegativeAssertionException: The empty string is provided \
as one of the assertion patterns.
'''
def __init__(self, pres: tuple[_pre.Pregex or str], transform) -> _pre.Pregex:
'''
Constitutes the base class for classes ``NotFollowedBy`` and ``NotPrecededBy`` \
that are part of this module.
:param Pregex | str pre1: A Pregex instance or string representing the `match` pattern.
:param Pregex | str *pres: One or more Pregex instances or strings representing the `assertion` patterns.
:param Pregex | str *pres: Two or more Pregex instances, the first of which always \
represents the `match` pattern, while the rest constitute `assertion` patterns.
:param (tuple[Pregex | str] => str) transform: A `transform` function for the provided patterns.
:raises LessThanTwoArgumentsException: Less than two arguments are provided.
:raises NotEnoughArgumentsException: No assertion patterns were provided.
:raises EmptyNegativeAssertionException: The empty string is provided \
as one of the assertion patterns.
'''
if len(pres) < 2:
raise _ex.LessThanTwoArgumentsException()
message = "At least one assertion pattern is required."
raise _ex.NotEnoughArgumentsException(message)
result = __class__._to_pregex(pres[0])
for pre in pres[1:]:
result = _pre.Pregex(transform(result, __class__._to_pregex(pre)), escape=False)
pre = __class__._to_pregex(pre)
if pre._get_type() == _pre._Type.Empty:
result = _pre.Empty()
raise _ex.EmptyNegativeAssertionException()
result = _pre.Pregex(transform(result, pre), escape=False)
super().__init__(str(result))


Expand Down Expand Up @@ -208,106 +219,126 @@ def __init__(self):

class FollowedBy(__PositiveLookaround):
'''
Matches pattern ``pre1`` only if it is followed by pattern ``pre2``, \
without the latter being included into the match.
Matches pattern ``match`` only if it is followed by pattern \
``assertion``, without the latter being included into the match.
:param Pregex | str pre1: The pattern that is to be matched.
:param Pregex | str pre2: The pattern that must follow pattern ``pre1`` \
in order for it to be considered a match.
:param Pregex | str match: A Pregex instance or string \
representing the `match` pattern.
:param Pregex | str assertion: A Pregex instance or string \
representing the `assertion` pattern.
'''

def __init__(self, pre1: _pre.Pregex or str, pre2: _pre.Pregex or str):
def __init__(self, match: _pre.Pregex or str, assertion: _pre.Pregex or str):
'''
Matches pattern ``pre1`` only if it is followed by pattern ``pre2``, \
without the latter being included into the match.
Matches pattern ``match`` only if it is followed by pattern \
``assertion``, without the latter being included into the match.
:param Pregex | str pre1: The pattern that is to be matched.
:param Pregex | str pre2: The pattern that must follow pattern ``pre1`` \
in order for it to be considered a match.
:param Pregex | str match: A Pregex instance or string \
representing the `match` pattern.
:param Pregex | str assertion: A Pregex instance or string \
representing the `assertion` pattern.
'''
super().__init__(pre1, pre2, lambda pre1, pre2: str(pre1._followed_by(pre2)))
super().__init__(match, assertion, lambda pre1, pre2: str(pre1._followed_by(pre2)))


class NotFollowedBy(__NegativeLookaround):
'''
Matches pattern ``pre`` only if it is not followed by any one of \
the rest of the provided patterns.
Matches pattern ``match` only if it is not followed by any one of \
the `provided ``assertion`` patterns.
:param Pregex | str pre: The pattern that is to be matched.
:param Pregex | str \*pres: One or more patterns, none of which must \
come right after ``pre`` in order for it to be considered a match.
:param Pregex | str match: The pattern that is to be matched.
:param Pregex | str \*assertions: One or more patterns, none of which must \
come right after ``match`` in order for it to be considered a match.
:raises NotEnoughArgumentsException: No assertion patterns were provided.
:raises EmptyNegativeAssertionException: The empty string is provided \
as one of the assertion patterns.
'''

def __init__(self, pre: _pre.Pregex or str, *pres: _pre.Pregex or str):
def __init__(self, match: _pre.Pregex or str, *assertions: _pre.Pregex or str):
'''
Matches pattern ``pre`` only if it is not followed by any one of \
rest of the provided patterns.
Matches pattern ``match` only if it is not followed by any one of \
the `provided ``assertion`` patterns.
:param Pregex | str pre: The pattern that is to be matched.
:param Pregex | str \*pres: One or more patterns, none of which must \
come right after ``pre`` in order for it to be considered a match.
:param Pregex | str match: The pattern that is to be matched.
:param Pregex | str \*assertions: One or more patterns, none of which must \
come right after ``match`` in order for it to be considered a match.
:raises NotEnoughArgumentsException: No assertion patterns were provided.
:raises EmptyNegativeAssertionException: The empty string is provided \
as one of the assertion patterns.
'''
super().__init__((pre, *pres), lambda pre1, pre2: str(pre1._not_followed_by(pre2)))
super().__init__((match, *assertions),
lambda pre1, pre2: str(pre1._not_followed_by(pre2)))


class PrecededBy(__PositiveLookaround):
'''
Matches pattern ``pre1`` only if it is preceded by pattern ``pre2``, \
without the latter being included into the match.
Matches pattern ``match`` only if it is preceded by pattern \
``assertion``, without the latter being included into the match.
:param Pregex | str pre1: The pattern that is to be matched.
:param Pregex | str pre2: The pattern that must precede pattern ``pre1`` \
in order for it to be considered a match.
:param Pregex | str match: A Pregex instance or string \
representing the `match` pattern.
:param Pregex | str assertion: A Pregex instance or string \
representing the `assertion` pattern.
:raises NonFixedWidthPatternException: A class that represents a non-fixed-width \
pattern is provided as parameter ``pre2``.
:raises NonFixedWidthPatternException: A non-fixed-width pattern \
is provided in place of parameter ``assertion``.
'''

def __init__(self, pre1: _pre.Pregex or str, pre2: _pre.Pregex or str):
def __init__(self, match: _pre.Pregex or str, assertion: _pre.Pregex or str):
'''
Matches pattern ``pre1`` only if it is preceded by pattern ``pre2``, \
without the latter being included into the match.
Matches pattern ``match`` only if it is preceded by pattern \
``assertion``, without the latter being included into the match.
:param Pregex | str pre1: The pattern that is to be matched.
:param Pregex | str pre2: The pattern that must precede pattern ``pre1`` \
in order for it to be considered a match.
:param Pregex | str match: A Pregex instance or string \
representing the `match` pattern.
:param Pregex | str assertion: A Pregex instance or string \
representing the `assertion` pattern.
:raises NonFixedWidthPatternException: A class that represents a non-fixed-width \
pattern is provided as parameter ``pre2``.
:raises NonFixedWidthPatternException: A non-fixed-width pattern \
is provided in place of parameter ``assertion``.
'''
if isinstance(pre2, _pre.Pregex):
if pre2._get_type() == _pre._Type.Quantifier and (not isinstance(pre2, _Exactly)):
raise _ex.NonFixedWidthPatternException(self, pre2)
super().__init__(pre1, pre2, lambda pre1, pre2: str(pre1._preceded_by(pre2)))
if isinstance(assertion, _pre.Pregex):
if assertion._get_type() == _pre._Type.Quantifier \
and (not isinstance(assertion, _Exactly)):
raise _ex.NonFixedWidthPatternException(self, assertion)
super().__init__(match, assertion, lambda pre1, pre2: str(pre1._preceded_by(pre2)))


class NotPrecededBy(__NegativeLookaround):
'''
Matches pattern ``pre`` only if it is not preceded by any one of \
the rest of the provided patterns.
:param Pregex | str pre: The pattern that is to be matched.
:param Pregex | str \*pres: One or more patterns, none of which must \
come right before ``pre`` in order for it to be considered a match.
:raises NonFixedWidthPatternException: At least one of the provided classes \
in ``pres`` represents a non-fixed-width pattern.
Matches pattern ``match` only if it is not preceded by any one of \
the `provided ``assertion`` patterns.
:param Pregex | str match: The pattern that is to be matched.
:param Pregex | str \*assertions: One or more patterns, none of which must \
come right before ``match`` in order for it to be considered a match.
:raises NotEnoughArgumentsException: No assertion patterns were provided.
:raises EmptyNegativeAssertionException: The empty string is provided \
as one of the assertion patterns.
:raises NonFixedWidthPatternException: At least one of the provided assertion \
patterns is a non-fixed-width pattern.
'''

def __init__(self, pre: _pre.Pregex or str, *pres: _pre.Pregex or str):
def __init__(self, match: _pre.Pregex or str, *assertions: _pre.Pregex or str):
'''
Matches pattern ``pre`` only if it is not preceded by any one of \
the rest of the provided patterns.
:param Pregex | str pre: The pattern that is to be matched.
:param Pregex | str \*pres: One or more patterns, none of which must \
come right before ``pre`` in order for it to be considered a match.
:raises NonFixedWidthPatternException: At least one of the provided classes \
in ``pres`` represents a non-fixed-width pattern.
Matches pattern ``match` only if it is not preceded by any one of \
the `provided ``assertion`` patterns.
:param Pregex | str match: The pattern that is to be matched.
:param Pregex | str \*assertions: One or more patterns, none of which must \
come right before ``match`` in order for it to be considered a match.
:raises NotEnoughArgumentsException: No assertion patterns were provided.
:raises EmptyNegativeAssertionException: The empty string is provided \
as one of the assertion patterns.
:raises NonFixedWidthPatternException: At least one of the provided assertion \
patterns is a non-fixed-width pattern.
'''
for p in pres:
if isinstance(p, _pre.Pregex):
if p._get_type() == _pre._Type.Quantifier and (not isinstance(p, _Exactly)):
raise _ex.NonFixedWidthPatternException(self, p)
super().__init__((pre, *pres), lambda pre1, pre2: str(pre1._not_preceded_by(pre2)))
for pre in assertions:
if isinstance(pre, _pre.Pregex):
if pre._get_type() == _pre._Type.Quantifier and (not isinstance(pre, _Exactly)):
raise _ex.NonFixedWidthPatternException(self, pre)
super().__init__((match, *assertions), lambda pre1, pre2: str(pre1._not_preceded_by(pre2)))
Loading

0 comments on commit 0edc98f

Please sign in to comment.