From b0cf1fc7535766612cacc38ea87f0000c54c50e8 Mon Sep 17 00:00:00 2001 From: "Md. Almas Ali" Date: Sat, 1 Jun 2024 17:13:49 +0600 Subject: [PATCH 1/4] fix: updated examples --- examples/files.rn | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/files.rn b/examples/files.rn index 14b7eca..3680c05 100644 --- a/examples/files.rn +++ b/examples/files.rn @@ -2,6 +2,14 @@ f = File("examples/files.rn") contents = f.read() f.close() +f.is_closed() print(contents) +print("-------------") + +f = File("examples/files.rn") +print(f.readline()) +print(f.readlines()) + +f.close() From a003799cbe5c2f1ddb5fb420ec764fa07c0bc394 Mon Sep 17 00:00:00 2001 From: "Md. Almas Ali" Date: Sat, 1 Jun 2024 17:14:26 +0600 Subject: [PATCH 2/4] fix: Error class has not context option. --- core/errors.py | 1 + 1 file changed, 1 insertion(+) diff --git a/core/errors.py b/core/errors.py index 8ccf4f9..9fc0949 100755 --- a/core/errors.py +++ b/core/errors.py @@ -55,6 +55,7 @@ class Error: pos_end: Position error_name: str details: Optional[str] + context: Optional[Context] = None def as_string(self) -> str: """Return error as string""" From a85483ae1f23a4f3738d37d68369021d81c3c091 Mon Sep 17 00:00:00 2001 From: "Md. Almas Ali" Date: Sat, 1 Jun 2024 17:15:09 +0600 Subject: [PATCH 3/4] feat: added new standard library io. --- core/tokens.py | 1 + stdlib/io.rn | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 stdlib/io.rn diff --git a/core/tokens.py b/core/tokens.py index 5d89863..a471d8b 100755 --- a/core/tokens.py +++ b/core/tokens.py @@ -15,6 +15,7 @@ "argparser", "array", "colorlib", + "io", "math", "radiation", "system", diff --git a/stdlib/io.rn b/stdlib/io.rn new file mode 100644 index 0000000..9e4bee8 --- /dev/null +++ b/stdlib/io.rn @@ -0,0 +1,53 @@ +import radiation + + +class Input { + static fun get_int(text="") { + const _val = input(text) + try { + return int(_val) + } catch as err { + raise radiation.ValueError("Invalid input") + } + } + + static fun get_float(text="") { + const _val = input(text) + try { + return float(_val) + } catch as err { + raise radiation.ValueError("Invalid input") + } + } + + static fun get_string(text="") { + return input(text) + } + + static fun get_bool(text="") { + const _val = String(input(text)) + if _val.casefold() == "true" { + return true + } elif _val.casefold() == "false" { + return false + } else { + raise radiation.ValueError("Invalid input") + } + } + + static fun get_password(text="") { + var ns = {"text": text} + pyapi("import getpass; val = getpass.getpass(text)", ns) + return ns["val"] + } +} + +class Output { + static fun write(...values, sep=" ", end="\n") { + var output = "" + for value in values { + output += str(value) + sep + } + print(output + end) + } +} \ No newline at end of file From ee8db7b69bb8aeec29ed133bd71033601600f414 Mon Sep 17 00:00:00 2001 From: "Md. Almas Ali" Date: Sat, 1 Jun 2024 17:15:44 +0600 Subject: [PATCH 4/4] feat: added io test examples. --- examples/io-test.rn | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 examples/io-test.rn diff --git a/examples/io-test.rn b/examples/io-test.rn new file mode 100644 index 0000000..a03e25a --- /dev/null +++ b/examples/io-test.rn @@ -0,0 +1,17 @@ +import io + +var int_num = io.Input.get_int("Enter an integer number: ") +print(int_num) + +var float_num = io.Input.get_float("Enter a float number: ") +print(float_num) + +var str_val = io.Input.get_string("Enter a string: ") +print(str_val) + +var password = io.Input.get_password("Enter a password: ") +print(password) + +# issue here +var val = input("Enter a value: ") +io.Output.write(val)