2023-10-31 13:26:31 -04:00
|
|
|
/**
|
|
|
|
* @file regexp.h
|
|
|
|
*
|
|
|
|
* A regular expression parser.
|
|
|
|
*/
|
2023-09-27 12:24:48 -04:00
|
|
|
#ifndef PRISM_REGEXP_H
|
|
|
|
#define PRISM_REGEXP_H
|
2023-06-20 11:53:02 -04:00
|
|
|
|
2023-09-27 12:24:48 -04:00
|
|
|
#include "prism/defines.h"
|
|
|
|
#include "prism/parser.h"
|
2023-11-30 11:36:10 -05:00
|
|
|
#include "prism/encoding.h"
|
2023-09-27 12:24:48 -04:00
|
|
|
#include "prism/util/pm_memchr.h"
|
|
|
|
#include "prism/util/pm_string.h"
|
2023-06-30 14:30:24 -04:00
|
|
|
|
2023-06-20 11:53:02 -04:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2023-10-31 11:35:56 -04:00
|
|
|
/**
|
2024-06-04 12:05:48 -04:00
|
|
|
* This callback is called when a named capture group is found.
|
|
|
|
*/
|
|
|
|
typedef void (*pm_regexp_name_callback_t)(const pm_string_t *name, void *data);
|
|
|
|
|
2024-06-05 10:50:18 -04:00
|
|
|
/**
|
|
|
|
* This callback is called when a parse error is found.
|
|
|
|
*/
|
|
|
|
typedef void (*pm_regexp_error_callback_t)(const uint8_t *start, const uint8_t *end, const char *message, void *data);
|
|
|
|
|
2024-06-04 12:05:48 -04:00
|
|
|
/**
|
|
|
|
* Parse a regular expression.
|
2023-10-31 11:35:56 -04:00
|
|
|
*
|
2024-06-04 12:11:25 -04:00
|
|
|
* @param parser The parser that is currently being used.
|
2023-10-31 11:35:56 -04:00
|
|
|
* @param source The source code to parse.
|
|
|
|
* @param size The size of the source code.
|
2024-07-01 10:28:52 -04:00
|
|
|
* @param extended_mode Whether to parse the regular expression in extended mode.
|
2024-06-05 10:50:18 -04:00
|
|
|
* @param name_callback The optional callback to call when a named capture group is found.
|
|
|
|
* @param name_data The optional data to pass to the name callback.
|
|
|
|
* @param error_callback The callback to call when a parse error is found.
|
|
|
|
* @param error_data The data to pass to the error callback.
|
2023-10-31 11:35:56 -04:00
|
|
|
*/
|
2024-07-01 10:28:52 -04:00
|
|
|
PRISM_EXPORTED_FUNCTION void pm_regexp_parse(pm_parser_t *parser, const uint8_t *source, size_t size, bool extended_mode, pm_regexp_name_callback_t name_callback, void *name_data, pm_regexp_error_callback_t error_callback, void *error_data);
|
2023-06-20 11:53:02 -04:00
|
|
|
|
|
|
|
#endif
|