const AccessorNode* ParseNode::AsAccessor() const { return NULL; }
const BinaryOpNode* ParseNode::AsBinaryOp() const { return NULL; }
+const BlockCommentNode* ParseNode::AsBlockComment() const { return NULL; }
const BlockNode* ParseNode::AsBlock() const { return NULL; }
const ConditionNode* ParseNode::AsConditionNode() const { return NULL; }
+const EndNode* ParseNode::AsEnd() const { return NULL; }
const FunctionCallNode* ParseNode::AsFunctionCall() const { return NULL; }
const IdentifierNode* ParseNode::AsIdentifier() const { return NULL; }
const ListNode* ParseNode::AsList() const { return NULL; }
const LiteralNode* ParseNode::AsLiteral() const { return NULL; }
const UnaryOpNode* ParseNode::AsUnaryOp() const { return NULL; }
-const BlockCommentNode* ParseNode::AsBlockComment() const { return NULL; }
Comments* ParseNode::comments_mutable() {
if (!comments_)
void ParseNode::PrintComments(std::ostream& out, int indent) const {
if (comments_) {
std::string ind = IndentFor(indent + 1);
- for (std::vector<Token>::const_iterator i(comments_->before().begin());
- i != comments_->before().end();
- ++i) {
- out << ind << "+BEFORE_COMMENT(\"" << i->value() << "\")\n";
- }
- for (std::vector<Token>::const_iterator i(comments_->suffix().begin());
- i != comments_->suffix().end();
- ++i) {
- out << ind << "+SUFFIX_COMMENT(\"" << i->value() << "\")\n";
- }
- for (std::vector<Token>::const_iterator i(comments_->after().begin());
- i != comments_->after().end();
- ++i) {
- out << ind << "+AFTER_COMMENT(\"" << i->value() << "\")\n";
- }
+ for (const auto& token : comments_->before())
+ out << ind << "+BEFORE_COMMENT(\"" << token.value() << "\")\n";
+ for (const auto& token : comments_->suffix())
+ out << ind << "+SUFFIX_COMMENT(\"" << token.value() << "\")\n";
+ for (const auto& token : comments_->after())
+ out << ind << "+AFTER_COMMENT(\"" << token.value() << "\")\n";
}
}
LocationRange BlockNode::GetRange() const {
if (begin_token_.type() != Token::INVALID &&
- end_token_.type() != Token::INVALID) {
- return begin_token_.range().Union(end_token_.range());
+ end_->value().type() != Token::INVALID) {
+ return begin_token_.range().Union(end_->value().range());
} else if (!statements_.empty()) {
return statements_[0]->GetRange().Union(
statements_[statements_.size() - 1]->GetRange());
void BlockNode::Print(std::ostream& out, int indent) const {
out << IndentFor(indent) << "BLOCK\n";
PrintComments(out, indent);
- for (size_t i = 0; i < statements_.size(); i++)
- statements_[i]->Print(out, indent + 1);
+ for (const auto& statement : statements_)
+ statement->Print(out, indent + 1);
+ if (end_ && end_->comments())
+ end_->Print(out, indent + 1);
}
Value BlockNode::ExecuteBlockInScope(Scope* our_scope, Err* err) const {
std::vector<Value>& results = result_value.list_value();
results.reserve(contents_.size());
- for (size_t i = 0; i < contents_.size(); i++) {
- const ParseNode* cur = contents_[i];
+ for (const auto& cur : contents_) {
if (cur->AsBlockComment())
continue;
results.push_back(cur->Execute(scope, err));
}
LocationRange ListNode::GetRange() const {
- return LocationRange(begin_token_.location(), end_token_.location());
+ return LocationRange(begin_token_.location(),
+ end_->value().location());
}
Err ListNode::MakeErrorDescribing(const std::string& msg,
void ListNode::Print(std::ostream& out, int indent) const {
out << IndentFor(indent) << "LIST\n";
PrintComments(out, indent);
- for (size_t i = 0; i < contents_.size(); i++)
- contents_[i]->Print(out, indent + 1);
+ for (const auto& cur : contents_)
+ cur->Print(out, indent + 1);
+ if (end_ && end_->comments())
+ end_->Print(out, indent + 1);
}
// LiteralNode -----------------------------------------------------------------
out << IndentFor(indent) << "BLOCK_COMMENT(" << comment_.value() << ")\n";
PrintComments(out, indent);
}
+
+
+// EndNode ---------------------------------------------------------------------
+
+EndNode::EndNode(const Token& token) : value_(token) {
+}
+
+EndNode::~EndNode() {
+}
+
+const EndNode* EndNode::AsEnd() const {
+ return this;
+}
+
+Value EndNode::Execute(Scope* scope, Err* err) const {
+ return Value();
+}
+
+LocationRange EndNode::GetRange() const {
+ return value_.range();
+}
+
+Err EndNode::MakeErrorDescribing(const std::string& msg,
+ const std::string& help) const {
+ return Err(value_, msg, help);
+}
+
+void EndNode::Print(std::ostream& out, int indent) const {
+ out << IndentFor(indent) << "END(" << value_.value() << ")\n";
+ PrintComments(out, indent);
+}