diff --git a/README.md b/README.md index dfccba9..5bd714a 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Adds [RedSeaMarkupLanguage]("https://github.com/OceanApocalypseStudios/RedSeaMar **Requirements:** - [ ] RSML.CLI (the executable) and RSML (dll) for the correct system and architecture - **OR** -- [ ] A way to compile these (requires dotnet) +- [ ] A way to compile these programatically (requires dotnet) **Installation (via pip):** diff --git a/pyproject.toml b/pyproject.toml index e54c92c..d0252aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "rsml_python" -version = "1.0.2" +version = "1.0.5" authors = [ { name="MF366", email="real_mf366@yahoo.com" }, ] diff --git a/src/rsml_python/__init__.py b/src/rsml_python/__init__.py index b1c9147..f3c705e 100644 --- a/src/rsml_python/__init__.py +++ b/src/rsml_python/__init__.py @@ -6,6 +6,7 @@ """ import subprocess +from os import linesep class RedSeaDocument: @@ -71,6 +72,15 @@ def write_document_to_file(self, filepath: str, encoding: str = 'utf-8'): with open(filepath, "w", encoding=encoding) as f: f.write(self._rsml) + + def write_document_to_new_list(self): + """ + write_document_to_new_list + ====================== + Writes the loaded document to a list. + """ + + return self._rsml.split(linesep) class RedSeaCLIExecutable: @@ -133,7 +143,8 @@ def evaluate_document_as_mfroad(self) -> str: def evaluate_document(self, custom_rid: str | None = None, primary_only: bool = False, - fallbacks: tuple[str | None, str] = (None, "[WARNING] No match was found.")) -> str: + fallbacks: tuple[str | None, str] = (None, "[WARNING] No match was found."), + expand_any: bool = False) -> str: """ evaluate_document =================== @@ -142,6 +153,7 @@ def evaluate_document(self, :param str | None custom_rid: custom RID to check against, defaults to system RID :param bool primary_only: whether to only output primary operator results and errors (true) or to output everything (false), defaults to False :param tuple[str | None, str] fallbacks: the error/null message fallbacks, defaults to RSML.CLI's messages + :param bool expand_any: whether to expand `any` into `.+` or not (defaults to no expansion) :raises ValueError: executable not loaded :return str: output """ @@ -151,6 +163,9 @@ def evaluate_document(self, argument_list: list[str] = [self._path_to_executable, "evaluate", "--no-pretty"] + if expand_any: + argument_list.append('--expand-any') + if fallbacks[0]: argument_list.append("--antierror-fallback") argument_list.append(fallbacks[0]) @@ -248,7 +263,19 @@ def repository(self) -> str: :return str: https://github.com/OceanApocalypseStudios/RedSeaMarkupLanguage """ - return "https://github.com/OceanApocalypseStudios/RedSeaMarkupLanguage" + if self._path_to_executable is None: + raise ValueError("Executable is null.") + + argument_list: list[str] = [self._path_to_executable, "repo", "--no-pretty"] + + process = subprocess.run( + argument_list, + text=True, + capture_output=True + ) + + process.check_returncode() + return process.stdout.split('\n')[0][25:] # yes magic number here cry about it if __name__ == '__main__': @@ -257,9 +284,10 @@ def repository(self) -> str: EXE_PATH = r"YOUR PATH GOES HERE" executable = RedSeaCLIExecutable(EXE_PATH) document = RedSeaDocument() - document.load_from_string('win.+ || "good stuff"\nlinux.+ -> "Hey, Tux"\nwin.+ -> "Hey, corporate greed"\nosx.+ ^! "Error"\n') + document.load_from_string('any -> "Expansions are nice"\nwin.+ || "good stuff"\nlinux.+ -> "Hey, Tux"\nwin.+ -> "Hey, corporate greed"\nosx.+ ^! "Error"\n') executable.load_document(document) + out0 = executable.repository # https:/......MarkupLanguage out1 = executable.evaluate_document() # good stuff .. Hey, corporate greed out2 = executable.evaluate_document("linux-x64") # Hey, Tux out3 = executable.evaluate_document(None, True) # Hey, corporate greed @@ -267,13 +295,17 @@ def repository(self) -> str: out5 = executable.evaluate_document("stuff", False, (None, "No match damn")) # No match damn out6 = executable.evaluate_document("stuff", True) # default warning message out7 = executable.evaluate_document("linux-x86", True) # Hey, Tux - out8 = executable.get_runtime_id() # win-x64 - out9 = executable.version # v1.0.2 + out8 = executable.get_runtime_id() + out9 = executable.version + out10 = executable.evaluate_document(expand_any=True) # Expansions are nice while True: a = input("Test case: ") match int(a): + case 0: + print(out0, end='\n\n') + case 1: print(out1, end='\n\n') @@ -300,6 +332,9 @@ def repository(self) -> str: case 9: print(out9, end='\n\n') + + case 10: + print(out10, end='\n\n') case _: print("Error.", end='\n\n')