diff options
| author | Bobby <[email protected]> | 2022-08-31 13:08:27 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-08-31 13:08:27 -0400 |
| commit | 45fff43e5ff2e6de1a22a8c6bf99be6496540dc9 (patch) | |
| tree | 4eaa0db11edfcdfecb29b5704c1c3901d1141733 | |
| parent | 202fbe83351c0c205b20eeca73f7e9fcfd601ef5 (diff) | |
| download | edify-45fff43e5ff2e6de1a22a8c6bf99be6496540dc9.tar.xz edify-45fff43e5ff2e6de1a22a8c6bf99be6496540dc9.zip | |
Added Basic Datatypes
| -rw-r--r-- | src/edify/builder/builder.py | 14 | ||||
| -rw-r--r-- | src/edify/builder/datatypes.py | 73 |
2 files changed, 87 insertions, 0 deletions
diff --git a/src/edify/builder/builder.py b/src/edify/builder/builder.py new file mode 100644 index 0000000..2150314 --- /dev/null +++ b/src/edify/builder/builder.py @@ -0,0 +1,14 @@ +"""This is the main module for the edify builder. It is responsible for building +Regular Expressions from simple function chains. +""" + +class RegexBuilder: + """RegexBuilder helps build and use regular expressions using its methods. + """ + + regex = None + + def __init__(self): + """Initialize the RegexBuilder. + """ + self.regex = "" diff --git a/src/edify/builder/datatypes.py b/src/edify/builder/datatypes.py new file mode 100644 index 0000000..cb3ea13 --- /dev/null +++ b/src/edify/builder/datatypes.py @@ -0,0 +1,73 @@ +""" + This file contains the datatypes used by the edify regex builder. + + The datatypes are: + - letter: A single upper or lowercase letter (a-z or A-Z) + - digit: A single digit (0-9) + - word: A single word (a-z, A-Z, 0-9, _) + - space: A single space (\s) + - any: Any character or special character +""" + + +def letter(type: str = "all") -> str: + """Returns a regex that matches a single letter. + + Parameters: + type (str): The type of letter to match. + - "all" (default): Matches any letter (a-z or A-Z) + - "upper": Matches any upper case letter (A-Z) + - "lower": Matches any lower case letter (a-z) + + Returns: + str: A regex that matches a single letter. + + Raises: + ValueError: If any of the parameters are invalid. + """ + letters = "abcdefghijklmnopqrstuvwxyz" + if type == "upper": + letters = letters.upper() + elif type == "lower": + letters = letters + elif type == "all": + letters = letters + letters.upper() + else: + raise ValueError("Invalid letter type: " + type) + return "[" + letters + "]" + + +def digit() -> str: + """Returns a regex that matches a single digit. + + Returns: + str: A regex that matches a single digit. + """ + return "[1234567890]" + + +def word() -> str: + """Returns a regex that matches a single word. + + Returns: + str: A regex that matches a single word. + """ + return "[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_]" + + +def space() -> str: + """Returns a regex that matches a single space. + + Returns: + str: A regex that matches a single space. + """ + return "[\s]" + + +def any() -> str: + """Returns a regex that matches any character. + + Returns: + str: A regex that matches any character. + """ + return "." |
