Skip to content

Commit d79d5a0

Browse files
committed
Documentation in progress.
1 parent 3b4e8b6 commit d79d5a0

12 files changed

+737
-135
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ The included [grammar analysis](doc/Grammar-Analysis.md) finds several typical e
5656
5757
## Design
5858
59-
The PEGTL is designed to be "lean and mean", the core library consists of around 10K lines of code.
59+
The PEGTL is designed to be "lean and mean".
60+
The core library consists of around 10K lines of code.
6061
Emphasis is on simplicity and efficiency, putting a well-tuned *relatively* simple approach above overly complex optimisations.
6162
6263
The PEGTL is mostly concerned with parsing combinators and grammar rules, and with giving the user of the library (the possibility of) full control over all other aspects of a parsing run.

doc/Action-Reference.md

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,13 @@ This default can be changed via the macro `TAO_PEGTL_NAMESPACE` in `tao/pegtl/co
1919

2020
## Contents
2121

22-
* [Nothing](#nothing)
23-
* [Maybe Nothing](#maybe-nothing)
24-
* [Add Guard](#add-guard)
25-
* [Add State](#add-state)
26-
* [Change Action](#change-action)
27-
* [Change Action and State](#change-action-and-state)
28-
* [Change Action and States](#change-action-and-states)
29-
* [Change Control](#change-control)
30-
* [Change State](#change-state)
31-
* [Change States](#change-states)
32-
* [Control Action](#control-action)
33-
* [Disable Action](#disable-action)
34-
* [Enable Action](#enable-action)
35-
* [Require Apply](#require-apply)
36-
* [Require Apply0](#require-apply0)
22+
* [Default](#default)
23+
* [Tag Classes](#tag-classes)
24+
* [Index](#index)
3725

38-
### Nothing
26+
## Default
27+
28+
###### `nothing< R >`
3929

4030
An action class template that does nothing, simply a *nop* action.
4131

@@ -46,7 +36,7 @@ template< typename Rule >
4636
struct nothing {};
4737
```
4838
49-
Usually also serves as base class for the default case of custom action class templates to indicate that the default is "no action".
39+
Also serves as base class for the default case of custom action class templates.
5040
5141
```c++
5242
template< typename Rule >
@@ -57,17 +47,48 @@ struct my_action
5747
// that define static apply() or apply0() functions.
5848
```
5949

60-
### Maybe Nothing
50+
When `my_action< Rule >` is publicly derived from `tao::pegtl::nothing< Rule >` it indicates to the PEGTL that no `apply()` or `apply0()` should be expected in `my_action< Rule >`.
51+
52+
## Tag Classes
53+
54+
Other tag classes beyond `nothing< Rule >` to inform the PEGTL of what is intended for or expected of an action.
55+
56+
####### `maybe_nothing`
6157

6258
An action class alias defined as `nothing< void >`.
63-
An action class for `Rule` that is not derived from `nothing< Rule >` but intentionally has no `apply()` or `apply0()` must/should (TODO) derive from `maybe_nohting` to signal that the absence of these functions is not an error.
59+
An action class for `Rule` that is not derived from `nothing< Rule >` but intentionally has no `apply()` or `apply0()` must derive from `maybe_nothing` to signal that the absence of these functions is not an error.
60+
61+
This is usually the case for actions that define a `match()` function, and which might or might not also have an `apply()` or `apply0()` added later down the inheritance chain.
62+
63+
###### `require_apply`
64+
65+
The class `require_apply` is an empty class used as tag.
66+
An action class that is publicly derived from `require_apply` must define a static `apply()` function that can be called as action function.
67+
68+
Wins against [`maybe_nothing`](#maybe-nothing) whan a class has both as public base classes.
69+
Included via `tao/pegtl/action/require_apply.hpp`.
70+
71+
###### `require_apply0`
72+
73+
The class `require_apply0` is an empty class used as tag.
74+
An action class that is publicly derived from `require_apply0` must define a static `apply0()` function that can be called as action function.
75+
76+
Wins against [`maybe_nothing`](#maybe-nothing) whan a class has both as public base classes.
77+
Included via `tao/pegtl/action/require_apply0.hpp`.
78+
6479

6580
### Add Guard
6681
add_guard
6782

83+
Publicly derives from [`maybe_nothing`](#maybe-nothing).
84+
Included via `tao/pegtl/action/add_guard.hpp`.
85+
6886
### Add State
6987
add_state
7088

89+
Publicly derives from [`maybe_nothing`](#maybe-nothing).
90+
Included via `tao/pegtl/action/add_state.hpp`.
91+
7192
### Change Action
7293

7394
An action class template with a `match()` function that parses the rule to which it is attached with its template parameter as action class template.
@@ -115,21 +136,23 @@ In other words, an action version of the [`enable`](Rule-Reference.md#enable) ru
115136
Publicly derives from [`maybe_nothing`](#maybe-nothing).
116137
Included via `tao/pegtl/action/enable_action.hpp`.
117138

118-
### Require Apply
119-
120-
The class `require_apply` is an empty class used as tag.
121-
An action class that is publicly derived from `require_apply` must define a static `apply()` function that can be called as action function.
122-
123-
Wins against [`maybe_nothing`](#maybe-nothing) whan a class has both as public base classes.
124-
Included via `tao/pegtl/action/require_apply.hpp`.
125-
126-
### Require Apply0
127-
128-
The class `require_apply0` is an empty class used as tag.
129-
An action class that is publicly derived from `require_apply` must define a static `apply0()` function that can be called as action function.
139+
## Index
130140

131-
Wins against [`maybe_nothing`](#maybe-nothing) whan a class has both as public base classes.
132-
Included via `tao/pegtl/action/require_apply0.hpp`.
141+
* [`nothing`](#nothing) <sup>[(default)](#default)</sup>
142+
* [`maybe_nothing`](#maybe-nothing) <sup>[(tag classes)](#tag-classes)</sup>
143+
* [`require_apply`](#require-apply) <sup>[(tag classes)](#tag-classes)</sup>
144+
* [`require_apply0`](#require-apply0) <sup>[(tag classes)](#tag-classes)</sup>
145+
* [Add Guard](#add-guard)
146+
* [Add State](#add-state)
147+
* [Change Action](#change-action)
148+
* [Change Action and State](#change-action-and-state)
149+
* [Change Action and States](#change-action-and-states)
150+
* [Change Control](#change-control)
151+
* [Change State](#change-state)
152+
* [Change States](#change-states)
153+
* [Control Action](#control-action)
154+
* [Disable Action](#disable-action)
155+
* [Enable Action](#enable-action)
133156

134157
---
135158

doc/Changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
**Not yet released**
66

7-
* *Moar templates*, more templates in more places!
7+
* Even more templates, in even more places, templates everywhere!
88
* Use the [**migration guide**](Migration-Guide.md#version-400) when updating.
99
* Infrastructure
1010
* Switched to Boost Software License, Version 1.0.
@@ -92,6 +92,7 @@
9292
* Added new customization point for error messages. -- TODO!
9393
* Added optional source line output for the tracer. -- TODO?
9494
* Other
95+
* Routed rewind-guard creation through the Control class.
9596
* Renamed contrib "limit_depth" functionality to "check_depth".
9697
* Renamed contrib "check_bytes" functionality to "check_count".
9798
* Renamed contrib "limit_bytes" functionality to "limit_count".
@@ -101,6 +102,7 @@
101102
* Renamed `end_of_line()` input member function to `end_of_line_or_file()`.
102103
* Renamed contrib "to_string" functionality to "type_to_string".
103104
* Added `type_to_string_view` function that mirrors `type_to_string`.
105+
* Renamed `alphabet.hpp` to `alphabet_constants.hpp`.
104106
* Cleanup
105107
* Removed rule `forty_two`, we apologize for any inconvenience.
106108
* Removed rule `bytes` and replaced with `many` for different data types.

doc/Contrib-and-Examples.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,16 @@ For all questions and remarks contact us at **taocpp(at)icemx.net**.
2626

2727
###### `<tao/pegtl/contrib/alphabet.hpp>`
2828

29-
* Constants for ASCII letters.
30-
* Shortens `string<'f','o','o'>` to `string<f,o,o>`.
31-
* Ready for production use.
32-
* Superceeded by `TAO_PEGTL_STRING()`.
29+
* Character constants for ASCII letters.
30+
* In sub-namespace `alphabet`.
31+
* Shorten e.g. `string<'f','o','o'>` to `string<f,o,o>`.
32+
* Probably better to use `TAO_PEGTL_STRING()`.
33+
34+
###### `<tao/pegtl/contrib/alphabet_rules.hpp>`
35+
36+
* Rules for single ASCII letters.
37+
* In sub-namespace `alphabet::rules`.
38+
* Shorten e.g. `one<'a'>` to `a`.
3339

3440
###### `<tao/pegtl/contrib/http.hpp>`
3541

doc/Development.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Development
22

3-
Notes on future development and public parts of the development roadmap.
3+
Notes on past, present and future development.
4+
Public parts of the development roadmap.
45

56

67
## C++ Standard
@@ -15,7 +16,7 @@ Version 3.x of the PEGTL requires at least C++17.
1516

1617
Version 4.x of the PEGTL requires at least C++17.
1718

18-
Version 5.x of the PEGTL will make the jump to C++20 or newer.
19+
Version 5.x of the PEGTL will jump to C++20 or C++23.
1920

2021

2122
## C++ Features
@@ -30,6 +31,7 @@ Version 5.x of the PEGTL will make the jump to C++20 or newer.
3031
* Keep an open eye for opportunities to use C++20 `[[likely]]` and `[[unlikely]]`.
3132
* Keep an open eye for opportunities to use C++20 `constinit` and `consteval`, and
3233
* keep an open eye for opportunities to use the extended `constexpr` facilities.
34+
* For example make the bulk() and size() functions in the peek classes consteval!
3335
* Keep an open eye for opportunities to use the extended CTAD facilities from C++20.
3436
* Keep an open eye for opportunities to use class types as non-type template parameters.
3537
* Replace the hand-crafted endian facilities with C++20 `std::endian` and C++23 `std::byteswap`.
@@ -56,6 +58,17 @@ A couple of things that *could* be done in the area of buffer inputs.
5658
* Investigate the use of ("stackful") coroutines for parsing from a network socket, and
5759
* investigate whether this can also be used for incremental parsing that keeps everything.
5860

61+
62+
## Development Tools
63+
64+
We use the code coverage facilities of the GCC and Clang compilers to meet our goal of 100% code coverage with unit tests.
65+
Unfortunately the coverage reports are not 100% reliable.
66+
67+
We also try to use `clang-format` to ensure consistent formatting of our source code.
68+
Unfortunately it, too, can get confused and result in incorrectly formatted code.
69+
70+
For example under some circumstances `clang-format` does not understand whether a `&&` is the logical operator or an r-value reference declarator, or whether a `<` is a comparison operator or introduces a template argument list.
71+
5972
---
6073

6174
This document is part of the [PEGTL](https://github.com/taocpp/PEGTL).

doc/Getting-Started.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Getting Started
22

3-
Since the PEGTL is a parser library, here is an "inverse hello world" example that parses,
4-
rather than prints, the string `Hello, foo!` for any sequence of alphabetic ASCII characters `foo`.
3+
Since the PEGTL is a parser library, here is an "inverse hello world" example that parses, rather than prints, the string `Hello, foo!` for any sequence of alphabetic ASCII characters `foo`.
54

65
```c++
76
#include <string>
@@ -50,8 +49,8 @@ namespace hello
5049
template<>
5150
struct action< name >
5251
{
53-
template< typename ParseInput >
54-
static void apply( const ParseInput& in, std::string& v )
52+
template< typename ActionInput >
53+
static void apply( const ActionInput& in, std::string& v )
5554
{
5655
v = in.string();
5756
}
@@ -61,21 +60,22 @@ namespace hello
6160

6261
int main( int argc, char* argv[] )
6362
{
64-
if( argc != 2 ) return 1;
65-
63+
if( argc < 2 ) {
64+
return 1;
65+
}
6666
// Start a parsing run of argv[1] with the string
6767
// variable 'name' as additional argument that will
6868
// be passed to all called actions, including the
6969
// one we attached to the 'name' rule above.
7070

7171
std::string name;
7272
pegtl::argv_input in( argv, 1 );
73-
if( pegtl::parse< hello::grammar, hello::action >( in, name ) ) {
74-
std::cout << "Good bye, " << name << "!" << std::endl;
75-
}
76-
else {
77-
std::cout << "I don't understand." << std::endl;
73+
74+
if( !pegtl::parse< hello::grammar, hello::action >( in, name ) ) {
75+
std::cout << "I can't parse you!" << std::endl;
76+
return 1;
7877
}
78+
std::cout << "Good bye, " << name << "!" << std::endl;
7979
return 0;
8080
}
8181
```
@@ -126,7 +126,7 @@ Beyond these standard combinators the PEGTL contains a [large number of addition
126126
127127
The PEGTL also contains a [large number of atomic rules](Rule-Reference.md) for matching ASCII and Unicode characters, strings, ranges of characters, integers, beginning-of-file or end-of-line, ...
128128
129-
Many of these rules can directly be applied to objects in the input, frequently of type `char`, but also to data members or the return values of global or member functions in cases where the input is a sequence of non-trivial objects.
129+
Many of these rules can directly be applied to objects in the input, frequently of type `char`, but also to data members or the return values of global or member functions in cases where the input is a sequence of other types.
130130
131131
## Grammar Analysis
132132
@@ -141,7 +141,8 @@ It is best practice to create a separate dedicated program that does nothing els
141141
#include <tao/pegtl.hpp>
142142
#include <tao/pegtl/analyze.hpp>
143143
144-
// This example uses the included JSON grammar
144+
// For this example we use the included JSON grammar.
145+
145146
#include <tao/pegtl/contrib/json.hpp>
146147
147148
namespace pegtl = tao::pegtl;
@@ -151,10 +152,9 @@ using grammar = pegtl::must< pegtl::json::text, pegtl::eof >;
151152
int main()
152153
{
153154
if( pegtl::analyze< grammar >() != 0 ) {
154-
std::cerr << "Cycles without progress detected!\n";
155+
std::cerr << "Cycles without progress detected!" << std::endl;
155156
return 1;
156157
}
157-
158158
return 0;
159159
}
160160
```

0 commit comments

Comments
 (0)