<commit_before>#include <pddlparse/detail/parsing/Precondition.h>

#include <pddlparse/AST.h>
#include <pddlparse/detail/parsing/Expressions.h>
#include <pddlparse/detail/parsing/Predicate.h>
#include <pddlparse/detail/parsing/Unsupported.h>
#include <pddlparse/detail/parsing/Utils.h>

namespace pddl
{
namespace detail
{

////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Precondition
//
////////////////////////////////////////////////////////////////////////////////////////////////////

std::experimental::optional<ast::Precondition> parsePreconditionBody(Context &context, ASTContext &astContext, VariableStack &variableStack);

////////////////////////////////////////////////////////////////////////////////////////////////////

std::experimental::optional<ast::Precondition> parsePrecondition(Context &context, ASTContext &astContext, VariableStack &variableStack)
{
	auto &tokenizer = context.tokenizer;

	tokenizer.skipWhiteSpace();

	std::experimental::optional<ast::Precondition> precondition;

	if ((precondition = parseAnd<ast::Precondition>(context, astContext, variableStack, parsePrecondition))
	    || (precondition = parseForAll<ast::Precondition>(context, astContext, variableStack, parsePrecondition)))
	{
		return std::move(precondition.value());
	}

	const auto position = tokenizer.position();

	tokenizer.expect<std::string>("(");

	const auto expressionIdentifierPosition = tokenizer.position();

	if (tokenizer.testIdentifierAndSkip("preference"))
	{
		// TODO: refactor
		tokenizer.seek(expressionIdentifierPosition);
		const auto expressionIdentifier = tokenizer.getIdentifier();

		tokenizer.seek(position);
		return parseUnsupported(context);
	}

	tokenizer.seek(position);
	return parsePreconditionBody(context, astContext, variableStack);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

std::experimental::optional<ast::Precondition> parsePreconditionBody(Context &context, ASTContext &astContext, VariableStack &variableStack)
{
	auto &tokenizer = context.tokenizer;

	tokenizer.skipWhiteSpace();

	std::experimental::optional<ast::Precondition> precondition;

	if ((precondition = parseAnd<ast::Precondition>(context, astContext, variableStack, parsePrecondition))
	    || (precondition = parseOr<ast::Precondition>(context, astContext, variableStack, parsePrecondition))
	    || (precondition = parseExists<ast::Precondition>(context, astContext, variableStack, parsePrecondition))
	    || (precondition = parseForAll<ast::Precondition>(context, astContext, variableStack, parsePrecondition))
		|| (precondition = parseNot<ast::Precondition>(context, astContext, variableStack, parsePrecondition))
	    || (precondition = parseImply<ast::Precondition>(context, astContext, variableStack, parsePrecondition))
	    || (precondition = parsePredicate(context, astContext, variableStack)))
	{
		return std::move(precondition.value());
	}

	const auto position = tokenizer.position();

	tokenizer.expect<std::string>("(");
	tokenizer.skipWhiteSpace();

	const auto expressionIdentifierPosition = tokenizer.position();

	if (tokenizer.testIdentifierAndReturn("-")
		|| tokenizer.testIdentifierAndReturn("=")
		|| tokenizer.testIdentifierAndReturn("*")
		|| tokenizer.testIdentifierAndReturn("+")
		|| tokenizer.testIdentifierAndReturn("-")
		|| tokenizer.testIdentifierAndReturn("/")
		|| tokenizer.testIdentifierAndReturn(">")
		|| tokenizer.testIdentifierAndReturn("<")
		|| tokenizer.testIdentifierAndReturn("=")
		|| tokenizer.testIdentifierAndReturn(">=")
		|| tokenizer.testIdentifierAndReturn("<="))
	{
		const auto expressionIdentifier = tokenizer.getIdentifier();
		tokenizer.expect<std::string>("(");

		skipSection(tokenizer);
		return parseUnsupported(context);
	}

	tokenizer.seek(expressionIdentifierPosition);
	const auto expressionIdentifier = tokenizer.getIdentifier();

	tokenizer.seek(position);
	throw tokenize::TokenizerException(tokenizer.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
}

////////////////////////////////////////////////////////////////////////////////////////////////////

}
}<commit_msg>Finished precondition parsing.<commit_after>#include <pddlparse/detail/parsing/Precondition.h>

#include <pddlparse/AST.h>
#include <pddlparse/detail/parsing/Expressions.h>
#include <pddlparse/detail/parsing/Predicate.h>
#include <pddlparse/detail/parsing/Unsupported.h>
#include <pddlparse/detail/parsing/Utils.h>

namespace pddl
{
namespace detail
{

////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Precondition
//
////////////////////////////////////////////////////////////////////////////////////////////////////

std::experimental::optional<ast::Precondition> parsePreconditionBody(Context &context, ASTContext &astContext, VariableStack &variableStack);

////////////////////////////////////////////////////////////////////////////////////////////////////

std::experimental::optional<ast::Precondition> parsePrecondition(Context &context, ASTContext &astContext, VariableStack &variableStack)
{
	auto &tokenizer = context.tokenizer;

	tokenizer.skipWhiteSpace();

	std::experimental::optional<ast::Precondition> precondition;

	if ((precondition = parseAnd<ast::Precondition>(context, astContext, variableStack, parsePrecondition))
	    || (precondition = parseForAll<ast::Precondition>(context, astContext, variableStack, parsePrecondition)))
	{
		return std::move(precondition.value());
	}

	const auto position = tokenizer.position();

	tokenizer.expect<std::string>("(");

	const auto expressionIdentifierPosition = tokenizer.position();

	if (tokenizer.testIdentifierAndSkip("preference"))
	{
		// TODO: refactor
		tokenizer.seek(expressionIdentifierPosition);
		const auto expressionIdentifier = tokenizer.getIdentifier();

		tokenizer.seek(position);
		return parseUnsupported(context);
	}

	tokenizer.seek(position);
	return parsePreconditionBody(context, astContext, variableStack);
}

////////////////////////////////////////////////////////////////////////////////////////////////////

std::experimental::optional<ast::Precondition> parsePreconditionBody(Context &context, ASTContext &astContext, VariableStack &variableStack)
{
	auto &tokenizer = context.tokenizer;

	tokenizer.skipWhiteSpace();

	std::experimental::optional<ast::Precondition> precondition;

	if ((precondition = parseAnd<ast::Precondition>(context, astContext, variableStack, parsePrecondition))
	    || (precondition = parseOr<ast::Precondition>(context, astContext, variableStack, parsePrecondition))
	    || (precondition = parseExists<ast::Precondition>(context, astContext, variableStack, parsePrecondition))
	    || (precondition = parseForAll<ast::Precondition>(context, astContext, variableStack, parsePrecondition))
		|| (precondition = parseNot<ast::Precondition>(context, astContext, variableStack, parsePrecondition))
	    || (precondition = parseImply<ast::Precondition>(context, astContext, variableStack, parsePrecondition))
	    || (precondition = parsePredicate(context, astContext, variableStack)))
	{
		return std::move(precondition.value());
	}

	const auto position = tokenizer.position();

	tokenizer.expect<std::string>("(");
	tokenizer.skipWhiteSpace();

	const auto expressionIdentifierPosition = tokenizer.position();

	if (tokenizer.testIdentifierAndReturn("-")
		|| tokenizer.testIdentifierAndReturn("=")
		|| tokenizer.testIdentifierAndReturn("*")
		|| tokenizer.testIdentifierAndReturn("+")
		|| tokenizer.testIdentifierAndReturn("-")
		|| tokenizer.testIdentifierAndReturn("/")
		|| tokenizer.testIdentifierAndReturn(">")
		|| tokenizer.testIdentifierAndReturn("<")
		|| tokenizer.testIdentifierAndReturn("=")
		|| tokenizer.testIdentifierAndReturn(">=")
		|| tokenizer.testIdentifierAndReturn("<="))
	{
		tokenizer.seek(position);
		return parseUnsupported(context);
	}

	tokenizer.seek(expressionIdentifierPosition);
	const auto expressionIdentifier = tokenizer.getIdentifier();

	tokenizer.seek(position);
	throw tokenize::TokenizerException(tokenizer.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
}

////////////////////////////////////////////////////////////////////////////////////////////////////

}
}
{'fraction_non_alphanumeric': 0.23844224107036197, 'fraction_numerical': 0.0, 'mean_word_length': 3.477005347593583, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2367247', 'n_tokens_mistral': 2186, 'n_tokens_neox': 2087, 'n_words': 345}