From bf7a0b54ad2b2548d16ba2574d8ed78c5e26ceaf Mon Sep 17 00:00:00 2001 From: Calloc <140273795+CallocGD@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:12:23 -0600 Subject: [PATCH 1/8] Add A Safety Variable for no-exit version of parsing broma files --- include/ast.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/ast.hpp b/include/ast.hpp index fcddf12..4ae74c1 100644 --- a/include/ast.hpp +++ b/include/ast.hpp @@ -218,4 +218,20 @@ namespace broma { return &*it; } }; + + /// @brief Used as a safety mechanism for parsing + // broma files in other languages such as Rust and + // Python or upon use with servers or when in use + // with discord bots so that the code doesn't need + // to exit upon having an error thrown. + typedef struct SafeRootResult { + /// @brief Root result if code has been parsed successfully. + Root root; + /// @brief A list of errors grabbed if any exist. + std::vectorerros; + /// @brief a fag for check if parsing threw an error to begin with. + bool has_errors; + } SafeRootResult; + + } // namespace broma From 257ec9e6fc6ea757c62d8071f2afc4026c20956e Mon Sep 17 00:00:00 2001 From: Calloc <140273795+CallocGD@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:13:54 -0600 Subject: [PATCH 2/8] Update broma.hpp --- include/broma.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/broma.hpp b/include/broma.hpp index 510efa7..8c88221 100644 --- a/include/broma.hpp +++ b/include/broma.hpp @@ -9,4 +9,10 @@ namespace broma { /// /// @param fname The path of the file you want to parse, as a string. Root parse_file(std::string const& fname); + + /// @brief Parses a broma file safely by not exiting when the parser throws an error + /// @param fname The path of the file you want to parse, as a string. + /// @return A root result with a boolean value to check for errors. + SafeRootResult parse_file_safely(std::string const& fname); + } From 995dfbce0d46da16904ee4a5c3cbd0f88a18e5db Mon Sep 17 00:00:00 2001 From: Calloc <140273795+CallocGD@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:15:02 -0600 Subject: [PATCH 3/8] Update broma.cpp --- src/broma.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/broma.cpp b/src/broma.cpp index 9202da8..049da6a 100644 --- a/src/broma.cpp +++ b/src/broma.cpp @@ -36,4 +36,26 @@ namespace broma { return root; } + + SafeRootResult parse_file_safely(std::string const& fname){ + file_input<> input(fname); + + SafeRootResult srr; + + srr.has_errors = false; + + ScratchData scratch; + parse, run_action>(input, &srr.root, &scratch); + post_process(srr.root); + + + if (scratch.errors.size()){ + srr.has_errors = true; + + for (auto& e : scratch.errors) { + srr.erros.emplace_back(e.what()); + } + } + return srr; + } } // namespace broma From f39a5a59a48a2b465babd81cfafc3165a20a0cae Mon Sep 17 00:00:00 2001 From: Calloc <140273795+CallocGD@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:16:11 -0600 Subject: [PATCH 4/8] Fix Tab intending and grammer in parse_file_safely --- include/broma.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/broma.hpp b/include/broma.hpp index 8c88221..fe049d9 100644 --- a/include/broma.hpp +++ b/include/broma.hpp @@ -11,7 +11,7 @@ namespace broma { Root parse_file(std::string const& fname); /// @brief Parses a broma file safely by not exiting when the parser throws an error - /// @param fname The path of the file you want to parse, as a string. + /// @param fname The path of the file you want to parse as a string. /// @return A root result with a boolean value to check for errors. SafeRootResult parse_file_safely(std::string const& fname); From c057945a7bfb4dca37317977928b15666487d6e1 Mon Sep 17 00:00:00 2001 From: Calloc <140273795+CallocGD@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:31:15 -0600 Subject: [PATCH 5/8] Update broma.cpp --- src/broma.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/broma.cpp b/src/broma.cpp index 049da6a..54e548b 100644 --- a/src/broma.cpp +++ b/src/broma.cpp @@ -40,22 +40,24 @@ namespace broma { SafeRootResult parse_file_safely(std::string const& fname){ file_input<> input(fname); - SafeRootResult srr; - - srr.has_errors = false; + SafeRootResult result; + Root root; ScratchData scratch; - parse, run_action>(input, &srr.root, &scratch); - post_process(srr.root); - + parse, run_action>(input, &root, &scratch); + post_process(root); - if (scratch.errors.size()){ - srr.has_errors = true; - - for (auto& e : scratch.errors) { - srr.erros.emplace_back(e.what()); + if (scratch.errors.size()) { + std::vectorerr_data; + for (auto&e : scratch.errors){ + err_data.emplace_back(e.what()); } + result.result = reinterpret_cast(&err_data); + result.is_error = true; + } else { + result.result = reinterpret_cast(&root); + result.is_error = false; } - return srr; + return result; } } // namespace broma From da37534dbb211f30cd7c612ba6afbca7703911bb Mon Sep 17 00:00:00 2001 From: Calloc <140273795+CallocGD@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:31:53 -0600 Subject: [PATCH 6/8] Update broma.hpp --- include/broma.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/broma.hpp b/include/broma.hpp index fe049d9..d4d6ce0 100644 --- a/include/broma.hpp +++ b/include/broma.hpp @@ -11,7 +11,7 @@ namespace broma { Root parse_file(std::string const& fname); /// @brief Parses a broma file safely by not exiting when the parser throws an error - /// @param fname The path of the file you want to parse as a string. + /// @param fname The filename or path of the file you want to parse as a string. /// @return A root result with a boolean value to check for errors. SafeRootResult parse_file_safely(std::string const& fname); From 50867b87eba87ff0e0bf5765e6288c2b947a6931 Mon Sep 17 00:00:00 2001 From: Calloc <140273795+CallocGD@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:32:47 -0600 Subject: [PATCH 7/8] Update ast.hpp --- include/ast.hpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/include/ast.hpp b/include/ast.hpp index 4ae74c1..f53740d 100644 --- a/include/ast.hpp +++ b/include/ast.hpp @@ -220,17 +220,10 @@ namespace broma { }; /// @brief Used as a safety mechanism for parsing - // broma files in other languages such as Rust and - // Python or upon use with servers or when in use - // with discord bots so that the code doesn't need - // to exit upon having an error thrown. + // in other languages or on multiple threads. typedef struct SafeRootResult { - /// @brief Root result if code has been parsed successfully. - Root root; - /// @brief A list of errors grabbed if any exist. - std::vectorerros; - /// @brief a fag for check if parsing threw an error to begin with. - bool has_errors; + void* result; + bool is_error; } SafeRootResult; From fd49a5a48cb2a79a0adb02ab7adf083d02f7804f Mon Sep 17 00:00:00 2001 From: Calloc <140273795+CallocGD@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:33:27 -0600 Subject: [PATCH 8/8] Update ast.hpp --- include/ast.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ast.hpp b/include/ast.hpp index f53740d..0695027 100644 --- a/include/ast.hpp +++ b/include/ast.hpp @@ -220,7 +220,7 @@ namespace broma { }; /// @brief Used as a safety mechanism for parsing - // in other languages or on multiple threads. + // in other languages or on multiple threads. typedef struct SafeRootResult { void* result; bool is_error;