Loading...
Searching...
No Matches
Regex lexer node
Grammar nodes

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

Collaboration diagram for Regex lexer node:

## Functions

struct ec_node * | ec_node_re_lex (const char *id, struct ec_node *child)
| Create a regex-based lexer node.
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.

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

  id | The node identifier.
  child | The 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_node | The regex lexer node.
  pattern | The regular expression pattern for matching tokens.
  keep | If non-zero, include matched tokens in the output; if zero, discard them.
  attr_name | Optional attribute name to attach to matched tokens, or NULL.

Returns
  0 on success, -1 on error (errno is set).