Flecs v3.2
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
Parser

Query DSL parser and parsing utilities. More...

Collaboration diagram for Parser:

Macros

#define ECS_PARSER_MAX_ARGS   (16)
 Maximum number of extra arguments in term expression.
 

Functions

FLECS_API const char * ecs_parse_ws (const char *ptr)
 Skip whitespace characters.
 
FLECS_API const char * ecs_parse_ws_eol (const char *ptr)
 Skip whitespace and newline characters.
 
const char * ecs_parse_identifier (const char *name, const char *expr, const char *ptr, char *token_out)
 Utility function to parse an identifier.
 
FLECS_API const char * ecs_parse_digit (const char *ptr, char *token)
 Parse digit.
 
FLECS_API const char * ecs_parse_token (const char *name, const char *expr, const char *ptr, char *token_out, char delim)
 Parse a single token.
 
FLECS_API char * ecs_parse_term (const ecs_world_t *world, const char *name, const char *expr, const char *ptr, ecs_term_t *term_out, ecs_oper_kind_t *extra_oper, ecs_term_id_t *extra_args, bool allow_newline)
 Parse term in expression.
 

Detailed Description

Query DSL parser and parsing utilities.

Macro Definition Documentation

◆ ECS_PARSER_MAX_ARGS

#define ECS_PARSER_MAX_ARGS   (16)

Maximum number of extra arguments in term expression.

Definition at line 23 of file parser.h.

Function Documentation

◆ ecs_parse_digit()

FLECS_API const char * ecs_parse_digit ( const char * ptr,
char * token )

Parse digit.

This function will parse until the first non-digit character is found. The provided expression must contain at least one digit character.

Parameters
ptrThe expression to parse.
tokenThe output buffer.
Returns
Pointer to the first non-digit character.

◆ ecs_parse_term()

FLECS_API char * ecs_parse_term ( const ecs_world_t * world,
const char * name,
const char * expr,
const char * ptr,
ecs_term_t * term_out,
ecs_oper_kind_t * extra_oper,
ecs_term_id_t * extra_args,
bool allow_newline )

Parse term in expression.

This operation parses a single term in an expression and returns a pointer to the next term expression.

If the returned pointer points to the 0-terminator, the expression is fully parsed. The function would typically be called in a while loop:

const char *ptr = expr;
while (ptr[0] && (ptr = ecs_parse_term(world, name, expr, ptr, &term))) { }
FLECS_API char * ecs_parse_term(const ecs_world_t *world, const char *name, const char *expr, const char *ptr, ecs_term_t *term_out, ecs_oper_kind_t *extra_oper, ecs_term_id_t *extra_args, bool allow_newline)
Parse term in expression.

The operation does not attempt to find entity ids from the names in the expression. Use the ecs_term_resolve_ids() function to resolve the identifiers in the parsed term.

The returned term will in most cases contain allocated resources, which should freed (or used) by the application. To free the resources for a term, use the ecs_term_free() function.

The parser accepts expressions in the legacy string format.

Parameters
worldThe world.
nameThe name of the expression (optional, improves error logs)
exprThe expression to parse (optional, improves error logs)
ptrThe pointer to the current term (must be in expr).
term_outOut parameter for the term.
extra_argsOut array for extra args, must be of size ECS_PARSER_MAX_ARGS.
Returns
pointer to next term if successful, NULL if failed.

◆ ecs_parse_token()

FLECS_API const char * ecs_parse_token ( const char * name,
const char * expr,
const char * ptr,
char * token_out,
char delim )

Parse a single token.

This function can be used as simple tokenizer by other parsers.

Parameters
nameof program (used for logging).
exprpointer to token to parse.
ptrpointer to first character to parse.
token_outParsed token (buffer should be ECS_MAX_TOKEN_SIZE large)
Returns
Pointer to the next token, or NULL if error occurred.

◆ ecs_parse_ws()

FLECS_API const char * ecs_parse_ws ( const char * ptr)

Skip whitespace characters.

This function skips whitespace characters. Does not skip newlines.

Parameters
ptrPointer to (potential) whitespaces to skip.
Returns
Pointer to the next non-whitespace character.

◆ ecs_parse_ws_eol()

FLECS_API const char * ecs_parse_ws_eol ( const char * ptr)

Skip whitespace and newline characters.

This function skips whitespace characters.

Parameters
ptrPointer to (potential) whitespaces to skip.
Returns
Pointer to the next non-whitespace character.