Skip to content

Commit

Permalink
ignore newlines in script
Browse files Browse the repository at this point in the history
  • Loading branch information
facontidavide committed Oct 9, 2023
1 parent ac3396b commit 283f6b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/behaviortree_cpp/scripting/operators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ struct stmt
// This is because we can't easily know whether we need to request more input when seeing a
// newline or not. Once we're having a e.g. parenthesized expression, we know that we need more
// input until we've reached ), so then change the whitespace rule.
static constexpr auto whitespace = dsl::ascii::blank | escaped_newline;
static constexpr auto whitespace = dsl::ascii::blank | escaped_newline | dsl::newline;

static constexpr auto rule = [] {
// We can't use `dsl::eol` as our terminator directly,
Expand Down
20 changes: 20 additions & 0 deletions tests/script_parser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,23 @@ TEST(ParserTest, Issue595)
ASSERT_EQ(status, BT::NodeStatus::SUCCESS);
ASSERT_EQ(0, counters[0]);
}

TEST(ParserTest, NewLine)
{
BT::BehaviorTreeFactory factory;

const std::string xml_text = R"(
<root BTCPP_format="4" >
<BehaviorTree ID="Main">
<Script code="A:=5;&#10;B:=6"/>
</BehaviorTree>
</root> )";


auto tree = factory.createTreeFromText(xml_text);
const auto status = tree.tickWhileRunning();

ASSERT_EQ(status, BT::NodeStatus::SUCCESS);
ASSERT_EQ(tree.rootBlackboard()->get<int>("A"), 5);
ASSERT_EQ(tree.rootBlackboard()->get<int>("B"), 6);
}

0 comments on commit 283f6b2

Please sign in to comment.