Reactions  0.1.2
Handling reaction trees and decays
tokens.hpp
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include <cstdlib>
7 #include <string>
8 #include <utility>
9 
12 namespace reactions::tokens {
13 
15  template <char... C> struct token {
16  static const size_t size = sizeof...(C);
17  };
18 
20  using space = token<' '>;
22  using arrow = token<'-', '>'>;
24  using left_bra = token<'{'>;
27 
29  template <char... C, std::size_t... I>
31  std::string::const_iterator const &it) {
32  return ((*(it + I) == C) && ...);
33  }
34 
36  template <class Token>
37  bool match_token(std::string::const_iterator const &it) {
39  it);
40  }
41 
43  template <char... C> constexpr bool match_any(char c) {
44  return ((C == c) || ...);
45  }
46 
49  template <char C0, char C1> constexpr bool match_range(char c) {
50  return (c >= C0) && (c <= C1);
51  }
52 } // namespace reactions::tokens
constexpr bool match_range(char c)
Definition: tokens.hpp:49
static const size_t size
Definition: tokens.hpp:16
constexpr bool match_any(char c)
Check if the given character matches any of the template arguments.
Definition: tokens.hpp:43
Template to define new tokens.
Definition: tokens.hpp:15
bool match_token(std::string::const_iterator const &it)
Check if the iterator at the current position matches the token.
Definition: tokens.hpp:37
Syntax tokens.
Definition: tokens.hpp:12
bool match_token_impl(token< C... >, std::index_sequence< I... >, std::string::const_iterator const &it)
Check if the iterator at the current position matches the token.
Definition: tokens.hpp:30