#ifndef __REG_CORE_H__ #define __REG_CORE_H__ /* * @author fenrir (https://fenrir.naruoka.org/) * * reg_core.h * 正規表現のコアとなるヘッダ。 * 実際に使用する際はこのヘッダのみをincludeすればよい。 */ #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #ifdef __cplusplus extern "C"{ #endif typedef unsigned char boolean; struct reg_stack_t{ struct reg_state_t{ struct reg_node_t{ void *info; struct reg_state_t *(*transit)(struct reg_state_t *current, struct reg_stack_t *stack); } *node; char *input_index; } *top; struct reg_state_t *bottom; int size; }; typedef struct reg_state_t reg_state_t; typedef struct reg_node_t reg_node_t; typedef struct reg_stack_t reg_stack_t; /** * 遷移表 */ typedef struct reg_list_t{ reg_node_t *top; reg_node_t *end; int max; } reg_list_t; typedef struct reg_range_t{ char *start; char *end; } reg_range_t; typedef struct reg_submatch_t{ reg_node_t *start; reg_node_t *end; reg_range_t range; } reg_submatch_t; /** * マッチオブジェクト */ typedef struct reg_match_t{ reg_submatch_t *submatch_top; reg_submatch_t *submatch_end; int submatch_max; } reg_match_t; /** * コンパイルやマッチのときの状態を格納するオブジェクト */ typedef int reg_status_t; /** * 正規表現オブジェクト */ typedef struct regexp_t{ reg_list_t list; reg_match_t match_object; reg_status_t status; } regexp_t; /* コンパイル処理(reg_compile.c) */ regexp_t *reg_before_compile(regexp_t *regexp, reg_node_t *node, int node_max, reg_submatch_t *submatch, int submatch_max); regexp_t *reg_compile(regexp_t *regexp, char *regexp_str); #define reg_precompile(_regexp, _node_max, _sub_match_max) \ reg_node_t node_ ## _regexp[_node_max];\ reg_submatch_t submatch_ ## _regexp[_sub_match_max];\ reg_before_compile(&(_regexp), \ node_ ## _regexp, _node_max, \ submatch_ ## _regexp, _sub_match_max); /* コンパイル時エラーコード */ #define REG_ERR_C_TOO_FEW_PARENTHESIS -1 #define REG_ERR_C_TOO_FEW_BRACKET -2 #define REG_ERR_C_IREGAL_LOOP_NUMBER -3 #define REG_ERR_C_IREGAL_BACKREF -4 #define REG_ERR_C_TOO_FEW_CHARACTERS -5 /* マッチ処理(reg_core.c) */ reg_match_t *reg_scan(regexp_t *regexp, char *target, int buffer_size); reg_match_t *reg_match(regexp_t *regexp, char *target, int buffer_size); char *reg_submatch(reg_match_t *match_object, int index, char *dist, int buffer_size); #ifdef __cplusplus }; #endif #endif /* __REG_CORE_H__ */