Skip to content

Commit 4f99008

Browse files
committed
fixing list-tests.ark ; fixing FFI/List.cpp (std::distance couldn't get the type of the iterator used) ; fixing parser (detection of ill formed code based on the previous token)
1 parent 5710ca4 commit 4f99008

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/Parser/Parser.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,18 @@ namespace Ark
100100
// parse block
101101
if (token.token == "(")
102102
{
103+
bool previous_token_was_lparen = true;
104+
103105
// create a list node to host the block
104106
Node block(NodeType::List);
105107
block.setPos(token.line, token.col);
106108

107109
// handle sub-blocks
108110
if (tokens.front().token == "(")
111+
{
109112
block.push_back(parse(tokens));
113+
previous_token_was_lparen = false;
114+
}
110115

111116
// take next token, we don't want to play with a "("
112117
token = nextToken(tokens);
@@ -125,12 +130,13 @@ namespace Ark
125130

126131
if (std::find(m_warns.begin(), m_warns.end(), warn_info) == m_warns.end() &&
127132
(atomized.nodeType() == NodeType::String || atomized.nodeType() == NodeType::Number ||
128-
atomized.nodeType() == NodeType::List))
133+
atomized.nodeType() == NodeType::List) &&
134+
previous_token_was_lparen)
129135
{
130136
if ((m_options & FeatureDisallowInvalidTokenAfterParen) == 0)
131137
{
132138
m_warns.push_back(std::move(warn_info));
133-
Ark::logger.warn("Found a possible ill-formed code line: invalid token after `(' (token: {0}, at {1}:{2})"s, token.token, token.line, token.col);
139+
Ark::logger.warn("Found a possible ill-formed code line: invalid token after `(' (token: {0}, at {1}:{2}, in {3})"s, token.token, token.line, token.col, m_file);
134140
}
135141
else
136142
throwParseError("Ill-formed code line: invalid token after `('", token);

src/VM/FFI/List.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <Ark/VM/FFI.hpp>
22

3+
#include <iterator>
4+
35
#define FFI_Function(name) Value name(const std::vector<Value>& n)
46

57
namespace Ark::internal::FFI::List
@@ -66,7 +68,7 @@ namespace Ark::internal::FFI::List
6668
for (Value::Iterator it=l.begin(); it != l.end(); ++it)
6769
{
6870
if (*it == n[1])
69-
return Value(static_cast<int>(std::distance(l.begin(), it)));
71+
return Value(static_cast<int>(std::distance<Value::Iterator>(l.begin(), it)));
7072
}
7173

7274
return FFI::nil;

tests/list-tests.ark

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
(assert (= ["three" 2 1] (reverseList [1 2 "three"])) "List test 10°2 failed")
3333
(assert (= [] (reverseList [])) "List test 10°3 failed")
3434

35-
(assert (= (findInList [1 2 3 "asdf"] "asd") false) "List test 11 failed")
35+
(assert (nil? (findInList [1 2 3 "asdf"] "asd")) "List test 11 failed")
3636
(assert (findInList [2 3 4 5 6 1] 1) "List test 11°2 failed")
37-
(assert (= (findInList [] nil) false) "List test 11°3 failed")
37+
(assert (nil? (findInList [] nil)) "List test 11°3 failed")
3838

3939
(assert (= (removeAtList [1 2 3] 1) [1 3]) "List test 12 failed")
4040
(assert (= (removeAtList [1] 0) []) "List test 12°2 failed")

0 commit comments

Comments
 (0)