15 #include "rcl/error_handling.h"
42 return zero_initialized;
57 if (NULL != buffer->
impl) {
58 RCL_SET_ERROR_MSG(
"buffer must be zero initialized");
63 RCL_CHECK_FOR_NULL_WITH_MSG(
66 buffer->
impl->text = text;
67 buffer->
impl->text_idx = 0u;
68 buffer->
impl->start[0] = 0u;
69 buffer->
impl->start[1] = 0u;
70 buffer->
impl->end[0] = 0u;
71 buffer->
impl->end[1] = 0u;
74 buffer->
impl->allocator = allocator;
84 RCL_CHECK_FOR_NULL_WITH_MSG(
89 buffer->
impl->allocator.deallocate(buffer->
impl, buffer->
impl->allocator.state);
102 RCL_CHECK_FOR_NULL_WITH_MSG(
109 if (buffer->
impl->text_idx >= buffer->
impl->end[0]) {
113 &(buffer->
impl->type[0]),
120 buffer->
impl->start[0] = buffer->
impl->text_idx;
121 buffer->
impl->end[0] = buffer->
impl->start[0] + length;
124 *next_type = buffer->
impl->type[0];
146 *next_type2 = *next_type1;
152 if (buffer->
impl->text_idx >= buffer->
impl->end[1]) {
155 &(buffer->
impl->text[buffer->
impl->end[0]]),
156 &(buffer->
impl->type[1]),
163 buffer->
impl->start[1] = buffer->
impl->end[0];
164 buffer->
impl->end[1] = buffer->
impl->start[1] + length;
167 *next_type2 = buffer->
impl->type[1];
174 const char ** lexeme_text,
175 size_t * lexeme_text_length)
181 RCL_CHECK_FOR_NULL_WITH_MSG(
184 (NULL == lexeme_text && NULL != lexeme_text_length) ||
185 (NULL != lexeme_text && NULL == lexeme_text_length))
187 RCL_SET_ERROR_MSG(
"text and length must both be set or both be NULL");
193 if (NULL != lexeme_text && NULL != lexeme_text_length) {
195 *lexeme_text_length = 0u;
200 if (buffer->
impl->text_idx >= buffer->
impl->end[0]) {
201 RCL_SET_ERROR_MSG(
"no lexeme to accept");
205 if (NULL != lexeme_text && NULL != lexeme_text_length) {
206 *lexeme_text = &(buffer->
impl->text[buffer->
impl->start[0]]);
207 *lexeme_text_length = buffer->
impl->end[0] - buffer->
impl->start[0];
211 buffer->
impl->text_idx = buffer->
impl->end[0];
214 buffer->
impl->start[0] = buffer->
impl->start[1];
215 buffer->
impl->end[0] = buffer->
impl->end[1];
216 buffer->
impl->type[0] = buffer->
impl->type[1];
225 const char ** lexeme_text,
226 size_t * lexeme_text_length)
237 if (type != lexeme) {
239 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
240 "Expected lexeme type (%d) not found, search ended at index %zu",
241 type, buffer->
impl->text_idx);
244 RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(
245 "Expected lexeme type %d, got %d at index %zu", type, lexeme,
246 buffer->
impl->text_idx);
256 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.