From 3e962cc4d5c261d95c359276146c376e04770d84 Mon Sep 17 00:00:00 2001 From: andrei_orazov Date: Thu, 8 Feb 2024 13:05:22 +0300 Subject: [PATCH] peg: throw compilation error instead of exiting --- modules/dasPEG/peg/detail/helpers.das | 3 +-- modules/dasPEG/peg/parse_macro.das | 23 ++++++++++++++--------- modules/dasPEG/peg/parser_generator.das | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/dasPEG/peg/detail/helpers.das b/modules/dasPEG/peg/detail/helpers.das index a6341a564..277e8e69d 100644 --- a/modules/dasPEG/peg/detail/helpers.das +++ b/modules/dasPEG/peg/detail/helpers.das @@ -9,9 +9,8 @@ module helpers shared require daslib/fio def abort(message: string) - print("{message}\n") false |> stackwalk <| false // God I love the pipe syntax so much - unsafe { exit(1); } + panic(message) def iota diff --git a/modules/dasPEG/peg/parse_macro.das b/modules/dasPEG/peg/parse_macro.das index f8fe7faa8..d72e9f770 100644 --- a/modules/dasPEG/peg/parse_macro.das +++ b/modules/dasPEG/peg/parse_macro.das @@ -351,19 +351,24 @@ class ParseMacro : AstCallMacro var inscope gen <- [[ParserGenerator id = times_invoked++]] - for mrule in rules_ - gram |> emplace(mrule |> transform) + try + for mrule in rules_ + gram |> emplace(mrule |> transform) - if failed_to_transform - return <- [[ExpressionPtr]] + if failed_to_transform + return <- [[ExpressionPtr]] - // Generate + // Generate - for mrule in rules_ - for opt in mrule.options_ - gen |> accept_option(opt) // Set the state of the generator up + for mrule in rules_ + for opt in mrule.options_ + gen |> accept_option(opt) // Set the state of the generator up - gen |> generate_grammar(gram, name) + gen |> generate_grammar(gram, name) + + recover + if failed_to_transform + return <- [[ExpressionPtr]] // Emit wrapper code var first_method_name = gram[0].name diff --git a/modules/dasPEG/peg/parser_generator.das b/modules/dasPEG/peg/parser_generator.das index d10123518..e83bcfc10 100644 --- a/modules/dasPEG/peg/parser_generator.das +++ b/modules/dasPEG/peg/parser_generator.das @@ -991,7 +991,7 @@ def generate_terminal(var gen: ParserGenerator; var terminal: Terminal): Express if $v(gen.tracing) let ch = parser |> get_current_char if ch != -1 && (ch < 0 || ch >= 256) - builtin_throw("failed character set check {ch}") + panic("failed character set check {ch}") parser |> log_fail <| "Failed the range check for character {parser.index}" if parser.error_reporting && !parser.suppress_errors |> back && parser.index == parser.longest_prefix