Libecoli 0.11.1
Extensible COmmand LIne library
Loading...
Searching...
No Matches
Regex lexer node

A lexer node using regular expressions for tokenization. More...

Functions

struct ec_nodeec_node_re_lex (const char *id, struct ec_node *child)
int ec_node_re_lex_add (struct ec_node *gen_node, const char *pattern, int keep, const char *attr_name)

Detailed Description

A lexer node using regular expressions for tokenization.

Configuration Schema

schema re_lex {
list patterns {
description "The list of patterns elements.";
dict {
description "A pattern element.";
string pattern {
description "The pattern to match.";
}
bool keep {
description "Whether to keep or drop the string matching the regular expression.";
}
string attr {
description "The optional attribute name to attach.";
}
}
}
node child {
description "The child node.";
}
}

Function Documentation

◆ ec_node_re_lex()

struct ec_node * ec_node_re_lex ( const char * id,
struct ec_node * child )

Create a regex-based lexer node.

This node tokenizes the input using regular expressions added with ec_node_re_lex_add() and passes the resulting tokens to the child node.

Parameters
idThe node identifier.
childThe child node. It is consumed and will be freed when the parent is freed, or immediately on error.
Returns
The node, or NULL on error (errno is set).

◆ ec_node_re_lex_add()

int ec_node_re_lex_add ( struct ec_node * gen_node,
const char * pattern,
int keep,
const char * attr_name )

Add a token pattern to a regex lexer node.

Parameters
gen_nodeThe regex lexer node.
patternThe regular expression pattern for matching tokens.
keepIf non-zero, include matched tokens in the output; if zero, discard them.
attr_nameOptional attribute name to attach to matched tokens, or NULL.
Returns
0 on success, -1 on error (errno is set).