You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -56,7 +56,8 @@ The included [grammar analysis](doc/Grammar-Analysis.md) finds several typical e
56
56
57
57
## Design
58
58
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.
60
61
Emphasis is on simplicity and efficiency, putting a well-tuned *relatively* simple approach above overly complex optimisations.
61
62
62
63
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.
Copy file name to clipboardExpand all lines: doc/Action-Reference.md
+56-33Lines changed: 56 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -19,23 +19,13 @@ This default can be changed via the macro `TAO_PEGTL_NAMESPACE` in `tao/pegtl/co
19
19
20
20
## Contents
21
21
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)
37
25
38
-
### Nothing
26
+
## Default
27
+
28
+
###### `nothing< R >`
39
29
40
30
An action class template that does nothing, simply a *nop* action.
41
31
@@ -46,7 +36,7 @@ template< typename Rule >
46
36
structnothing {};
47
37
```
48
38
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.
50
40
51
41
```c++
52
42
template< typename Rule >
@@ -57,17 +47,48 @@ struct my_action
57
47
// that define static apply() or apply0() functions.
58
48
```
59
49
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`
61
57
62
58
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
+
64
79
65
80
### Add Guard
66
81
add_guard
67
82
83
+
Publicly derives from [`maybe_nothing`](#maybe-nothing).
84
+
Included via `tao/pegtl/action/add_guard.hpp`.
85
+
68
86
### Add State
69
87
add_state
70
88
89
+
Publicly derives from [`maybe_nothing`](#maybe-nothing).
90
+
Included via `tao/pegtl/action/add_state.hpp`.
91
+
71
92
### Change Action
72
93
73
94
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
115
136
Publicly derives from [`maybe_nothing`](#maybe-nothing).
116
137
Included via `tao/pegtl/action/enable_action.hpp`.
117
138
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
130
140
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`.
Copy file name to clipboardExpand all lines: doc/Development.md
+15-2Lines changed: 15 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
# Development
2
2
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.
4
5
5
6
6
7
## C++ Standard
@@ -15,7 +16,7 @@ Version 3.x of the PEGTL requires at least C++17.
15
16
16
17
Version 4.x of the PEGTL requires at least C++17.
17
18
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.
19
20
20
21
21
22
## C++ Features
@@ -30,6 +31,7 @@ Version 5.x of the PEGTL will make the jump to C++20 or newer.
30
31
* Keep an open eye for opportunities to use C++20 `[[likely]]` and `[[unlikely]]`.
31
32
* Keep an open eye for opportunities to use C++20 `constinit` and `consteval`, and
32
33
* 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!
33
35
* Keep an open eye for opportunities to use the extended CTAD facilities from C++20.
34
36
* Keep an open eye for opportunities to use class types as non-type template parameters.
35
37
* 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.
56
58
* Investigate the use of ("stackful") coroutines for parsing from a network socket, and
57
59
* investigate whether this can also be used for incremental parsing that keeps everything.
58
60
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
+
59
72
---
60
73
61
74
This document is part of the [PEGTL](https://github.com/taocpp/PEGTL).
Copy file name to clipboardExpand all lines: doc/Getting-Started.md
+15-15Lines changed: 15 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,6 @@
1
1
# Getting Started
2
2
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`.
5
4
6
5
```c++
7
6
#include<string>
@@ -50,8 +49,8 @@ namespace hello
50
49
template<>
51
50
struct action< name >
52
51
{
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 )
55
54
{
56
55
v = in.string();
57
56
}
@@ -61,21 +60,22 @@ namespace hello
61
60
62
61
intmain( int argc, char* argv[] )
63
62
{
64
-
if( argc != 2 ) return 1;
65
-
63
+
if( argc < 2 ) {
64
+
return 1;
65
+
}
66
66
// Start a parsing run of argv[1] with the string
67
67
// variable 'name' as additional argument that will
68
68
// be passed to all called actions, including the
69
69
// one we attached to the 'name' rule above.
70
70
71
71
std::string name;
72
72
pegtl::argv_input in( argv, 1 );
73
-
if( pegtl::parse< hello::grammar, hello::action >( in, name ) ) {
@@ -126,7 +126,7 @@ Beyond these standard combinators the PEGTL contains a [large number of addition
126
126
127
127
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, ...
128
128
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.
130
130
131
131
## Grammar Analysis
132
132
@@ -141,7 +141,8 @@ It is best practice to create a separate dedicated program that does nothing els
141
141
#include <tao/pegtl.hpp>
142
142
#include <tao/pegtl/analyze.hpp>
143
143
144
-
// This example uses the included JSON grammar
144
+
// For this example we use the included JSON grammar.
0 commit comments