2006-07-17 06:21:39 +00:00
|
|
|
/*
|
2006-07-26 16:43:35 +00:00
|
|
|
* $Id: rex.h,v 1.10 2006-07-26 16:43:35 bacon Exp $
|
2006-07-17 06:21:39 +00:00
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef _XP_AWK_REX_H_
|
|
|
|
#define _XP_AWK_REX_H_
|
|
|
|
|
2006-07-26 05:19:46 +00:00
|
|
|
#include <xp/types.h>
|
|
|
|
#include <xp/macros.h>
|
|
|
|
|
2006-07-17 06:21:39 +00:00
|
|
|
|
2006-07-19 15:58:01 +00:00
|
|
|
/*
|
|
|
|
* Regular Expression Syntax
|
|
|
|
* A regular expression is zero or more branches, separated by '|'.
|
|
|
|
* ......
|
|
|
|
* ......
|
|
|
|
*
|
|
|
|
* Compiled form of a regular expression:
|
|
|
|
*
|
2006-07-20 16:21:54 +00:00
|
|
|
* | expression |
|
|
|
|
* | header | branch | branch | branch |
|
|
|
|
* | nb | el | na | bl | cmd | arg | cmd | arg | na | bl | cmd | arg | na | bl | cmd |
|
2006-07-19 15:58:01 +00:00
|
|
|
*
|
|
|
|
* nb: the number of branches
|
2006-07-26 16:43:35 +00:00
|
|
|
* el: the length of a expression including the length of nb and el
|
2006-07-20 16:21:54 +00:00
|
|
|
* na: the number of atoms
|
2006-07-26 16:43:35 +00:00
|
|
|
* bl: the length of a branch including the length of na and bl
|
2006-07-19 15:58:01 +00:00
|
|
|
* cmd: The command and repetition info encoded together.
|
|
|
|
* Some commands require an argument to follow them but some other don't.
|
|
|
|
* It is encoded as follows:
|
|
|
|
*
|
|
|
|
* Subexpressions can be nested by having the command "GROUP"
|
|
|
|
* and a subexpression as its argument.
|
|
|
|
*
|
|
|
|
* Examples:
|
|
|
|
* a.c -> |1|6|5|ORD_CHAR(no bound)|a|ANY_CHAR(no bound)|ORD_CHAR(no bound)|c|
|
|
|
|
* ab|xy -> |2|10|4|ORD_CHAR(no bound)|a|ORD_CHAR(no bound)|b|4|ORD_CHAR(no bound)|x|ORD_CHAR(no bound)|y|
|
|
|
|
*/
|
|
|
|
|
2006-07-24 16:23:19 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
XP_AWK_REX_ENOERR, /* no error */
|
|
|
|
XP_AWK_REX_ENOMEM, /* ran out of memory */
|
|
|
|
XP_AWK_REX_ERPAREN, /* a right parenthesis is expected */
|
|
|
|
XP_AWK_REX_ERBRACKET, /* a right bracket is expected */
|
|
|
|
XP_AWK_REX_ERBRACE, /* a right brace is expected */
|
|
|
|
XP_AWK_REX_ECOLON, /* a colon is expected */
|
|
|
|
XP_AWK_REX_ECRANGE, /* invalid character range */
|
|
|
|
XP_AWK_REX_ECCLASS, /* invalid character class */
|
|
|
|
XP_AWK_REX_EBRANGE, /* invalid boundary range */
|
|
|
|
XP_AWK_REX_EEND, /* unexpected end of the pattern */
|
|
|
|
XP_AWK_REX_EGARBAGE /* garbage after the pattern */
|
|
|
|
};
|
|
|
|
|
2006-07-26 16:43:35 +00:00
|
|
|
#define XP_AWK_REX_NA(code) (*(xp_size_t*)(code))
|
2006-07-26 05:19:46 +00:00
|
|
|
|
2006-07-26 16:43:35 +00:00
|
|
|
#define XP_AWK_REX_LEN(code) \
|
2006-07-26 05:19:46 +00:00
|
|
|
(*(xp_size_t*)((xp_byte_t*)(code)+xp_sizeof(xp_size_t)))
|
|
|
|
|
2006-07-17 06:21:39 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2006-07-26 16:43:35 +00:00
|
|
|
const xp_char_t* xp_awk_getrexerrstr (int errnum);
|
2006-07-26 02:25:47 +00:00
|
|
|
|
2006-07-26 16:43:35 +00:00
|
|
|
void* xp_awk_buildrex (const xp_char_t* ptn, xp_size_t len, int* errnum);
|
2006-07-24 11:58:55 +00:00
|
|
|
|
2006-07-26 05:19:46 +00:00
|
|
|
int xp_awk_matchrex (void* code,
|
2006-07-24 11:58:55 +00:00
|
|
|
const xp_char_t* str, xp_size_t len,
|
2006-07-26 16:43:35 +00:00
|
|
|
const xp_char_t** match_ptr, xp_size_t* match_len, int* errnum);
|
2006-07-24 11:58:55 +00:00
|
|
|
|
2006-07-26 05:19:46 +00:00
|
|
|
void xp_awk_printrex (void* code);
|
2006-07-24 16:23:19 +00:00
|
|
|
|
2006-07-17 06:21:39 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|