Skip to content

Commit

Permalink
feat(parser, tests): improving diagnostics for incomplete conditions …
Browse files Browse the repository at this point in the history
…and loops
  • Loading branch information
SuperFola committed Oct 27, 2024
1 parent 0707ff5 commit 8e1fefa
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/arkreactor/Compiler/AST/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ namespace Ark::internal
if (auto condition = nodeOrValue(); condition.has_value())
leaf->push_back(condition.value().attachNearestCommentBefore(comment));
else
errorWithNextToken("If need a valid condition");
errorWithNextToken("`if' needs a valid condition");

comment.clear();
newlineOrComment(&comment);

if (auto value_if_true = nodeOrValue(); value_if_true.has_value())
leaf->push_back(value_if_true.value().attachNearestCommentBefore(comment));
else
errorWithNextToken("Expected a value");
errorWithNextToken("Expected a node or value after condition");

comment.clear();
newlineOrComment(&comment);
Expand Down Expand Up @@ -252,15 +252,15 @@ namespace Ark::internal
if (auto condition = nodeOrValue(); condition.has_value())
leaf->push_back(condition.value().attachNearestCommentBefore(comment));
else
errorWithNextToken("While need a valid condition");
errorWithNextToken("`while' needs a valid condition");

comment.clear();
newlineOrComment(&comment);

if (auto body = nodeOrValue(); body.has_value())
leaf->push_back(body.value().attachNearestCommentBefore(comment));
else
errorWithNextToken("Expected a value");
errorWithNextToken("Expected a node or value after loop condition");

setNodePosAndFilename(leaf->list().back());
return leaf;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(while 1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
At ) @ 1:9
1 | (while 1)
| ^
2 |
Expected a node or value after loop condition
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(if)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
At ) @ 1:4
1 | (if)
| ^
2 |
`if' needs a valid condition
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(while)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
At ) @ 1:7
1 | (while)
| ^
2 |
`while' needs a valid condition
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(if 1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
At ) @ 1:6
1 | (if 1)
| ^
2 |
Expected a node or value after condition

0 comments on commit 8e1fefa

Please sign in to comment.