<commit_before>#include "match_parser.hpp"
#include "ast_node.hpp"
#include <memory>

namespace thewizardplusplus::wizard_parser::parser {

match_parser::match_parser(const match_type& type, const std::string& sample):
	type{type},
	sample{sample}
{}

parsing_result match_parser::parse(const lexer::token_span& tokens) const {
	if (tokens.empty()) {
		return {};
	}

	const auto matched_value = type == match_type::by_type
		? tokens[0].type
		: tokens[0].value;
	return matched_value == sample
		? parsing_result{
			ast_node{tokens[0].type, tokens[0].value, {}, lexer::get_offset(tokens)},
			tokens.subspan(1)
		}
		: parsing_result{{}, tokens};<commit_msg>Refactor the `parser::match_parser::parse()` method<commit_after>#include "match_parser.hpp"
#include "ast_node.hpp"
#include <memory>

namespace thewizardplusplus::wizard_parser::parser {

match_parser::match_parser(const match_type& type, const std::string& sample):
	type{type},
	sample{sample}
{}

parsing_result match_parser::parse(const lexer::token_span& tokens) const {
	if (tokens.empty()) {
		return {{}, {}};
	}

	const auto token = tokens[0];
	const auto match = type == match_type::by_type ? token.type : token.value;
	return match == sample
		? parsing_result{
			ast_node{token.type, token.value, {}, lexer::get_offset(tokens)},
			tokens.subspan(1)
		}
		: parsing_result{{}, tokens};
{'fraction_non_alphanumeric': 0.1550330639235856, 'fraction_numerical': 0.005143277002204262, 'mean_word_length': 6.2063492063492065, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2141820', 'n_tokens_mistral': 492, 'n_tokens_neox': 462, 'n_words': 88}