Skip to content

Commit

Permalink
fixing list-tests.ark ; fixing FFI/List.cpp (std::distance couldn't g…
Browse files Browse the repository at this point in the history
…et the type of the iterator used) ; fixing parser (detection of ill formed code based on the previous token)
  • Loading branch information
SuperFola committed Oct 22, 2019
1 parent 5710ca4 commit 4f99008
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,18 @@ namespace Ark
// parse block
if (token.token == "(")
{
bool previous_token_was_lparen = true;

// create a list node to host the block
Node block(NodeType::List);
block.setPos(token.line, token.col);

// handle sub-blocks
if (tokens.front().token == "(")
{
block.push_back(parse(tokens));
previous_token_was_lparen = false;
}

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

if (std::find(m_warns.begin(), m_warns.end(), warn_info) == m_warns.end() &&
(atomized.nodeType() == NodeType::String || atomized.nodeType() == NodeType::Number ||
atomized.nodeType() == NodeType::List))
atomized.nodeType() == NodeType::List) &&
previous_token_was_lparen)
{
if ((m_options & FeatureDisallowInvalidTokenAfterParen) == 0)
{
m_warns.push_back(std::move(warn_info));
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);
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);
}
else
throwParseError("Ill-formed code line: invalid token after `('", token);
Expand Down
4 changes: 3 additions & 1 deletion src/VM/FFI/List.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <Ark/VM/FFI.hpp>

#include <iterator>

#define FFI_Function(name) Value name(const std::vector<Value>& n)

namespace Ark::internal::FFI::List
Expand Down Expand Up @@ -66,7 +68,7 @@ namespace Ark::internal::FFI::List
for (Value::Iterator it=l.begin(); it != l.end(); ++it)
{
if (*it == n[1])
return Value(static_cast<int>(std::distance(l.begin(), it)));
return Value(static_cast<int>(std::distance<Value::Iterator>(l.begin(), it)));
}

return FFI::nil;
Expand Down
4 changes: 2 additions & 2 deletions tests/list-tests.ark
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
(assert (= ["three" 2 1] (reverseList [1 2 "three"])) "List test 10°2 failed")
(assert (= [] (reverseList [])) "List test 10°3 failed")

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

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

0 comments on commit 4f99008

Please sign in to comment.