From 8ca7749b5509a40256195563fa52d3ede4bd1a34 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 16 Jan 2019 16:31:49 -0800 Subject: Better error messaging (using pretty_error in more places) --- lib/core/control_flow.nom | 64 +++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 25 deletions(-) (limited to 'lib/core/control_flow.nom') diff --git a/lib/core/control_flow.nom b/lib/core/control_flow.nom index 715630b..c4c1770 100644 --- a/lib/core/control_flow.nom +++ b/lib/core/control_flow.nom @@ -328,29 +328,34 @@ test: $clause = "if" $else_allowed = (yes) unless ($body.type is "Block"): - compile error at $body "'if' expected a Block, but got a \($body.type)." - "Perhaps you forgot to put a ':' after 'if'?" + at $body fail (" + Compile error: 'if' expected a Block, but got a \($body.type). + Hint: Perhaps you forgot to put a ':' after 'if'? + ") for $line in $body: unless (($line.type is "Action") and ((size of $line) >= 2)) and $line.(size of $line) is "Block" syntax tree ..: - compile error at $line "Invalid line for the body of an 'if' block." (" - Each line should contain one or more conditional expressions followed by a block, or "else"\ - .. followed by a block. + at $line fail (" + Compile error: Invalid line for the body of an 'if' block. + Hint: Each line should contain one or more conditional expressions followed \ + ..by a block, or "else" followed by a block. ") $action = $line.(size of $line) if (($line.1 is "else") and ((size of $line) == 2)): unless $else_allowed: - compile error at $line "You can't have two 'else' blocks." - "Merge all of the 'else' blocks together." + at $line fail (" + Compile error: You can't have two 'else' blocks. + Hint: Merge all of the 'else' blocks together. + ") unless ((size of "\$code") > 0): - compile error at $line - .."You can't have an 'else' block without a preceding condition" (" - If you want the code in this block to always execute, you don't need a conditional block \ - ..around it. Otherwise, make sure the 'else' block comes last. + at $line fail (" + Compile error: You can't have an 'else' block without a preceding condition. + Hint: If you want the code in this block to always execute, you don't need a \ + ..conditional block around it. Otherwise, make sure the 'else' block comes last. ") $code, add "\nelse\n " ($action as lua) @@ -365,8 +370,10 @@ test: $clause = "\nelseif" if ((size of "\$code") == 0): - compile error at $body "'if' block has an empty body." - "This means nothing would happen, so the 'if' block should be deleted." + at $body fail (" + Compile error: 'if' block has an empty body. + Hint: This means nothing would happen, so the 'if' block should be deleted. + ") $code, add "\nend --when" return $code @@ -392,28 +399,33 @@ test: $else_allowed = (yes) define mangler unless ($body.type is "Block"): - compile error at $body "'if' expected a Block, but got a \($body.type)" - "Perhaps you forgot to put a ':' after the 'is'?" + at $body fail (" + Compile error: 'if' expected a Block, but got a \($body.type). + Hint: Perhaps you forgot to put a ':' after the 'is'? + ") for $line in $body: unless (($line.type is "Action") and ((size of $line) >= 2)) and $line.(size of $line) is "Block" syntax tree ..: - compile error at $line "Invalid line for 'if' block." (" - Each line should contain expressions followed by a block, or "else" followed by a block + at $line fail (" + Compile error: Invalid line for 'if' block. + Hint: Each line should contain expressions followed by a block, or "else" followed by a block. ") $action = $line.(size of $line) if (($line.1 is "else") and ((size of $line) == 2)): unless $else_allowed: - compile error at $line "You can't have two 'else' blocks." - "Merge all of the 'else' blocks together." + at $line fail (" + Compile error: You can't have two 'else' blocks. + Hint: Merge all of the 'else' blocks together. + ") unless ((size of "\$code") > 0): - compile error at $line - .."You can't have an 'else' block without a preceding condition" (" - If you want the code in this block to always execute, you don't need a conditional block \ - ..around it. Otherwise, make sure the 'else' block comes last. + at $line fail (" + Compile error: You can't have an 'else' block without a preceding condition. + Hint: If you want the code in this block to always execute, you don't need \ + ..a conditional block around it. Otherwise, make sure the 'else' block comes last. ") $code, add "\nelse\n " ($action as lua) @@ -428,8 +440,10 @@ test: $clause = "\nelseif" if ((size of "\$code") == 0): - compile error at $body "'if' block has an empty body." - "This means nothing would happen, so the 'if' block should be deleted." + at $body fail (" + Compile error: 'if' block has an empty body. + Hint: This means nothing would happen, so the 'if' block should be deleted. + ") $code, add "\nend --when" return -- cgit v1.2.3