rcl  master
C API providing common ROS client library functionality.
Classes | Typedefs | Functions
lexer_lookahead.h File Reference
#include <stddef.h>
#include "rcl/allocator.h"
#include "rcl/lexer.h"
#include "rcl/macros.h"
#include "rcl/types.h"
#include "rcl/visibility_control.h"
Include dependency graph for lexer_lookahead.h:

Go to the source code of this file.

Classes

struct  rcl_lexer_lookahead2_t
 Track lexical analysis and allow looking ahead 2 lexemes. More...
 

Typedefs

typedef struct rcl_lexer_lookahead2_t rcl_lexer_lookahead2_t
 Track lexical analysis and allow looking ahead 2 lexemes.
 

Functions

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...
 

Function Documentation

◆ rcl_get_zero_initialized_lexer_lookahead2()

rcl_lexer_lookahead2_t rcl_get_zero_initialized_lexer_lookahead2 ( )

Get a zero initialized rcl_lexer_lookahead2_t instance.

See also
rcl_lexer_lookahead2_init()
Attribute Adherence
Allocates Memory No
Thread-Safe Yes
Uses Atomics No
Lock-Free Yes
Returns
zero initialized lookahead2 buffer.

◆ rcl_lexer_lookahead2_init()

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.

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]bufferA buffer that is zero initialized.
See also
rcl_get_zero_initialized_lexer_lookahead2()
Parameters
[in]textThe string to analyze.
[in]allocatorAn 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()

rcl_ret_t rcl_lexer_lookahead2_fini ( rcl_lexer_lookahead2_t buffer)

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]bufferThe 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()

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.

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]bufferthe lookahead2 buffer being used to analyze a string.
[out]next_typean 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()

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.

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]bufferthe lookahead2 buffer being used to analyze a string.
[out]next_type1an output variable for the next lexeme in the string.
[out]next_type2an 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()

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.

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]bufferthe lookahead2 buffer being used to analyze a string.
[out]lexeme_textpointer to where lexeme begins in string.
[out]lexeme_text_lengthlength 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()

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.

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]bufferthe lookahead2 buffer being used to analyze a string.
[in]typethe type the next lexeme must be.
[out]lexeme_textpointer to where lexeme begins in string.
[out]lexeme_text_lengthlength 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()

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.


Attribute Adherence
Allocates Memory No
Thread-Safe Yes
Uses Atomics No
Lock-Free Yes
Parameters
[in]bufferthe 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.