3rdparty
lexy
include
lexy
dsl
eof.hpp
Go to the documentation of this file.
1
// Copyright (C) 2020-2024 Jonathan Müller and lexy contributors
2
// SPDX-License-Identifier: BSL-1.0
3
4
#ifndef LEXY_DSL_EOF_HPP_INCLUDED
5
#define LEXY_DSL_EOF_HPP_INCLUDED
6
7
#include <
lexy/dsl/base.hpp
>
8
#include <
lexy/error.hpp
>
9
10
namespace
lexy
11
{
12
struct
expected_eof
13
{
14
static
LEXY_CONSTEVAL
auto
name
()
15
{
16
return
"expected EOF"
;
17
}
18
};
19
}
// namespace lexy
20
21
namespace
lexyd
22
{
23
struct
_eof
:
branch_base
24
{
25
template
<
typename
Reader>
26
struct
bp
27
{
28
constexpr
bool
try_parse
(
const
void
*,
const
Reader& reader)
29
{
30
return
reader.peek() ==
Reader::encoding::eof
();
31
}
32
33
template
<
typename
Context>
34
constexpr
void
cancel
(Context&)
35
{}
36
37
template
<
typename
NextParser,
typename
Context,
typename
... Args>
38
LEXY_PARSER_FUNC
bool
finish
(Context& context, Reader& reader, Args&&... args)
39
{
40
auto
pos = reader.position();
41
context.on(
_ev::token
{},
lexy::eof_token_kind
, pos, pos);
42
return
NextParser::parse
(context, reader,
LEXY_FWD
(args)...);
43
}
44
};
45
46
template
<
typename
NextParser>
47
struct
p
48
{
49
template
<
typename
Context,
typename
Reader,
typename
... Args>
50
LEXY_PARSER_FUNC
static
bool
parse
(Context& context, Reader& reader, Args&&... args)
51
{
52
if
(reader.peek() !=
Reader::encoding::eof
())
53
{
54
// Report that we've failed.
55
auto
err =
lexy::error<Reader, lexy::expected_eof>
(reader.position());
56
context.on(
_ev::error
{}, err);
57
58
// But recover immediately, as we wouldn't have consumed anything either way.
59
}
60
else
61
{
62
auto
pos = reader.position();
63
context.on(
_ev::token
{},
lexy::eof_token_kind
, pos, pos);
64
}
65
66
return
NextParser::parse
(context, reader,
LEXY_FWD
(args)...);
67
}
68
};
69
};
70
72
constexpr
auto
eof
=
_eof
{};
73
}
// namespace lexyd
74
75
#endif // LEXY_DSL_EOF_HPP_INCLUDED
76
lexy::eof_token_kind
@ eof_token_kind
Definition:
grammar.hpp:92
LEXY_CONSTEVAL
#define LEXY_CONSTEVAL
Definition:
config.hpp:98
lexyd::branch_base
Definition:
grammar.hpp:20
LEXY_FWD
#define LEXY_FWD(...)
Definition:
config.hpp:30
lexy
Definition:
any_ref.hpp:12
lexy::error
Generic failure.
Definition:
error.hpp:14
lexy::expected_eof::name
static LEXY_CONSTEVAL auto name()
Definition:
eof.hpp:14
lexy::parse
constexpr auto parse(const Input &input, const ErrorCallback &callback)
Parses the production into a value, invoking the callback on error.
Definition:
parse.hpp:171
lexyd::_eof::bp::finish
LEXY_PARSER_FUNC bool finish(Context &context, Reader &reader, Args &&... args)
Definition:
eof.hpp:38
lexyd::_eof
Definition:
eof.hpp:23
lexy::parse_events::error
Definition:
dsl/base.hpp:68
LEXY_PARSER_FUNC
#define LEXY_PARSER_FUNC
Definition:
dsl/base.hpp:108
lexyd::_eof::p
Definition:
eof.hpp:47
base.hpp
lexy::parse_events::token
Definition:
dsl/base.hpp:57
lexyd::_eof::bp
Definition:
eof.hpp:26
lexyd::_eof::bp::cancel
constexpr void cancel(Context &)
Definition:
eof.hpp:34
lexyd::_eof::bp::try_parse
constexpr bool try_parse(const void *, const Reader &reader)
Definition:
eof.hpp:28
lexyd::_eof::p::parse
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, Args &&... args)
Definition:
eof.hpp:50
lexyd
Definition:
trace.hpp:22
lexyd::eof
constexpr auto eof
Matches EOF.
Definition:
eof.hpp:72
lexy::expected_eof
Definition:
eof.hpp:12
error.hpp
behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Dec 13 2024 03:19:16