rugnux: read mmCIF models with --model, and say when a model could not be used

--model called gemmi::read_pdb unconditionally, so a coordinate file in mmCIF -
which is how the PDB serves coordinates by default - was refused outright:

  Model validation: cannot read model 6G8A.cif:
  Incorrect file format (perhaps it is cif not pdb?)

Worse than the refusal was what followed it. ValidateAgainstModel logged,
returned an empty result, and the run went on to finish with exit code 0, no
R-free, no maps and nothing in the report - indistinguishable from a run that was
never given --model at all. A script that passed a .cif, checked the exit code
and grepped for R-free simply got nothing back.

Both read sites now go through read_structure_gz with CoorFormat::Detect, so PDB,
mmCIF and mmJSON are all read, gzipped or not, and the format comes from the
file's content rather than from its name. Detect is passed explicitly: GEMMI
otherwise takes the extension and only falls back to the content when it does not
recognise one, and a model arrives named however whoever produced it named it.

That needed a part of GEMMI the vendored subset had trimmed away. mmread.hpp was
already here but its CIF parser was not, so this restores what upstream GEMMI
ships: read_cif/mmcif/json/mmread_gz, plus GEMMI's own copies of PEGTL (MIT,
Colin Hirsch and Daniel Frey; 155 headers, 672 kB) and sajson (MIT, Chad Austin;
one header). Both are listed in THIRD_PARTY_NOTICES.md with their own licence
texts, PEGTL's collected by COLLECT.sh and sajson's kept by hand, its terms being
a comment block rather than a file. json.cpp carries a one-line change: upstream
keeps sajson at the root of its repository, outside the include tree this subset
copies, so the include points at where the other bundled headers live.

ModelValidationResult gains failure_reason, and a model that was asked for and
could not be used now reaches the results report as

  WARNING: Model validation did not run: model bogus.pdb has no atoms or no unit cell

in --mode mx and --mode scale alike. The run still succeeds - a merge that is good
is not made bad by a model that was not - but it no longer does so quietly.

One log line was making a claim it could not support: the indexing-ambiguity
message said the ambiguity was "resolved against the supplied model" while being
printed before the model is read, so it announced a resolution that a failed model
never performed. It now says the model will be used; the reference branch, where
the work really has already happened, keeps the past tense.

Verified on the rotation test dataset with a deposited mmCIF, the same file
gzipped, an mmCIF under a .pdb name, a PDB, and an unreadable file.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WmryXe8ASbNi632sUMfsa
This commit is contained in:
2026-08-27 22:09:51 +02:00
committed by leonarski_f
co-authored by Claude Opus 5
parent e4dce1d778
commit 18d3f55325
174 changed files with 13550 additions and 15 deletions
+2
View File
@@ -48,6 +48,8 @@ These are copied into the source tree (see the path) rather than fetched.
| [LZ4](https://github.com/lz4/lz4) | `compression/lz4/` | Yann Collet | BSD-2-Clause | [lz4.txt](licenses/lz4.txt) |
| [HLS arbitrary-precision types](https://github.com/Xilinx/HLS_arbitrary_Precision_Types) | `fpga/include/` | Xilinx, Inc. | Apache-2.0 | [xilinx-hls-headers.txt](licenses/xilinx-hls-headers.txt) |
| [GEMMI](https://github.com/project-gemmi/gemmi) | `gemmi_gph/` | Global Phasing Ltd. | MPL-2.0 | [gemmi.txt](licenses/gemmi.txt) |
| [PEGTL](https://github.com/taocpp/PEGTL) | `gemmi_gph/gemmi/third_party/tao/` | Dr. Colin Hirsch and Daniel Frey | MIT | [pegtl.txt](licenses/pegtl.txt) |
| [sajson](https://github.com/chadaustin/sajson) | `gemmi_gph/gemmi/third_party/sajson.h` | Chad Austin | MIT | [sajson.txt](licenses/sajson.txt) |
| [traccc (ACTS)](https://github.com/acts-project/traccc) | `image_analysis/spot_finding/StrongPixelSet.cpp`, `SpotExtractorGPU.cu` | CERN, for the benefit of the ACTS project | MPL-2.0 | [traccc.txt](licenses/traccc.txt) |
| [xbflash.qspi](https://github.com/Xilinx/XRT) | `tools/xbflash.qspi/` | Xilinx / AMD | Apache-2.0 | [xbflash-qspi.txt](licenses/xbflash-qspi.txt) |
| [wingetopt](https://github.com/alex85k/wingetopt) | `tools/wingetopt/` | Todd C. Miller; The NetBSD Foundation | ISC AND BSD-2-Clause | [wingetopt.txt](licenses/wingetopt.txt) |
+2
View File
@@ -4,6 +4,8 @@
This is an UNSTABLE release. It includes many experimental features, as well as many AI generated fixes. We recommend using rc.152 for production use.
* The rugnux results report records how the run was invoked, what it cost and what it ran on: `COMMAND_LINE=` is the command line as one shell-ready line, `WALL_TIME=` the whole invocation in seconds, and `GPU_COUNT=` / `GPU=` how many GPUs were visible and which ones. The total wall time is also printed on stdout, next to the processing time it is slightly larger than.
* `rugnux --model` reads an mmCIF coordinate file as well as a PDB one, gzipped or not, taking the format from the file's content rather than its name. A `.cif` model was rejected before, and the run then finished successfully with no R-free and no maps.
* A model `rugnux --model` cannot use - unreadable, or without atoms, a unit cell or a usable space group - is reported as a `WARNING:` line in the results report instead of only in the log, so a run that was asked to validate and could not is no longer indistinguishable from one that was never asked.
* rugnux says which GPUs it can see before it starts processing, so a machine that turns out to have none - a driver mismatch, a leftover `CUDA_VISIBLE_DEVICES` - is noticed while there is still time to stop rather than after a run that took far longer than it should have.
* rugnux writes `<prefix>_unmerged.mtz` on every run that produces an output prefix, instead of only when asked for it with `--export-unmerged`. It is written in `--mode mx` and `--mode scale` and with `--no-merge`, alongside the merged files and replacing none of them. `--no-export-unmerged` turns it off.
* `/start` asks the writer whether the run can be written before the detector is armed, so a run whose output file already exists, or whose output directory cannot be created, is refused up front with the writer's own message instead of failing once the detector is running. This needs the TCP image stream or the built-in HDF5 writer; the ZeroMQ stream has no way to answer and is unchanged.
+9 -2
View File
@@ -761,13 +761,20 @@ The algorithms behind both are in
## Validating against a model (`rugnux --model`)
Given a PDB atomic model of the same structure, `--model model.pdb` scales the model structure
Given an atomic model of the same structure, `--model model.pdb` scales the model structure
factors to the merged amplitudes — fitting a flat bulk-solvent contribution and an overall
anisotropic *B* — and reports **R-work / R-free** and the mean 2Fo-Fc density at the atom centres.
It also writes `<prefix>_2fofc.ccp4`, `<prefix>_fofc.ccp4` and `<prefix>_maps.mtz` next to the
merged reflections. Nothing about the model is refined; it is only re-fractionalized into the data
cell, so a deposited model with a slightly different cell still lines up.
The model may be **PDB or mmCIF**, gzipped or not, and the format is taken from the file's own
content rather than from its name — a model downloaded as `.cif`, `.pdb`, `.ent` or with no useful
extension at all is read the same way. A model that cannot be read, or that has no atoms, no unit
cell or no usable space group, does not fail the run: it is logged, and the results report carries a
`WARNING: Model validation did not run: …` line, so a run that silently produced no R-free and no
maps cannot be mistaken for one that was never given `--model`.
It is a *data-quality lens*, independent of the internal statistics: R-free measures the merged
intensities against external truth, where CC1/2 and R<sub>meas</sub> only measure them against
themselves. It also settles the two things merged intensities alone cannot: the enantiomorph (data
@@ -990,7 +997,7 @@ Scaling and merging:
| `--scaling-iterations <num>` | Scaling iterations with no reference data (default: 3) |
| `-z, --reference-mtz <file>` | Reference MTZ of the same crystal form: fixes the space group and cell, resolves the [indexing ambiguity](#the-indexing-ambiguity), hands over the R-free set and reports CC<sub>ref</sub>. Not a scale anchor |
| `--reference-column <label>` | Reference MTZ column to use (default: auto — F-model, else IMEAN/I/…) |
| `--model <file.pdb>` | Validate the merged intensities against this atomic model — R-work / R-free and maps (see [Validating against a model](#validating-against-a-model-rugnux-model)). It also settles the frame the reflections are written in: the enantiomorph, and the [indexing ambiguity](#the-indexing-ambiguity) where no `-z` did. For serial stills given `-C` / `-S`, the model's structure factors become the per-image reference |
| `--model <file>` | Validate the merged intensities against this atomic model (PDB or mmCIF, gzipped or not; the format is taken from the file's content) — R-work / R-free and maps (see [Validating against a model](#validating-against-a-model-rugnux-model)). It also settles the frame the reflections are written in: the enantiomorph, and the [indexing ambiguity](#the-indexing-ambiguity) where no `-z` did. For serial stills given `-C` / `-S`, the model's structure factors become the per-image reference |
| `--write-process-h5` | Also write the (large) `_process.h5` when merging (default: only `.mtz`/`.cif`) |
| `--no-export-unmerged` | Do not write `<prefix>_unmerged.mtz`. It is written by default: an unmerged MTZ (POINTLESS column layout) of the integrated observations, for aimless / pointless / careless. Rotation partials are summed into one full per reflection. Intensities carry the Lorentz-polarization factor and nothing else — the partiality is not divided out and the per-image scale is not applied. Written in `--mode mx` and `--mode scale`, and with `--no-merge`. See [The unmerged export](#the-unmerged-export) |
| `--export-unmerged-partials` | Also write `<prefix>_unmerged_partials.mtz`, the same observations with each partial as its own row (one batch per image) for the reading program to sum |
+6
View File
@@ -1,9 +1,15 @@
# Vendored subset of GEMMI (Global Phasing), v0.7.5. A single static `gemmi` target with all
# the compiled sources: symmetry/MTZ/XDS I/O plus the atomic-model reading and structure-factor /
# bulk-solvent / map machinery (pdb, ccp4, calculate, eig3, resinfo, polyheur).
#
# read_cif/mmcif/json/mmread_gz are the mmCIF and mmJSON side of coordinate reading, so `--model`
# takes a .cif as readily as a .pdb. They bring GEMMI's own copy of the PEGTL parser with them
# (gemmi/third_party/tao, MIT, Colin Hirsch and Daniel Frey) - header-only, and included from
# gemmi/cif.hpp exactly where upstream GEMMI expects it.
ADD_LIBRARY(gemmi STATIC
symmetry.cpp gz.cpp mtz.cpp sprintf.cpp xds_ascii.cpp
pdb.cpp resinfo.cpp polyheur.cpp calculate.cpp eig3.cpp ccp4.cpp
read_cif.cpp mmcif.cpp json.cpp mmread_gz.cpp
gemmi/cellred.hpp
gemmi/symmetry.hpp
gemmi/fail.hpp
File diff suppressed because it is too large Load Diff
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2007-2018 Dr. Colin Hirsch and Daniel Frey
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+11
View File
@@ -0,0 +1,11 @@
This directory contains files from PEGTL 2.8.3:
LICENSE and include/tao/pegtl* except contrib/ and file_mapper_win32.hpp
with minor modifications (in position.hpp, input_error.hpp, file_input.hpp):
- changed formatting of error messages,
- using std::system_error instead of pegtl::input_error.
- avoiding mmap on Windows (until we upgrade to PEGTL v3),
because PEGTL v2 API doesn't support Unicode filenames
(and also, including <windows.h> has side-effects)
PEGTL can be updated to v3 only when gemmi drops support for C++11/14.
https://github.com/project-gemmi/gemmi/issues/212
+53
View File
@@ -0,0 +1,53 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_HPP
#define TAO_PEGTL_HPP
#include "pegtl/config.hpp"
#include "pegtl/version.hpp"
#include "pegtl/parse.hpp"
#include "pegtl/ascii.hpp"
#include "pegtl/rules.hpp"
#include "pegtl/uint16.hpp"
#include "pegtl/uint32.hpp"
#include "pegtl/uint64.hpp"
#include "pegtl/uint8.hpp"
#include "pegtl/utf16.hpp"
#include "pegtl/utf32.hpp"
#include "pegtl/utf8.hpp"
#include "pegtl/argv_input.hpp"
#include "pegtl/buffer_input.hpp"
#include "pegtl/cstream_input.hpp"
#include "pegtl/istream_input.hpp"
#include "pegtl/memory_input.hpp"
#include "pegtl/read_input.hpp"
#include "pegtl/string_input.hpp"
// this has to be included *after* the above inputs,
// otherwise the amalgamated header will not work!
#include "pegtl/file_input.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/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"
// The following are not included by
// default because they include <iostream>.
// #include "pegtl/analyze.hpp"
#endif
@@ -0,0 +1,135 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_ANALYSIS_ANALYZE_CYCLES_HPP
#define TAO_PEGTL_ANALYSIS_ANALYZE_CYCLES_HPP
#include <cassert>
#include <map>
#include <set>
#include <stdexcept>
#include <iostream>
#include <utility>
#include "../config.hpp"
#include "grammar_info.hpp"
#include "insert_guard.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace analysis
{
class analyze_cycles_impl
{
protected:
explicit analyze_cycles_impl( const bool verbose ) noexcept
: m_verbose( verbose ),
m_problems( 0 )
{
}
const bool m_verbose;
unsigned m_problems;
grammar_info m_info;
std::set< std::string > m_stack;
std::map< std::string, bool > m_cache;
std::map< std::string, bool > m_results;
std::map< std::string, rule_info >::const_iterator find( const std::string& name ) const noexcept
{
const auto iter = m_info.map.find( name );
assert( iter != m_info.map.end() );
return iter;
}
bool work( const std::map< std::string, rule_info >::const_iterator& start, const bool accum )
{
const auto j = m_cache.find( start->first );
if( j != m_cache.end() ) {
return j->second;
}
if( const auto g = make_insert_guard( m_stack, start->first ) ) {
switch( start->second.type ) {
case rule_type::any: {
bool a = false;
for( const auto& r : start->second.rules ) {
a = a || work( find( r ), accum || a );
}
return m_cache[ start->first ] = true;
}
case rule_type::opt: {
bool a = false;
for( const auto& r : start->second.rules ) {
a = a || work( find( r ), accum || a );
}
return m_cache[ start->first ] = false;
}
case rule_type::seq: {
bool a = false;
for( const auto& r : start->second.rules ) {
a = a || work( find( r ), accum || a );
}
return m_cache[ start->first ] = a;
}
case rule_type::sor: {
bool a = true;
for( const auto& r : start->second.rules ) {
a = a && work( find( r ), accum );
}
return m_cache[ start->first ] = a;
}
}
throw std::logic_error( "code should be unreachable: invalid rule_type value" ); // NOLINT, LCOV_EXCL_LINE
}
if( !accum ) {
++m_problems;
if( m_verbose ) {
std::cout << "problem: cycle without progress detected at rule class " << start->first << std::endl; // LCOV_EXCL_LINE
}
}
return m_cache[ start->first ] = accum;
}
};
template< typename Grammar >
class analyze_cycles
: private analyze_cycles_impl
{
public:
explicit analyze_cycles( const bool verbose )
: analyze_cycles_impl( verbose )
{
Grammar::analyze_t::template insert< Grammar >( m_info );
}
std::size_t problems()
{
for( auto i = m_info.map.begin(); i != m_info.map.end(); ++i ) {
m_results[ i->first ] = work( i, false );
m_cache.clear();
}
return m_problems;
}
template< typename Rule >
bool consumes() const noexcept
{
const auto i = m_results.find( internal::demangle< Rule >() );
assert( i != m_results.end() );
return i->second;
}
};
} // namespace analysis
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,31 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_ANALYSIS_COUNTED_HPP
#define TAO_PEGTL_ANALYSIS_COUNTED_HPP
#include "../config.hpp"
#include <cstddef>
#include "generic.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace analysis
{
template< rule_type Type, std::size_t Count, typename... Rules >
struct counted
: generic< ( Count != 0 ) ? Type : rule_type::opt, Rules... >
{
};
} // namespace analysis
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,43 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_ANALYSIS_GENERIC_HPP
#define TAO_PEGTL_ANALYSIS_GENERIC_HPP
#include "../config.hpp"
#include "grammar_info.hpp"
#include "rule_type.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace analysis
{
template< rule_type Type, typename... Rules >
struct generic
{
template< typename Name >
static std::string insert( grammar_info& g )
{
const auto r = g.insert< Name >( Type );
if( r.second ) {
#ifdef __cpp_fold_expressions
( r.first->second.rules.push_back( Rules::analyze_t::template insert< Rules >( g ) ), ... );
#else
using swallow = bool[];
(void)swallow{ ( r.first->second.rules.push_back( Rules::analyze_t::template insert< Rules >( g ) ), true )..., true };
#endif
}
return r.first->first;
}
};
} // namespace analysis
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,40 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_ANALYSIS_GRAMMAR_INFO_HPP
#define TAO_PEGTL_ANALYSIS_GRAMMAR_INFO_HPP
#include <map>
#include <string>
#include <utility>
#include "../config.hpp"
#include "../internal/demangle.hpp"
#include "rule_info.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace analysis
{
struct grammar_info
{
using map_t = std::map< std::string, rule_info >;
map_t map;
template< typename Name >
std::pair< map_t::iterator, bool > insert( const rule_type type )
{
return map.insert( map_t::value_type( internal::demangle< Name >(), rule_info( type ) ) );
}
};
} // namespace analysis
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,68 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_ANALYSIS_INSERT_GUARD_HPP
#define TAO_PEGTL_ANALYSIS_INSERT_GUARD_HPP
#include <utility>
#include "../config.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace analysis
{
template< typename C >
class insert_guard
{
public:
insert_guard( C& container, const typename C::value_type& value )
: m_i( container.insert( value ) ),
m_c( &container )
{
}
insert_guard( const insert_guard& ) = delete;
insert_guard( insert_guard&& other ) noexcept
: m_i( other.m_i ),
m_c( other.m_c )
{
other.m_c = nullptr;
}
~insert_guard()
{
if( m_c && m_i.second ) {
m_c->erase( m_i.first );
}
}
void operator=( const insert_guard& ) = delete;
void operator=( insert_guard&& ) = delete;
explicit operator bool() const noexcept
{
return m_i.second;
}
private:
const std::pair< typename C::iterator, bool > m_i;
C* m_c;
};
template< typename C >
insert_guard< C > make_insert_guard( C& container, const typename C::value_type& value )
{
return insert_guard< C >( container, value );
}
} // namespace analysis
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,37 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_ANALYSIS_RULE_INFO_HPP
#define TAO_PEGTL_ANALYSIS_RULE_INFO_HPP
#include <string>
#include <vector>
#include "../config.hpp"
#include "rule_type.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace analysis
{
struct rule_info
{
explicit rule_info( const rule_type in_type ) noexcept
: type( in_type )
{
}
rule_type type;
std::vector< std::string > rules;
};
} // namespace analysis
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,35 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_ANALYSIS_RULE_TYPE_HPP
#define TAO_PEGTL_ANALYSIS_RULE_TYPE_HPP
#include "../config.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace analysis
{
enum class rule_type : char
{
any, // Consumption-on-success is always true; assumes bounded repetition of conjunction of sub-rules.
opt, // Consumption-on-success not necessarily true; assumes bounded repetition of conjunction of sub-rules.
seq, // Consumption-on-success depends on consumption of (non-zero bounded repetition of) conjunction of sub-rules.
sor, // Consumption-on-success depends on consumption of (non-zero bounded repetition of) disjunction of sub-rules.
// Compatibility, remove with 3.0.0
ANY = any,
OPT = opt,
SEQ = seq,
SOR = sor
};
} // namespace analysis
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+25
View File
@@ -0,0 +1,25 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_ANALYZE_HPP
#define TAO_PEGTL_ANALYZE_HPP
#include "config.hpp"
#include "analysis/analyze_cycles.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
template< typename Rule >
std::size_t analyze( const bool verbose = true )
{
return analysis::analyze_cycles< Rule >( verbose ).problems();
}
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+27
View File
@@ -0,0 +1,27 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_APPLY_MODE_HPP
#define TAO_PEGTL_APPLY_MODE_HPP
#include "config.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
enum class apply_mode : bool
{
action = true,
nothing = false,
// Compatibility, remove with 3.0.0
ACTION = action,
NOTHING = nothing
};
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+57
View File
@@ -0,0 +1,57 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_ARGV_INPUT_HPP
#define TAO_PEGTL_ARGV_INPUT_HPP
#include <cstddef>
#include <sstream>
#include <string>
#include <utility>
#include "config.hpp"
#include "eol.hpp"
#include "memory_input.hpp"
#include "tracking_mode.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
inline std::string make_argv_source( const std::size_t argn )
{
std::ostringstream os;
os << "argv[" << argn << ']';
return os.str();
}
} // namespace internal
template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf >
struct argv_input
: public memory_input< P, Eol >
{
template< typename T >
argv_input( char** argv, const std::size_t argn, T&& in_source )
: memory_input< P, Eol >( static_cast< const char* >( argv[ argn ] ), std::forward< T >( in_source ) )
{
}
argv_input( char** argv, const std::size_t argn )
: argv_input( argv, argn, internal::make_argv_source( argn ) )
{
}
};
#ifdef __cpp_deduction_guides
template< typename... Ts >
argv_input( Ts&&... )->argv_input<>;
#endif
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+71
View File
@@ -0,0 +1,71 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_ASCII_HPP
#define TAO_PEGTL_ASCII_HPP
#include "config.hpp"
#include "eol.hpp"
#include "internal/always_false.hpp"
#include "internal/result_on_found.hpp"
#include "internal/rules.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
inline namespace ascii
{
// clang-format off
struct alnum : internal::alnum {};
struct alpha : internal::alpha {};
struct any : internal::any< internal::peek_char > {};
struct blank : internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\t' > {};
struct digit : internal::range< internal::result_on_found::success, internal::peek_char, '0', '9' > {};
struct ellipsis : internal::string< '.', '.', '.' > {};
struct eolf : internal::eolf {};
template< char... Cs > struct forty_two : internal::rep< 42, internal::one< internal::result_on_found::success, internal::peek_char, Cs... > > {};
struct identifier_first : internal::identifier_first {};
struct identifier_other : internal::identifier_other {};
struct identifier : internal::identifier {};
template< char... Cs > struct istring : internal::istring< Cs... > {};
template< char... Cs > struct keyword : internal::seq< internal::string< Cs... >, internal::not_at< internal::identifier_other > > {};
struct lower : internal::range< internal::result_on_found::success, internal::peek_char, 'a', 'z' > {};
template< char... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_char, Cs... > {};
template< char Lo, char Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_char, Lo, Hi > {};
struct nul : internal::one< internal::result_on_found::success, internal::peek_char, char( 0 ) > {};
template< char... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_char, Cs... > {};
struct print : internal::range< internal::result_on_found::success, internal::peek_char, char( 32 ), char( 126 ) > {};
template< char Lo, char Hi > struct range : internal::range< internal::result_on_found::success, internal::peek_char, Lo, Hi > {};
template< char... Cs > struct ranges : internal::ranges< internal::peek_char, Cs... > {};
struct seven : internal::range< internal::result_on_found::success, internal::peek_char, char( 0 ), char( 127 ) > {};
struct shebang : internal::if_must< false, internal::string< '#', '!' >, internal::until< internal::eolf > > {};
struct space : internal::one< internal::result_on_found::success, internal::peek_char, ' ', '\n', '\r', '\t', '\v', '\f' > {};
template< char... Cs > struct string : internal::string< Cs... > {};
template< char C > struct three : internal::string< C, C, C > {};
template< char C > struct two : internal::string< C, C > {};
struct upper : internal::range< internal::result_on_found::success, internal::peek_char, 'A', 'Z' > {};
struct xdigit : internal::ranges< internal::peek_char, '0', '9', 'a', 'f', 'A', 'F' > {};
// clang-format on
template<>
struct keyword<>
{
template< typename Input >
static bool match( Input& /*unused*/ ) noexcept
{
static_assert( internal::always_false< Input >::value, "empty keywords not allowed" );
return false;
}
};
} // namespace ascii
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#include "internal/pegtl_string.hpp"
#endif
+222
View File
@@ -0,0 +1,222 @@
// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_BUFFER_INPUT_HPP
#define TAO_PEGTL_BUFFER_INPUT_HPP
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <memory>
#include <stdexcept>
#include <string>
#include "config.hpp"
#include "eol.hpp"
#include "memory_input.hpp"
#include "position.hpp"
#include "tracking_mode.hpp"
#include "internal/action_input.hpp"
#include "internal/bump.hpp"
#include "internal/iterator.hpp"
#include "internal/marker.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
template< typename Reader, typename Eol = eol::lf_crlf, typename Source = std::string, std::size_t Chunk = 64 >
class buffer_input
{
public:
using reader_t = Reader;
using eol_t = Eol;
using source_t = Source;
using iterator_t = internal::iterator;
using action_t = internal::action_input< buffer_input >;
static constexpr std::size_t chunk_size = Chunk;
static constexpr tracking_mode tracking_mode_v = tracking_mode::eager;
template< typename T, typename... As >
buffer_input( T&& in_source, const std::size_t maximum, As&&... as )
: m_reader( std::forward< As >( as )... ),
m_maximum( maximum + Chunk ),
m_buffer( new char[ maximum + Chunk ] ),
m_current( m_buffer.get() ),
m_end( m_buffer.get() ),
m_source( std::forward< T >( in_source ) )
{
static_assert( Chunk != 0, "zero chunk size not implemented" );
assert( m_maximum > maximum ); // Catches overflow; change to >= when zero chunk size is implemented.
}
buffer_input( const buffer_input& ) = delete;
buffer_input( buffer_input&& ) = delete;
~buffer_input() = default;
void operator=( const buffer_input& ) = delete;
void operator=( buffer_input&& ) = delete;
bool empty()
{
require( 1 );
return m_current.data == m_end;
}
std::size_t size( const std::size_t amount )
{
require( amount );
return buffer_occupied();
}
const char* current() const noexcept
{
return m_current.data;
}
const char* end( const std::size_t amount )
{
require( amount );
return m_end;
}
std::size_t byte() const noexcept
{
return m_current.byte;
}
std::size_t line() const noexcept
{
return m_current.line;
}
std::size_t byte_in_line() const noexcept
{
return m_current.byte_in_line;
}
const Source& source() const noexcept
{
return m_source;
}
char peek_char( const std::size_t offset = 0 ) const noexcept
{
return m_current.data[ offset ];
}
std::uint8_t peek_uint8( const std::size_t offset = 0 ) const noexcept
{
return static_cast< std::uint8_t >( peek_char( offset ) );
}
// Compatibility, remove with 3.0.0
std::uint8_t peek_byte( const std::size_t offset = 0 ) const noexcept
{
return static_cast< std::uint8_t >( peek_char( offset ) );
}
void bump( const std::size_t in_count = 1 ) noexcept
{
internal::bump( m_current, in_count, Eol::ch );
}
void bump_in_this_line( const std::size_t in_count = 1 ) noexcept
{
internal::bump_in_this_line( m_current, in_count );
}
void bump_to_next_line( const std::size_t in_count = 1 ) noexcept
{
internal::bump_to_next_line( m_current, in_count );
}
void discard() noexcept
{
if( m_current.data > m_buffer.get() + Chunk ) {
const auto s = m_end - m_current.data;
std::memmove( m_buffer.get(), m_current.data, s );
m_current.data = m_buffer.get();
m_end = m_buffer.get() + s;
}
}
void require( const std::size_t amount )
{
if( m_current.data + amount <= m_end ) {
return;
}
if( m_current.data + amount > m_buffer.get() + m_maximum ) {
throw std::overflow_error( "require beyond end of buffer" );
}
if( const auto r = m_reader( m_end, ( std::min )( buffer_free_after_end(), ( std::max )( amount - buffer_occupied(), Chunk ) ) ) ) {
m_end += r;
}
}
template< rewind_mode M >
internal::marker< iterator_t, M > mark() noexcept
{
return internal::marker< iterator_t, M >( m_current );
}
TAO_PEGTL_NAMESPACE::position position( const iterator_t& it ) const
{
return TAO_PEGTL_NAMESPACE::position( it, m_source );
}
TAO_PEGTL_NAMESPACE::position position() const
{
return position( m_current );
}
const iterator_t& iterator() const noexcept
{
return m_current;
}
std::size_t buffer_capacity() const noexcept
{
return m_maximum;
}
std::size_t buffer_occupied() const noexcept
{
assert( m_end >= m_current.data );
return std::size_t( m_end - m_current.data );
}
std::size_t buffer_free_before_current() const noexcept
{
assert( m_current.data >= m_buffer.get() );
return std::size_t( m_current.data - m_buffer.get() );
}
std::size_t buffer_free_after_end() const noexcept
{
assert( m_buffer.get() + m_maximum >= m_end );
return std::size_t( m_buffer.get() + m_maximum - m_end );
}
private:
Reader m_reader;
std::size_t m_maximum;
std::unique_ptr< char[] > m_buffer; // NOLINT
iterator_t m_current;
char* m_end;
const Source m_source;
};
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+42
View File
@@ -0,0 +1,42 @@
// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_CHANGE_ACTION_HPP
#define TAO_PEGTL_CHANGE_ACTION_HPP
#include <type_traits>
#include "apply_mode.hpp"
#include "config.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
template< template< typename... > class NewAction >
struct change_action
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
static_assert( !std::is_same< Action< void >, NewAction< void > >::value, "old and new action class templates are identical" );
return Control< Rule >::template match< A, M, NewAction, Control >( in, st... );
}
};
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,73 @@
// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_CHANGE_ACTION_AND_STATE_HPP
#define TAO_PEGTL_CHANGE_ACTION_AND_STATE_HPP
#include <type_traits>
#include "apply_mode.hpp"
#include "config.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
template< template< typename... > class NewAction, typename NewState >
struct change_action_and_state
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static auto match( Input& in, States&&... st )
-> typename std::enable_if< ( A == apply_mode::action ), bool >::type
{
static_assert( !std::is_same< Action< void >, NewAction< void > >::value, "old and new action class templates are identical" );
NewState s( static_cast< const Input& >( in ), st... );
if( Control< Rule >::template match< A, M, NewAction, Control >( in, s ) ) {
Action< Rule >::success( static_cast< const Input& >( in ), s, st... );
return true;
}
return false;
}
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States,
int = 1 >
static auto match( Input& in, States&&... st )
-> typename std::enable_if< ( A == apply_mode::nothing ), bool >::type
{
static_assert( !std::is_same< Action< void >, NewAction< void > >::value, "old and new action class templates are identical" );
NewState s( static_cast< const Input& >( in ), st... );
return Control< Rule >::template match< A, M, NewAction, Control >( in, s );
}
template< typename Input,
typename... States >
static void success( const Input& in, NewState& s, States&&... st ) noexcept( noexcept( s.success( in, st... ) ) )
{
s.success( in, st... );
}
};
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,83 @@
// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_CHANGE_ACTION_AND_STATES_HPP
#define TAO_PEGTL_CHANGE_ACTION_AND_STATES_HPP
#include <tuple>
#include <type_traits>
#include "apply_mode.hpp"
#include "config.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
#include "internal/integer_sequence.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
template< template< typename... > class NewAction, typename... NewStates >
struct change_action_and_states
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
std::size_t... Ns,
typename Input,
typename... States >
static bool match( TAO_PEGTL_NAMESPACE::internal::index_sequence< Ns... >, Input& in, States&&... st )
{
auto t = std::tie( st... );
if( Control< Rule >::template match< A, M, NewAction, Control >( in, std::get< Ns >( t )... ) ) {
Action< Rule >::success( static_cast< const Input& >( in ), st... );
return true;
}
return false;
}
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static auto match( Input& in, States&&... st )
-> typename std::enable_if< ( A == apply_mode::action ), bool >::type
{
static_assert( !std::is_same< Action< void >, NewAction< void > >::value, "old and new action class templates are identical" );
return match< Rule, A, M, Action, Control >( TAO_PEGTL_NAMESPACE::internal::index_sequence_for< NewStates... >(), in, NewStates()..., st... );
}
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States,
int = 1 >
static auto match( Input& in, States&&... /*unused*/ )
-> typename std::enable_if< ( A == apply_mode::nothing ), bool >::type
{
static_assert( !std::is_same< Action< void >, NewAction< void > >::value, "old and new action class templates are identical" );
return Control< Rule >::template match< A, M, NewAction, Control >( in, NewStates()... );
}
};
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,40 @@
// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_CHANGE_CONTROL_HPP
#define TAO_PEGTL_CHANGE_CONTROL_HPP
#include "apply_mode.hpp"
#include "config.hpp"
#include "match.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
template< template< typename... > class NewControl >
struct change_control
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
return TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, NewControl >( in, st... );
}
};
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+72
View File
@@ -0,0 +1,72 @@
// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_CHANGE_STATE_HPP
#define TAO_PEGTL_CHANGE_STATE_HPP
#include <type_traits>
#include "apply_mode.hpp"
#include "config.hpp"
#include "match.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
template< typename NewState >
struct change_state
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static auto match( Input& in, States&&... st )
-> typename std::enable_if< ( A == apply_mode::action ), bool >::type
{
NewState s( static_cast< const Input& >( in ), st... );
if( TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, s ) ) {
Action< Rule >::success( static_cast< const Input& >( in ), s, st... );
return true;
}
return false;
}
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States,
int = 1 >
static auto match( Input& in, States&&... st )
-> typename std::enable_if< ( A == apply_mode::nothing ), bool >::type
{
NewState s( static_cast< const Input& >( in ), st... );
return TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, s );
}
template< typename Input,
typename... States >
static void success( const Input& in, NewState& s, States&&... st ) noexcept( noexcept( s.success( in, st... ) ) )
{
s.success( in, st... );
}
};
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+81
View File
@@ -0,0 +1,81 @@
// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_CHANGE_STATES_HPP
#define TAO_PEGTL_CHANGE_STATES_HPP
#include <tuple>
#include "apply_mode.hpp"
#include "config.hpp"
#include "match.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
#include "internal/integer_sequence.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
template< typename... NewStates >
struct change_states
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
std::size_t... Ns,
typename Input,
typename... States >
static bool match( TAO_PEGTL_NAMESPACE::internal::index_sequence< Ns... >, Input& in, States&&... st )
{
auto t = std::tie( st... );
if( TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, std::get< Ns >( t )... ) ) {
Action< Rule >::success( static_cast< const Input& >( in ), st... );
return true;
}
return false;
}
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static auto match( Input& in, States&&... st )
-> typename std::enable_if< ( A == apply_mode::action ), bool >::type
{
return match< Rule, A, M, Action, Control >( TAO_PEGTL_NAMESPACE::internal::index_sequence_for< NewStates... >(), in, NewStates()..., st... );
}
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States,
int = 1 >
static auto match( Input& in, States&&... /*unused*/ )
-> typename std::enable_if< ( A == apply_mode::nothing ), bool >::type
{
return TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, NewStates()... );
}
};
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+20
View File
@@ -0,0 +1,20 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_CONFIG_HPP
#define TAO_PEGTL_CONFIG_HPP
// Compatibility, remove with 3.0.0
#ifdef TAOCPP_PEGTL_NAMESPACE
#define TAO_PEGTL_NAMESPACE TAOCPP_PEGTL_NAMESPACE
#endif
#ifndef TAO_PEGTL_NAMESPACE
#define TAO_PEGTL_NAMESPACE pegtl
#endif
// Enable some improvements to the readability of
// demangled type names under some circumstances.
// #define TAO_PEGTL_PRETTY_DEMANGLE
#endif
+39
View File
@@ -0,0 +1,39 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_CSTREAM_INPUT_HPP
#define TAO_PEGTL_CSTREAM_INPUT_HPP
#include <cstdio>
#include "buffer_input.hpp"
#include "config.hpp"
#include "eol.hpp"
#include "internal/cstream_reader.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
template< typename Eol = eol::lf_crlf, std::size_t Chunk = 64 >
struct cstream_input
: buffer_input< internal::cstream_reader, Eol, std::string, Chunk >
{
template< typename T >
cstream_input( std::FILE* in_stream, const std::size_t in_maximum, T&& in_source )
: buffer_input< internal::cstream_reader, Eol, std::string, Chunk >( std::forward< T >( in_source ), in_maximum, in_stream )
{
}
};
#ifdef __cpp_deduction_guides
template< typename... Ts >
cstream_input( Ts&&... )->cstream_input<>;
#endif
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,39 @@
// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_DISABLE_ACTION_HPP
#define TAO_PEGTL_DISABLE_ACTION_HPP
#include "apply_mode.hpp"
#include "config.hpp"
#include "match.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
struct disable_action
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
return TAO_PEGTL_NAMESPACE::match< Rule, apply_mode::nothing, M, Action, Control >( in, st... );
}
};
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+41
View File
@@ -0,0 +1,41 @@
// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_DISCARD_INPUT_HPP
#define TAO_PEGTL_DISCARD_INPUT_HPP
#include "apply_mode.hpp"
#include "config.hpp"
#include "match.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
struct discard_input
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
const bool result = TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... );
in.discard();
return result;
}
};
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,43 @@
// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_DISCARD_INPUT_ON_FAILURE_HPP
#define TAO_PEGTL_DISCARD_INPUT_ON_FAILURE_HPP
#include "apply_mode.hpp"
#include "config.hpp"
#include "match.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
struct discard_input_on_failure
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
const bool result = TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... );
if( !result ) {
in.discard();
}
return result;
}
};
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,43 @@
// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_DISCARD_INPUT_ON_SUCCESS_HPP
#define TAO_PEGTL_DISCARD_INPUT_ON_SUCCESS_HPP
#include "apply_mode.hpp"
#include "config.hpp"
#include "match.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
struct discard_input_on_success
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
const bool result = TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... );
if( result ) {
in.discard();
}
return result;
}
};
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+39
View File
@@ -0,0 +1,39 @@
// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_ENABLE_ACTION_HPP
#define TAO_PEGTL_ENABLE_ACTION_HPP
#include "apply_mode.hpp"
#include "config.hpp"
#include "match.hpp"
#include "nothing.hpp"
#include "rewind_mode.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
struct enable_action
: maybe_nothing
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
return TAO_PEGTL_NAMESPACE::match< Rule, apply_mode::action, M, Action, Control >( in, st... );
}
};
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+41
View File
@@ -0,0 +1,41 @@
// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_EOL_HPP
#define TAO_PEGTL_EOL_HPP
#include "config.hpp"
#include "internal/eol.hpp"
#include "internal/cr_crlf_eol.hpp"
#include "internal/cr_eol.hpp"
#include "internal/crlf_eol.hpp"
#include "internal/lf_crlf_eol.hpp"
#include "internal/lf_eol.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
inline namespace ascii
{
// this is both a rule and a pseudo-namespace for eol::cr, ...
struct eol : internal::eol
{
// clang-format off
struct cr : internal::cr_eol {};
struct cr_crlf : internal::cr_crlf_eol {};
struct crlf : internal::crlf_eol {};
struct lf : internal::lf_eol {};
struct lf_crlf : internal::lf_crlf_eol {};
// clang-format on
};
} // namespace ascii
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+22
View File
@@ -0,0 +1,22 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_EOL_PAIR_HPP
#define TAO_PEGTL_EOL_PAIR_HPP
#include <cstddef>
#include <utility>
#include "config.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
using eol_pair = std::pair< bool, std::size_t >;
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+50
View File
@@ -0,0 +1,50 @@
// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_FILE_INPUT_HPP
#define TAO_PEGTL_FILE_INPUT_HPP
#include "config.hpp"
#include "eol.hpp"
#include "tracking_mode.hpp"
#if defined( __unix__ ) || ( defined( __APPLE__ ) && defined( __MACH__ ) )
#include <unistd.h> // Required for _POSIX_MAPPED_FILES
#endif
#if defined( _POSIX_MAPPED_FILES )
#include "mmap_input.hpp"
#else
#include "read_input.hpp"
#endif
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
#if defined( _POSIX_MAPPED_FILES )
template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf >
struct file_input
: mmap_input< P, Eol >
{
using mmap_input< P, Eol >::mmap_input;
};
#else
template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf >
struct file_input
: read_input< P, Eol >
{
using read_input< P, Eol >::read_input;
};
#endif
#ifdef __cpp_deduction_guides
template< typename... Ts >
explicit file_input( Ts&&... )->file_input<>;
#endif
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+57
View File
@@ -0,0 +1,57 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INPUT_ERROR_HPP
#define TAO_PEGTL_INPUT_ERROR_HPP
#include <cerrno>
#include <sstream>
#include <stdexcept>
#include <system_error>
#include "config.hpp"
// In PEGTL 3 input_error was changed to std::system_error and
// std::filesystem::filesystem_error (the latter is derived from the former).
// Here we half-backported it - input_error is replaced with system_error.
#if 0
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
struct input_error
: std::runtime_error
{
input_error( const std::string& message, const int in_errorno )
: std::runtime_error( message ),
errorno( in_errorno )
{
}
int errorno;
};
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
#define TAO_PEGTL_INTERNAL_UNWRAP( ... ) __VA_ARGS__
#define TAO_PEGTL_THROW_INPUT_ERROR( MESSAGE ) \
do { \
const int errorno = errno; \
std::ostringstream oss; \
oss << TAO_PEGTL_INTERNAL_UNWRAP( MESSAGE ); \
throw std::system_error( errorno, std::system_category(), oss.str() ); \
} while( false )
#define TAO_PEGTL_THROW_INPUT_WIN32_ERROR( MESSAGE ) \
do { \
const int errorno = GetLastError(); \
std::ostringstream oss; \
oss << TAO_PEGTL_INTERNAL_UNWRAP( MESSAGE ); \
throw std::system_error( errorno, std::system_category(), oss.str() ); \
} while( false )
#endif
@@ -0,0 +1,59 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_ACTION_HPP
#define TAO_PEGTL_INTERNAL_ACTION_HPP
#include "../config.hpp"
#include "seq.hpp"
#include "skip_control.hpp"
#include "../apply_mode.hpp"
#include "../rewind_mode.hpp"
#include "../analysis/generic.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< template< typename... > class Action, typename... Rules >
struct action
: action< Action, seq< Rules... > >
{
};
template< template< typename... > class Action, typename Rule >
struct action< Action, Rule >
{
using analyze_t = analysis::generic< analysis::rule_type::seq, Rule >;
template< apply_mode A,
rewind_mode M,
template< typename... >
class,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
return Control< Rule >::template match< A, M, Action, Control >( in, st... );
}
};
template< template< typename... > class Action, typename... Rules >
struct skip_control< action< Action, Rules... > > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,120 @@
// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_ACTION_INPUT_HPP
#define TAO_PEGTL_INTERNAL_ACTION_INPUT_HPP
#include <cstddef>
#include <cstdint>
#include <string>
#include "iterator.hpp"
#include "../config.hpp"
#include "../position.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
inline const char* begin_c_ptr( const char* p ) noexcept
{
return p;
}
inline const char* begin_c_ptr( const iterator& it ) noexcept
{
return it.data;
}
template< typename Input >
class action_input
{
public:
using input_t = Input;
using iterator_t = typename Input::iterator_t;
action_input( const iterator_t& in_begin, const Input& in_input ) noexcept
: m_begin( in_begin ),
m_input( in_input )
{
}
action_input( const action_input& ) = delete;
action_input( action_input&& ) = delete;
~action_input() = default;
action_input& operator=( const action_input& ) = delete;
action_input& operator=( action_input&& ) = delete;
const iterator_t& iterator() const noexcept
{
return m_begin;
}
const Input& input() const noexcept
{
return m_input;
}
const char* begin() const noexcept
{
return begin_c_ptr( iterator() );
}
const char* end() const noexcept
{
return input().current();
}
bool empty() const noexcept
{
return begin() == end();
}
std::size_t size() const noexcept
{
return std::size_t( end() - begin() );
}
std::string string() const
{
return std::string( begin(), end() );
}
char peek_char( const std::size_t offset = 0 ) const noexcept
{
return begin()[ offset ];
}
std::uint8_t peek_uint8( const std::size_t offset = 0 ) const noexcept
{
return static_cast< std::uint8_t >( peek_char( offset ) );
}
// Compatibility, remove with 3.0.0
std::uint8_t peek_byte( const std::size_t offset = 0 ) const noexcept
{
return static_cast< std::uint8_t >( peek_char( offset ) );
}
TAO_PEGTL_NAMESPACE::position position() const
{
return input().position( iterator() ); // NOTE: Not efficient with lazy inputs.
}
protected:
const iterator_t m_begin;
const Input& m_input;
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,26 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_ALNUM_HPP
#define TAO_PEGTL_INTERNAL_ALNUM_HPP
#include "../config.hpp"
#include "peek_char.hpp"
#include "ranges.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
using alnum = ranges< peek_char, 'a', 'z', 'A', 'Z', '0', '9' >;
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,26 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_ALPHA_HPP
#define TAO_PEGTL_INTERNAL_ALPHA_HPP
#include "../config.hpp"
#include "peek_char.hpp"
#include "ranges.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
using alpha = ranges< peek_char, 'a', 'z', 'A', 'Z' >;
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,29 @@
// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_ALWAYS_FALSE_HPP
#define TAO_PEGTL_INTERNAL_ALWAYS_FALSE_HPP
#include "../config.hpp"
#include <type_traits>
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename... >
struct always_false
: std::false_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+66
View File
@@ -0,0 +1,66 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_ANY_HPP
#define TAO_PEGTL_INTERNAL_ANY_HPP
#include "../config.hpp"
#include "peek_char.hpp"
#include "skip_control.hpp"
#include "../analysis/generic.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename Peek >
struct any;
template<>
struct any< peek_char >
{
using analyze_t = analysis::generic< analysis::rule_type::any >;
template< typename Input >
static bool match( Input& in ) noexcept( noexcept( in.empty() ) )
{
if( !in.empty() ) {
in.bump();
return true;
}
return false;
}
};
template< typename Peek >
struct any
{
using analyze_t = analysis::generic< analysis::rule_type::any >;
template< typename Input >
static bool match( Input& in ) noexcept( noexcept( Peek::peek( in ) ) )
{
if( const auto t = Peek::peek( in ) ) {
in.bump( t.size );
return true;
}
return false;
}
};
template< typename Peek >
struct skip_control< any< Peek > > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,94 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_APPLY_HPP
#define TAO_PEGTL_INTERNAL_APPLY_HPP
#include "../config.hpp"
#include "apply_single.hpp"
#include "skip_control.hpp"
#include "../analysis/counted.hpp"
#include "../apply_mode.hpp"
#include "../rewind_mode.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< apply_mode A, typename... Actions >
struct apply_impl;
template<>
struct apply_impl< apply_mode::action >
{
template< typename Input, typename... States >
static bool match( Input& /*unused*/, States&&... /*unused*/ )
{
return true;
}
};
template< typename... Actions >
struct apply_impl< apply_mode::action, Actions... >
{
template< typename Input, typename... States >
static bool match( Input& in, States&&... st )
{
using action_t = typename Input::action_t;
const action_t i2( in.iterator(), in ); // No data -- range is from begin to begin.
#ifdef __cpp_fold_expressions
return ( apply_single< Actions >::match( i2, st... ) && ... );
#else
bool result = true;
using swallow = bool[];
(void)swallow{ result = result && apply_single< Actions >::match( i2, st... )... };
return result;
#endif
}
};
template< typename... Actions >
struct apply_impl< apply_mode::nothing, Actions... >
{
template< typename Input, typename... States >
static bool match( Input& /*unused*/, States&&... /*unused*/ )
{
return true;
}
};
template< typename... Actions >
struct apply
{
using analyze_t = analysis::counted< analysis::rule_type::any, 0 >;
template< apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
return apply_impl< A, Actions... >::match( in, st... );
}
};
template< typename... Actions >
struct skip_control< apply< Actions... > > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,92 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_APPLY0_HPP
#define TAO_PEGTL_INTERNAL_APPLY0_HPP
#include "../config.hpp"
#include "apply0_single.hpp"
#include "skip_control.hpp"
#include "../analysis/counted.hpp"
#include "../apply_mode.hpp"
#include "../rewind_mode.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< apply_mode A, typename... Actions >
struct apply0_impl;
template<>
struct apply0_impl< apply_mode::action >
{
template< typename... States >
static bool match( States&&... /*unused*/ ) noexcept
{
return true;
}
};
template< typename... Actions >
struct apply0_impl< apply_mode::action, Actions... >
{
template< typename... States >
static bool match( States&&... st )
{
#ifdef __cpp_fold_expressions
return ( apply0_single< Actions >::match( st... ) && ... );
#else
bool result = true;
using swallow = bool[];
(void)swallow{ result = result && apply0_single< Actions >::match( st... )... };
return result;
#endif
}
};
template< typename... Actions >
struct apply0_impl< apply_mode::nothing, Actions... >
{
template< typename... States >
static bool match( States&&... /*unused*/ ) noexcept
{
return true;
}
};
template< typename... Actions >
struct apply0
{
using analyze_t = analysis::counted< analysis::rule_type::any, 0 >;
template< apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& /*unused*/, States&&... st )
{
return apply0_impl< A, Actions... >::match( st... );
}
};
template< typename... Actions >
struct skip_control< apply0< Actions... > > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,42 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_APPLY0_SINGLE_HPP
#define TAO_PEGTL_INTERNAL_APPLY0_SINGLE_HPP
#include "../config.hpp"
#include <type_traits>
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename Action >
struct apply0_single
{
template< typename... States >
static auto match( States&&... st )
-> typename std::enable_if< std::is_same< decltype( Action::apply0( st... ) ), void >::value, bool >::type
{
Action::apply0( st... );
return true;
}
template< typename... States >
static auto match( States&&... st )
-> typename std::enable_if< std::is_same< decltype( Action::apply0( st... ) ), bool >::value, bool >::type
{
return Action::apply0( st... );
}
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,42 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_APPLY_SINGLE_HPP
#define TAO_PEGTL_INTERNAL_APPLY_SINGLE_HPP
#include "../config.hpp"
#include <type_traits>
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename Action >
struct apply_single
{
template< typename Input, typename... States >
static auto match( const Input& i2, States&&... st )
-> typename std::enable_if< std::is_same< decltype( Action::apply( i2, st... ) ), void >::value, bool >::type
{
Action::apply( i2, st... );
return true;
}
template< typename Input, typename... States >
static auto match( const Input& i2, States&&... st )
-> typename std::enable_if< std::is_same< decltype( Action::apply( i2, st... ) ), bool >::value, bool >::type
{
return Action::apply( i2, st... );
}
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+67
View File
@@ -0,0 +1,67 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_AT_HPP
#define TAO_PEGTL_INTERNAL_AT_HPP
#include "../config.hpp"
#include "seq.hpp"
#include "skip_control.hpp"
#include "trivial.hpp"
#include "../apply_mode.hpp"
#include "../rewind_mode.hpp"
#include "../analysis/generic.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename... Rules >
struct at
: at< seq< Rules... > >
{
};
template<>
struct at<>
: trivial< true >
{
};
template< typename Rule >
struct at< Rule >
{
using analyze_t = analysis::generic< analysis::rule_type::opt, Rule >;
template< apply_mode,
rewind_mode,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
const auto m = in.template mark< rewind_mode::required >();
return Control< Rule >::template match< apply_mode::nothing, rewind_mode::active, Action, Control >( in, st... );
}
};
template< typename... Rules >
struct skip_control< at< Rules... > > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+41
View File
@@ -0,0 +1,41 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_BOF_HPP
#define TAO_PEGTL_INTERNAL_BOF_HPP
#include "../config.hpp"
#include "skip_control.hpp"
#include "../analysis/generic.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
struct bof
{
using analyze_t = analysis::generic< analysis::rule_type::opt >;
template< typename Input >
static bool match( Input& in ) noexcept
{
return in.byte() == 0;
}
};
template<>
struct skip_control< bof > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+41
View File
@@ -0,0 +1,41 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_BOL_HPP
#define TAO_PEGTL_INTERNAL_BOL_HPP
#include "../config.hpp"
#include "skip_control.hpp"
#include "../analysis/generic.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
struct bol
{
using analyze_t = analysis::generic< analysis::rule_type::opt >;
template< typename Input >
static bool match( Input& in ) noexcept
{
return in.byte_in_line() == 0;
}
};
template<>
struct skip_control< bol > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+53
View File
@@ -0,0 +1,53 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_BUMP_HPP
#define TAO_PEGTL_INTERNAL_BUMP_HPP
#include "../config.hpp"
#include "iterator.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
inline void bump( iterator& iter, const std::size_t count, const int ch ) noexcept
{
for( std::size_t i = 0; i < count; ++i ) {
if( iter.data[ i ] == ch ) {
++iter.line;
iter.byte_in_line = 0;
}
else {
++iter.byte_in_line;
}
}
iter.byte += count;
iter.data += count;
}
inline void bump_in_this_line( iterator& iter, const std::size_t count ) noexcept
{
iter.data += count;
iter.byte += count;
iter.byte_in_line += count;
}
inline void bump_to_next_line( iterator& iter, const std::size_t count ) noexcept
{
++iter.line;
iter.byte += count;
iter.byte_in_line = 0;
iter.data += count;
}
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,63 @@
// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_BUMP_HELP_HPP
#define TAO_PEGTL_INTERNAL_BUMP_HELP_HPP
#include <cstddef>
#include <type_traits>
#include "../config.hpp"
#include "result_on_found.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< bool >
struct bump_impl;
template<>
struct bump_impl< true >
{
template< typename Input >
static void bump( Input& in, const std::size_t count ) noexcept
{
in.bump( count );
}
};
template<>
struct bump_impl< false >
{
template< typename Input >
static void bump( Input& in, const std::size_t count ) noexcept
{
in.bump_in_this_line( count );
}
};
template< bool... >
struct bool_list
{
};
template< bool... Bs >
using bool_and = std::is_same< bool_list< Bs..., true >, bool_list< true, Bs... > >;
template< result_on_found R, typename Input, typename Char, Char... Cs >
void bump_help( Input& in, const std::size_t count ) noexcept
{
bump_impl< bool_and< ( Cs != Input::eol_t::ch )... >::value != bool( R ) >::bump( in, count );
}
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,46 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_BYTES_HPP
#define TAO_PEGTL_INTERNAL_BYTES_HPP
#include "../config.hpp"
#include "skip_control.hpp"
#include "../analysis/counted.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< unsigned Num >
struct bytes
{
using analyze_t = analysis::counted< analysis::rule_type::any, Num >;
template< typename Input >
static bool match( Input& in ) noexcept( noexcept( in.size( 0 ) ) )
{
if( in.size( Num ) >= Num ) {
in.bump( Num );
return true;
}
return false;
}
};
template< unsigned Num >
struct skip_control< bytes< Num > > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,59 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_CONTROL_HPP
#define TAO_PEGTL_INTERNAL_CONTROL_HPP
#include "../config.hpp"
#include "seq.hpp"
#include "skip_control.hpp"
#include "../apply_mode.hpp"
#include "../rewind_mode.hpp"
#include "../analysis/generic.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< template< typename... > class Control, typename... Rules >
struct control
: control< Control, seq< Rules... > >
{
};
template< template< typename... > class Control, typename Rule >
struct control< Control, Rule >
{
using analyze_t = analysis::generic< analysis::rule_type::seq, Rule >;
template< apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
return Control< Rule >::template match< A, M, Action, Control >( in, st... );
}
};
template< template< typename... > class Control, typename... Rules >
struct skip_control< control< Control, Rules... > > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,40 @@
// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_CR_CRLF_EOL_HPP
#define TAO_PEGTL_INTERNAL_CR_CRLF_EOL_HPP
#include "../config.hpp"
#include "../eol_pair.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
struct cr_crlf_eol
{
static constexpr int ch = '\r';
template< typename Input >
static eol_pair match( Input& in ) noexcept( noexcept( in.size( 2 ) ) )
{
eol_pair p = { false, in.size( 2 ) };
if( p.second ) {
if( in.peek_char() == '\r' ) {
in.bump_to_next_line( 1 + ( ( p.second > 1 ) && ( in.peek_char( 1 ) == '\n' ) ) );
p.first = true;
}
}
return p;
}
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,40 @@
// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_CR_EOL_HPP
#define TAO_PEGTL_INTERNAL_CR_EOL_HPP
#include "../config.hpp"
#include "../eol_pair.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
struct cr_eol
{
static constexpr int ch = '\r';
template< typename Input >
static eol_pair match( Input& in ) noexcept( noexcept( in.size( 1 ) ) )
{
eol_pair p = { false, in.size( 1 ) };
if( p.second ) {
if( in.peek_char() == '\r' ) {
in.bump_to_next_line();
p.first = true;
}
}
return p;
}
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,40 @@
// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_CRLF_EOL_HPP
#define TAO_PEGTL_INTERNAL_CRLF_EOL_HPP
#include "../config.hpp"
#include "../eol_pair.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
struct crlf_eol
{
static constexpr int ch = '\n';
template< typename Input >
static eol_pair match( Input& in ) noexcept( noexcept( in.size( 2 ) ) )
{
eol_pair p = { false, in.size( 2 ) };
if( p.second > 1 ) {
if( ( in.peek_char() == '\r' ) && ( in.peek_char( 1 ) == '\n' ) ) {
in.bump_to_next_line( 2 );
p.first = true;
}
}
return p;
}
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,50 @@
// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_CSTREAM_READER_HPP
#define TAO_PEGTL_INTERNAL_CSTREAM_READER_HPP
#include <cassert>
#include <cstddef>
#include <cstdio>
#include "../config.hpp"
#include "../input_error.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
struct cstream_reader
{
explicit cstream_reader( std::FILE* s ) noexcept
: m_cstream( s )
{
assert( m_cstream != nullptr );
}
std::size_t operator()( char* buffer, const std::size_t length ) const
{
if( const auto r = std::fread( buffer, 1, length, m_cstream ) ) {
return r;
}
if( std::feof( m_cstream ) != 0 ) {
return 0;
}
// Please contact us if you know how to provoke the following exception.
// The example on cppreference.com doesn't work, at least not on macOS.
TAO_PEGTL_THROW_INPUT_ERROR( "error in fread() from cstream" ); // LCOV_EXCL_LINE
}
std::FILE* m_cstream;
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,49 @@
// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_CSTRING_READER_HPP
#define TAO_PEGTL_INTERNAL_CSTRING_READER_HPP
#include <cassert>
#include <cstddef>
#include "../config.hpp"
#include "../input_error.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
struct cstring_reader
{
explicit cstring_reader( const char* zero_terminated ) noexcept
: m_cstring( zero_terminated )
{
assert( m_cstring != nullptr );
}
std::size_t operator()( char* buffer, const std::size_t length ) noexcept
{
std::size_t i = 0;
char c;
while( ( i < length ) && ( ( c = m_cstring[ i ] ) != 0 ) ) {
*buffer++ = c;
++i;
}
m_cstring += i;
return i;
}
const char* m_cstring;
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,85 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_DEMANGLE_HPP
#define TAO_PEGTL_INTERNAL_DEMANGLE_HPP
#include <string>
#include <typeinfo>
#include "../config.hpp"
#if defined( __clang__ )
#if __has_feature( cxx_rtti )
#define TAO_PEGTL_RTTI_ENABLED
#endif
#elif defined( __GNUC__ )
#if defined( __GXX_RTTI )
#define TAO_PEGTL_RTTI_ENABLED
#endif
#elif defined( _MSC_VER )
#if defined( _CPPRTTI )
#define TAO_PEGTL_RTTI_ENABLED
#endif
#else
#define TAO_PEGTL_RTTI_ENABLED
#endif
#if !defined( TAO_PEGTL_RTTI_ENABLED )
#include <cassert>
#include <cstring>
#endif
#if defined( TAO_PEGTL_RTTI_ENABLED )
#if defined( __GLIBCXX__ )
#define TAO_PEGTL_USE_CXXABI_DEMANGLE
#elif defined( __has_include )
#if __has_include( <cxxabi.h> )
#define TAO_PEGTL_USE_CXXABI_DEMANGLE
#endif
#endif
#endif
#if defined( TAO_PEGTL_USE_CXXABI_DEMANGLE )
#include "demangle_cxxabi.hpp"
#undef TAO_PEGTL_USE_CXXABI_DEMANGLE
#else
#include "demangle_nop.hpp"
#endif
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename T >
std::string demangle()
{
#if defined( TAO_PEGTL_RTTI_ENABLED )
return demangle( typeid( T ).name() );
#else
const char* start = nullptr;
const char* stop = nullptr;
#if defined( __clang__ ) || defined( __GNUC__ )
start = std::strchr( __PRETTY_FUNCTION__, '=' ) + 2;
stop = std::strrchr( start, ';' );
#elif defined( _MSC_VER )
start = std::strstr( __FUNCSIG__, "demangle<" ) + ( sizeof( "demangle<" ) - 1 );
stop = std::strrchr( start, '>' );
#else
static_assert( false, "expected to use rtti with this compiler" );
#endif
assert( start != nullptr );
assert( stop != nullptr );
return { start, std::size_t( stop - start ) };
#endif
}
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,41 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_DEMANGLE_CXXABI_HPP
#define TAO_PEGTL_INTERNAL_DEMANGLE_CXXABI_HPP
#include <cstdlib>
#include <cxxabi.h>
#include <memory>
#include <string>
#include "../config.hpp"
#include "demangle_sanitise.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
inline std::string demangle( const char* symbol )
{
const std::unique_ptr< char, decltype( &std::free ) > demangled( abi::__cxa_demangle( symbol, nullptr, nullptr, nullptr ), &std::free );
if( !demangled ) {
return symbol;
}
std::string result( demangled.get() );
#ifdef TAO_PEGTL_PRETTY_DEMANGLE
demangle_sanitise_chars( result ); // LCOV_EXCL_LINE
#endif
return result;
}
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,28 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_DEMANGLE_NOP_HPP
#define TAO_PEGTL_INTERNAL_DEMANGLE_NOP_HPP
#include <string>
#include "../config.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
inline std::string demangle( const char* symbol )
{
return symbol;
}
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,48 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_DEMANGLE_SANITISE_HPP
#define TAO_PEGTL_INTERNAL_DEMANGLE_SANITISE_HPP
#include <string>
#include "../config.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
inline void demangle_sanitise_chars( std::string& s )
{
std::string::size_type p;
while( ( p = s.find( "(char)" ) ) != std::string::npos ) {
int c = 0;
std::string::size_type q;
for( q = p + 6; ( q < s.size() ) && ( s[ q ] >= '0' ) && ( s[ q ] <= '9' ); ++q ) {
c *= 10;
c += s[ q ] - '0';
}
if( c == '\'' ) {
s.replace( p, q - p, "'\\''" );
}
else if( c == '\\' ) {
s.replace( p, q - p, "'\\\\'" );
}
else if( ( c < 32 ) || ( c > 126 ) ) {
s.replace( p, 6, std::string() );
}
else {
s.replace( p, q - p, std::string( 1, '\'' ) + char( c ) + '\'' );
}
}
}
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,59 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_DISABLE_HPP
#define TAO_PEGTL_INTERNAL_DISABLE_HPP
#include "../config.hpp"
#include "seq.hpp"
#include "skip_control.hpp"
#include "../apply_mode.hpp"
#include "../rewind_mode.hpp"
#include "../analysis/generic.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename... Rules >
struct disable
: disable< seq< Rules... > >
{
};
template< typename Rule >
struct disable< Rule >
{
using analyze_t = analysis::generic< analysis::rule_type::seq, Rule >;
template< apply_mode,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
return Control< Rule >::template match< apply_mode::nothing, M, Action, Control >( in, st... );
}
};
template< typename... Rules >
struct skip_control< disable< Rules... > > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,43 @@
// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_DISCARD_HPP
#define TAO_PEGTL_INTERNAL_DISCARD_HPP
#include "../config.hpp"
#include "skip_control.hpp"
#include "../analysis/generic.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
struct discard
{
using analyze_t = analysis::generic< analysis::rule_type::opt >;
template< typename Input >
static bool match( Input& in ) noexcept
{
static_assert( noexcept( in.discard() ), "an input's discard()-method must be noexcept" );
in.discard();
return true;
}
};
template<>
struct skip_control< discard > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,31 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_DUSEL_MODE_HPP
#define TAO_PEGTL_INTERNAL_DUSEL_MODE_HPP
#include "../config.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
enum class dusel_mode : char
{
nothing = 0,
control = 1,
control_and_apply_void = 2,
control_and_apply_bool = 3,
control_and_apply0_void = 4,
control_and_apply0_bool = 5,
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,188 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_DUSELTRONIK_HPP
#define TAO_PEGTL_INTERNAL_DUSELTRONIK_HPP
#include "../apply_mode.hpp"
#include "../config.hpp"
#include "../rewind_mode.hpp"
#include "dusel_mode.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
dusel_mode = dusel_mode::nothing >
struct duseltronik;
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control >
struct duseltronik< Rule, A, M, Action, Control, dusel_mode::nothing >
{
template< typename Input, typename... States >
static auto match( Input& in, States&&... st )
-> decltype( Rule::template match< A, M, Action, Control >( in, st... ), true )
{
return Rule::template match< A, M, Action, Control >( in, st... );
}
// NOTE: The additional "int = 0" is a work-around for missing expression SFINAE in VS2015.
template< typename Input, typename... States, int = 0 >
static auto match( Input& in, States&&... /*unused*/ )
-> decltype( Rule::match( in ), true )
{
return Rule::match( in );
}
};
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control >
struct duseltronik< Rule, A, M, Action, Control, dusel_mode::control >
{
template< typename Input, typename... States >
static bool match( Input& in, States&&... st )
{
Control< Rule >::start( static_cast< const Input& >( in ), st... );
if( duseltronik< Rule, A, M, Action, Control, dusel_mode::nothing >::match( in, st... ) ) {
Control< Rule >::success( static_cast< const Input& >( in ), st... );
return true;
}
Control< Rule >::failure( static_cast< const Input& >( in ), st... );
return false;
}
};
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control >
struct duseltronik< Rule, A, M, Action, Control, dusel_mode::control_and_apply_void >
{
template< typename Input, typename... States >
static bool match( Input& in, States&&... st )
{
auto m = in.template mark< rewind_mode::required >();
Control< Rule >::start( static_cast< const Input& >( in ), st... );
if( duseltronik< Rule, A, rewind_mode::active, Action, Control, dusel_mode::nothing >::match( in, st... ) ) {
Control< Rule >::template apply< Action >( m.iterator(), static_cast< const Input& >( in ), st... );
Control< Rule >::success( static_cast< const Input& >( in ), st... );
return m( true );
}
Control< Rule >::failure( static_cast< const Input& >( in ), st... );
return false;
}
};
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control >
struct duseltronik< Rule, A, M, Action, Control, dusel_mode::control_and_apply_bool >
{
template< typename Input, typename... States >
static bool match( Input& in, States&&... st )
{
auto m = in.template mark< rewind_mode::required >();
Control< Rule >::start( static_cast< const Input& >( in ), st... );
if( duseltronik< Rule, A, rewind_mode::active, Action, Control, dusel_mode::nothing >::match( in, st... ) ) {
if( Control< Rule >::template apply< Action >( m.iterator(), static_cast< const Input& >( in ), st... ) ) {
Control< Rule >::success( static_cast< const Input& >( in ), st... );
return m( true );
}
}
Control< Rule >::failure( static_cast< const Input& >( in ), st... );
return false;
}
};
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control >
struct duseltronik< Rule, A, M, Action, Control, dusel_mode::control_and_apply0_void >
{
template< typename Input, typename... States >
static bool match( Input& in, States&&... st )
{
Control< Rule >::start( static_cast< const Input& >( in ), st... );
if( duseltronik< Rule, A, M, Action, Control, dusel_mode::nothing >::match( in, st... ) ) {
Control< Rule >::template apply0< Action >( static_cast< const Input& >( in ), st... );
Control< Rule >::success( static_cast< const Input& >( in ), st... );
return true;
}
Control< Rule >::failure( static_cast< const Input& >( in ), st... );
return false;
}
};
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control >
struct duseltronik< Rule, A, M, Action, Control, dusel_mode::control_and_apply0_bool >
{
template< typename Input, typename... States >
static bool match( Input& in, States&&... st )
{
auto m = in.template mark< rewind_mode::required >();
Control< Rule >::start( static_cast< const Input& >( in ), st... );
if( duseltronik< Rule, A, rewind_mode::active, Action, Control, dusel_mode::nothing >::match( in, st... ) ) {
if( Control< Rule >::template apply0< Action >( static_cast< const Input& >( in ), st... ) ) {
Control< Rule >::success( static_cast< const Input& >( in ), st... );
return m( true );
}
}
Control< Rule >::failure( static_cast< const Input& >( in ), st... );
return false;
}
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,59 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_ENABLE_HPP
#define TAO_PEGTL_INTERNAL_ENABLE_HPP
#include "../config.hpp"
#include "seq.hpp"
#include "skip_control.hpp"
#include "../apply_mode.hpp"
#include "../rewind_mode.hpp"
#include "../analysis/generic.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename... Rules >
struct enable
: enable< seq< Rules... > >
{
};
template< typename Rule >
struct enable< Rule >
{
using analyze_t = analysis::generic< analysis::rule_type::seq, Rule >;
template< apply_mode,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
return Control< Rule >::template match< apply_mode::action, M, Action, Control >( in, st... );
}
};
template< typename... Rules >
struct skip_control< enable< Rules... > > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,70 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_ENDIAN_HPP
#define TAO_PEGTL_INTERNAL_ENDIAN_HPP
#include <cstdint>
#include <cstring>
#include "../config.hpp"
#if defined( _WIN32 ) && !defined( __MINGW32__ )
#include "endian_win.hpp"
#else
#include "endian_gcc.hpp"
#endif
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename N >
N h_to_be( const N n ) noexcept
{
return N( to_and_from_be< sizeof( N ) >::convert( n ) );
}
template< typename N >
N be_to_h( const N n ) noexcept
{
return h_to_be( n );
}
template< typename N >
N be_to_h( const void* p ) noexcept
{
N n;
std::memcpy( &n, p, sizeof( n ) );
return internal::be_to_h( n );
}
template< typename N >
N h_to_le( const N n ) noexcept
{
return N( to_and_from_le< sizeof( N ) >::convert( n ) );
}
template< typename N >
N le_to_h( const N n ) noexcept
{
return h_to_le( n );
}
template< typename N >
N le_to_h( const void* p ) noexcept
{
N n;
std::memcpy( &n, p, sizeof( n ) );
return internal::le_to_h( n );
}
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,214 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_ENDIAN_GCC_HPP
#define TAO_PEGTL_INTERNAL_ENDIAN_GCC_HPP
#include <cstdint>
#include <cstring>
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
#if !defined( __BYTE_ORDER__ )
#error No byte order defined!
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
template< std::size_t S >
struct to_and_from_be
{
template< typename T >
static T convert( const T n ) noexcept
{
return n;
}
};
template< std::size_t S >
struct to_and_from_le;
template<>
struct to_and_from_le< 1 >
{
static std::uint8_t convert( const std::uint8_t n ) noexcept
{
return n;
}
static std::int8_t convert( const std::int8_t n ) noexcept
{
return n;
}
};
template<>
struct to_and_from_le< 2 >
{
static std::int16_t convert( const std::int16_t n ) noexcept
{
return static_cast< std::int16_t >( __builtin_bswap16( static_cast< std::uint16_t >( n ) ) );
}
static std::uint16_t convert( const std::uint16_t n ) noexcept
{
return __builtin_bswap16( n );
}
};
template<>
struct to_and_from_le< 4 >
{
static float convert( float n ) noexcept
{
std::uint32_t u;
std::memcpy( &u, &n, 4 );
u = convert( u );
std::memcpy( &n, &u, 4 );
return n;
}
static std::int32_t convert( const std::int32_t n ) noexcept
{
return static_cast< std::int32_t >( __builtin_bswap32( static_cast< std::uint32_t >( n ) ) );
}
static std::uint32_t convert( const std::uint32_t n ) noexcept
{
return __builtin_bswap32( n );
}
};
template<>
struct to_and_from_le< 8 >
{
static double convert( double n ) noexcept
{
std::uint64_t u;
std::memcpy( &u, &n, 8 );
u = convert( u );
std::memcpy( &n, &u, 8 );
return n;
}
static std::int64_t convert( const std::int64_t n ) noexcept
{
return static_cast< std::int64_t >( __builtin_bswap64( static_cast< std::uint64_t >( n ) ) );
}
static std::uint64_t convert( const std::uint64_t n ) noexcept
{
return __builtin_bswap64( n );
}
};
#define TAO_PEGTL_NATIVE_ORDER be
#define TAO_PEGTL_NATIVE_UTF16 utf16_be
#define TAO_PEGTL_NATIVE_UTF32 utf32_be
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
template< std::size_t S >
struct to_and_from_le
{
template< typename T >
static T convert( const T n ) noexcept
{
return n;
}
};
template< std::size_t S >
struct to_and_from_be;
template<>
struct to_and_from_be< 1 >
{
static std::int8_t convert( const std::int8_t n ) noexcept
{
return n;
}
static std::uint8_t convert( const std::uint8_t n ) noexcept
{
return n;
}
};
template<>
struct to_and_from_be< 2 >
{
static std::int16_t convert( const std::int16_t n ) noexcept
{
return static_cast< std::int16_t >( __builtin_bswap16( static_cast< std::uint16_t >( n ) ) );
}
static std::uint16_t convert( const std::uint16_t n ) noexcept
{
return __builtin_bswap16( n );
}
};
template<>
struct to_and_from_be< 4 >
{
static float convert( float n ) noexcept
{
std::uint32_t u;
std::memcpy( &u, &n, 4 );
u = convert( u );
std::memcpy( &n, &u, 4 );
return n;
}
static std::int32_t convert( const std::int32_t n ) noexcept
{
return static_cast< std::int32_t >( __builtin_bswap32( static_cast< std::uint32_t >( n ) ) );
}
static std::uint32_t convert( const std::uint32_t n ) noexcept
{
return __builtin_bswap32( n );
}
};
template<>
struct to_and_from_be< 8 >
{
static double convert( double n ) noexcept
{
std::uint64_t u;
std::memcpy( &u, &n, 8 );
u = convert( u );
std::memcpy( &n, &u, 8 );
return n;
}
static std::int64_t convert( const std::int64_t n ) noexcept
{
return static_cast< std::int64_t >( __builtin_bswap64( static_cast< std::uint64_t >( n ) ) );
}
static std::uint64_t convert( const std::uint64_t n ) noexcept
{
return __builtin_bswap64( n );
}
};
#define TAO_PEGTL_NATIVE_ORDER le
#define TAO_PEGTL_NATIVE_UTF16 utf16_le
#define TAO_PEGTL_NATIVE_UTF32 utf32_le
#else
#error Unknown host byte order!
#endif
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,115 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_ENDIAN_WIN_HPP
#define TAO_PEGTL_INTERNAL_ENDIAN_WIN_HPP
#include <cstdint>
#include <cstring>
#include <stdlib.h>
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< std::size_t S >
struct to_and_from_le
{
template< typename T >
static T convert( const T t ) noexcept
{
return t;
}
};
template< std::size_t S >
struct to_and_from_be;
template<>
struct to_and_from_be< 1 >
{
static std::int8_t convert( const std::int8_t n ) noexcept
{
return n;
}
static std::uint8_t convert( const std::uint8_t n ) noexcept
{
return n;
}
};
template<>
struct to_and_from_be< 2 >
{
static std::int16_t convert( const std::int16_t n ) noexcept
{
return std::int16_t( _byteswap_ushort( std::uint16_t( n ) ) );
}
static std::uint16_t convert( const std::uint16_t n ) noexcept
{
return _byteswap_ushort( n );
}
};
template<>
struct to_and_from_be< 4 >
{
static float convert( float n ) noexcept
{
std::uint32_t u;
std::memcpy( &u, &n, 4 );
u = convert( u );
std::memcpy( &n, &u, 4 );
return n;
}
static std::int32_t convert( const std::int32_t n ) noexcept
{
return std::int32_t( _byteswap_ulong( std::uint32_t( n ) ) );
}
static std::uint32_t convert( const std::uint32_t n ) noexcept
{
return _byteswap_ulong( n );
}
};
template<>
struct to_and_from_be< 8 >
{
static double convert( double n ) noexcept
{
std::uint64_t u;
std::memcpy( &u, &n, 8 );
u = convert( u );
std::memcpy( &n, &u, 8 );
return n;
}
static std::int64_t convert( const std::int64_t n ) noexcept
{
return std::int64_t( _byteswap_uint64( std::uint64_t( n ) ) );
}
static std::uint64_t convert( const std::uint64_t n ) noexcept
{
return _byteswap_uint64( n );
}
};
#define TAO_PEGTL_NATIVE_ORDER le
#define TAO_PEGTL_NATIVE_UTF16 utf16_le
#define TAO_PEGTL_NATIVE_UTF32 utf32_le
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+41
View File
@@ -0,0 +1,41 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_EOF_HPP
#define TAO_PEGTL_INTERNAL_EOF_HPP
#include "../config.hpp"
#include "skip_control.hpp"
#include "../analysis/generic.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
struct eof
{
using analyze_t = analysis::generic< analysis::rule_type::opt >;
template< typename Input >
static bool match( Input& in ) noexcept( noexcept( in.empty() ) )
{
return in.empty();
}
};
template<>
struct skip_control< eof > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+41
View File
@@ -0,0 +1,41 @@
// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_EOL_HPP
#define TAO_PEGTL_INTERNAL_EOL_HPP
#include "../config.hpp"
#include "skip_control.hpp"
#include "../analysis/generic.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
struct eol
{
using analyze_t = analysis::generic< analysis::rule_type::any >;
template< typename Input >
static bool match( Input& in ) noexcept( noexcept( Input::eol_t::match( in ) ) )
{
return Input::eol_t::match( in ).first;
}
};
template<>
struct skip_control< eol > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+42
View File
@@ -0,0 +1,42 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_EOLF_HPP
#define TAO_PEGTL_INTERNAL_EOLF_HPP
#include "../config.hpp"
#include "skip_control.hpp"
#include "../analysis/generic.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
struct eolf
{
using analyze_t = analysis::generic< analysis::rule_type::opt >;
template< typename Input >
static bool match( Input& in ) noexcept( noexcept( Input::eol_t::match( in ) ) )
{
const auto p = Input::eol_t::match( in );
return p.first || ( !p.second );
}
};
template<>
struct skip_control< eolf > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,95 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_FILE_MAPPER_POSIX_HPP
#define TAO_PEGTL_INTERNAL_FILE_MAPPER_POSIX_HPP
#include <sys/mman.h>
#include <unistd.h>
#include "../config.hpp"
#include "file_opener.hpp"
#include "../input_error.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
class file_mapper
{
public:
explicit file_mapper( const char* filename )
: file_mapper( file_opener( filename ) )
{
}
explicit file_mapper( const file_opener& reader )
: m_size( reader.size() ),
m_data( static_cast< const char* >( ::mmap( nullptr, m_size, PROT_READ, MAP_PRIVATE, reader.m_fd, 0 ) ) )
{
if( ( m_size != 0 ) && ( intptr_t( m_data ) == -1 ) ) {
TAO_PEGTL_THROW_INPUT_ERROR( "unable to mmap() file " << reader.m_source << " descriptor " << reader.m_fd );
}
}
file_mapper( const file_mapper& ) = delete;
file_mapper( file_mapper&& ) = delete;
~file_mapper() noexcept
{
// Legacy C interface requires pointer-to-mutable but does not write through the pointer.
::munmap( const_cast< char* >( m_data ), m_size ); // NOLINT
}
void operator=( const file_mapper& ) = delete;
void operator=( file_mapper&& ) = delete;
bool empty() const noexcept
{
return m_size == 0;
}
std::size_t size() const noexcept
{
return m_size;
}
using iterator = const char*;
using const_iterator = const char*;
iterator data() const noexcept
{
return m_data;
}
iterator begin() const noexcept
{
return m_data;
}
iterator end() const noexcept
{
return m_data + m_size;
}
std::string string() const
{
return std::string( m_data, m_size );
}
private:
const std::size_t m_size;
const char* const m_data;
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,78 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_FILE_OPENER_HPP
#define TAO_PEGTL_INTERNAL_FILE_OPENER_HPP
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <utility>
#include "../config.hpp"
#include "../input_error.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
struct file_opener
{
explicit file_opener( const char* filename )
: m_source( filename ),
m_fd( open() )
{
}
file_opener( const file_opener& ) = delete;
file_opener( file_opener&& ) = delete;
~file_opener() noexcept
{
::close( m_fd );
}
void operator=( const file_opener& ) = delete;
void operator=( file_opener&& ) = delete;
std::size_t size() const
{
struct stat st; // NOLINT
errno = 0;
if( ::fstat( m_fd, &st ) < 0 ) {
TAO_PEGTL_THROW_INPUT_ERROR( "unable to fstat() file " << m_source << " descriptor " << m_fd );
}
return std::size_t( st.st_size );
}
const char* const m_source;
const int m_fd;
private:
int open() const
{
errno = 0;
const int fd = ::open( m_source, // NOLINT
O_RDONLY
#ifdef O_CLOEXEC
| O_CLOEXEC
#endif
);
if( fd >= 0 ) {
return fd;
}
TAO_PEGTL_THROW_INPUT_ERROR( "unable to open() file " << m_source << " for reading" );
}
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,109 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_FILE_READER_HPP
#define TAO_PEGTL_INTERNAL_FILE_READER_HPP
#include <cstdio>
#include <memory>
#include <string>
#include <utility>
#include "../config.hpp"
#include "../input_error.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
inline std::FILE* file_open( const char* filename )
{
errno = 0;
#if defined( _MSC_VER )
std::FILE* file;
if( ::fopen_s( &file, filename, "rb" ) == 0 )
#elif defined( __MINGW32__ )
if( auto* file = std::fopen( filename, "rb" ) ) // NOLINT
#else
if( auto* file = std::fopen( filename, "rbe" ) ) // NOLINT
#endif
{
return file;
}
TAO_PEGTL_THROW_INPUT_ERROR( "unable to fopen() file " << filename << " for reading" );
}
struct file_close
{
void operator()( FILE* f ) const noexcept
{
std::fclose( f ); // NOLINT
}
};
class file_reader
{
public:
explicit file_reader( const char* filename )
: m_source( filename ),
m_file( file_open( m_source ) )
{
}
file_reader( FILE* file, const char* filename ) noexcept
: m_source( filename ),
m_file( file )
{
}
file_reader( const file_reader& ) = delete;
file_reader( file_reader&& ) = delete;
~file_reader() = default;
void operator=( const file_reader& ) = delete;
void operator=( file_reader&& ) = delete;
std::size_t size() const
{
errno = 0;
if( std::fseek( m_file.get(), 0, SEEK_END ) != 0 ) {
TAO_PEGTL_THROW_INPUT_ERROR( "unable to fseek() to end of file " << m_source ); // LCOV_EXCL_LINE
}
errno = 0;
const auto s = std::ftell( m_file.get() );
if( s < 0 ) {
TAO_PEGTL_THROW_INPUT_ERROR( "unable to ftell() file size of file " << m_source ); // LCOV_EXCL_LINE
}
errno = 0;
if( std::fseek( m_file.get(), 0, SEEK_SET ) != 0 ) {
TAO_PEGTL_THROW_INPUT_ERROR( "unable to fseek() to beginning of file " << m_source ); // LCOV_EXCL_LINE
}
return std::size_t( s );
}
std::string read() const
{
std::string nrv;
nrv.resize( size() );
errno = 0;
if( !nrv.empty() && ( std::fread( &nrv[ 0 ], nrv.size(), 1, m_file.get() ) != 1 ) ) {
TAO_PEGTL_THROW_INPUT_ERROR( "unable to fread() file " << m_source << " size " << nrv.size() ); // LCOV_EXCL_LINE
}
return nrv;
}
private:
const char* const m_source;
const std::unique_ptr< std::FILE, file_close > m_file;
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,33 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_HAS_APPLY_HPP
#define TAO_PEGTL_INTERNAL_HAS_APPLY_HPP
#include <type_traits>
#include "../config.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename, typename, template< typename... > class, typename... >
struct has_apply
: std::false_type
{};
template< typename C, template< typename... > class Action, typename... S >
struct has_apply< C, decltype( C::template apply< Action >( std::declval< S >()... ) ), Action, S... >
: std::true_type
{};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,33 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_HAS_APPLY0_HPP
#define TAO_PEGTL_INTERNAL_HAS_APPLY0_HPP
#include <type_traits>
#include "../config.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename, typename, template< typename... > class, typename... >
struct has_apply0
: std::false_type
{};
template< typename C, template< typename... > class Action, typename... S >
struct has_apply0< C, decltype( C::template apply0< Action >( std::declval< S >()... ) ), Action, S... >
: std::true_type
{};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,53 @@
// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_HAS_MATCH_HPP
#define TAO_PEGTL_INTERNAL_HAS_MATCH_HPP
#include <type_traits>
#include <utility>
#include "../apply_mode.hpp"
#include "../config.hpp"
#include "../rewind_mode.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename,
typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
struct has_match
: std::false_type
{};
template< typename Rule,
apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
struct has_match< decltype( Action< Rule >::template match< Rule, A, M, Action, Control >( std::declval< Input& >(), std::declval< States&& >()... ), void() ), Rule, A, M, Action, Control, Input, States... >
: std::true_type
{};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,30 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_IDENTIFIER_HPP
#define TAO_PEGTL_INTERNAL_IDENTIFIER_HPP
#include "../config.hpp"
#include "peek_char.hpp"
#include "ranges.hpp"
#include "seq.hpp"
#include "star.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
using identifier_first = ranges< peek_char, 'a', 'z', 'A', 'Z', '_' >;
using identifier_other = ranges< peek_char, 'a', 'z', 'A', 'Z', '0', '9', '_' >;
using identifier = seq< identifier_first, star< identifier_other > >;
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,118 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_IF_APPLY_HPP
#define TAO_PEGTL_INTERNAL_IF_APPLY_HPP
#include "../config.hpp"
#include "apply_single.hpp"
#include "skip_control.hpp"
#include "../analysis/counted.hpp"
#include "../apply_mode.hpp"
#include "../rewind_mode.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< apply_mode A, typename Rule, typename... Actions >
struct if_apply_impl;
template< typename Rule >
struct if_apply_impl< apply_mode::action, Rule >
{
template< rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
return Control< Rule >::template match< apply_mode::action, M, Action, Control >( in, st... );
}
};
template< typename Rule, typename... Actions >
struct if_apply_impl< apply_mode::action, Rule, Actions... >
{
template< rewind_mode,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
using action_t = typename Input::action_t;
auto m = in.template mark< rewind_mode::required >();
if( Control< Rule >::template match< apply_mode::action, rewind_mode::active, Action, Control >( in, st... ) ) {
const action_t i2( m.iterator(), in );
#ifdef __cpp_fold_expressions
return m( ( apply_single< Actions >::match( i2, st... ) && ... ) );
#else
bool result = true;
using swallow = bool[];
(void)swallow{ result = result && apply_single< Actions >::match( i2, st... )... };
return m( result );
#endif
}
return false;
}
};
template< typename Rule, typename... Actions >
struct if_apply_impl< apply_mode::nothing, Rule, Actions... >
{
template< rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
return Control< Rule >::template match< apply_mode::nothing, M, Action, Control >( in, st... );
}
};
template< typename Rule, typename... Actions >
struct if_apply
{
using analyze_t = typename Rule::analyze_t;
template< apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
return if_apply_impl< A, Rule, Actions... >::template match< M, Action, Control >( in, st... );
}
};
template< typename Rule, typename... Actions >
struct skip_control< if_apply< Rule, Actions... > > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,72 @@
// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_IF_MISSING_HPP
#define TAO_PEGTL_INTERNAL_IF_MISSING_HPP
#include "../config.hpp"
#include "../rewind_mode.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< bool >
struct if_missing;
template<>
struct if_missing< true >
{
template< typename Control,
template< typename... >
class Action,
typename Input,
typename... States >
static void apply( Input& in, States&&... st )
{
auto m = in.template mark< rewind_mode::required >();
Control::template apply< Action >( m.iterator(), in, st... );
}
template< typename Control,
template< typename... >
class Action,
typename Input,
typename... States >
static void apply0( Input& in, States&&... st )
{
Control::template apply0< Action >( in, st... );
}
};
template<>
struct if_missing< false >
{
template< typename Control,
template< typename... >
class Action,
typename Input,
typename... States >
static void apply( Input& /*unused*/, States&&... /*unused*/ )
{
}
template< typename Control,
template< typename... >
class Action,
typename Input,
typename... States >
static void apply0( Input& /*unused*/, States&&... /*unused*/ )
{
}
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,58 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_IF_MUST_HPP
#define TAO_PEGTL_INTERNAL_IF_MUST_HPP
#include "../config.hpp"
#include "must.hpp"
#include "skip_control.hpp"
#include "trivial.hpp"
#include "../apply_mode.hpp"
#include "../rewind_mode.hpp"
#include "../analysis/counted.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< bool Default, typename Cond, typename... Rules >
struct if_must
{
using analyze_t = analysis::counted< analysis::rule_type::seq, Default ? 0 : 1, Cond, must< Rules... > >;
template< apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
if( Control< Cond >::template match< A, M, Action, Control >( in, st... ) ) {
Control< must< Rules... > >::template match< A, M, Action, Control >( in, st... );
return true;
}
return Default;
}
};
template< bool Default, typename Cond, typename... Rules >
struct skip_control< if_must< Default, Cond, Rules... > > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,27 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_IF_MUST_ELSE_HPP
#define TAO_PEGTL_INTERNAL_IF_MUST_ELSE_HPP
#include "../config.hpp"
#include "if_then_else.hpp"
#include "must.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename Cond, typename Then, typename Else >
using if_must_else = if_then_else< Cond, must< Then >, must< Else > >;
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,61 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_IF_THEN_ELSE_HPP
#define TAO_PEGTL_INTERNAL_IF_THEN_ELSE_HPP
#include "../config.hpp"
#include "not_at.hpp"
#include "seq.hpp"
#include "skip_control.hpp"
#include "sor.hpp"
#include "../apply_mode.hpp"
#include "../rewind_mode.hpp"
#include "../analysis/generic.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename Cond, typename Then, typename Else >
struct if_then_else
{
using analyze_t = analysis::generic< analysis::rule_type::sor, seq< Cond, Then >, seq< not_at< Cond >, Else > >;
template< apply_mode A,
rewind_mode M,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
auto m = in.template mark< M >();
using m_t = decltype( m );
if( Control< Cond >::template match< A, rewind_mode::required, Action, Control >( in, st... ) ) {
return m( Control< Then >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) );
}
return m( Control< Else >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) );
}
};
template< typename Cond, typename Then, typename Else >
struct skip_control< if_then_else< Cond, Then, Else > > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,37 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_INPUT_PAIR_HPP
#define TAO_PEGTL_INTERNAL_INPUT_PAIR_HPP
#include <cstdint>
#include "../config.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename Data >
struct input_pair
{
Data data;
std::uint8_t size;
using data_t = Data;
explicit operator bool() const noexcept
{
return size > 0;
}
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,86 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_INTEGER_SEQUENCE_HPP
#define TAO_PEGTL_INTERNAL_INTEGER_SEQUENCE_HPP
#include <cstddef>
#include <type_traits>
#include <utility>
#include "../config.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename T, T... Ns >
struct integer_sequence
{
using value_type = T;
static constexpr std::size_t size() noexcept
{
return sizeof...( Ns );
}
};
template< std::size_t... Ns >
using index_sequence = integer_sequence< std::size_t, Ns... >;
template< bool V, bool E >
struct generate_sequence;
template<>
struct generate_sequence< false, true >
{
template< typename T, T M, T N, std::size_t S, T... Ns >
using f = integer_sequence< T, Ns... >;
};
template<>
struct generate_sequence< true, true >
{
template< typename T, T M, T N, std::size_t S, T... Ns >
using f = integer_sequence< T, Ns..., S >;
};
template<>
struct generate_sequence< false, false >
{
template< typename T, T M, T N, std::size_t S, T... Ns >
using f = typename generate_sequence< ( N & ( M / 2 ) ) != 0, ( M / 2 ) == 0 >::template f< T, M / 2, N, 2 * S, Ns..., ( Ns + S )... >;
};
template<>
struct generate_sequence< true, false >
{
template< typename T, T M, T N, std::size_t S, T... Ns >
using f = typename generate_sequence< ( N & ( M / 2 ) ) != 0, ( M / 2 ) == 0 >::template f< T, M / 2, N, 2 * S + 1, Ns..., ( Ns + S )..., 2 * S >;
};
template< typename T, T N >
struct memoize_sequence
{
static_assert( N < T( 1 << 20 ), "N too large" );
using type = typename generate_sequence< false, false >::template f< T, ( N < T( 1 << 1 ) ) ? T( 1 << 1 ) : ( N < T( 1 << 2 ) ) ? T( 1 << 2 ) : ( N < T( 1 << 3 ) ) ? T( 1 << 3 ) : ( N < T( 1 << 4 ) ) ? T( 1 << 4 ) : ( N < T( 1 << 5 ) ) ? T( 1 << 5 ) : ( N < T( 1 << 6 ) ) ? T( 1 << 6 ) : ( N < T( 1 << 7 ) ) ? T( 1 << 7 ) : ( N < T( 1 << 8 ) ) ? T( 1 << 8 ) : ( N < T( 1 << 9 ) ) ? T( 1 << 9 ) : ( N < T( 1 << 10 ) ) ? T( 1 << 10 ) : ( N < T( 1 << 11 ) ) ? T( 1 << 11 ) : ( N < T( 1 << 12 ) ) ? T( 1 << 12 ) : ( N < T( 1 << 13 ) ) ? T( 1 << 13 ) : ( N < T( 1 << 14 ) ) ? T( 1 << 14 ) : ( N < T( 1 << 15 ) ) ? T( 1 << 15 ) : ( N < T( 1 << 16 ) ) ? T( 1 << 16 ) : ( N < T( 1 << 17 ) ) ? T( 1 << 17 ) : ( N < T( 1 << 18 ) ) ? T( 1 << 18 ) : ( N < T( 1 << 19 ) ) ? T( 1 << 19 ) : T( 1 << 20 ), N, 0 >;
};
template< typename T, T N >
using make_integer_sequence = typename memoize_sequence< T, N >::type;
template< std::size_t N >
using make_index_sequence = make_integer_sequence< std::size_t, N >;
template< typename... Ts >
using index_sequence_for = make_index_sequence< sizeof...( Ts ) >;
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,47 @@
// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_ISTREAM_READER_HPP
#define TAO_PEGTL_INTERNAL_ISTREAM_READER_HPP
#include <istream>
#include "../config.hpp"
#include "../input_error.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
struct istream_reader
{
explicit istream_reader( std::istream& s ) noexcept
: m_istream( s )
{
}
std::size_t operator()( char* buffer, const std::size_t length )
{
m_istream.read( buffer, std::streamsize( length ) );
if( const auto r = m_istream.gcount() ) {
return std::size_t( r );
}
if( m_istream.eof() ) {
return 0;
}
TAO_PEGTL_THROW_INPUT_ERROR( "error in istream.read()" );
}
std::istream& m_istream;
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,107 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_ISTRING_HPP
#define TAO_PEGTL_INTERNAL_ISTRING_HPP
#include <type_traits>
#include "../config.hpp"
#include "bump_help.hpp"
#include "result_on_found.hpp"
#include "skip_control.hpp"
#include "trivial.hpp"
#include "../analysis/counted.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< char C >
using is_alpha = std::integral_constant< bool, ( ( 'a' <= C ) && ( C <= 'z' ) ) || ( ( 'A' <= C ) && ( C <= 'Z' ) ) >;
template< char C, bool A = is_alpha< C >::value >
struct ichar_equal;
template< char C >
struct ichar_equal< C, true >
{
static bool match( const char c ) noexcept
{
return ( C | 0x20 ) == ( c | 0x20 );
}
};
template< char C >
struct ichar_equal< C, false >
{
static bool match( const char c ) noexcept
{
return c == C;
}
};
template< char... Cs >
struct istring_equal;
template<>
struct istring_equal<>
{
static bool match( const char* /*unused*/ ) noexcept
{
return true;
}
};
template< char C, char... Cs >
struct istring_equal< C, Cs... >
{
static bool match( const char* r ) noexcept
{
return ichar_equal< C >::match( *r ) && istring_equal< Cs... >::match( r + 1 );
}
};
template< char... Cs >
struct istring;
template<>
struct istring<>
: trivial< true >
{
};
template< char... Cs >
struct istring
{
using analyze_t = analysis::counted< analysis::rule_type::any, sizeof...( Cs ) >;
template< typename Input >
static bool match( Input& in ) noexcept( noexcept( in.size( 0 ) ) )
{
if( in.size( sizeof...( Cs ) ) >= sizeof...( Cs ) ) {
if( istring_equal< Cs... >::match( in.current() ) ) {
bump_help< result_on_found::success, Input, char, Cs... >( in, sizeof...( Cs ) );
return true;
}
}
return false;
}
};
template< char... Cs >
struct skip_control< istring< Cs... > > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,60 @@
// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_ITERATOR_HPP
#define TAO_PEGTL_INTERNAL_ITERATOR_HPP
#include <cstdlib>
#include "../config.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
struct iterator
{
iterator() noexcept = default;
explicit iterator( const char* in_data ) noexcept
: data( in_data )
{
}
iterator( const char* in_data, const std::size_t in_byte, const std::size_t in_line, const std::size_t in_byte_in_line ) noexcept
: data( in_data ),
byte( in_byte ),
line( in_line ),
byte_in_line( in_byte_in_line )
{
}
iterator( const iterator& ) = default;
iterator( iterator&& ) = default;
~iterator() = default;
iterator& operator=( const iterator& ) = default;
iterator& operator=( iterator&& ) = default;
void reset() noexcept
{
*this = iterator();
}
const char* data = nullptr;
std::size_t byte = 0;
std::size_t line = 1;
std::size_t byte_in_line = 0;
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,45 @@
// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_LF_CRLF_EOL_HPP
#define TAO_PEGTL_INTERNAL_LF_CRLF_EOL_HPP
#include "../config.hpp"
#include "../eol_pair.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
struct lf_crlf_eol
{
static constexpr int ch = '\n';
template< typename Input >
static eol_pair match( Input& in ) noexcept( noexcept( in.size( 2 ) ) )
{
eol_pair p = { false, in.size( 2 ) };
if( p.second ) {
const auto a = in.peek_char();
if( a == '\n' ) {
in.bump_to_next_line();
p.first = true;
}
else if( ( a == '\r' ) && ( p.second > 1 ) && ( in.peek_char( 1 ) == '\n' ) ) {
in.bump_to_next_line( 2 );
p.first = true;
}
}
return p;
}
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,40 @@
// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_LF_EOL_HPP
#define TAO_PEGTL_INTERNAL_LF_EOL_HPP
#include "../config.hpp"
#include "../eol_pair.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
struct lf_eol
{
static constexpr int ch = '\n';
template< typename Input >
static eol_pair match( Input& in ) noexcept( noexcept( in.size( 1 ) ) )
{
eol_pair p = { false, in.size( 1 ) };
if( p.second ) {
if( in.peek_char() == '\n' ) {
in.bump_to_next_line();
p.first = true;
}
}
return p;
}
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+27
View File
@@ -0,0 +1,27 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_LIST_HPP
#define TAO_PEGTL_INTERNAL_LIST_HPP
#include "../config.hpp"
#include "seq.hpp"
#include "star.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename Rule, typename Sep >
using list = seq< Rule, star< Sep, Rule > >;
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,28 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_LIST_MUST_HPP
#define TAO_PEGTL_INTERNAL_LIST_MUST_HPP
#include "../config.hpp"
#include "must.hpp"
#include "seq.hpp"
#include "star.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename Rule, typename Sep >
using list_must = seq< Rule, star< Sep, must< Rule > > >;
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,28 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_LIST_TAIL_HPP
#define TAO_PEGTL_INTERNAL_LIST_TAIL_HPP
#include "../config.hpp"
#include "list.hpp"
#include "opt.hpp"
#include "seq.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename Rule, typename Sep >
using list_tail = seq< list< Rule, Sep >, opt< Sep > >;
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,30 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_LIST_TAIL_PAD_HPP
#define TAO_PEGTL_INTERNAL_LIST_TAIL_PAD_HPP
#include "../config.hpp"
#include "list.hpp"
#include "opt.hpp"
#include "pad.hpp"
#include "seq.hpp"
#include "star.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename Rule, typename Sep, typename Pad >
using list_tail_pad = seq< list< Rule, pad< Sep, Pad > >, opt< star< Pad >, Sep > >;
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,99 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_MARKER_HPP
#define TAO_PEGTL_INTERNAL_MARKER_HPP
#include "../config.hpp"
#include "../rewind_mode.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename Iterator, rewind_mode M >
class marker
{
public:
static constexpr rewind_mode next_rewind_mode = M;
explicit marker( const Iterator& /*unused*/ ) noexcept
{
}
marker( const marker& ) = delete;
marker( marker&& /*unused*/ ) noexcept
{
}
~marker() = default;
void operator=( const marker& ) = delete;
void operator=( marker&& ) = delete;
bool operator()( const bool result ) const noexcept
{
return result;
}
};
template< typename Iterator >
class marker< Iterator, rewind_mode::required >
{
public:
static constexpr rewind_mode next_rewind_mode = rewind_mode::active;
explicit marker( Iterator& i ) noexcept
: m_saved( i ),
m_input( &i )
{
}
marker( const marker& ) = delete;
marker( marker&& i ) noexcept
: m_saved( i.m_saved ),
m_input( i.m_input )
{
i.m_input = nullptr;
}
~marker() noexcept
{
if( m_input != nullptr ) {
( *m_input ) = m_saved;
}
}
void operator=( const marker& ) = delete;
void operator=( marker&& ) = delete;
bool operator()( const bool result ) noexcept
{
if( result ) {
m_input = nullptr;
return true;
}
return false;
}
const Iterator& iterator() const noexcept
{
return m_saved;
}
private:
const Iterator m_saved;
Iterator* m_input;
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
+70
View File
@@ -0,0 +1,70 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_MUST_HPP
#define TAO_PEGTL_INTERNAL_MUST_HPP
#include "../config.hpp"
#include "raise.hpp"
#include "seq.hpp"
#include "skip_control.hpp"
#include "../apply_mode.hpp"
#include "../rewind_mode.hpp"
#include "../analysis/generic.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
// The general case applies must<> to each of the
// rules in the 'Rules' parameter pack individually.
template< typename... Rules >
struct must
: seq< must< Rules >... >
{
};
// While in theory the implementation for a single rule could
// be simplified to must< Rule > = sor< Rule, raise< Rule > >, this
// would result in some unnecessary run-time overhead.
template< typename Rule >
struct must< Rule >
{
using analyze_t = typename Rule::analyze_t;
template< apply_mode A,
rewind_mode,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
if( !Control< Rule >::template match< A, rewind_mode::dontcare, Action, Control >( in, st... ) ) {
raise< Rule >::template match< A, rewind_mode::dontcare, Action, Control >( in, st... );
}
return true;
}
};
template< typename... Rules >
struct skip_control< must< Rules... > > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif
@@ -0,0 +1,67 @@
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAO_PEGTL_INTERNAL_NOT_AT_HPP
#define TAO_PEGTL_INTERNAL_NOT_AT_HPP
#include "../config.hpp"
#include "seq.hpp"
#include "skip_control.hpp"
#include "trivial.hpp"
#include "../apply_mode.hpp"
#include "../rewind_mode.hpp"
#include "../analysis/generic.hpp"
namespace tao
{
namespace TAO_PEGTL_NAMESPACE
{
namespace internal
{
template< typename... Rules >
struct not_at
: not_at< seq< Rules... > >
{
};
template<>
struct not_at<>
: trivial< false >
{
};
template< typename Rule >
struct not_at< Rule >
{
using analyze_t = analysis::generic< analysis::rule_type::opt, Rule >;
template< apply_mode,
rewind_mode,
template< typename... >
class Action,
template< typename... >
class Control,
typename Input,
typename... States >
static bool match( Input& in, States&&... st )
{
const auto m = in.template mark< rewind_mode::required >();
return !Control< Rule >::template match< apply_mode::nothing, rewind_mode::active, Action, Control >( in, st... );
}
};
template< typename... Rules >
struct skip_control< not_at< Rules... > > : std::true_type
{
};
} // namespace internal
} // namespace TAO_PEGTL_NAMESPACE
} // namespace tao
#endif

Some files were not shown because too many files have changed in this diff Show More