Skip to content

Commit

Permalink
Format.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinH committed Apr 18, 2024
1 parent 0f22c9e commit 5f584cb
Show file tree
Hide file tree
Showing 53 changed files with 593 additions and 261 deletions.
8 changes: 6 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The Art of C++
# https://github.com/taocpp

# Copyright (c) 2016-2023 Dr. Colin Hirsch and Daniel Frey
# Copyright (c) 2016-2024 Dr. Colin Hirsch and Daniel Frey
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)

Expand All @@ -14,17 +14,21 @@ Standard: Latest

AccessModifierOffset: -3
AlignAfterOpenBracket: Align
AlignArrayOfStructures: Left
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
Expand Down
1 change: 0 additions & 1 deletion src/example/pegtl/abnf2_errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ namespace TAO_PEGTL_NAMESPACE::abnf2
} // namespace TAO_PEGTL_NAMESPACE::abnf2

#endif

5 changes: 2 additions & 3 deletions src/example/pegtl/abnf2_record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape)
pegtl::abnf2::option,
pegtl::abnf2::rulename,
pegtl::abnf2::repetition,
pegtl::ascii::digit
>::parse< pegtl::abnf2::rulelist,
pegtl::abnf2::control >( in );
pegtl::ascii::digit >::parse< pegtl::abnf2::rulelist,
pegtl::abnf2::control >( in );
std::cout << v;
}
catch( const pegtl::parse_error< input_t::error_position_t >& e ) {
Expand Down
3 changes: 2 additions & 1 deletion src/example/pegtl/calculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace calculator
// number indicates a lower priority.

enum class order : int
{};
{
};

// For each binary operator known to the calculator we need an
// instance of the following data structure with the priority,
Expand Down
90 changes: 90 additions & 0 deletions src/example/pegtl/cst.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include <cassert>
#include <string_view>
#include <vector>

#include <tao/pegtl.hpp>
#include <tao/pegtl/contrib/abnf.hpp>

namespace TAO_PEGTL_NAMESPACE
{
namespace cst
{
template< typename Data, typename Position >
struct node
{
Position pos;
std::string_view rule;
std::span< const Data > data;
std::vector< std::unique_ptr< node > > children;
};

namespace internal
{
template< typename Data, typename Position >
struct state
{
state()
{
stack.emplace_back( new node );
}

std::vector< std::size_t > rewind;
std::vector< std::unique_ptr< node > > stack;
};

template< typename Rule >
struct control
{
template< typename ParseInput, typename State >
static void prep_rewind( const ParseInput& /*unused*/, State& st )
{
st.rewind.emplace_back( st.stack.size() );
}

template< typename ParseInput, typename State >
static void will_rewind( const ParseInput& /*unused*/, State& st )
{
assert( !st.rewind.empty() );
assert( st.stack.size() >= st.rewind.back() );
st.stack.resize( st.rewind.back() );
st.rewind.pop_back();
}

template< typename ParseInput, typename State >
static void wont_rewind( const ParseInput& /*unused*/, State& st )
{
assert( !st.rewind.empty() );
st.rewind.pop_back();
}
};

} // namespace internal

template< typename Rule, typename ParseInput >
[[nodiscard]] std::unique_ptr< typename ParseInput::data_t > parse( ParseInput& in )
{
internal::state< typename ParseInput::data_t, typename ParseInput::error_position_t > st;
if( !TAO_PEGTL_NAMESPACE::parse< Rule, ..., rewind_control< control >::type >( in, st ) ) {
return nullptr;
}
assert( st.rewind.empty() );
assert( st.stack.size() == 1 );
return std::move( st.stack.back() );
}

} // namespace cst

namespace ast
{
} // namespace ast

namespace tst
{
} // namespace tst

} // namespace TAO_PEGTL_NAMESPACE

int main( int argc, char** argv )
{
return 0;
}
2 changes: 1 addition & 1 deletion src/example/pegtl/json_analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <iostream>

#include <tao/pegtl.hpp>
#include <tao/pegtl/debug/analyze.hpp>
#include <tao/pegtl/contrib/json.hpp>
#include <tao/pegtl/debug/analyze.hpp>

namespace pegtl = TAO_PEGTL_NAMESPACE;

Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/json_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <iostream>

#include <tao/pegtl.hpp>
#include <tao/pegtl/contrib/check_depth.hpp>
#include <tao/pegtl/contrib/input_with_depth.hpp>
#include <tao/pegtl/contrib/json.hpp>
#include <tao/pegtl/contrib/check_depth.hpp>

#include "json_errors.hpp"

Expand Down
3 changes: 1 addition & 2 deletions src/example/pegtl/json_record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape)
pegtl::json::string_content,
pegtl::json::true_,
pegtl::json::false_,
pegtl::json::null
>::parse< example::grammar >( in );
pegtl::json::null >::parse< example::grammar >( in );
std::cout << v;
}
catch( const pegtl::parse_error< input_t::error_position_t >& e ) {
Expand Down
8 changes: 5 additions & 3 deletions src/example/pegtl/json_tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
#include <vector>

#include <tao/pegtl.hpp>
#include <tao/pegtl/debug/analyze.hpp>
#include <tao/pegtl/contrib/json.hpp>
#include <tao/pegtl/debug/analyze.hpp>

namespace TAO_PEGTL_NAMESPACE::json
{
struct token_rule : padr< sor< one< '[' >, one< ']' >, one< '{' >, one< '}' >, one< ':' >, one< ',' >, string, number, false_, true_, null > > {};
struct token_rule : padr< sor< one< '[' >, one< ']' >, one< '{' >, one< '}' >, one< ':' >, one< ',' >, string, number, false_, true_, null > >
{};

struct token_file : until< eof, token_rule > {};
struct token_file : until< eof, token_rule >
{};

enum class token_type
{
Expand Down
3 changes: 2 additions & 1 deletion src/example/pegtl/random_order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ int main( int argc, char** argv )
argv_input< scan::lf_crlf > in( argv, i );
const bool b = parse< grammar1 >( in );
std::cout << "input: " << argv[ i ] << " rnd: " << b << std::endl;
} {
}
{
argv_input< scan::lf_crlf > in( argv, i );
const bool b = parse< grammar2 >( in );
std::cout << "input: " << argv[ i ] << " rnd_opt: " << b << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion src/example/pegtl/uri_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ int main()
#include <iostream>

#include <tao/pegtl.hpp>
#include <tao/pegtl/debug/trace.hpp>
#include <tao/pegtl/contrib/uri.hpp>
#include <tao/pegtl/debug/trace.hpp>

namespace pegtl = TAO_PEGTL_NAMESPACE;

Expand Down
9 changes: 6 additions & 3 deletions src/test/pegtl/action_change_action_and_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,22 @@ namespace TAO_PEGTL_NAMESPACE
const auto result = parse< AB, my_action_1 >( in, c );
TAO_PEGTL_TEST_ASSERT( result );
TAO_PEGTL_TEST_ASSERT( c == 4 );
} {
}
{
text_view_input< scan::lf > in( "a" );
int c = 0;
const auto result = parse< AB, my_action_1 >( in, c );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( c == 1 );
} {
}
{
text_view_input< scan::lf > in( "b" );
int c = 0;
const auto result = parse< AB, my_action_1 >( in, c );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( c == 0 );
} {
}
{
text_view_input< scan::lf > in( "ab" );
int c = 5;
const auto result = parse< disable< AB >, my_action_1 >( in, c );
Expand Down
9 changes: 6 additions & 3 deletions src/test/pegtl/action_change_action_and_states.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,22 @@ namespace TAO_PEGTL_NAMESPACE
const auto result = parse< AB, my_action_1 >( in, c );
TAO_PEGTL_TEST_ASSERT( result );
TAO_PEGTL_TEST_ASSERT( c == 3 );
} {
}
{
text_view_input< scan::lf > in( "a" );
int c = 0;
const auto result = parse< AB, my_action_1 >( in, c );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( c == 1 );
} {
}
{
text_view_input< scan::lf > in( "b" );
int c = 0;
const auto result = parse< AB, my_action_1 >( in, c );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( c == 0 );
} {
}
{
text_view_input< scan::lf > in( "ab" );
int c = 5;
const auto result = parse< disable< AB >, my_action_1 >( in, c );
Expand Down
9 changes: 6 additions & 3 deletions src/test/pegtl/action_change_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,22 @@ namespace TAO_PEGTL_NAMESPACE
const auto result = parse< AB, my_action >( in, c );
TAO_PEGTL_TEST_ASSERT( result );
TAO_PEGTL_TEST_ASSERT( c == 4 );
} {
}
{
text_view_input< scan::lf > in( "a" );
int c = 0;
const auto result = parse< AB, my_action >( in, c );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( c == 1 );
} {
}
{
text_view_input< scan::lf > in( "b" );
int c = 0;
const auto result = parse< AB, my_action >( in, c );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( c == 0 );
} {
}
{
text_view_input< scan::lf > in( "ab" );
int c = 5;
const auto result = parse< disable< AB >, my_action >( in, c );
Expand Down
9 changes: 6 additions & 3 deletions src/test/pegtl/action_change_states.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,22 @@ namespace TAO_PEGTL_NAMESPACE
const auto result = parse< AB, my_action >( in, c );
TAO_PEGTL_TEST_ASSERT( result );
TAO_PEGTL_TEST_ASSERT( c == 3 );
} {
}
{
text_view_input< scan::lf > in( "a" );
int c = 0;
const auto result = parse< AB, my_action >( in, c );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( c == 1 );
} {
}
{
text_view_input< scan::lf > in( "b" );
int c = 0;
const auto result = parse< AB, my_action >( in, c );
TAO_PEGTL_TEST_ASSERT( !result );
TAO_PEGTL_TEST_ASSERT( c == 0 );
} {
}
{
text_view_input< scan::lf > in( "ab" );
int c = 5;
const auto result = parse< disable< AB >, my_action >( in, c );
Expand Down
3 changes: 2 additions & 1 deletion src/test/pegtl/buffer_cstream_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ namespace TAO_PEGTL_NAMESPACE
TAO_PEGTL_TEST_ASSERT( parse< file_grammar >( in ) );
TAO_PEGTL_TEST_ASSERT( in.empty() );
std::fclose( stream );
} {
}
{
#if defined( _MSC_VER )
std::FILE* stream;
::fopen_s( &stream, filename, "rb" );
Expand Down
3 changes: 2 additions & 1 deletion src/test/pegtl/buffer_istream_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ namespace TAO_PEGTL_NAMESPACE
static_istream_input< void > in( stream );
TAO_PEGTL_TEST_ASSERT( parse< file_grammar >( in ) );
TAO_PEGTL_TEST_ASSERT( in.empty() );
} {
}
{
std::ifstream stream( filename );
dynamic_istream_input< void > in( 100, 90, stream );
TAO_PEGTL_TEST_ASSERT( parse< file_grammar >( in ) );
Expand Down
21 changes: 14 additions & 7 deletions src/test/pegtl/contrib_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,38 @@ namespace TAO_PEGTL_NAMESPACE
{
text_view_input< ascii::crlf > in( "0\r\n\r\n" );
TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( in ) );
} {
}
{
std::string dummy;
text_view_input< ascii::crlf > in( "0\r\n\r\n" );
TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( in, dummy ) );
} {
}
{
std::string state;
text_view_input< ascii::crlf > in( "0\r\n\r\n" );
TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR, chunked_action >( in, state ) );
TAO_PEGTL_TEST_ASSERT( state == "a" );
} {
}
{
std::string state;
text_view_input< ascii::crlf > in( "\r\n\r\n" );
TAO_PEGTL_TEST_THROWS( parse< GRAMMAR, chunked_action >( in, state ) );
} {
}
{
std::string state;
text_view_input< ascii::crlf > in( "1\r\n" );
TAO_PEGTL_TEST_THROWS( parse< GRAMMAR, chunked_action >( in, state ) );
} {
}
{
text_view_input< ascii::crlf > in( "01\r\nX\r\n1a\r\nabcdefghijklmnopqrstuvwxyz\r\n0\r\n\r\n" );
TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( in ) );
} {
}
{
std::string dummy;
text_view_input< ascii::crlf > in( "01\r\nX\r\n1a\r\nabcdefghijklmnopqrstuvwxyz\r\n0\r\n\r\n" );
TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( in, dummy ) );
} {
}
{
std::string state;
text_view_input< ascii::crlf > in( "01\r\nX\r\n1A\r\nabcdefghijklmnopqrstuvwxyz\r\n0\r\n\r\n" );
TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR, chunked_action >( in, state ) );
Expand Down
Loading

0 comments on commit 5f584cb

Please sign in to comment.