Go to the documentation of this file.
4 #ifndef LEXY_DSL_SYMBOL_HPP_INCLUDED
5 #define LEXY_DSL_SYMBOL_HPP_INCLUDED
15 #define LEXY_SYMBOL(Str) LEXY_NTTP_STRING(::lexy::_detail::type_string, Str)
17 template <
typename T,
template <
typename>
typename CaseFolding,
typename... Strings>
22 if constexpr (
sizeof...(Strings) == 0)
42 template <
typename CaseFoldingDSL>
49 template <
typename SymbolString,
typename... Args>
52 using next_table =
_symbol_table<T, CaseFolding, Strings..., SymbolString>;
53 if constexpr (
empty())
60 template <_detail::string_literal SymbolString,
typename... Args>
63 return map<_detail::to_type_string<_detail::type_string, SymbolString>>(
LEXY_FWD(args)...);
66 # if (defined(__clang__) && __clang_major__ <= 7) \
67 || (defined(__clang__) && defined(__apple_build_version__) && __clang_major__ <= 10)
68 template <
char C,
typename... Args>
70 template <
auto C,
typename... Args>
78 template <
typename CharT, CharT... C,
typename... Args>
85 static constexpr
bool empty() noexcept
90 static constexpr std::size_t
size() noexcept
92 return sizeof...(Strings);
103 if constexpr (
empty())
111 constexpr
const char_type* strings[] = {Strings::template c_str<char_type>...};
130 return _idx == rhs._idx;
163 constexpr
explicit operator bool() const noexcept
170 return lhs._value == rhs._value;
174 return lhs._value != rhs._value;
178 template <
typename Reader>
181 static_assert(!
empty(),
"symbol table must not be empty");
182 using encoding =
typename Reader::encoding;
185 if (result == _trie<encoding>.node_no_match)
191 template <
typename Input>
194 auto reader = input.reader();
205 return _data[idx._value];
211 template <
typename Encoding>
221 template <
typename Encoding>
223 = _build_trie<Encoding>();
225 template <std::size_t... Idx,
typename... Args>
231 template <std::size_t... Idx,
template <
typename>
typename OtherCaseFolding>
234 :
_data{table._data[Idx]...}
239 template <
typename,
template <
typename>
typename,
typename...>
243 template <
typename T>
253 return "unknown symbol";
260 template <
typename Leading,
typename Trailing>
262 template <
typename Leading,
typename Trailing,
typename... Reserved>
265 template <const auto& Table,
typename Token,
typename Tag>
266 struct _sym : branch_base
268 template <
typename Reader>
271 static_assert(lexy::is_char_encoding<typename Reader::encoding>);
272 typename Reader::marker
end;
280 template <
typename ControlBlock>
281 constexpr
bool try_parse(ControlBlock&,
const Reader& reader)
285 if (!parser.try_parse(reader))
291 symbol = Table.parse(content);
294 return static_cast<bool>(
symbol);
297 template <
typename Context>
301 template <
typename NextParser,
typename Context,
typename... Args>
305 context.on(
_ev::token{}, Token{}, reader.position(),
end.position());
314 template <
typename NextParser>
317 template <
typename... PrevArgs>
320 template <
typename Context,
typename Reader>
326 auto symbol = Table.parse(content);
341 template <
typename Context,
typename Reader,
typename... Args>
344 static_assert(lexy::is_char_encoding<typename Reader::encoding>);
352 template <
typename ErrorTag>
359 template <const auto& Table,
typename L,
typename T,
typename Tag>
362 template <
typename Reader>
365 static_assert(lexy::is_char_encoding<typename Reader::encoding>);
367 typename Reader::marker
end;
377 symbol = Table.try_parse(reader);
380 end = reader.current();
386 template <
typename Context>
390 template <
typename NextParser,
typename Context,
typename... Args>
403 template <
typename NextParser>
406 template <
typename Context,
typename Reader,
typename... Args>
409 static_assert(lexy::is_char_encoding<typename Reader::encoding>);
410 auto begin = reader.position();
413 auto symbol_reader = reader;
414 auto symbol = Table.try_parse(symbol_reader);
434 auto end = symbol_reader.current();
446 template <
typename ErrorTag>
450 template <const auto& Table,
typename Tag>
453 template <
typename Reader>
456 static_assert(lexy::is_char_encoding<typename Reader::encoding>);
458 typename Reader::marker
end;
468 symbol = Table.try_parse(reader);
469 end = reader.current();
472 return static_cast<bool>(
symbol);
475 template <
typename Context>
479 template <
typename NextParser,
typename Context,
typename... Args>
493 template <
typename NextParser>
496 template <
typename Context,
typename Reader,
typename... Args>
499 static_assert(lexy::is_char_encoding<typename Reader::encoding>);
501 if (impl.try_parse(context.control_block, reader))
502 return impl.template finish<NextParser>(context, reader,
LEXY_FWD(args)...);
503 impl.cancel(context);
515 template <
typename ErrorTag>
519 template <const auto& Table>
522 template <
typename Token>
525 static_assert(lexy::is_token_rule<Token>);
528 template <
typename L,
typename T,
typename... R>
531 static_assert(
sizeof...(R) == 0,
532 "symbol() must not be used in the presence of reserved identifiers");
533 return _sym<Table, decltype(
id.pattern()),
void>{};
538 template <const auto& Table>
542 #endif // LEXY_DSL_SYMBOL_HPP_INCLUDED
constexpr auto size(const C &c) -> decltype(c.size())
constexpr void cancel(Context &)
static LEXY_CONSTEVAL auto _build_trie()
constexpr bool try_parse(const void *, Reader reader)
static constexpr lexy::_detail::lit_trie< Encoding, CaseFolding, _max_char_count > _trie
LEXY_PARSER_FUNC bool finish(Context &context, Reader &reader, Args &&... args)
constexpr friend bool operator==(key_index lhs, key_index rhs) noexcept
constexpr _symbol_table(lexy::_detail::index_sequence< Idx... >, const _symbol_table< T, OtherCaseFolding, Strings... > &table)
constexpr iterator(const _symbol_table *table, std::size_t idx) noexcept
static constexpr bool empty() noexcept
string_view::value_type char_type
std::remove_cv_t< value_type > value_type
constexpr value_type deref() const noexcept
constexpr auto operator()(_id< L, T, R... > id) const
LEXY_PARSER_FUNC bool finish(Context &context, Reader &reader, Args &&... args)
constexpr auto operator()(Token) const
friend class _symbol_table
constexpr key_index(std::size_t idx) noexcept
LEXY_CONSTEVAL _symbol_table()
constexpr auto symbol_table
constexpr iterator end() const noexcept
std::conditional_t< std::is_void_v< T >, Fallback, T > type_or
LEXY_CONSTEVAL std::size_t insert(std::size_t from, CharT _c)
LEXY_DECAY_DECLTYPE(Table) Reader::marker end
static constexpr std::size_t size() noexcept
LEXY_DECAY_DECLTYPE(Table) Reader::marker end
constexpr auto value() const
#define LEXY_PRECONDITION(Expr)
std::conditional_t< empty(), char, T > _data[empty() ? 1 :size()]
typename _make_index_sequence< Size >::type make_index_sequence
constexpr auto end(const C &c) -> decltype(c.end())
constexpr friend bool operator!=(key_index lhs, key_index rhs) noexcept
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, Args &&... args)
constexpr bool try_parse(const void *, Reader reader)
constexpr bool equal(iterator rhs) const noexcept
constexpr iterator() noexcept
constexpr auto parse(const Input &input, const ErrorCallback &callback)
Parses the production into a value, invoking the callback on error.
constexpr auto symbol
Parses optional rule, then matches the resulting lexeme against the symbol table.
const mapped_type & value
LEXY_CONSTEVAL auto map(lexyd::_lit< CharT, C... >, Args &&... args) const
constexpr void decrement() noexcept
constexpr LEXY_FORCE_INLINE auto try_match_token(TokenRule, Reader &reader)
static constexpr auto _max_char_count
std::size_t node_value[max_node_count]
#define LEXY_DECAY_DECLTYPE(...)
constexpr auto partial_input(const Reader &, typename Reader::iterator begin, typename Reader::iterator end)
decltype(_char_type()) char_type
constexpr auto begin(const C &c) -> decltype(c.begin())
constexpr key_index() noexcept
constexpr iterator begin() const noexcept
constexpr key_index try_parse(Reader &reader) const
A parser that does not support any arguments.
LEXY_PARSER_FUNC bool finish(Context &context, Reader &reader, Args &&... args)
const _symbol_table * _table
constexpr void cancel(Context &)
constexpr bool try_parse(ControlBlock &, const Reader &reader)
lexeme(const Reader &, typename Reader::iterator) -> lexeme< typename Reader::canonical_reader >
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, Args &&... args)
typename Rule::template p< NextParser > parser_for
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, Args &&... args)
constexpr auto value() const
constexpr LEXY_DECAY_DECLTYPE(Table) auto value() const
constexpr void increment() noexcept
static LEXY_PARSER_FUNC bool parse(Context &context, Reader &reader, PrevArgs &&... args, lexy::lexeme< Reader > lexeme)
LEXY_CONSTEVAL auto case_folding(CaseFoldingDSL) const
constexpr void cancel(Context &)
constexpr key_index parse(const Input &input) const
#define LEXY_DECLVAL(...)
constexpr _symbol_table(lexy::_detail::index_sequence< Idx... >, const T *data, Args &&... args)
LEXY_CONSTEVAL auto map(Args &&... args) const
typename TokenRule::template tp< Reader > token_parser_for
constexpr const T & operator[](key_index idx) const noexcept
constexpr auto eof
Matches EOF.
constexpr auto p
Parses the production.
static LEXY_CONSTEVAL auto name()