Skip to content

Commit 4c54cf4

Browse files
committed
feat(tests): adding parser tests to improve coverage
1 parent 2126629 commit 4c54cf4

21 files changed

+62
-23
lines changed

include/Ark/Compiler/AST/BaseParser.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ namespace Ark::internal
3030
std::string m_str;
3131
std::vector<std::pair<std::string::iterator, std::size_t>> m_it_to_row; ///< A crude map of \n position to line number to speed up line number computing
3232
std::string::iterator m_it, m_next_it;
33-
utf8_char_t m_sym; ///< The current utf8 character we're on
34-
FilePosition m_filepos; ///< The position of the cursor in the file
35-
FilePosition m_previous_filepos; ///< The previous position of the cursor in the file
33+
utf8_char_t m_sym; ///< The current utf8 character we're on
34+
FilePosition m_filepos; ///< The position of the cursor in the file
3635

3736
/**
3837
* @brief Register the position of a new line, with an iterator pointing to the new line and the row number
@@ -53,7 +52,6 @@ namespace Ark::internal
5352
void initParser(const std::string& filename, const std::string& code);
5453

5554
[[nodiscard]] FilePosition getCursor() const;
56-
[[nodiscard]] FilePosition getPreviousCursor() const;
5755

5856
[[nodiscard]] CodeErrorContext generateErrorContextAtCurrentPosition() const;
5957

src/arkreactor/Compiler/AST/BaseParser.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ namespace Ark::internal
5151
m_next_it = it;
5252
m_sym = sym;
5353

54-
m_previous_filepos = m_filepos;
55-
5654
if (*m_it == '\n')
5755
{
5856
++m_filepos.row;
@@ -109,21 +107,13 @@ namespace Ark::internal
109107
m_filepos.col = it_pos - nearest_newline_index;
110108
else
111109
m_filepos.col = it_pos + 1;
112-
// We can say that the previous position is the current one, as there isn't anything usable right now
113-
// Which means we will have to use accept()/next(), which will move filepos and previous_filepos correctly
114-
m_previous_filepos = m_filepos;
115110
}
116111

117112
FilePosition BaseParser::getCursor() const
118113
{
119114
return m_filepos;
120115
}
121116

122-
FilePosition BaseParser::getPreviousCursor() const
123-
{
124-
return m_previous_filepos;
125-
}
126-
127117
CodeErrorContext BaseParser::generateErrorContextAtCurrentPosition() const
128118
{
129119
const auto [row, col] = getCursor();

src/arkreactor/Compiler/AST/Parser.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ namespace Ark::internal
473473
has_captures = true;
474474
std::string capture;
475475
if (!name(&capture))
476-
break;
476+
error("No symbol provided to capture", pos);
477477

478478
args->push_back(positioned(Node(NodeType::Capture, capture), pos));
479479
}
@@ -647,12 +647,7 @@ namespace Ark::internal
647647

648648
comment = newlineOrComment();
649649
if (!comment.empty())
650-
{
651-
if (args->list().empty())
652-
args->attachCommentAfter(comment);
653-
else
654-
args->list().back().attachCommentAfter(comment);
655-
}
650+
args->attachCommentAfter(comment);
656651

657652
return positioned(args, filepos);
658653
}
@@ -858,7 +853,7 @@ namespace Ark::internal
858853
res += "u" + seq;
859854
}
860855
else
861-
error("Invalid escape sequence", pos);
856+
error("Invalid escape sequence, expected 4 hex digits: \\uabcd", pos);
862857
}
863858
else if (accept(IsChar('U')))
864859
{
@@ -880,7 +875,7 @@ namespace Ark::internal
880875
res += "U" + seq;
881876
}
882877
else
883-
error("Invalid escape sequence", pos);
878+
error("Invalid escape sequence, expected 8 hex digits: \\UABCDEF78", pos);
884879
}
885880
else
886881
{
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(let foo (fun (a b &) ()))
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1 | (let foo (fun (a b &) ()))
2+
| ^
3+
2 |
4+
No symbol provided to capture
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(macro bar (
2+
a
3+
b
4+
) # c
5+
())
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(macro bar (a b) # c
2+
())
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(print a.)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
In file tests/unittests/resources/ParserSuite/failure/incomplete_field.ark:1
2+
1 | (print a.)
3+
| ^
4+
2 |
5+
Expected a field name: <symbol>.<field>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(macro bar {
2+
(let foo (fun (a b))) })

0 commit comments

Comments
 (0)