#include <lexer.hpp>
template<StandardCharacter CharType>
class fly::BasicLexer< CharType >
Helper class to perform lexical analysis of a C-string literal. All methods are constant expressions, allowing for string analysis at compile time.
- Author
- Timothy Flynn (trfly.nosp@m.nn89.nosp@m.@pm.m.nosp@m.e)
- Version
- January 3, 2021
◆ BasicLexer() [1/2]
template<StandardCharacter CharType>
template<std::size_t N>
|
explicitconstexprnoexcept |
Constructor. Stores a view into a C-string literal.
- Template Parameters
-
N | The size of the C-string literal. |
- Parameters
-
literals | Reference to a C-string literal of size N. |
◆ BasicLexer() [2/2]
template<StandardCharacter CharType>
|
explicitconstexprnoexcept |
Constructor. Stores an existing view into a string.
- Parameters
-
view | The existing view into the string. |
◆ consume()
template<StandardCharacter CharType>
If a character is available at the current position in the C-string literal, return that character and advance the current position to the next character.
- Returns
- If available, the current character. Otherwise, an uninitialized value.
◆ consume_hex_number()
template<StandardCharacter CharType>
constexpr std::optional< std::uintmax_t > fly::BasicLexer< CharType >::consume_hex_number |
|
constexpr |
Beginning with the current position, retrieve characters from the C-string literal and advance the current position to the next character until a character is either not available or not a hexadecimal digit. Convert the retrieved characters to an unsigned number.
- Returns
- If consumed, the parsed hexadecimal number. Otherwise, an uninitialized value.
◆ consume_if()
template<StandardCharacter CharType>
If a character is available at the current position in the C-string literal, and if that character is equivalent to the provided character, advance the current position to the next character.
- Parameters
-
ch | The character to test with. |
- Returns
- Whether the current character was available and matched the provided character.
◆ consume_number()
template<StandardCharacter CharType>
constexpr std::optional< std::uintmax_t > fly::BasicLexer< CharType >::consume_number |
|
constexpr |
Beginning with the current position, retrieve characters from the C-string literal and advance the current position to the next character until a character is either not available or not a decimal digit. Convert the retrieved characters to an unsigned number.
- Returns
- If consumed, the parsed decimal number. Otherwise, an uninitialized value.
◆ peek()
template<StandardCharacter CharType>
constexpr std::optional< CharType > fly::BasicLexer< CharType >::peek |
( |
std::size_t |
offset = 0 | ) |
|
|
constexpr |
If a character is available at the current position (or some offset from the current position) in the C-string literal, return that character.
- Parameters
-
offset | The offset from the current position to peek. |
- Returns
- If available, the character at the provided offset. Otherwise, an uninitialized value.
◆ position()
template<StandardCharacter CharType>
- Returns
- The lexer's current position into the C-string literal.
◆ set_position()
template<StandardCharacter CharType>
constexpr void fly::BasicLexer< CharType >::set_position |
( |
std::size_t |
position | ) |
|
|
constexpr |
Set the lexer's current position into the C-string literal.
The provided position is not checked for validity. If the position is past-the-end of the C-string literal, further operations will fail (i.e. |peek| and |consume| will return std::nullopt).
- Parameters
-
position | The lexer's new position. |
◆ view()
template<StandardCharacter CharType>
- Returns
- A string view into the C-string literal.
The documentation for this class was generated from the following file: