Skip to content

Commit

Permalink
peg: throw compilation error instead of exiting
Browse files Browse the repository at this point in the history
  • Loading branch information
otakubeam committed Feb 8, 2024
1 parent 14ae881 commit 3e962cc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
3 changes: 1 addition & 2 deletions modules/dasPEG/peg/detail/helpers.das
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 14 additions & 9 deletions modules/dasPEG/peg/parse_macro.das
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/dasPEG/peg/parser_generator.das
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3e962cc

Please sign in to comment.