Skip to content

Commit

Permalink
Update PEGTL, fix #140, fix #144.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinH committed Sep 17, 2023
1 parent 0242c8c commit 345cb7e
Show file tree
Hide file tree
Showing 27 changed files with 72 additions and 86 deletions.
2 changes: 1 addition & 1 deletion external/PEGTL
Submodule PEGTL updated 429 files
8 changes: 4 additions & 4 deletions include/tao/json/cbor/consume_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#ifndef TAO_JSON_CBOR_CONSUME_FILE_HPP
#define TAO_JSON_CBOR_CONSUME_FILE_HPP

#include <tao/pegtl/file_input.hpp>
#include <filesystem>

#include "../internal/filesystem.hpp"
#include <tao/pegtl/file_input.hpp>

#include "../consume.hpp"
#include "../forward.hpp"
Expand All @@ -16,14 +16,14 @@
namespace tao::json::cbor
{
template< typename T, template< typename... > class Traits = traits >
[[nodiscard]] T consume_file( const json::internal::filesystem::path& path )
[[nodiscard]] T consume_file( const std::filesystem::path& path )
{
cbor::basic_parts_parser< utf8_mode::check, 8, pegtl::file_input< pegtl::tracking_mode::lazy > > pp( path );
return json::consume< T, Traits >( pp );
}

template< template< typename... > class Traits = traits, typename T >
void consume_file( const json::internal::filesystem::path& path, T& t )
void consume_file( const std::filesystem::path& path, T& t )
{
cbor::basic_parts_parser< utf8_mode::check, 8, pegtl::file_input< pegtl::tracking_mode::lazy > > pp( path );
json::consume< Traits >( pp, t );
Expand Down
6 changes: 3 additions & 3 deletions include/tao/json/cbor/events/from_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
#ifndef TAO_JSON_CBOR_EVENTS_FROM_FILE_HPP
#define TAO_JSON_CBOR_EVENTS_FROM_FILE_HPP

#include <filesystem>

#include <tao/pegtl/file_input.hpp>
#include <tao/pegtl/parse.hpp>

#include "../../internal/filesystem.hpp"

#include "../internal/grammar.hpp"

namespace tao::json::cbor::events
{
// Events producer to parse a file containing a CBOR string representation.

template< typename Consumer >
void from_file( Consumer& consumer, const json::internal::filesystem::path& path )
void from_file( Consumer& consumer, const std::filesystem::path& path )
{
pegtl::file_input< pegtl::tracking_mode::lazy > in( path );
pegtl::parse< internal::grammar >( in, consumer );
Expand Down
6 changes: 3 additions & 3 deletions include/tao/json/cbor/from_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
#ifndef TAO_JSON_CBOR_FROM_FILE_HPP
#define TAO_JSON_CBOR_FROM_FILE_HPP

#include <filesystem>
#include <utility>

#include "../events/to_value.hpp"
#include "../events/transformer.hpp"
#include "../internal/filesystem.hpp"

#include "events/from_file.hpp"

namespace tao::json::cbor
{
template< template< typename... > class Traits, template< typename... > class... Transformers >
[[nodiscard]] basic_value< Traits > basic_from_file( const json::internal::filesystem::path& path )
[[nodiscard]] basic_value< Traits > basic_from_file( const std::filesystem::path& path )
{
json::events::transformer< json::events::to_basic_value< Traits >, Transformers... > consumer;
events::from_file( consumer, path );
return std::move( consumer.value );
}

template< template< typename... > class... Transformers >
[[nodiscard]] value from_file( const json::internal::filesystem::path& path )
[[nodiscard]] value from_file( const std::filesystem::path& path )
{
return basic_from_file< traits, Transformers... >( path );
}
Expand Down
2 changes: 1 addition & 1 deletion include/tao/json/cbor/parts_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ namespace tao::json::cbor

[[nodiscard]] auto mark()
{
return m_input.template mark< pegtl::rewind_mode::required >();
return m_input.template auto_rewind< pegtl::rewind_mode::required >();
}

template< typename T >
Expand Down
8 changes: 4 additions & 4 deletions include/tao/json/consume_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#ifndef TAO_JSON_CONSUME_FILE_HPP
#define TAO_JSON_CONSUME_FILE_HPP

#include <tao/pegtl/file_input.hpp>
#include <filesystem>

#include "internal/filesystem.hpp"
#include <tao/pegtl/file_input.hpp>

#include "consume.hpp"
#include "forward.hpp"
Expand All @@ -15,14 +15,14 @@
namespace tao::json
{
template< typename T, template< typename... > class Traits = traits >
[[nodiscard]] T consume_file( const internal::filesystem::path& path )
[[nodiscard]] T consume_file( const std::filesystem::path& path )
{
basic_parts_parser< pegtl::file_input< pegtl::tracking_mode::lazy > > pp( path );
return consume< T, Traits >( pp );
}

template< template< typename... > class Traits = traits, typename T >
void consume_file( const internal::filesystem::path& path, T& t )
void consume_file( const std::filesystem::path& path, T& t )
{
basic_parts_parser< pegtl::file_input< pegtl::tracking_mode::lazy > > pp( path );
consume< Traits >( pp, t );
Expand Down
6 changes: 3 additions & 3 deletions include/tao/json/contrib/position.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#ifndef TAO_JSON_CONTRIB_POSITION_HPP
#define TAO_JSON_CONTRIB_POSITION_HPP

#include <filesystem>
#include <ostream>
#include <string>
#include <type_traits>
#include <utility>

#include "../events/to_value.hpp"
#include "../events/transformer.hpp"
#include "../internal/filesystem.hpp"

#include "../from_file.hpp"
#include "../message_extension.hpp"
Expand Down Expand Up @@ -147,7 +147,7 @@ namespace tao::json
};

template< template< typename... > class Traits, template< typename... > class... Transformers >
[[nodiscard]] auto basic_from_file_with_position( const internal::filesystem::path& path )
[[nodiscard]] auto basic_from_file_with_position( const std::filesystem::path& path )
{
events::transformer< events::to_basic_value< Traits >, Transformers... > consumer;
pegtl::file_input< pegtl::tracking_mode::eager > in( path );
Expand All @@ -156,7 +156,7 @@ namespace tao::json
}

template< template< typename... > class... Transformers >
[[nodiscard]] auto from_file_with_position( const internal::filesystem::path& path )
[[nodiscard]] auto from_file_with_position( const std::filesystem::path& path )
{
return basic_from_file_with_position< make_position_traits< traits >::template type, Transformers... >( path );
}
Expand Down
5 changes: 3 additions & 2 deletions include/tao/json/events/from_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#ifndef TAO_JSON_EVENTS_FROM_FILE_HPP
#define TAO_JSON_EVENTS_FROM_FILE_HPP

#include <filesystem>

#include "../internal/action.hpp"
#include "../internal/errors.hpp"
#include "../internal/filesystem.hpp"
#include "../internal/grammar.hpp"

#include <tao/pegtl/file_input.hpp>
Expand All @@ -17,7 +18,7 @@ namespace tao::json::events
// Events producer to parse a file containing a JSON string representation.

template< typename Consumer >
void from_file( Consumer& consumer, const internal::filesystem::path& path )
void from_file( Consumer& consumer, const std::filesystem::path& path )
{
pegtl::file_input< pegtl::tracking_mode::lazy > in( path );
pegtl::parse< internal::grammar, internal::action, internal::errors >( in, consumer );
Expand Down
6 changes: 3 additions & 3 deletions include/tao/json/from_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
#ifndef TAO_JSON_FROM_FILE_HPP
#define TAO_JSON_FROM_FILE_HPP

#include <filesystem>
#include <utility>

#include "events/from_file.hpp"
#include "events/to_value.hpp"
#include "events/transformer.hpp"
#include "internal/filesystem.hpp"

namespace tao::json
{
template< template< typename... > class Traits, template< typename... > class... Transformers >
[[nodiscard]] basic_value< Traits > basic_from_file( const internal::filesystem::path& path )
[[nodiscard]] basic_value< Traits > basic_from_file( const std::filesystem::path& path )
{
events::transformer< events::to_basic_value< Traits >, Transformers... > consumer;
events::from_file( consumer, path );
return std::move( consumer.value );
}

template< template< typename... > class... Transformers >
[[nodiscard]] value from_file( const internal::filesystem::path& path )
[[nodiscard]] value from_file( const std::filesystem::path& path )
{
return basic_from_file< traits, Transformers... >( path );
}
Expand Down
15 changes: 0 additions & 15 deletions include/tao/json/internal/filesystem.hpp

This file was deleted.

4 changes: 2 additions & 2 deletions include/tao/json/internal/grammar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ namespace tao::json::internal
[[nodiscard]] static bool match_number( Input& in, States&&... st )
{
if( in.peek_char() == '0' ) {
if( !match_zero< NEG, A, rewind_mode::dontcare, Action, Control >( in, st... ) ) {
if( !match_zero< NEG, A, rewind_mode::optional, Action, Control >( in, st... ) ) {
throw pegtl::parse_error( "incomplete number", in );
}
return true;
Expand All @@ -192,7 +192,7 @@ namespace tao::json::internal

case '-':
in.bump_in_this_line();
if( in.empty() || !match_number< true, A, rewind_mode::dontcare, Action, Control >( in, st... ) ) {
if( in.empty() || !match_number< true, A, rewind_mode::optional, Action, Control >( in, st... ) ) {
throw pegtl::parse_error( "incomplete number", in );
}
return true;
Expand Down
8 changes: 4 additions & 4 deletions include/tao/json/jaxn/consume_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#ifndef TAO_JSON_JAXN_CONSUME_FILE_HPP
#define TAO_JSON_JAXN_CONSUME_FILE_HPP

#include <tao/pegtl/file_input.hpp>
#include <filesystem>

#include "../internal/filesystem.hpp"
#include <tao/pegtl/file_input.hpp>

#include "../consume.hpp"
#include "../forward.hpp"
Expand All @@ -16,14 +16,14 @@
namespace tao::json::jaxn
{
template< typename T, template< typename... > class Traits = traits >
[[nodiscard]] T consume_file( const json::internal::filesystem::path& path )
[[nodiscard]] T consume_file( const std::filesystem::path& path )
{
jaxn::basic_parts_parser< pegtl::file_input< pegtl::tracking_mode::lazy > > pp( path );
return json::consume< T, Traits >( pp );
}

template< template< typename... > class Traits = traits, typename T >
void consume_file( const json::internal::filesystem::path& path, T& t )
void consume_file( const std::filesystem::path& path, T& t )
{
jaxn::basic_parts_parser< pegtl::file_input< pegtl::tracking_mode::lazy > > pp( path );
json::consume< Traits >( pp, t );
Expand Down
6 changes: 3 additions & 3 deletions include/tao/json/jaxn/events/from_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
#ifndef TAO_JSON_JAXN_EVENTS_FROM_FILE_HPP
#define TAO_JSON_JAXN_EVENTS_FROM_FILE_HPP

#include <filesystem>

#include <tao/pegtl/file_input.hpp>
#include <tao/pegtl/parse.hpp>

#include "../internal/action.hpp"
#include "../internal/errors.hpp"
#include "../internal/grammar.hpp"

#include "../../internal/filesystem.hpp"

namespace tao::json::jaxn::events
{
// Events producer to parse a file containing a JAXN string representation.

template< typename Consumer >
void from_file( Consumer& consumer, const json::internal::filesystem::path& path )
void from_file( Consumer& consumer, const std::filesystem::path& path )
{
pegtl::file_input< pegtl::tracking_mode::lazy > in( path );
pegtl::parse< internal::grammar, internal::action, internal::errors >( in, consumer );
Expand Down
6 changes: 3 additions & 3 deletions include/tao/json/jaxn/from_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
#ifndef TAO_JSON_JAXN_FROM_FILE_HPP
#define TAO_JSON_JAXN_FROM_FILE_HPP

#include <filesystem>
#include <utility>

#include "../events/to_value.hpp"
#include "../events/transformer.hpp"
#include "../internal/filesystem.hpp"

#include "events/from_file.hpp"

namespace tao::json::jaxn
{
template< template< typename... > class Traits, template< typename... > class... Transformers >
[[nodiscard]] basic_value< Traits > basic_from_file( const json::internal::filesystem::path& path )
[[nodiscard]] basic_value< Traits > basic_from_file( const std::filesystem::path& path )
{
json::events::transformer< json::events::to_basic_value< Traits >, Transformers... > consumer;
events::from_file( consumer, path );
return std::move( consumer.value );
}

template< template< typename... > class... Transformers >
[[nodiscard]] value from_file( const json::internal::filesystem::path& path )
[[nodiscard]] value from_file( const std::filesystem::path& path )
{
return basic_from_file< traits, Transformers... >( path );
}
Expand Down
8 changes: 4 additions & 4 deletions include/tao/json/jaxn/internal/grammar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ namespace tao::json::jaxn::internal
typename... States >
[[nodiscard]] static bool match_must( Input& in, States&&... st )
{
return Control< must< Rule > >::template match< A, rewind_mode::dontcare, Action, Control >( in, st... );
return Control< must< Rule > >::template match< A, rewind_mode::optional, Action, Control >( in, st... );
}

template< bool NEG,
Expand Down Expand Up @@ -299,7 +299,7 @@ namespace tao::json::jaxn::internal
return Control< must< kw_infinity< NEG > > >::template match< A, M, Action, Control >( in, st... );

case '0':
if( !match_zero< NEG, A, rewind_mode::dontcare, Action, Control >( in, st... ) ) {
if( !match_zero< NEG, A, rewind_mode::optional, Action, Control >( in, st... ) ) {
throw pegtl::parse_error( "incomplete number", in );
}
return true;
Expand Down Expand Up @@ -333,14 +333,14 @@ namespace tao::json::jaxn::internal

case '+':
in.bump_in_this_line();
if( in.empty() || !match_number< false, A, rewind_mode::dontcare, Action, Control >( in, st... ) ) {
if( in.empty() || !match_number< false, A, rewind_mode::optional, Action, Control >( in, st... ) ) {
throw pegtl::parse_error( "incomplete number", in );
}
return true;

case '-':
in.bump_in_this_line();
if( in.empty() || !match_number< true, A, rewind_mode::dontcare, Action, Control >( in, st... ) ) {
if( in.empty() || !match_number< true, A, rewind_mode::optional, Action, Control >( in, st... ) ) {
throw pegtl::parse_error( "incomplete number", in );
}
return true;
Expand Down
8 changes: 4 additions & 4 deletions include/tao/json/jaxn/parts_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ namespace tao::json::jaxn
switch( in.peek_char() ) {
case '+':
in.bump_in_this_line();
if( in.empty() || !sor_value::match_number< false, A, rewind_mode::dontcare, Action, Control >( in, st... ) ) {
if( in.empty() || !sor_value::match_number< false, A, rewind_mode::optional, Action, Control >( in, st... ) ) {
throw pegtl::parse_error( "incomplete number", in );
}
return true;

case '-':
in.bump_in_this_line();
if( in.empty() || !sor_value::match_number< true, A, rewind_mode::dontcare, Action, Control >( in, st... ) ) {
if( in.empty() || !sor_value::match_number< true, A, rewind_mode::optional, Action, Control >( in, st... ) ) {
throw pegtl::parse_error( "incomplete number", in );
}
return true;
Expand Down Expand Up @@ -239,9 +239,9 @@ namespace tao::json::jaxn
pegtl::parse< pegtl::disable< pegtl::must< jaxn::internal::rules::sor_value, json::internal::rules::wss > > >( m_input );
}

[[nodiscard]] auto mark() // noexcept( noexcept( m_input.template mark< pegtl::rewind_mode::required >() ) )
[[nodiscard]] auto mark() // noexcept( noexcept( m_input.template auto_rewind< pegtl::rewind_mode::required >() ) )
{
return m_input.template mark< pegtl::rewind_mode::required >();
return m_input.template auto_rewind< pegtl::rewind_mode::required >();
}

template< typename T >
Expand Down
Loading

0 comments on commit 345cb7e

Please sign in to comment.