Skip to content

Commit

Permalink
Input refactoring in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinH committed Dec 16, 2023
1 parent 71e1807 commit 3fec7aa
Show file tree
Hide file tree
Showing 66 changed files with 1,486 additions and 716 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ During development of a new major version the main branch can go through incompa
## Documentation

* [Changelog](doc/Changelog.md)
* [Development](doc/README.md) (requires C++17)
* [Version 3.x](https://github.com/taocpp/PEGTL/blob/3.x/doc/README.md) (requires C++17)
* [Version 2.x](https://github.com/taocpp/PEGTL/blob/2.x/doc/README.md) (requires C++11)
* [Version 1.x](https://github.com/taocpp/PEGTL/blob/1.x/doc/README.md) (requires C++11)
* [Development](doc/README.md) (C++20)
* [Version 4.x](https://github.com/taocpp/PEGTL/blob/4.x/doc/README.md) (C++17)
* [Version 3.x](https://github.com/taocpp/PEGTL/blob/3.x/doc/README.md) (C++17)
* [Version 2.x](https://github.com/taocpp/PEGTL/blob/2.x/doc/README.md) (C++11)
* [Version 1.x](https://github.com/taocpp/PEGTL/blob/1.x/doc/README.md) (C++11)

## Contact

Expand Down
2 changes: 2 additions & 0 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
* Added new customization point for error messages.
* Added optional source line output for the tracer.
* Added new ASCII rules [`cntrl`](Rule-Reference.md#cntrl), [`cr`](Rule-Reference.md#cr), [`crlf`](Rule-Reference.md#crlf), [`esc`](Rule-Reference.md#esc), [`ff`](Rule-Reference.md#ff), [`graph`](Rule-Reference.md#graph), [`ht`](Rule-Reference.md#ht), [`lf`](Rule-Reference.md#lf), [`lfcr`](Rule-Reference.md#lfcr), [`sp`](Rule-Reference.md#sp), [`vt`](Rule-Reference.md#vt).
* Added new atomic rule [`consume`](Rule-Reference.md#consume-count-).
* Added new atomic rule [`everything`](Rule-Reference.md#everything).
* Added new rule [`invert`](Rule-Reference.md#invert-r-) to convert between `one` and `not_one` etc.
* Added new convenience rule [`partial`](Rule-Reference.md#partial-r-).
* Added new convenience rule [`star_partial`](Rule-Reference.md#star_partial-r-).
* Added new convenience rule [`strict`](Rule-Reference.md#strict-r-).
Expand Down
4 changes: 4 additions & 0 deletions doc/Rule-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,10 @@ Atomic rules do not rely on other rules.
* [Meta data] and [implementation] mapping:
- `bol::rule_t` is `internal::bol`

###### `consume< Count >`

TODO

###### `eof`

* Succeeds at "end-of-file", i.e. when the input is empty or all input has been consumed.
Expand Down
7 changes: 7 additions & 0 deletions include/tao/pegtl/analyze_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ namespace TAO_PEGTL_NAMESPACE
: analyze_opt_traits<>
{};

template< typename Name, std::size_t Count >
struct analyze_traits< Name, internal::consume< Count > >
: std::conditional_t< ( Count > 0 ), analyze_any_traits<>, analyze_opt_traits<> >
{};

template< typename Name, template< typename... > class Control, typename... Rules >
struct analyze_traits< Name, internal::control< Control, Rules... > >
: analyze_traits< Name, typename seq< Rules... >::rule_t >
Expand Down Expand Up @@ -130,6 +135,8 @@ namespace TAO_PEGTL_NAMESPACE
: analyze_any_traits<>
{};

// No general analyze_traits for internal::function<> for obvious reasons.

template< typename Name, typename Rule, typename... Actions >
struct analyze_traits< Name, internal::if_apply< Rule, Actions... > >
: analyze_traits< Name, typename Rule::rule_t >
Expand Down
2 changes: 1 addition & 1 deletion include/tao/pegtl/ascii.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "config.hpp"

#include "internal/peek_direct.hpp"
#include "internal/peeks.hpp"
#include "internal/result_on_found.hpp"
#include "internal/rules.hpp"

Expand Down
52 changes: 0 additions & 52 deletions include/tao/pegtl/contrib/function.hpp

This file was deleted.

14 changes: 8 additions & 6 deletions include/tao/pegtl/contrib/integer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "../parse_error.hpp"
#include "../rules.hpp"

#include "../internal/text_eol_tags.hpp"

namespace TAO_PEGTL_NAMESPACE
{
struct unsigned_rule_old
Expand Down Expand Up @@ -153,12 +155,12 @@ namespace TAO_PEGTL_NAMESPACE
if( !in.empty() ) {
const char c = in.peek_char();
if( is_digit( c ) ) {
in.template consume< unsigned >( 1 );
in.template consume< eol_exclude_tag >( 1 );
if( c == '0' ) {
return in.empty() || ( !is_digit( in.peek_char() ) );
}
while( ( !in.empty() ) && is_digit( in.peek_char() ) ) {
in.template consume< unsigned >( 1 );
in.template consume< eol_exclude_tag >( 1 );
}
return true;
}
Expand All @@ -177,14 +179,14 @@ namespace TAO_PEGTL_NAMESPACE
char c = in.peek_char();
if( is_digit( c ) ) {
if( c == '0' ) {
in.template consume< unsigned >( 1 );
in.template consume< eol_exclude_tag >( 1 );
return in.empty() || ( !is_digit( in.peek_char() ) );
}
do {
if( !accumulate_digit< Unsigned, Maximum >( st, c ) ) {
throw TAO_PEGTL_NAMESPACE::parse_error( "integer overflow", in );
}
in.template consume< unsigned >( 1 );
in.template consume< eol_exclude_tag >( 1 );
} while( ( !in.empty() ) && is_digit( c = in.peek_char() ) );
return true;
}
Expand All @@ -203,7 +205,7 @@ namespace TAO_PEGTL_NAMESPACE
char c = in.peek_char();
if( c == '0' ) {
if( ( in.size( 2 ) < 2 ) || ( !is_digit( in.peek_char( 1 ) ) ) ) {
in.template consume< unsigned >( 1 );
in.template consume< eol_exclude_tag >( 1 );
return true;
}
return false;
Expand All @@ -217,7 +219,7 @@ namespace TAO_PEGTL_NAMESPACE
}
++b;
} while( ( !in.empty() ) && is_digit( c = in.peek_char( b ) ) );
in.template consume< unsigned >( b );
in.template consume< eol_exclude_tag >( b );
return true;
}
}
Expand Down
8 changes: 5 additions & 3 deletions include/tao/pegtl/contrib/raw_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "../rewind_mode.hpp"
#include "../rules.hpp"

#include "../internal/text_eol_tags.hpp"

namespace TAO_PEGTL_NAMESPACE
{
namespace internal
Expand All @@ -42,7 +44,7 @@ namespace TAO_PEGTL_NAMESPACE
switch( const auto c = in.peek_char( i ) ) {
case Open:
marker_size = i + 1;
in.template consume< raw_string_open >( marker_size );
in.template consume< eol_exclude_tag >( marker_size );
(void)Control< eol >::template match< A, M, Action, Control >( in );
return true;
case Marker:
Expand Down Expand Up @@ -121,7 +123,7 @@ namespace TAO_PEGTL_NAMESPACE
if( in.empty() ) {
return false;
}
in.template consume< raw_string_until >( 1 );
in.template consume< eol_unknown_tag >( 1 );
}
return m( true );
}
Expand Down Expand Up @@ -209,7 +211,7 @@ namespace TAO_PEGTL_NAMESPACE
std::size_t marker_size;
if( Control< internal::raw_string_open< Open, Marker > >::template match< A, M, Action, Control >( in, marker_size ) ) {
if( Control< content >::template match< A, M, Action, Control >( in, marker_size, st... ) ) {
in.template consume< raw_string >( marker_size );
in.template consume< internal::eol_exclude_tag >( marker_size );
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/tao/pegtl/internal/any.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "../type_list.hpp"

#include "enable_control.hpp"
#include "peek_direct.hpp"
#include "peeks.hpp"

namespace TAO_PEGTL_NAMESPACE::internal
{
Expand Down
94 changes: 64 additions & 30 deletions include/tao/pegtl/internal/bump_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,24 @@
#define TAO_PEGTL_INTERNAL_BUMP_TRAITS_HPP

#include <cstddef>
#include <type_traits>

#include "../config.hpp"

#include "any.hpp"
#include "at.hpp"
#include "eol.hpp"
#include "eolf.hpp"
#include "consume.hpp"
#include "everything.hpp"
#include "many.hpp"
#include "text_eol_tags.hpp"
#include "until.hpp"

namespace TAO_PEGTL_NAMESPACE::internal
{
template< typename Eol, typename Rule, typename = void >
struct bump_traits
{
// template< typename Data, typename Position >
// static void bump( Position& pos, const Data* /*unused*/, const std::size_t count ) noexcept
// {
// pos.column += count;
// pos.count += count;
// }

template< typename Data, typename Position >
static void bump( Position& pos, const Data* data, const std::size_t count ) noexcept
{
text_eol_scan< Eol >( pos, data, data + count );
}
};
struct bump_traits;

template< typename Eol >
struct bump_traits< Eol, eol_exclude_tag >
Expand All @@ -50,7 +43,7 @@ namespace TAO_PEGTL_NAMESPACE::internal
static void bump( Position& pos, const Data* /*unused*/, const std::size_t count ) noexcept
{
pos.line++;
pos.column = 1; // TODO: Incrementing column while matching Eol is redundant!
pos.column = 1;
pos.count += count;
}
};
Expand All @@ -65,25 +58,66 @@ namespace TAO_PEGTL_NAMESPACE::internal
}
};

template< typename Eol, typename Rule >
struct bump_traits< Eol, Rule, std::enable_if_t< std::is_same_v< Eol, Rule > > >
: bump_traits< Eol, eol_matched_tag >
{};

// TODO: Anything else to detect and optimise eol_rule sub-rules?

template< typename Eol, typename Peek >
struct bump_traits< Eol, any< Peek > >
{
template< typename Data, typename Position >
static void bump( Position& pos, const Data* data, const std::size_t count )
{
text_eol_scan< Eol >( pos, data, data + count );
}
};
: bump_traits< Eol, eol_unknown_tag > // TODO: Only when single-char eol possible?
{};

template< typename Eol, unsigned Count >
struct bump_traits< Eol, consume< Count > >
: bump_traits< Eol, eol_unknown_tag >
{};

template< typename Eol, typename Size >
struct bump_traits< Eol, everything< Size > >
: bump_traits< Eol, eol_unknown_tag >
{};

template< typename Eol, unsigned Count, typename Peek >
struct bump_traits< Eol, many< Count, Peek > >
{
template< typename Data, typename Position >
static void bump( Position& pos, const Data* data, const std::size_t count )
{
text_eol_scan< Eol >( pos, data, data + count );
}
};
: bump_traits< Eol, eol_unknown_tag >
{};

template< typename Eol, typename Cond >
struct bump_traits< Eol, until< Cond > >
: bump_traits< Eol, eol_unknown_tag >
{};

template< typename Eol >
struct bump_traits< Eol, until< eol > >
: bump_traits< Eol, eol_exclude_tag >
{};

template< typename Eol >
struct bump_traits< Eol, until< eolf > >
: bump_traits< Eol, eol_exclude_tag >
{};

template< typename Eol, typename Cond >
struct bump_traits< Eol, until< Cond >, std::enable_if_t< std::is_same_v< Eol, Cond > > >
: bump_traits< Eol, eol_exclude_tag >
{};

template< typename Eol, typename Cond >
struct bump_traits< Eol, until< at< Cond > > >
: bump_traits< Eol, until< typename Cond::rule_t > >
{};

// TODO: Anything else that can be made independent of the default case?
// TODO: Most importantly: one, range(s), (i)string (and the ICU rules?)

template< typename Eol, typename Rule, typename >
struct bump_traits
: bump_traits< Eol, eol_unknown_tag > // check
// : bump_traits< Eol, eol_exclude_tag > // trust
{};

} // namespace TAO_PEGTL_NAMESPACE::internal

Expand Down
14 changes: 14 additions & 0 deletions include/tao/pegtl/internal/byteswap.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) 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_PEGTL_INTERNAL_BYTESWAP_HPP
#define TAO_PEGTL_INTERNAL_BYTESWAP_HPP

#if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( __CYGWIN__ )
#include "byteswap_win32.hpp"
#else
#include "byteswap_gcc_clang.hpp"
#endif

#endif
Loading

0 comments on commit 3fec7aa

Please sign in to comment.