-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix multi-line string etc. positions.
- Loading branch information
Showing
4 changed files
with
137 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) 2019-2023 Dr. Colin Hirsch and Daniel Frey | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#ifndef TAO_CONFIG_INTERNAL_CHANGE_ACTION_AND_STATES_HPP | ||
#define TAO_CONFIG_INTERNAL_CHANGE_ACTION_AND_STATES_HPP | ||
|
||
#include <tuple> | ||
#include <utility> | ||
|
||
#include "pegtl.hpp" | ||
|
||
namespace tao::config::internal | ||
{ | ||
template< template< typename... > class NewAction, typename... NewStates > | ||
struct change_action_and_states | ||
: pegtl::maybe_nothing | ||
{ | ||
template< typename Rule, | ||
pegtl::apply_mode A, | ||
pegtl::rewind_mode M, | ||
template< typename... > | ||
class Action, | ||
template< typename... > | ||
class Control, | ||
std::size_t... Ns, | ||
typename ParseInput, | ||
typename... States > | ||
[[nodiscard]] static bool match( std::index_sequence< Ns... > /*unused*/, ParseInput& in, States&&... st ) | ||
{ | ||
auto t = std::tie( st... ); | ||
const auto pos = in.position(); | ||
if( Control< Rule >::template match< A, M, NewAction, Control >( in, std::get< Ns >( t )... ) ) { | ||
if constexpr( A == pegtl::apply_mode::action ) { | ||
Action< Rule >::success( pos, st... ); | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
template< typename Rule, | ||
pegtl::apply_mode A, | ||
pegtl::rewind_mode M, | ||
template< typename... > | ||
class Action, | ||
template< typename... > | ||
class Control, | ||
typename ParseInput, | ||
typename... States > | ||
[[nodiscard]] static bool match( ParseInput& in, States&&... st ) | ||
{ | ||
static_assert( !std::is_same_v< Action< void >, NewAction< void > >, "old and new action class templates are identical" ); | ||
return match< Rule, A, M, Action, Control >( std::index_sequence_for< NewStates... >(), in, NewStates()..., st... ); | ||
} | ||
}; | ||
|
||
} // tao::config::internal | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2023 Dr. Colin Hirsch and Daniel Frey | ||
// Please see LICENSE for license or visit https://github.com/taocpp/config/ | ||
|
||
#include <cassert> | ||
|
||
#include <tao/config.hpp> | ||
|
||
namespace tao | ||
{ | ||
void test1() | ||
{ | ||
const std::string input = "foo = '''a\nb\nc\n'''"; | ||
const auto config = config::from_string( input, __FUNCTION__ ); | ||
const auto string = config.get_object().at( "foo" ); | ||
assert( string.position.line() == 1 ); | ||
assert( string.get_string() == "a\nb\nc\n" ); | ||
} | ||
|
||
void test2() | ||
{ | ||
const std::string input = "foo = '''\na\nb\nc\n'''"; | ||
const auto config = config::from_string( input, __FUNCTION__ ); | ||
const auto string = config.get_object().at( "foo" ); | ||
assert( string.position.line() == 1 ); // Should this be 2? | ||
assert( string.get_string() == "a\nb\nc\n" ); | ||
} | ||
|
||
void test3() | ||
{ | ||
const std::string input = "\n\n\nfoo = '''a\nb\nc\n'''"; | ||
const auto config = config::from_string( input, __FUNCTION__ ); | ||
const auto string = config.get_object().at( "foo" ); | ||
assert( string.position.line() == 4 ); | ||
assert( string.get_string() == "a\nb\nc\n" ); | ||
} | ||
|
||
void test4() | ||
{ | ||
const std::string input = "\n\n\nfoo = '''\na\nb\nc\n'''"; | ||
const auto config = config::from_string( input, __FUNCTION__ ); | ||
const auto string = config.get_object().at( "foo" ); | ||
assert( string.position.line() == 4 ); // Should this be 5? | ||
assert( string.get_string() == "a\nb\nc\n" ); | ||
} | ||
|
||
} // namespace tao | ||
|
||
int main() | ||
{ | ||
tao::test1(); | ||
tao::test2(); | ||
tao::test3(); | ||
tao::test4(); | ||
return 0; | ||
} |