Review all tests

This commit is contained in:
Federico Aponte
2025-02-03 14:38:51 +01:00
parent aba386a11c
commit 5a47094e35
15 changed files with 2536 additions and 1212 deletions

View File

@@ -0,0 +1,41 @@
//: test_grammar_ut.hpp
// vb6_parser
// Copyright (c) 2022 Federico Aponte
// This code is licensed under GNU Software License (see LICENSE.txt for details)
#pragma once
#include "color_console.hpp"
#include "vb6_config.hpp"
#include <boost/spirit/home/x3.hpp>
#include <iostream>
#include <string_view>
#include <utility>
template <class ruleType, class attrType>
std::pair<bool, std::string_view> test_grammar(std::string_view fragment, ruleType rule, attrType& attr)
{
namespace x3 = boost::spirit::x3;
auto it1 = cbegin(fragment);
auto const it2 = cend(fragment);
std::stringstream out;
vb6_grammar::error_handler_type error_handler(it1, it2, out, "source.bas");
auto const parser =
// we pass our error handler to the parser so we can access
// it later on in our on_error and on_success handlers
x3::with<vb6_grammar::vb6_error_handler_tag>(std::ref(error_handler))
[
rule
];
bool res = x3::phrase_parse(it1, it2, parser, vb6_grammar::skip, attr);
return std::make_pair(res, std::string_view(it1, it2));
}