From 2f8017d9fb3161865fd7372d650c1669baa0ecf1 Mon Sep 17 00:00:00 2001 From: "Md. Almas Ali" Date: Sun, 26 May 2024 18:13:13 +0600 Subject: [PATCH 1/9] fix: added cli help messages. --- radon.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/radon.py b/radon.py index 1bc92a6..0682844 100755 --- a/radon.py +++ b/radon.py @@ -62,7 +62,25 @@ def shell() -> None: def usage(program_name: str, stream: IO[str]) -> None: print( f"Usage: {program_name} [--source | -s] [--command | -c] [source_file] [--version | -v] [--help | -h]", - file=stream, + file=stream) + print( + ''' +Options and arguments: + --source | -s Run a source file + --command | -c Run a command + --version | -v Print the version + --help | -h Print this help message + + If no arguments are provided, the program will run in shell mode. + +Example: + radon --source source_file.rn + radon --command 'print("Hello, World!")' + radon --version + radon --help + +The Radon Programming Language. + ''' ) From 52775ff6bedb89308d7539f86fbed2e9e1fb13db Mon Sep 17 00:00:00 2001 From: "Md. Almas Ali" Date: Sun, 26 May 2024 19:24:46 +0600 Subject: [PATCH 2/9] feat: added builtin radiation errors. --- core/tokens.py | 1 + stdlib/radiation.rn | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 stdlib/radiation.rn diff --git a/core/tokens.py b/core/tokens.py index 89287cc..a941e7c 100755 --- a/core/tokens.py +++ b/core/tokens.py @@ -16,6 +16,7 @@ "array", "colorlib", "math", + "radiation", "system", "string", "universe", # ester egg diff --git a/stdlib/radiation.rn b/stdlib/radiation.rn new file mode 100644 index 0000000..e0b7611 --- /dev/null +++ b/stdlib/radiation.rn @@ -0,0 +1,17 @@ +fun ValueError(message = null) -> message +fun TypeError(message = null) -> message +fun IOError(message = null) -> message +fun MemoryError(message = null) -> message +fun KeyError(message = null) -> message +fun IndexError(message = null) -> message +fun NotImplementedError(message = null) -> message +fun AssertionError(message = null) -> message +fun SyntaxError(message = null) -> message +fun KeyboardInterrupt(message = null) -> message +fun StopIteration(message = null) -> message +fun DeprecationWarning(message = null) -> message +fun ReferenceError(message = null) -> message +fun BufferError(message = null) -> message +fun ArithmeticError(message = null) -> message +fun LogicalError(message = null) -> message +fun RuntimeError(message = null) -> message \ No newline at end of file From 83ebbee680891858d794670627175b0e4a2438a2 Mon Sep 17 00:00:00 2001 From: "Md. Almas Ali" Date: Sun, 26 May 2024 19:33:44 +0600 Subject: [PATCH 3/9] refactor: attempt to fix proper radiation underline and coloring. --- core/errors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/errors.py b/core/errors.py index 509e27c..0dbdc85 100755 --- a/core/errors.py +++ b/core/errors.py @@ -31,7 +31,7 @@ def string_with_arrows(text: str, pos_start: Position, pos_end: Position) -> str col_start = pos_start.col if i == 0 else 0 col_end = pos_end.col if i == line_count - 1 else len(line) - 1 - col_start_color = col_start + 1 + col_start_color = col_start #+ 1 col_end_color = col_end + 1 # Append to result From 718549751d64498f6fea8b0906ee66bbe1888bee Mon Sep 17 00:00:00 2001 From: "Md. Almas Ali" Date: Sun, 26 May 2024 19:34:39 +0600 Subject: [PATCH 4/9] feat: added example of radiation module and raise. --- examples/radiation-raise.rn | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 examples/radiation-raise.rn diff --git a/examples/radiation-raise.rn b/examples/radiation-raise.rn new file mode 100644 index 0000000..793980f --- /dev/null +++ b/examples/radiation-raise.rn @@ -0,0 +1,7 @@ +import radiation + +if 2 != 3 { + raise radiation.ValueError("2 != 3") +} + +print(sdf) \ No newline at end of file From 29fa330934ab4e7c7976851b17607bd0aecbc067 Mon Sep 17 00:00:00 2001 From: "Md. Almas Ali" Date: Sun, 26 May 2024 19:45:23 +0600 Subject: [PATCH 5/9] fix: radiation issue, no set_context() method in Error() class. --- core/errors.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/errors.py b/core/errors.py index 0dbdc85..9fa02f9 100755 --- a/core/errors.py +++ b/core/errors.py @@ -70,6 +70,10 @@ def set_pos(self, pos_start=None, pos_end=None): """Says it's gonna set the position, but actually does NOTHING""" return self + def set_context(self, context=None): + """Says it's gonna set the context, but actually does NOTHING""" + return self + def __repr__(self) -> str: if self.details is not None: return f"{self.error_name}: {self.details}" From c671cbc2d458e8d11cb347e9e55f1cbaecdcee9f Mon Sep 17 00:00:00 2001 From: "Md. Almas Ali" Date: Sun, 26 May 2024 19:46:01 +0600 Subject: [PATCH 6/9] feat: added all errors list for easy access. --- stdlib/radiation.rn | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/stdlib/radiation.rn b/stdlib/radiation.rn index e0b7611..53d0b08 100644 --- a/stdlib/radiation.rn +++ b/stdlib/radiation.rn @@ -1,3 +1,5 @@ +# All radiation built-in errors are defined here. + fun ValueError(message = null) -> message fun TypeError(message = null) -> message fun IOError(message = null) -> message @@ -14,4 +16,25 @@ fun ReferenceError(message = null) -> message fun BufferError(message = null) -> message fun ArithmeticError(message = null) -> message fun LogicalError(message = null) -> message -fun RuntimeError(message = null) -> message \ No newline at end of file +fun RuntimeError(message = null) -> message + +# List of all errors +errors = [ + ValueError, + TypeError, + IOError, + MemoryError, + KeyError, + IndexError, + NotImplementedError, + AssertionError, + SyntaxError, + KeyboardInterrupt, + StopIteration, + DeprecationWarning, + ReferenceError, + BufferError, + ArithmeticError, + LogicalError, + RuntimeError +] From 3f96fb929b1dd45c4da317372c51da83b20b08be Mon Sep 17 00:00:00 2001 From: "Md. Almas Ali" Date: Sun, 26 May 2024 19:54:35 +0600 Subject: [PATCH 7/9] fix: added python version no. --- test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test.py b/test.py index ca75bf6..953dc57 100755 --- a/test.py +++ b/test.py @@ -1,4 +1,5 @@ -#!/usr/bin/env python3 +#!/usr/bin/python3.12 + import sys import os import subprocess From 5e73815a90614155818d5095a7105b34887b10c5 Mon Sep 17 00:00:00 2001 From: "Md. Almas Ali" Date: Sun, 26 May 2024 19:58:54 +0600 Subject: [PATCH 8/9] tests: updated tests for raise and radiation features. --- tests/radiation-modules.rn | 16 ++++++++++++++++ tests/radiation-modules.rn.json | 1 + tests/raise.rn.json | 2 +- tests/raise2.rn.json | 2 +- tests/raise3.rn.json | 2 +- 5 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 tests/radiation-modules.rn create mode 100644 tests/radiation-modules.rn.json diff --git a/tests/radiation-modules.rn b/tests/radiation-modules.rn new file mode 100644 index 0000000..e895a8e --- /dev/null +++ b/tests/radiation-modules.rn @@ -0,0 +1,16 @@ +import radiation + +errors = radiation.errors + +# print(radiation.errors[0]) + +# print(errors[0]("ValueError: " + "This is a test error message")) + +assert arr_len(errors) == 17, "Error length is not 17" + +try { + raise errors[1]("This is error message!") +} +catch as err { + print(err) +} \ No newline at end of file diff --git a/tests/radiation-modules.rn.json b/tests/radiation-modules.rn.json new file mode 100644 index 0000000..4d6393a --- /dev/null +++ b/tests/radiation-modules.rn.json @@ -0,0 +1 @@ +{"code": 0, "stdout": "TypeError: This is error message!\n", "stderr": ""} \ No newline at end of file diff --git a/tests/raise.rn.json b/tests/raise.rn.json index 0cab28b..d0217b7 100644 --- a/tests/raise.rn.json +++ b/tests/raise.rn.json @@ -1 +1 @@ -{"code": 1, "stdout": "test1\ntest2\n\u001b[38;5;208mRadiation (most recent call last):\n\u001b[0m File \u001b[38;5;117mtests/raise.rn\u001b[0m, line \u001b[38;5;117m7\u001b[0m\n\u001b[1m\u001b[31mArgError\u001b[0m: \u001b[38;5;203mArgument `arg1` not found\u001b[0m\n\nraise \u001b[1m\u001b[31mArgError(\"arg1\"\u001b[0m)\n \u001b[1m\u001b[31m^^^^^^^^^^^^^^^\u001b[0m\n", "stderr": ""} \ No newline at end of file +{"code": 1, "stdout": "test1\ntest2\n\u001b[38;5;208mRadiation (most recent call last):\n\u001b[0m File \u001b[38;5;117mtests/raise.rn\u001b[0m, line \u001b[38;5;117m7\u001b[0m\n\u001b[1m\u001b[31mArgError\u001b[0m: \u001b[38;5;203mArgument `arg1` not found\u001b[0m\n\nraise\u001b[1m\u001b[31m ArgError(\"arg1\"\u001b[0m)\n \u001b[1m\u001b[31m^^^^^^^^^^^^^^^\u001b[0m\n", "stderr": ""} \ No newline at end of file diff --git a/tests/raise2.rn.json b/tests/raise2.rn.json index 4378096..6db5976 100644 --- a/tests/raise2.rn.json +++ b/tests/raise2.rn.json @@ -1 +1 @@ -{"code": 1, "stdout": "\u001b[38;5;208mRadiation (most recent call last):\n\u001b[0m File \u001b[38;5;117mtests/raise2.rn\u001b[0m, line \u001b[38;5;117m4\u001b[0m\n\u001b[1m\u001b[31mSomeError\u001b[0m: \u001b[38;5;203mThe massage: AAAAAAAAAAAAAAAAA\u001b[0m\n\nraise \u001b[1m\u001b[31mraise2_lib.SomeError(\"AAAAAAAAAAAAAAAAA\"\u001b[0m)\n \u001b[1m\u001b[31m^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m\n", "stderr": ""} \ No newline at end of file +{"code": 1, "stdout": "\u001b[38;5;208mRadiation (most recent call last):\n\u001b[0m File \u001b[38;5;117mtests/raise2.rn\u001b[0m, line \u001b[38;5;117m4\u001b[0m\n\u001b[1m\u001b[31mSomeError\u001b[0m: \u001b[38;5;203mThe massage: AAAAAAAAAAAAAAAAA\u001b[0m\n\nraise\u001b[1m\u001b[31m raise2_lib.SomeError(\"AAAAAAAAAAAAAAAAA\"\u001b[0m)\n \u001b[1m\u001b[31m^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m\n", "stderr": ""} \ No newline at end of file diff --git a/tests/raise3.rn.json b/tests/raise3.rn.json index 1106449..a6828a7 100644 --- a/tests/raise3.rn.json +++ b/tests/raise3.rn.json @@ -1 +1 @@ -{"code": 1, "stdout": "\u001b[38;5;208mRadiation (most recent call last):\n\u001b[0m File \u001b[38;5;117mtests/raise3.rn\u001b[0m, line \u001b[38;5;117m4\u001b[0m\n\u001b[1m\u001b[31mSomeError\u001b[0m: \u001b[38;5;203mThe massage: default massage\u001b[0m\n\nraise \u001b[1m\u001b[31mraise2_lib.SomeError\u001b[0m\n \u001b[1m\u001b[31m^^^^^^^^^^^^^^^^^^^^\u001b[0m\n", "stderr": ""} \ No newline at end of file +{"code": 1, "stdout": "\u001b[38;5;208mRadiation (most recent call last):\n\u001b[0m File \u001b[38;5;117mtests/raise3.rn\u001b[0m, line \u001b[38;5;117m4\u001b[0m\n\u001b[1m\u001b[31mSomeError\u001b[0m: \u001b[38;5;203mThe massage: default massage\u001b[0m\n\nraise\u001b[1m\u001b[31m raise2_lib.SomeError\u001b[0m\n \u001b[1m\u001b[31m^^^^^^^^^^^^^^^^^^^^\u001b[0m\n", "stderr": ""} \ No newline at end of file From 62ee361c11743c2a1f5bf3222a3c12975b2e887b Mon Sep 17 00:00:00 2001 From: "Md. Almas Ali" Date: Sun, 26 May 2024 20:01:47 +0600 Subject: [PATCH 9/9] fix: ruff formatted. --- core/errors.py | 2 +- radon.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/errors.py b/core/errors.py index 9fa02f9..c6798d9 100755 --- a/core/errors.py +++ b/core/errors.py @@ -31,7 +31,7 @@ def string_with_arrows(text: str, pos_start: Position, pos_end: Position) -> str col_start = pos_start.col if i == 0 else 0 col_end = pos_end.col if i == line_count - 1 else len(line) - 1 - col_start_color = col_start #+ 1 + col_start_color = col_start # + 1 col_end_color = col_end + 1 # Append to result diff --git a/radon.py b/radon.py index 0682844..49931dd 100755 --- a/radon.py +++ b/radon.py @@ -62,9 +62,10 @@ def shell() -> None: def usage(program_name: str, stream: IO[str]) -> None: print( f"Usage: {program_name} [--source | -s] [--command | -c] [source_file] [--version | -v] [--help | -h]", - file=stream) + file=stream, + ) print( - ''' + """ Options and arguments: --source | -s Run a source file --command | -c Run a command @@ -80,7 +81,7 @@ def usage(program_name: str, stream: IO[str]) -> None: radon --help The Radon Programming Language. - ''' + """ )