/* Copyright 1985 by Lattice, Inc. */

/*
 * Node and character types for regular expression representation
 */

#ifdef UGREP
#define NOT	'^'	/* UNIX "not" character */
#else
#define NOT	'!'	/* Our "not" character */
#define OCLOSURE '+'	/* closure -- one or more occurrences */
#endif
#define CHAR	'a'	/* representative individual character */
#define BOL	'^'	/* beginning of line */
#define EOL	'$'	/* end of line pattern marker */
#define ANY	'.'	/* any character */
#define CCL	'['	/* begin specification of character class */
#define CCLEND	']'	/* end specification of character class */
#define ZCLOSURE '*'	/* closure -- zero or more occurrences */
#define NCCL	NOT	/* negated character class */
#define STR	-1	/* pattern is a string */
#define ESCAPE	'\\'	/* escape character */
#define EOS	'\0'	/* end of string marker */
#define MAXSTRING 255	/* maximum length of a string */
#define DASH	'-'
#define NEWLINE '\n'
#define TAB	'\t'
#define BSP	'\b'
#define SP	' '
#define CR	'\r'
#define FF	'\f'
#ifdef ED
#define LPAR	0
#define RPAR	1
#endif

/*
 * A pattern specified by a regular expression will be represented
 * as a linked list of PATNODEs.  More specifically, a PATTERN is
 * defined as a pointer to (the initial node of) such a list.
 */

typedef struct p_node {
	char code;	/* type of node:  CHAR, BOL, ANY, etc. */
	char match_ch;	/* character to be matched, if code is CHAR */
	int size;	/* size of character class, if code is CCL */
	char *ch_class;	/* string of characters in a character class */
	struct p_node *pred;	/* backpointer to predecessor node in list */
	struct p_node *succ;	/* forward pointer to next node in list */
} PATNODE;

typedef PATNODE *PATTERN;

/*
 * Access macros for PATNODEs
 */

#define CODE(x)		((x)->code)
#define MATCH_CH(x)	((x)->match_ch)
#define SIZE(x)		((x)->size)
#define CH_CLASS(x)	((x)->ch_class)
#define PPRED(x)	((x)->pred)
#define PSUCC(x)	((x)->succ)

extern PATTERN mkpatnode(), re_gen(), getccl();
