#include <stddef.h>
#include "rcl/allocator.h"
#include "rcl/lexer.h"
#include "rcl/macros.h"
#include "rcl/types.h"
#include "rcl/visibility_control.h"
Go to the source code of this file.
|
rcl_lexer_lookahead2_t | rcl_get_zero_initialized_lexer_lookahead2 () |
| Get a zero initialized rcl_lexer_lookahead2_t instance. More...
|
|
rcl_ret_t | rcl_lexer_lookahead2_init (rcl_lexer_lookahead2_t *buffer, const char *text, rcl_allocator_t allocator) |
| Initialize an rcl_lexer_lookahead2_t instance. More...
|
|
rcl_ret_t | rcl_lexer_lookahead2_fini (rcl_lexer_lookahead2_t *buffer) |
| Finalize an instance of an rcl_lexer_lookahead2_t structure. More...
|
|
rcl_ret_t | rcl_lexer_lookahead2_peek (rcl_lexer_lookahead2_t *buffer, rcl_lexeme_t *next_type) |
| Look ahead at the next lexeme in the string. More...
|
|
rcl_ret_t | rcl_lexer_lookahead2_peek2 (rcl_lexer_lookahead2_t *buffer, rcl_lexeme_t *next_type1, rcl_lexeme_t *next_type2) |
| Look ahead at the next two lexemes in the string. More...
|
|
rcl_ret_t | rcl_lexer_lookahead2_accept (rcl_lexer_lookahead2_t *buffer, const char **lexeme_text, size_t *lexeme_text_length) |
| Accept a lexeme and advance analysis. More...
|
|
rcl_ret_t | rcl_lexer_lookahead2_expect (rcl_lexer_lookahead2_t *buffer, rcl_lexeme_t type, const char **lexeme_text, size_t *lexeme_text_length) |
| Require the next lexeme to be a certain type and advance analysis. More...
|
|
const char * | rcl_lexer_lookahead2_get_text (const rcl_lexer_lookahead2_t *buffer) |
| Get the text at the point where it is currently being analyzed. More...
|
|
◆ rcl_lexer_lookahead2_t
Track lexical analysis and allow looking ahead 2 lexemes.
◆ rcl_get_zero_initialized_lexer_lookahead2()
◆ rcl_lexer_lookahead2_init()
Initialize an rcl_lexer_lookahead2_t instance.
The lookahead2 buffer borrows a reference to the provided text. The text must not be freed before the buffer is finalized. The lookahead2 buffer only needs to be finalized if this function does not return RCL_RET_OK.
- See also
- rcl_lexer_lookahead2_fini()
Attribute | Adherence |
Allocates Memory | Yes |
Thread-Safe | No |
Uses Atomics | No |
Lock-Free | Yes |
- Parameters
-
[in] | buffer | A buffer that is zero initialized. |
- See also
- rcl_get_zero_initialized_lexer_lookahead2()
- Parameters
-
[in] | text | The string to analyze. |
[in] | allocator | An allocator to use if an error occurs. |
- Returns
RCL_RET_OK
if the buffer is successfully initialized, or
-
RCL_RET_INVALID_ARGUMENT
if any function arguments are invalid, or
-
RCL_RET_BAD_ALLOC
if allocating memory failed, or
-
RCL_RET_ERROR
if an unspecified error occurrs.
◆ rcl_lexer_lookahead2_fini()
Finalize an instance of an rcl_lexer_lookahead2_t structure.
- See also
- rcl_lexer_lookahead2_init()
Attribute | Adherence |
Allocates Memory | Yes [1] |
Thread-Safe | No |
Uses Atomics | No |
Lock-Free | Yes |
[1] Only allocates if an argument is invalid.
- Parameters
-
[in] | buffer | The structure to be deallocated. |
- Returns
RCL_RET_OK
if the structure was successfully finalized, or
-
RCL_RET_INVALID_ARGUMENT
if any function arguments are invalid, or
-
RCL_RET_ERROR
if an unspecified error occurs.
◆ rcl_lexer_lookahead2_peek()
Look ahead at the next lexeme in the string.
Repeated calls to peek will return the same lexeme. A parser that deems the next lexeme as valid must accept it to advance lexing.
- See also
- rcl_lexer_lookahead2_accept()
Attribute | Adherence |
Allocates Memory | Yes [1] |
Thread-Safe | No |
Uses Atomics | No |
Lock-Free | Yes |
[1] Only allocates if an argument is invalid or an internal bug is detected.
- Parameters
-
[in] | buffer | the lookahead2 buffer being used to analyze a string. |
[out] | next_type | an output variable for the next lexeme in the string. |
- Returns
RCL_RET_OK
if peeking was successfull, or
-
RCL_RET_INVALID_ARGUMENT
if any function arguments are invalid, or
-
RCL_RET_ERROR
if an unspecified error occurs.
◆ rcl_lexer_lookahead2_peek2()
Look ahead at the next two lexemes in the string.
Repeated calls to peek2 will return the same two lexemes. A parser that deems the next two lexemes as valid must accept twice to advance lexing.
- See also
- rcl_lexer_lookahead2_accept()
Attribute | Adherence |
Allocates Memory | Yes [1] |
Thread-Safe | No |
Uses Atomics | No |
Lock-Free | Yes |
[1] Only allocates if an argument is invalid or an internal bug is detected.
- Parameters
-
[in] | buffer | the lookahead2 buffer being used to analyze a string. |
[out] | next_type1 | an output variable for the next lexeme in the string. |
[out] | next_type2 | an output variable for the lexeme after the next lexeme in the string. |
- Returns
RCL_RET_OK
if peeking was successfull, or
-
RCL_RET_INVALID_ARGUMENT
if any function arguments are invalid, or
-
RCL_RET_ERROR
if an unspecified error occurs.
◆ rcl_lexer_lookahead2_accept()
Accept a lexeme and advance analysis.
A token must have been peeked before it can be accepted.
- See also
- rcl_lexer_lookahead2_peek()
-
rcl_lexer_lookahead2_peek2()
Attribute | Adherence |
Allocates Memory | Yes [1] |
Thread-Safe | No |
Uses Atomics | No |
Lock-Free | Yes |
[1] Only allocates if an argument is invalid or an error occurs.
- Parameters
-
[in] | buffer | the lookahead2 buffer being used to analyze a string. |
[out] | lexeme_text | pointer to where lexeme begins in string. |
[out] | lexeme_text_length | length of lexeme_text. |
- Returns
RCL_RET_OK
if peeking was successfull, or
-
RCL_RET_INVALID_ARGUMENT
if any function arguments are invalid, or
-
RCL_RET_ERROR
if an unspecified error occurs.
◆ rcl_lexer_lookahead2_expect()
Require the next lexeme to be a certain type and advance analysis.
This method is a shortcut to peeking and accepting a lexeme. It should be used by a parser when there is only one valid lexeme that could come next.
- See also
- rcl_lexer_lookahead2_peek()
-
rcl_lexer_lookahead2_accept()
Attribute | Adherence |
Allocates Memory | Yes [1] |
Thread-Safe | No |
Uses Atomics | No |
Lock-Free | Yes |
[1] Only allocates if an argument is invalid or an error occurs.
- Parameters
-
[in] | buffer | the lookahead2 buffer being used to analyze a string. |
[in] | type | the type the next lexeme must be. |
[out] | lexeme_text | pointer to where lexeme begins in string. |
[out] | lexeme_text_length | length of lexeme_text. |
- Returns
RCL_RET_OK
if the next lexeme was the expected one, or
-
RCL_RET_WRONG_LEXEME
if the next lexeme was not the expected one, or
-
RCL_RET_INVALID_ARGUMENT
if any function arguments are invalid, or
-
RCL_RET_ERROR
if an unspecified error occurs.
◆ rcl_lexer_lookahead2_get_text()
Get the text at the point where it is currently being analyzed.
Attribute | Adherence |
Allocates Memory | No |
Thread-Safe | Yes |
Uses Atomics | No |
Lock-Free | Yes |
- Parameters
-
[in] | buffer | the lookahead2 buffer being used to analyze a string. |
- Returns
- a pointer inside the original text at the position being analyzed, or
-
NULL
if buffer is itself NULL
or zero initialized, or
-
an undefined value if buffer is not initialized or has been finalized.