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 13, 2023
1 parent abcf942 commit 71e1807
Show file tree
Hide file tree
Showing 291 changed files with 4,884 additions and 3,714 deletions.
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ CXXFLAGS ?= -Wall -Wextra -Wshadow -Werror -O3 $(MINGW_CXXFLAGS)

HEADERS := $(shell find include -name '*.hpp')
SOURCES := $(shell find src -name '*.cpp')
DEPENDS := $(SOURCES:%.cpp=build/%.d)
BINARIES := $(SOURCES:%.cpp=build/%)
DEPENDS := $(SOURCES:src/%.cpp=build/dep/%.d)
BINARIES := $(SOURCES:src/%.cpp=build/bin/%)

UNIT_TESTS := $(filter build/src/test/%,$(BINARIES))
UNIT_TESTS := $(filter build/bin/test/%,$(BINARIES))

.PHONY: all
all: compile check
Expand All @@ -57,11 +57,12 @@ clean:
@rm -rf build/*
@find . -name '*~' -delete

build/%.d: %.cpp Makefile
build/dep/%.d: src/%.cpp Makefile
@mkdir -p $(@D)
$(CXX) $(CXXSTD) -Iinclude $(CPPFLAGS) -MM -MQ $@ $< -o $@

build/%: %.cpp build/%.d
build/bin/%: src/%.cpp build/dep/%.d
@mkdir -p $(@D)
$(CXX) $(CXXSTD) -Iinclude $(CPPFLAGS) $(CXXFLAGS) $< $(LDFLAGS) -o $@

ifeq ($(findstring $(MAKECMDGOALS),clean),)
Expand Down
4 changes: 4 additions & 0 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Added [control function](Control-and-Debug.md) to throw nested exceptions.
* Changed `parse_error` to contain only one `position`, and:
* Changed to **nested exceptions** for nested [parsing errors](Errors-and-Exceptions.md).
* Removed `action_t` type alias from all input classes in favour of using `internal::action_input`.
* Added functions to visit and flatten [nested exceptions](Contrib-and-Examples.md#taopegtlcontribnested_exceptionshpp).
* Added new customization point for error messages.
* Added optional source line output for the tracer.
Expand All @@ -32,6 +33,9 @@
* Moved `line_at()` from input member function to global function `line_view_at()`.
* Moved `begin_of_line()` from input member function to global function of same name.
* Moved `end_of_line()` from input member function to global function of same name.
* Makefile generates binaries in `build/bin/` instead of `build/src/`.
* Makefile generates dependencies in `build/dep/` instead of `build/src/`.
* Removed rule `bytes` and replaced with `many` for different data types.
* Removed support for `boost::filesystem` and `std::experimental::filesystem`.
* Removed support for building an amalgamated header.
* Removed support for Visual Studio 2017.
Expand Down
41 changes: 29 additions & 12 deletions doc/Rule-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -651,28 +651,22 @@ Atomic rules do not rely on other rules.

###### `bof`

* Succeeds at "beginning-of-file", i.e. when the input's `byte()` member function returns zero.
* Succeeds at "beginning-of-file", i.e. when the input is at its start.
* Does not consume input.
* Does **not** work with inputs that don't have a `byte()` member function.
* Requires an input `in` with the `in.start()` member function, and/or
* requires an input `in` where `in`direct_position()` has a `count` member.
* [Meta data] and [implementation] mapping:
- `bof::rule_t` is `internal::bof`

###### `bol`

* Succeeds at "beginning-of-line", i.e. when the input's `column()` member function returns one.
* Does not consume input.
* Does **not** work with inputs that don't have a `column()` member function.
* Requires an input with eager text position tracking, more precisely:
* Requires an input `in` where `in.direct_position().column` is available.
* [Meta data] and [implementation] mapping:
- `bol::rule_t` is `internal::bol`

###### `bytes< Num >`

* Succeeds when the input contains at least `Num` further bytes.
* Consumes these `Num` bytes from the input.
* [Meta data] and [implementation] mapping:
- `bytes< 0 >::rule_t` is `internal::success`
- `bytes< Num >::rule_t` is `internal::bytes< Num >`

###### `eof`

* Succeeds at "end-of-file", i.e. when the input is empty or all input has been consumed.
Expand Down Expand Up @@ -874,6 +868,15 @@ ASCII rules do not usually rely on other rules.
* Matches and consumes a single ASCII lower-case alphabetic character.
* [Equivalent] to `range< 'a', 'z' >`.

###### `many< Num >`

* Succeeds when the input contains at least `Num` further bytes.
* Consumes these `Num` bytes from the input.
* [Equivalent] to `rep< N, any >`.
* [Meta data] and [implementation] mapping:
- `many< 0 >::rule_t` is `internal::success`
- `many< Num >::rule_t` is `internal::many< Num, internal::peek_char >`

###### `not_one< C... >`

* Succeeds when the input is not empty, and:
Expand Down Expand Up @@ -1068,6 +1071,12 @@ Unicode rules do not rely on other rules.

* [Equivalent] to `one< 0xfeff >`.

###### `many< Num >`

* Succeeds when the input contains at least `Num` further code points.
* Consumes these `Num` code points from the input.
* [Equivalent] to `rep< N, any >`.

###### `not_one< C... >`

* Succeeds when the input is not empty, and:
Expand Down Expand Up @@ -1475,6 +1484,12 @@ Binary rules do not rely on other rules.
* Succeeds when the input contains at least N bytes.
* Consumes N bytes when it succeeds.

###### `many< Num >`

* Succeeds when the input contains at least `Num` times N bytes.
* Consumes these `Num` * N bytes from the input.
* [Equivalent] to `rep< N, any >`.

###### `mask_not_one< M, C... >`

* Succeeds when the input contains at least N bytes, and:
Expand Down Expand Up @@ -1570,7 +1585,6 @@ Binary rules do not rely on other rules.
* [`bof`](#bof) <sup>[(atomic rules)](#atomic-rules)</sup>
* [`bol`](#bol) <sup>[(atomic rules)](#atomic-rules)</sup>
* [`bom`](#bom) <sup>[(unicode rules)](#unicode-rules)</sup>
* [`bytes< Num >`](#bytes-num-) <sup>[(atomic rules)](#atomic-rules)</sup>
* [`canonical_combining_class< V >`](#canonical_combining_class-v-) <sup>[(icu rules)](#icu-rules-for-value-properties)</sup>
* [`case_sensitive`](#case_sensitive) <sup>[(icu rules)](#icu-rules-for-binary-properties)</sup>
* [`cntrl`](#cntrl) <sup>[(ascii rules)](#ascii-rules)</sup>
Expand Down Expand Up @@ -1636,6 +1650,9 @@ Binary rules do not rely on other rules.
* [`logical_order_exception`](#logical_order_exception) <sup>[(icu rules)](#icu-rules-for-binary-properties)</sup>
* [`lower`](#lower) <sup>[(ascii rules)](#ascii-rules)</sup>
* [`lowercase`](#lowercase) <sup>[(icu rules)](#icu-rules-for-binary-properties)</sup>
* [`many< Num >`](#many-num-) <sup>[(ascii rules)](#ascii-rules)</sup>
* [`many< Num >`](#many-num--1) <sup>[(unicode rules)](#unicode-rules)</sup>
* [`many< Num >`](#many-num--2) <sup>[(binary rules)](#binary-rules)</sup>
* [`mask_not_one< M, C... >`](#mask_not_one-m-c-) <sup>[(binary rules)](#binary-rules)</sup>
* [`mask_not_range< M, C, D >`](#mask_not_range-m-c-d-) <sup>[(binary rules)](#binary-rules)</sup>
* [`mask_one< M, C... >`](#mask_one-m-c-) <sup>[(binary rules)](#binary-rules)</sup>
Expand Down
39 changes: 16 additions & 23 deletions include/tao/pegtl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,39 @@
#ifndef TAO_PEGTL_HPP
#define TAO_PEGTL_HPP

#include "pegtl/ascii.hpp"
#include "pegtl/config.hpp"

#include "pegtl/demangle.hpp"
#include "pegtl/parse.hpp"
#include "pegtl/version.hpp"

#include "pegtl/ascii.hpp"
#include "pegtl/eol.hpp"
#include "pegtl/forward.hpp"
#include "pegtl/inputs.hpp"
#include "pegtl/parse.hpp"
#include "pegtl/print.hpp"
#include "pegtl/rules.hpp"
#include "pegtl/utf8.hpp"
#include "pegtl/version.hpp"
#include "pegtl/visit.hpp"

#include "pegtl/argv_input.hpp"
#include "pegtl/buffer_input.hpp"
#include "pegtl/cstream_input.hpp"
#include "pegtl/file_input.hpp"
#include "pegtl/istream_input.hpp"
#include "pegtl/memory_input.hpp"
#include "pegtl/read_input.hpp"
#include "pegtl/string_input.hpp"

#include "pegtl/line_view_at.hpp"

#include "pegtl/add_guard.hpp"
#include "pegtl/add_state.hpp"
#include "pegtl/change_action.hpp"
#include "pegtl/change_action_and_state.hpp"
#include "pegtl/change_action_and_states.hpp"
#include "pegtl/change_control.hpp"
#include "pegtl/change_state.hpp"
#include "pegtl/change_states.hpp"

#include "pegtl/control_action.hpp"
#include "pegtl/disable_action.hpp"
#include "pegtl/enable_action.hpp"

#include "pegtl/discard_input.hpp"
#include "pegtl/discard_input_on_failure.hpp"
#include "pegtl/discard_input_on_success.hpp"

#include "pegtl/visit.hpp"
#include "pegtl/remove_first_state.hpp"
#include "pegtl/remove_last_states.hpp"

#if defined( __cpp_exceptions )
#include "pegtl/must_if.hpp"
#include "pegtl/parse_error.hpp"
#include "pegtl/parse_error_base.hpp"
#endif

#include "pegtl/line_view_at.hpp"

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
// 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_CONTRIB_INSTANTIATE_HPP
#define TAO_PEGTL_CONTRIB_INSTANTIATE_HPP
#ifndef TAO_PEGTL_ADD_GUARD_HPP
#define TAO_PEGTL_ADD_GUARD_HPP

#include "../apply_mode.hpp"
#include "../config.hpp"
#include "../match.hpp"
#include "../nothing.hpp"
#include "../rewind_mode.hpp"
#include "apply_mode.hpp"
#include "config.hpp"
#include "match.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"

namespace TAO_PEGTL_NAMESPACE
{
template< typename T >
struct instantiate
template< typename AddGuard >
struct add_guard
: maybe_nothing
{
template< typename Rule,
Expand All @@ -28,7 +28,7 @@ namespace TAO_PEGTL_NAMESPACE
typename... States >
[[nodiscard]] static bool match( ParseInput& in, States&&... st )
{
const T t( static_cast< const ParseInput& >( in ), st... );
const AddGuard guard( static_cast< const ParseInput& >( in ), st... );
return TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... );
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
// 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_CONTRIB_ADD_STATE_HPP
#define TAO_PEGTL_CONTRIB_ADD_STATE_HPP
#ifndef TAO_PEGTL_ADD_STATE_HPP
#define TAO_PEGTL_ADD_STATE_HPP

#include <type_traits>

#include "../apply_mode.hpp"
#include "../config.hpp"
#include "../match.hpp"
#include "../nothing.hpp"
#include "../rewind_mode.hpp"
#include "apply_mode.hpp"
#include "config.hpp"
#include "match.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"

#include "../internal/dependent_false.hpp"
#include "internal/dependent_false.hpp"

namespace TAO_PEGTL_NAMESPACE
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// 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_CONTRIB_ANALYZE_HPP
#define TAO_PEGTL_CONTRIB_ANALYZE_HPP
#ifndef TAO_PEGTL_ANALYZE_HPP
#define TAO_PEGTL_ANALYZE_HPP

#include <cassert>
#include <cstddef>
Expand All @@ -15,8 +15,8 @@
#include <utility>
#include <vector>

#include "../config.hpp"
#include "../demangle.hpp"
#include "config.hpp"
#include "demangle.hpp"

#include "analyze_traits.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
// 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_CONTRIB_ANALYZE_TRAITS_HPP
#define TAO_PEGTL_CONTRIB_ANALYZE_TRAITS_HPP
#ifndef TAO_PEGTL_ANALYZE_TRAITS_HPP
#define TAO_PEGTL_ANALYZE_TRAITS_HPP

#include <type_traits>

#include "../ascii.hpp"
#include "../config.hpp"
#include "../rules.hpp"
#include "../type_list.hpp"

#include "ascii.hpp"
#include "config.hpp"
#include "forward.hpp"
#include "rules.hpp"
#include "type_list.hpp"

namespace TAO_PEGTL_NAMESPACE
{
Expand Down Expand Up @@ -91,11 +90,6 @@ namespace TAO_PEGTL_NAMESPACE
: analyze_opt_traits<>
{};

template< typename Name, unsigned Cnt >
struct analyze_traits< Name, internal::bytes< Cnt > >
: std::conditional_t< ( Cnt != 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 All @@ -106,11 +100,6 @@ namespace TAO_PEGTL_NAMESPACE
: analyze_traits< Name, typename seq< Rules... >::rule_t >
{};

template< typename Name >
struct analyze_traits< Name, internal::discard >
: analyze_opt_traits<>
{};

template< typename Name, typename... Rules >
struct analyze_traits< Name, internal::enable< Rules... > >
: analyze_traits< Name, typename seq< Rules... >::rule_t >
Expand Down Expand Up @@ -156,6 +145,11 @@ namespace TAO_PEGTL_NAMESPACE
: std::conditional_t< ( sizeof...( Cs ) != 0 ), analyze_any_traits<>, analyze_opt_traits<> >
{};

template< typename Name, unsigned Count, typename Peek >
struct analyze_traits< Name, internal::many< Count, Peek > >
: std::conditional_t< ( Count != 0 ), analyze_any_traits<>, analyze_opt_traits<> >
{};

template< typename Name, typename... Rules >
struct analyze_traits< Name, internal::not_at< Rules... > >
: analyze_traits< Name, typename opt< Rules... >::rule_t >
Expand Down Expand Up @@ -211,11 +205,6 @@ namespace TAO_PEGTL_NAMESPACE
: analyze_traits< Name, typename opt< Rules... >::rule_t >
{};

template< typename Name, unsigned Amount >
struct analyze_traits< Name, internal::require< Amount > >
: analyze_opt_traits<>
{};

template< typename Name, typename Rule, typename... Rules >
struct analyze_traits< Name, internal::seq< Rule, Rules... > >
: analyze_seq_traits< Rule, Rules... >
Expand Down
Loading

0 comments on commit 71e1807

Please sign in to comment.