void clean_token_list(token_list &tokens_) { token_list clean_tokens; for (token_entry current_token = tokens_.begin(); current_token != tokens_.end(); ++current_token) { if (current_token->type == type::EMPTY) continue; clean_tokens.push_back(*current_token); } tokens_ = clean_tokens; }
void carma::rules::script_command_rule::apply(carma::compiler::context& a_scope, token_list &tokens_, token_entry& start_entry_, token_entry& end_entry_) { auto types = script_command_parser::AllTypesForName(start_entry_->val); if (types.size() == 0) { throw compiler::exception::syntax_error("Not a valid script command ("+ start_entry_->val +")"); } bool valid = false; std::vector<std::string> errors_found; auto next = std::next(start_entry_); for (auto type : types) { if (type == script_command::Type::NONE) { // always valid ? valid = true; return; } else if (type == script_command::Type::LEFT_RIGHT) { bool rightSide = false; bool leftSide = false; // check right side if (next != end_entry_) { if (next->val != "}" && next->val != ")" && next->val != "]" && next->val != ";" && next->val != "=" && next->val != "<" && next->val != ">") { rightSide = true; } else { errors_found.push_back("Invalid Syntax for binary script command " + start_entry_->val + " With next: " + next->val); } } else { errors_found.push_back("Missing argument for binary script command " + start_entry_->val + " End of statement?"); } // Check left side if (start_entry_ == tokens_.begin()) { // nothing in front so... error errors_found.push_back("Missing argument for binary script command " + start_entry_->val); } else { auto prev = std::prev(start_entry_); if (prev->val != "{" && prev->val != "(" && prev->val != "[" && prev->val != ";" && prev->val != "=" && prev->val != "<" && prev->val != ">") { leftSide = true; } else { errors_found.push_back("Invalid Syntax for binary script command " + start_entry_->val + " With prev: " + prev->val); } } if (leftSide && rightSide) valid = true; } else if (type == script_command::Type::RIGHT) { // validate that we have some statement to our right if (next != end_entry_) { if (next->val != "}" && next->val != ")" && next->val != "]" && next->val != ";" && next->val != "=" && next->val != "<" && next->val != ">") { valid = true; } else { errors_found.push_back("Invalid Syntax for unary script command " + start_entry_->val + " With next: " + next->val); } } else { errors_found.push_back("Missing argument for unary script command " + start_entry_->val + " End of statement?"); } } }; if (!valid) { if (errors_found.size() == 0) errors_found.push_back("Unknown error"); throw compiler::exception::syntax_error("Syntax Error at script command (" + start_entry_->val + ")" + errors_found.at(0)); } }