18 #include "rcl/error_handling.h"
45 return zero_initialized;
60 if (NULL != buffer->
impl) {
61 RCL_SET_ERROR_MSG(
"buffer must be zero initialized");
66 RCL_CHECK_FOR_NULL_WITH_MSG(
69 buffer->
impl->text = text;
70 buffer->
impl->text_idx = 0u;
71 buffer->
impl->start[0] = 0u;
72 buffer->
impl->start[1] = 0u;
73 buffer->
impl->end[0] = 0u;
74 buffer->
impl->end[1] = 0u;
77 buffer->
impl->allocator = allocator;
87 RCL_CHECK_FOR_NULL_WITH_MSG(
92 buffer->
impl->allocator.deallocate(buffer->
impl, buffer->
impl->allocator.state);
105 RCL_CHECK_FOR_NULL_WITH_MSG(
112 if (buffer->
impl->text_idx >= buffer->
impl->end[0]) {
116 &(buffer->
impl->type[0]),
123 buffer->
impl->start[0] = buffer->
impl->text_idx;
124 buffer->
impl->end[0] = buffer->
impl->start[0] + length;
127 *next_type = buffer->
impl->type[0];
149 *next_type2 = *next_type1;
155 if (buffer->
impl->text_idx >= buffer->
impl->end[1]) {
158 &(buffer->
impl->text[buffer->
impl->end[0]]),
159 &(buffer->
impl->type[1]),
166 buffer->
impl->start[1] = buffer->
impl->end[0];
167 buffer->
impl->end[1] = buffer->
impl->start[1] + length;
170 *next_type2 = buffer->
impl->type[1];
177 const char ** lexeme_text,
178 size_t * lexeme_text_length)
184 RCL_CHECK_FOR_NULL_WITH_MSG(
187 (NULL == lexeme_text && NULL != lexeme_text_length) ||
188 (NULL != lexeme_text && NULL == lexeme_text_length))
190 RCL_SET_ERROR_MSG(
"text and length must both be set or both be NULL");
196 if (NULL != lexeme_text && NULL != lexeme_text_length) {
198 *lexeme_text_length = 0u;
203 if (buffer->
impl->text_idx >= buffer->
impl->end[0]) {
204 RCL_SET_ERROR_MSG(
"no lexeme to accept");
208 if (NULL != lexeme_text && NULL != lexeme_text_length) {
209 *lexeme_text = &(buffer->
impl->text[buffer->
impl->start[0]]);
210 *lexeme_text_length = buffer->
impl->end[0] - buffer->
impl->start[0];
214 buffer->
impl->text_idx = buffer->
impl->end[0];
217 buffer->
impl->start[0] = buffer->
impl->start[1];
218 buffer->
impl->end[0] = buffer->
impl->end[1];
219 buffer->
impl->type[0] = buffer->
impl->type[1];
228 const char ** lexeme_text,
229 size_t * lexeme_text_length)
240 if (type != lexeme) {
242 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
243 "Expected lexeme type (%d) not found, search ended at index %zu",
244 type, buffer->
impl->text_idx);
247 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
248 "Expected lexeme type %d, got %d at index %zu", type, lexeme,
249 buffer->
impl->text_idx);
259 return &(buffer->
impl->text[buffer->
impl->text_idx]);
#define RCL_CHECK_ALLOCATOR_WITH_MSG(allocator, msg, fail_statement)
Check that the given allocator is initialized, or fail with a message.
rcutils_allocator_t rcl_allocator_t
Encapsulation of an allocator.
@ RCL_LEXEME_NONE
Indicates no valid lexeme was found (end of input not reached)
@ RCL_LEXEME_EOF
Indicates end of input has been reached.
enum rcl_lexeme_e rcl_lexeme_t
Type of lexeme found by lexical analysis.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_lexer_analyze(const char *text, rcl_lexeme_t *lexeme, size_t *length)
Do lexical analysis on a string.
RCL_PUBLIC RCL_WARN_UNUSED rcl_lexer_lookahead2_t rcl_get_zero_initialized_lexer_lookahead2(void)
Get a zero initialized rcl_lexer_lookahead2_t instance.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_lexer_lookahead2_fini(rcl_lexer_lookahead2_t *buffer)
Finalize an instance of an rcl_lexer_lookahead2_t structure.
RCL_PUBLIC RCL_WARN_UNUSED 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.
RCL_PUBLIC RCL_WARN_UNUSED 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.
RCL_PUBLIC RCL_WARN_UNUSED 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.
RCL_PUBLIC RCL_WARN_UNUSED 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.
RCL_PUBLIC RCL_WARN_UNUSED 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.
RCL_PUBLIC RCL_WARN_UNUSED 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.
Track lexical analysis and allow looking ahead 2 lexemes.
rcl_lexer_lookahead2_impl_t * impl
Pointer to the lexer look ahead2 implementation.
#define RCL_RET_WRONG_LEXEME
Expected one type of lexeme but got another.
#define RCL_RET_OK
Success return code.
#define RCL_RET_BAD_ALLOC
Failed to allocate memory return code.
#define RCL_RET_INVALID_ARGUMENT
Invalid argument return code.
#define RCL_RET_ERROR
Unspecified error return code.
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.