oceanscript
Advanced tools
| Metadata-Version: 2.1 | ||
| Name: oceanscript | ||
| Version: 2.0.3 | ||
| Version: 2.1.0 | ||
| Summary: OceanScript is an Esoteric language used to encode and decode text into a formulation of characters - where the final result looks like waves in the ocean. | ||
@@ -21,10 +21,33 @@ Home-page: https://github.com/Kreusada/OceanScript | ||
| <br> | ||
| OceanScript Esoteric Language (2.0.3 release) | ||
| OceanScript Esoteric Language (2.1.0 release) | ||
| <br> | ||
| </h1> | ||
| [](https://github.com/psf/black) | ||
| [](https://github.com/PyCQA/isort) | ||
| [](http://makeapullrequest.com) | ||
| <p align="center"> | ||
| <a href="https://github.com/psf/black"> | ||
| <img alt="Code Style: Black" src="https://img.shields.io/badge/code%20style-black-000000.svg"> | ||
| </a> | ||
| <a href="https://pypi.org/project/Red-DiscordBot/"> | ||
| <img alt="Imports: Isort" src="https://user-images.githubusercontent.com/6032823/111363465-600fe880-8690-11eb-8377-ec1d4d5ff981.png"> | ||
| </a> | ||
| <a href="https://www.python.org/downloads/"> | ||
| <img alt="PyPI - Python Versions" src="https://img.shields.io/pypi/pyversions/OceanScript"> | ||
| </a> | ||
| <a href="https://www.patreon.com/kreusada"> | ||
| <img src="https://img.shields.io/badge/Support-on%20Patreon-red.svg" alt="Support on Patreon"> | ||
| </a> | ||
| </p> | ||
| <p align="center"> | ||
| <a href="https://pepy.tech/project/oceanscript"> | ||
| <img alt="Total downloads" src="https://pepy.tech/badge/oceanscript"> | ||
| </a> | ||
| <a href="https://pepy.tech/project/oceanscript"> | ||
| <img alt="Downloads in the past month" src="https://pepy.tech/badge/oceanscript/month"> | ||
| </a> | ||
| <a href="https://pepy.tech/project/oceanscript"> | ||
| <img alt="Downloads in the past week" src="https://pepy.tech/badge/oceanscript/week"> | ||
| </a> | ||
| </p> | ||
| # Overview | ||
@@ -270,16 +293,19 @@ | ||
| OceanScriptError has a `position` attribute, which is the string index in where the | ||
| exception was raised (at the start of the wave). | ||
| exception was raised (at the start of the wave affected). | ||
| ```py | ||
| >>> oceanscript.decode("*>....") # capitalizing int | ||
| OceanScriptError: Splash indicator not allowed for integers (position 0) | ||
| >>> oceanscript.decode("*^>....") # trying to capitalize integer (3) | ||
| OceanScriptError: [Position 0] Splash indicator not allowed for integer waves | ||
| >>> oceanscript.decode("=a") # rafting ascii value | ||
| OceanScriptError: Do not use lowercase ascii letters or digits on a raft ('=a'). Use '^<.' instead. (position 0) | ||
| >>> oceanscript.decode("=a") # rafting a-Z/0-9 | ||
| OceanScriptError: [Position 0] Do not use a-Z/0-9 on a raft ('=a'). Use '^<.' instead. | ||
| >>> oceanscript.decode("^-.~>..#>..") # invalid row indicator '#' | ||
| OceanScriptError: '#' is not a valid row indicator (position 7) | ||
| OceanScriptError: [Position 7] Invalid syntax: '#'. Perhaps you meant '=#'? | ||
| >>> oceanscript.decode("^+...") # invalid column indicator '+' | ||
| OceanScriptError: '^' indicator expected '<', '-', or '>', but received '+' instead (position 0) | ||
| >>> oceanscript.decode("*^-..._>._-.^<...,_>.^<...,~-..._>..~>..~-.._+.") # invalid column indicator '+' | ||
| OceanScriptError: [Position 44] Row indicator '_' expecting valid column indicator afterwards ('<', '-', or '>') | ||
| >>> oceanscript.encode("*~<.~-.^>..^-...^<.=:,*=Δ") # splash indicator before already capitalized alphabetic character | ||
| OceanScriptError: [Position 22] Splash is redundent in this position, given wave is already uppercase ('Δ'). Use '*=δ' or '=Δ' instead. | ||
| ``` | ||
@@ -289,2 +315,35 @@ | ||
| You can handle tracebacks to your own liking with the `.without_position_reference()` method | ||
| to remove the position reference prefixed to the start of the exception string. | ||
| ```py | ||
| >>> try: | ||
| >>> decode("*~>.._<.~>..~-..~-.^-..,*~>..=:,*=Ǫ") | ||
| >>> except OceanScriptError as err: | ||
| >>> print(err) | ||
| "[Position 32] Splash is redundent in this position, given wave is already uppercase ('Ǫ'). Use '*=ǫ' or '=Ǫ' instead." | ||
| >>> try: | ||
| >>> decode("*~>.._<.~>..~-..~-.^-..,*~>..=:,*=Ǫ") | ||
| >>> except OceanScriptError as err: | ||
| >>> print(err) | ||
| "Splash is redundent in this position, given wave is already uppercase ('Ǫ'). Use '*=ǫ' or '=Ǫ' instead." | ||
| ``` | ||
| ### Splitting Waves | ||
| Since `v2.1.0`, the functionality to split waves has been created as | ||
| a public method, and is continually used by the decoder when decoding. | ||
| It has an `include_invalid` keyword only argument which defines whether | ||
| to include invalid identifiers/waves in the string, defaulting to True. | ||
| ```py | ||
| >>> oceanscript.splitwaves("*_-.~-.^>..^>..~>..,~-...~>.._>..^>..~<.=!") | ||
| ('*_-.', '~-.', '^>..', '^>..', '~>..', '~-...', '~>..', '_>..', '^>..', '~<.', '=!') | ||
| >>> oceanscript.splitwaves("*_-.~-.^>..^>..~>..,~-...~>.._>..^>..~<.=!,whoops") | ||
| ('*_-.', '~-.', '^>..', '^>..', '~>..', ',', '~-...', '~>..', '_>..', '^>..', '~<.', '=!', ',', 'w', 'h', 'o', 'o', 'p', 's') | ||
| >>> oceanscript.splitwaves("*_-.~-.^>..^>..~>..,~-...~>.._>..^>..~<.=!,whoops") | ||
| ('*_-.', '~-.', '^>..', '^>..', '~>..', '~-...', '~>..', '_>..', '^>..', '~<.', '=!') | ||
| ``` | ||
| # Installation | ||
@@ -291,0 +350,0 @@ |
+141
-34
@@ -8,3 +8,3 @@ """ | ||
| import string | ||
| from typing import Literal, Optional | ||
| from typing import Literal, Optional, Tuple | ||
@@ -17,3 +17,3 @@ __all__ = ( | ||
| __version__ = "2.0.3" | ||
| __version__ = "2.1.0" | ||
@@ -54,7 +54,20 @@ ROW_INDICATORS = "^~_" | ||
| def __init__(self, *, message: str, position: int) -> None: | ||
| def __init__(self, *, message: str, position: Optional[int] = None) -> None: | ||
| self.position = position | ||
| super().__init__(f"{message} (position {position})") | ||
| self._message = message | ||
| if position is not None: | ||
| message = f"[Position {position}] " + message | ||
| super().__init__(message) | ||
| def without_position_reference(self) -> str: | ||
| """Returns the traceback string without the position reference at the end. | ||
| Returns | ||
| ------ | ||
| str | ||
| The traceback message without position reference. | ||
| """ | ||
| return self._message | ||
| def encode(text: str, *, mode: Optional[Literal["squash", "stretch"]] = "squash") -> str: | ||
@@ -83,3 +96,10 @@ """Encode text into oceanscript. | ||
| if char.isupper(): | ||
| # capitals in oceanscript use the splash indicator (*) | ||
| # before wave declaration | ||
| ret += "*" | ||
| # now that potential capitalization has been recorded, we will | ||
| # convert the character to lower case. This is to make encoding | ||
| # faster and easier, but also prevents errors with capitalized | ||
| # alphabetic characters after the splash indicator i.e. | ||
| # "*=λ" is allowed but "*=Λ" is not | ||
| char = char.lower() | ||
@@ -115,4 +135,7 @@ if char in R1S: | ||
| if mode == "squash": | ||
| # squash mode ensures that no whitespace characters | ||
| # are found in the encoding | ||
| ret += "," | ||
| elif mode == "stretch": | ||
| # stretch mode ensures a line break splits each wave | ||
| ret += "\n" | ||
@@ -122,4 +145,8 @@ else: | ||
| elif char == "\n": | ||
| # % is used to represent line breaks in oceanscript | ||
| ret += "%" | ||
| else: | ||
| # now we've covered all the special and default scenarios, | ||
| # this character requires a raft. Rafts are used to support | ||
| # any other characters that are not handled above | ||
| ret += "=" + char | ||
@@ -129,2 +156,32 @@ return ret | ||
| def splitwaves(text: str, *, include_invalid: bool = True) -> Tuple[str]: | ||
| """Split oceanscript into waves. | ||
| Invalid characters will not be omitted from the returned tuple. | ||
| Parameters | ||
| ---------- | ||
| text: str | ||
| The oceanscript to split. | ||
| include_invalid: bool | ||
| Whether to include invalid identifiers in the string. | ||
| Defaults to True. | ||
| Returns | ||
| ------- | ||
| Tuple[str] | ||
| A tuple of waves split from the oceanscript | ||
| """ | ||
| split = re.split(r"(\*?=.)|(\\n|,|%)|(\*?[\^~_][>\-<]\.+)|(.)", text.strip()) | ||
| if include_invalid: | ||
| check = None | ||
| else: | ||
| # all invalid identifiers are isolated as length 1 strings | ||
| check = lambda e: e and len(e) != 1 | ||
| return tuple(filter(check, split)) | ||
| def decode(text: str) -> str: | ||
@@ -144,7 +201,8 @@ """Decode oceanscript into text. | ||
| """ | ||
| split = re.split(r"(\*?=.)|(\\n|,|%)|(\*?[\^~_][>\-<]\.{1,4})", text.strip()) | ||
| chunks = tuple(filter(None, split)) | ||
| chunks = splitwaves(text) # this is now a public method | ||
| ret = "" | ||
| for i, s in enumerate(chunks): | ||
| position = sum(map(len, chunks[:i])) | ||
| # this position variable is the index of the first | ||
| # character of this current iteration inside the entire string | ||
| if s in ",\n": | ||
@@ -156,5 +214,31 @@ ret += " " | ||
| continue | ||
| if len(s) < 2: | ||
| if len(s) == 1: | ||
| # thanks to the regex, any invalid identifier will be isolated | ||
| # as an element with a length of 1 | ||
| # here, i am just finelining the traceback message to make it | ||
| # much clearer for the user where they went wrong | ||
| if s == "=": | ||
| message = "Raft deployed without passenger" | ||
| elif s == "*": | ||
| message = "Splash created without wave declaration" | ||
| elif s in ROW_INDICATORS: | ||
| message = f"Row indicator '{s}' expecting valid column indicator afterwards ('<', '-', or '>')" | ||
| elif s in COLUMN_INDICATORS: | ||
| message = f"Waves must start with row indicators, not a column indicator ('{s}'). Expecting valid row indicator instead ('^', '~', or '_')" | ||
| elif s == ".": | ||
| message = "Dot indicator expecting to follow partially established waves, but do not follow any partial wave at this position" | ||
| elif s in string.ascii_letters + string.digits: | ||
| message = f"Invalid syntax: '{s}'. Ascii letters and integers must be written in their encoded form ({s} = '{encode(s)}')." | ||
| if position == 0: | ||
| # start of the string, wrong method used, so this logical suggestion is made | ||
| message += " Perhaps you were meant to use oceanscript.encode()?" | ||
| else: | ||
| # just like encoding the string, passing through other scenarios | ||
| # has left us nowhere. This is an invalid character, so we will | ||
| # suggest to prefix it with a raft | ||
| message = f"Invalid syntax: '{s}'. Perhaps you meant '={s}'?" | ||
| raise OceanScriptError( | ||
| message=f"invalid syntax '{s}'", | ||
| message=message, | ||
| position=position, | ||
@@ -165,19 +249,34 @@ ) | ||
| s = s[1:] | ||
| join = "".join(s) | ||
| if join in ( | ||
| "_>...", | ||
| "^<....", | ||
| "^-....", | ||
| "^>....", | ||
| "~<....", | ||
| "~-....", | ||
| "~>....", | ||
| "_<....", | ||
| "_-....", | ||
| "_>....", | ||
| ): | ||
| raise OceanScriptError( | ||
| message="Splash indicator not allowed for integers", | ||
| position=position, | ||
| ) | ||
| try: | ||
| # this is being done because the | ||
| # splash indicator should only be used on alphabetic | ||
| # waves. we can't just check if an iterable of strings | ||
| # contains a-z, because greek (for example) letters | ||
| # need to be taken into consideration | ||
| # i.e.: "*=δ" but NOT "*=[" | ||
| d = decode("".join(s)) | ||
| except OceanScriptError: | ||
| # this will be handled with its full string | ||
| pass | ||
| else: | ||
| if d.isdigit(): | ||
| raise OceanScriptError( | ||
| message="Splash indicator not allowed for integer waves", position=position | ||
| ) | ||
| if not d.isalpha(): | ||
| raise OceanScriptError( | ||
| message="Splash indicator only allowed for alphabetic waves", | ||
| position=position, | ||
| ) | ||
| if d.isupper(): | ||
| raise OceanScriptError( | ||
| message=( | ||
| f"Splash is redundent in this position, given wave is already uppercase ('{d}'). " | ||
| f"Use '*={d.lower()}' or '={d}' instead." | ||
| ), | ||
| position=position, | ||
| ) | ||
| # splash indicator means the string in this iteration | ||
| # must be capitalized. For the sake of ease, an inutile | ||
| # lambda will otherwise call the string | ||
| func = str.upper | ||
@@ -189,6 +288,8 @@ else: | ||
| after = "".join(s[1:]) | ||
| for letter in string.ascii_letters + string.digits: | ||
| if letter in after: | ||
| for character in string.ascii_letters + string.digits: | ||
| if character in after: | ||
| # a-Z/0-9 are the only characters where a raft | ||
| # cannot be used | ||
| raise OceanScriptError( | ||
| message=f"Do not use lowercase ascii letters or digits on a raft ('={letter}'). Use '{encode(letter)}' instead.", | ||
| message=f"Do not use a-Z/0-9 on a raft ('={character}'). Use '{encode(character)}' instead.", | ||
| position=position, | ||
@@ -202,3 +303,3 @@ ) | ||
| raise OceanScriptError( | ||
| message=f"'{row_indicator}' is not a valid row indicator", | ||
| message=f"Expected '^', '~', or '_' as a row indicator, but received '{row_indicator}' instead", | ||
| position=position, | ||
@@ -209,10 +310,16 @@ ) | ||
| raise OceanScriptError( | ||
| message=f"'{row_indicator}' indicator expected '<', '-', or '>', but received '{column_indicator}' instead", | ||
| message=f"Row indicator '{row_indicator}' expected '<', '-', or '>', but received '{column_indicator}' instead", | ||
| position=position, | ||
| ) | ||
| dots = s[2:] | ||
| # <row_indicator><column_indicator><dots...> (2:) | ||
| cdots = len(dots) | ||
| if cdots not in range(1, 5): | ||
| dot_range = range(1, 5) # double reference | ||
| if cdots not in dot_range: | ||
| if cdots == 0: | ||
| m = "but did not find any" | ||
| else: | ||
| m = f"but found {cdots} instead" | ||
| raise OceanScriptError( | ||
| message=f"Expected 1, 2, 3 or 4 dots, but found {cdots} instead", | ||
| message=f"Partially established wave ('{row_indicator}{column_indicator}') expected 1, 2, 3, or 4 dots at the end, {m}", | ||
| position=position, | ||
@@ -222,3 +329,3 @@ ) | ||
| raise OceanScriptError( | ||
| message=f"'{column_indicator}' indicator expected only dots, but received '{dots}' instead", | ||
| message=f"'{column_indicator}' indicator expected only dot indicators, but received '{dots}' instead", | ||
| position=position, | ||
@@ -247,4 +354,4 @@ ) | ||
| selection = R3S3S | ||
| letters = dict(zip(range(1, 5), selection)) | ||
| letters = dict(zip(dot_range, selection)) | ||
| ret += func(letters[cdots]) | ||
| return ret |
+72
-13
| Metadata-Version: 2.1 | ||
| Name: oceanscript | ||
| Version: 2.0.3 | ||
| Version: 2.1.0 | ||
| Summary: OceanScript is an Esoteric language used to encode and decode text into a formulation of characters - where the final result looks like waves in the ocean. | ||
@@ -21,10 +21,33 @@ Home-page: https://github.com/Kreusada/OceanScript | ||
| <br> | ||
| OceanScript Esoteric Language (2.0.3 release) | ||
| OceanScript Esoteric Language (2.1.0 release) | ||
| <br> | ||
| </h1> | ||
| [](https://github.com/psf/black) | ||
| [](https://github.com/PyCQA/isort) | ||
| [](http://makeapullrequest.com) | ||
| <p align="center"> | ||
| <a href="https://github.com/psf/black"> | ||
| <img alt="Code Style: Black" src="https://img.shields.io/badge/code%20style-black-000000.svg"> | ||
| </a> | ||
| <a href="https://pypi.org/project/Red-DiscordBot/"> | ||
| <img alt="Imports: Isort" src="https://user-images.githubusercontent.com/6032823/111363465-600fe880-8690-11eb-8377-ec1d4d5ff981.png"> | ||
| </a> | ||
| <a href="https://www.python.org/downloads/"> | ||
| <img alt="PyPI - Python Versions" src="https://img.shields.io/pypi/pyversions/OceanScript"> | ||
| </a> | ||
| <a href="https://www.patreon.com/kreusada"> | ||
| <img src="https://img.shields.io/badge/Support-on%20Patreon-red.svg" alt="Support on Patreon"> | ||
| </a> | ||
| </p> | ||
| <p align="center"> | ||
| <a href="https://pepy.tech/project/oceanscript"> | ||
| <img alt="Total downloads" src="https://pepy.tech/badge/oceanscript"> | ||
| </a> | ||
| <a href="https://pepy.tech/project/oceanscript"> | ||
| <img alt="Downloads in the past month" src="https://pepy.tech/badge/oceanscript/month"> | ||
| </a> | ||
| <a href="https://pepy.tech/project/oceanscript"> | ||
| <img alt="Downloads in the past week" src="https://pepy.tech/badge/oceanscript/week"> | ||
| </a> | ||
| </p> | ||
| # Overview | ||
@@ -270,16 +293,19 @@ | ||
| OceanScriptError has a `position` attribute, which is the string index in where the | ||
| exception was raised (at the start of the wave). | ||
| exception was raised (at the start of the wave affected). | ||
| ```py | ||
| >>> oceanscript.decode("*>....") # capitalizing int | ||
| OceanScriptError: Splash indicator not allowed for integers (position 0) | ||
| >>> oceanscript.decode("*^>....") # trying to capitalize integer (3) | ||
| OceanScriptError: [Position 0] Splash indicator not allowed for integer waves | ||
| >>> oceanscript.decode("=a") # rafting ascii value | ||
| OceanScriptError: Do not use lowercase ascii letters or digits on a raft ('=a'). Use '^<.' instead. (position 0) | ||
| >>> oceanscript.decode("=a") # rafting a-Z/0-9 | ||
| OceanScriptError: [Position 0] Do not use a-Z/0-9 on a raft ('=a'). Use '^<.' instead. | ||
| >>> oceanscript.decode("^-.~>..#>..") # invalid row indicator '#' | ||
| OceanScriptError: '#' is not a valid row indicator (position 7) | ||
| OceanScriptError: [Position 7] Invalid syntax: '#'. Perhaps you meant '=#'? | ||
| >>> oceanscript.decode("^+...") # invalid column indicator '+' | ||
| OceanScriptError: '^' indicator expected '<', '-', or '>', but received '+' instead (position 0) | ||
| >>> oceanscript.decode("*^-..._>._-.^<...,_>.^<...,~-..._>..~>..~-.._+.") # invalid column indicator '+' | ||
| OceanScriptError: [Position 44] Row indicator '_' expecting valid column indicator afterwards ('<', '-', or '>') | ||
| >>> oceanscript.encode("*~<.~-.^>..^-...^<.=:,*=Δ") # splash indicator before already capitalized alphabetic character | ||
| OceanScriptError: [Position 22] Splash is redundent in this position, given wave is already uppercase ('Δ'). Use '*=δ' or '=Δ' instead. | ||
| ``` | ||
@@ -289,2 +315,35 @@ | ||
| You can handle tracebacks to your own liking with the `.without_position_reference()` method | ||
| to remove the position reference prefixed to the start of the exception string. | ||
| ```py | ||
| >>> try: | ||
| >>> decode("*~>.._<.~>..~-..~-.^-..,*~>..=:,*=Ǫ") | ||
| >>> except OceanScriptError as err: | ||
| >>> print(err) | ||
| "[Position 32] Splash is redundent in this position, given wave is already uppercase ('Ǫ'). Use '*=ǫ' or '=Ǫ' instead." | ||
| >>> try: | ||
| >>> decode("*~>.._<.~>..~-..~-.^-..,*~>..=:,*=Ǫ") | ||
| >>> except OceanScriptError as err: | ||
| >>> print(err) | ||
| "Splash is redundent in this position, given wave is already uppercase ('Ǫ'). Use '*=ǫ' or '=Ǫ' instead." | ||
| ``` | ||
| ### Splitting Waves | ||
| Since `v2.1.0`, the functionality to split waves has been created as | ||
| a public method, and is continually used by the decoder when decoding. | ||
| It has an `include_invalid` keyword only argument which defines whether | ||
| to include invalid identifiers/waves in the string, defaulting to True. | ||
| ```py | ||
| >>> oceanscript.splitwaves("*_-.~-.^>..^>..~>..,~-...~>.._>..^>..~<.=!") | ||
| ('*_-.', '~-.', '^>..', '^>..', '~>..', '~-...', '~>..', '_>..', '^>..', '~<.', '=!') | ||
| >>> oceanscript.splitwaves("*_-.~-.^>..^>..~>..,~-...~>.._>..^>..~<.=!,whoops") | ||
| ('*_-.', '~-.', '^>..', '^>..', '~>..', ',', '~-...', '~>..', '_>..', '^>..', '~<.', '=!', ',', 'w', 'h', 'o', 'o', 'p', 's') | ||
| >>> oceanscript.splitwaves("*_-.~-.^>..^>..~>..,~-...~>.._>..^>..~<.=!,whoops") | ||
| ('*_-.', '~-.', '^>..', '^>..', '~>..', '~-...', '~>..', '_>..', '^>..', '~<.', '=!') | ||
| ``` | ||
| # Installation | ||
@@ -291,0 +350,0 @@ |
+71
-12
@@ -5,10 +5,33 @@ <h1 align="center"> | ||
| <br> | ||
| OceanScript Esoteric Language (2.0.3 release) | ||
| OceanScript Esoteric Language (2.1.0 release) | ||
| <br> | ||
| </h1> | ||
| [](https://github.com/psf/black) | ||
| [](https://github.com/PyCQA/isort) | ||
| [](http://makeapullrequest.com) | ||
| <p align="center"> | ||
| <a href="https://github.com/psf/black"> | ||
| <img alt="Code Style: Black" src="https://img.shields.io/badge/code%20style-black-000000.svg"> | ||
| </a> | ||
| <a href="https://pypi.org/project/Red-DiscordBot/"> | ||
| <img alt="Imports: Isort" src="https://user-images.githubusercontent.com/6032823/111363465-600fe880-8690-11eb-8377-ec1d4d5ff981.png"> | ||
| </a> | ||
| <a href="https://www.python.org/downloads/"> | ||
| <img alt="PyPI - Python Versions" src="https://img.shields.io/pypi/pyversions/OceanScript"> | ||
| </a> | ||
| <a href="https://www.patreon.com/kreusada"> | ||
| <img src="https://img.shields.io/badge/Support-on%20Patreon-red.svg" alt="Support on Patreon"> | ||
| </a> | ||
| </p> | ||
| <p align="center"> | ||
| <a href="https://pepy.tech/project/oceanscript"> | ||
| <img alt="Total downloads" src="https://pepy.tech/badge/oceanscript"> | ||
| </a> | ||
| <a href="https://pepy.tech/project/oceanscript"> | ||
| <img alt="Downloads in the past month" src="https://pepy.tech/badge/oceanscript/month"> | ||
| </a> | ||
| <a href="https://pepy.tech/project/oceanscript"> | ||
| <img alt="Downloads in the past week" src="https://pepy.tech/badge/oceanscript/week"> | ||
| </a> | ||
| </p> | ||
| # Overview | ||
@@ -254,16 +277,19 @@ | ||
| OceanScriptError has a `position` attribute, which is the string index in where the | ||
| exception was raised (at the start of the wave). | ||
| exception was raised (at the start of the wave affected). | ||
| ```py | ||
| >>> oceanscript.decode("*>....") # capitalizing int | ||
| OceanScriptError: Splash indicator not allowed for integers (position 0) | ||
| >>> oceanscript.decode("*^>....") # trying to capitalize integer (3) | ||
| OceanScriptError: [Position 0] Splash indicator not allowed for integer waves | ||
| >>> oceanscript.decode("=a") # rafting ascii value | ||
| OceanScriptError: Do not use lowercase ascii letters or digits on a raft ('=a'). Use '^<.' instead. (position 0) | ||
| >>> oceanscript.decode("=a") # rafting a-Z/0-9 | ||
| OceanScriptError: [Position 0] Do not use a-Z/0-9 on a raft ('=a'). Use '^<.' instead. | ||
| >>> oceanscript.decode("^-.~>..#>..") # invalid row indicator '#' | ||
| OceanScriptError: '#' is not a valid row indicator (position 7) | ||
| OceanScriptError: [Position 7] Invalid syntax: '#'. Perhaps you meant '=#'? | ||
| >>> oceanscript.decode("^+...") # invalid column indicator '+' | ||
| OceanScriptError: '^' indicator expected '<', '-', or '>', but received '+' instead (position 0) | ||
| >>> oceanscript.decode("*^-..._>._-.^<...,_>.^<...,~-..._>..~>..~-.._+.") # invalid column indicator '+' | ||
| OceanScriptError: [Position 44] Row indicator '_' expecting valid column indicator afterwards ('<', '-', or '>') | ||
| >>> oceanscript.encode("*~<.~-.^>..^-...^<.=:,*=Δ") # splash indicator before already capitalized alphabetic character | ||
| OceanScriptError: [Position 22] Splash is redundent in this position, given wave is already uppercase ('Δ'). Use '*=δ' or '=Δ' instead. | ||
| ``` | ||
@@ -273,2 +299,35 @@ | ||
| You can handle tracebacks to your own liking with the `.without_position_reference()` method | ||
| to remove the position reference prefixed to the start of the exception string. | ||
| ```py | ||
| >>> try: | ||
| >>> decode("*~>.._<.~>..~-..~-.^-..,*~>..=:,*=Ǫ") | ||
| >>> except OceanScriptError as err: | ||
| >>> print(err) | ||
| "[Position 32] Splash is redundent in this position, given wave is already uppercase ('Ǫ'). Use '*=ǫ' or '=Ǫ' instead." | ||
| >>> try: | ||
| >>> decode("*~>.._<.~>..~-..~-.^-..,*~>..=:,*=Ǫ") | ||
| >>> except OceanScriptError as err: | ||
| >>> print(err) | ||
| "Splash is redundent in this position, given wave is already uppercase ('Ǫ'). Use '*=ǫ' or '=Ǫ' instead." | ||
| ``` | ||
| ### Splitting Waves | ||
| Since `v2.1.0`, the functionality to split waves has been created as | ||
| a public method, and is continually used by the decoder when decoding. | ||
| It has an `include_invalid` keyword only argument which defines whether | ||
| to include invalid identifiers/waves in the string, defaulting to True. | ||
| ```py | ||
| >>> oceanscript.splitwaves("*_-.~-.^>..^>..~>..,~-...~>.._>..^>..~<.=!") | ||
| ('*_-.', '~-.', '^>..', '^>..', '~>..', '~-...', '~>..', '_>..', '^>..', '~<.', '=!') | ||
| >>> oceanscript.splitwaves("*_-.~-.^>..^>..~>..,~-...~>.._>..^>..~<.=!,whoops") | ||
| ('*_-.', '~-.', '^>..', '^>..', '~>..', ',', '~-...', '~>..', '_>..', '^>..', '~<.', '=!', ',', 'w', 'h', 'o', 'o', 'p', 's') | ||
| >>> oceanscript.splitwaves("*_-.~-.^>..^>..~>..,~-...~>.._>..^>..~<.=!,whoops") | ||
| ('*_-.', '~-.', '^>..', '^>..', '~>..', '~-...', '~>..', '_>..', '^>..', '~<.', '=!') | ||
| ``` | ||
| # Installation | ||
@@ -275,0 +334,0 @@ |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
53256
32.83%309
44.39%