dfa.h

来自「linux平台中」· C头文件 代码 · 共 433 行 · 第 1/2 页

H
433
字号
/* dfa.h - declarations for GNU deterministic regexp compiler   Copyright (C) 1988, 1998 Free Software Foundation, Inc.   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2, or (at your option)   any later version.   This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA *//* Written June, 1988 by Mike Haertel *//* FIXME:   2.  We should not export so much of the DFA internals.   In addition to clobbering modularity, we eat up valuable   name space. */#ifdef __STDC__# ifndef _PTR_T# define _PTR_T  typedef void * ptr_t;# endif#else# ifndef _PTR_T# define _PTR_T  typedef char * ptr_t;# endif#endif#ifdef PARAMS# undef PARAMS#endif#if PROTOTYPES# define PARAMS(x) x#else# define PARAMS(x) ()#endif/* Number of bits in an unsigned char. */#ifndef CHARBITS#define CHARBITS 8#endif/* First integer value that is greater than any character code. */#define NOTCHAR (1 << CHARBITS)/* INTBITS need not be exact, just a lower bound. */#ifndef INTBITS#define INTBITS (CHARBITS * sizeof (int))#endif/* Number of ints required to hold a bit for every character. */#define CHARCLASS_INTS ((NOTCHAR + INTBITS - 1) / INTBITS)/* Sets of unsigned characters are stored as bit vectors in arrays of ints. */typedef int charclass[CHARCLASS_INTS];/* The regexp is parsed into an array of tokens in postfix form.  Some tokens   are operators and others are terminal symbols.  Most (but not all) of these   codes are returned by the lexical analyzer. */typedef enum{  END = -1,			/* END is a terminal symbol that matches the				   end of input; any value of END or less in				   the parse tree is such a symbol.  Accepting				   states of the DFA are those that would have				   a transition on END. */  /* Ordinary character values are terminal symbols that match themselves. */  EMPTY = NOTCHAR,		/* EMPTY is a terminal symbol that matches				   the empty string. */  BACKREF,			/* BACKREF is generated by \<digit>; it				   it not completely handled.  If the scanner				   detects a transition on backref, it returns				   a kind of "semi-success" indicating that				   the match will have to be verified with				   a backtracking matcher. */  BEGLINE,			/* BEGLINE is a terminal symbol that matches				   the empty string if it is at the beginning				   of a line. */  ENDLINE,			/* ENDLINE is a terminal symbol that matches				   the empty string if it is at the end of				   a line. */  BEGWORD,			/* BEGWORD is a terminal symbol that matches				   the empty string if it is at the beginning				   of a word. */  ENDWORD,			/* ENDWORD is a terminal symbol that matches				   the empty string if it is at the end of				   a word. */  LIMWORD,			/* LIMWORD is a terminal symbol that matches				   the empty string if it is at the beginning				   or the end of a word. */  NOTLIMWORD,			/* NOTLIMWORD is a terminal symbol that				   matches the empty string if it is not at				   the beginning or end of a word. */  QMARK,			/* QMARK is an operator of one argument that				   matches zero or one occurences of its				   argument. */  STAR,				/* STAR is an operator of one argument that				   matches the Kleene closure (zero or more				   occurrences) of its argument. */  PLUS,				/* PLUS is an operator of one argument that				   matches the positive closure (one or more				   occurrences) of its argument. */  REPMN,			/* REPMN is a lexical token corresponding				   to the {m,n} construct.  REPMN never				   appears in the compiled token vector. */  CAT,				/* CAT is an operator of two arguments that				   matches the concatenation of its				   arguments.  CAT is never returned by the				   lexical analyzer. */  OR,				/* OR is an operator of two arguments that				   matches either of its arguments. */  ORTOP,			/* OR at the toplevel in the parse tree.				   This is used for a boyer-moore heuristic. */  LPAREN,			/* LPAREN never appears in the parse tree,				   it is only a lexeme. */  RPAREN,			/* RPAREN never appears in the parse tree. */  CRANGE,			/* CRANGE never appears in the parse tree.				   It stands for a character range that can				   match a string of one or more characters.				   For example, [a-z] can match "ch" in				   a Spanish locale.  */#ifdef MBS_SUPPORT  ANYCHAR,                     /* ANYCHAR is a terminal symbol that matches                                  any multibyte(or singlebyte) characters.			          It is used only if MB_CUR_MAX > 1.  */  MBCSET,			/* MBCSET is similar to CSET, but for				   multibyte characters.  */#endif /* MBS_SUPPORT */  CSET				/* CSET and (and any value greater) is a				   terminal symbol that matches any of a				   class of characters. */} token;/* Sets are stored in an array in the compiled dfa; the index of the   array corresponding to a given set token is given by SET_INDEX(t). */#define SET_INDEX(t) ((t) - CSET)/* Sometimes characters can only be matched depending on the surrounding   context.  Such context decisions depend on what the previous character   was, and the value of the current (lookahead) character.  Context   dependent constraints are encoded as 8 bit integers.  Each bit that   is set indicates that the constraint succeeds in the corresponding   context.   bit 7 - previous and current are newlines   bit 6 - previous was newline, current isn't   bit 5 - previous wasn't newline, current is   bit 4 - neither previous nor current is a newline   bit 3 - previous and current are word-constituents   bit 2 - previous was word-constituent, current isn't   bit 1 - previous wasn't word-constituent, current is   bit 0 - neither previous nor current is word-constituent   Word-constituent characters are those that satisfy isalnum().   The macro SUCCEEDS_IN_CONTEXT determines whether a a given constraint   succeeds in a particular context.  Prevn is true if the previous character   was a newline, currn is true if the lookahead character is a newline.   Prevl and currl similarly depend upon whether the previous and current   characters are word-constituent letters. */#define MATCHES_NEWLINE_CONTEXT(constraint, prevn, currn) \  ((constraint) & 1 << (((prevn) ? 2 : 0) + ((currn) ? 1 : 0) + 4))#define MATCHES_LETTER_CONTEXT(constraint, prevl, currl) \  ((constraint) & 1 << (((prevl) ? 2 : 0) + ((currl) ? 1 : 0)))#define SUCCEEDS_IN_CONTEXT(constraint, prevn, currn, prevl, currl) \  (MATCHES_NEWLINE_CONTEXT(constraint, prevn, currn)		     \   && MATCHES_LETTER_CONTEXT(constraint, prevl, currl))/* The following macros give information about what a constraint depends on. */#define PREV_NEWLINE_DEPENDENT(constraint) \  (((constraint) & 0xc0) >> 2 != ((constraint) & 0x30))#define PREV_LETTER_DEPENDENT(constraint) \  (((constraint) & 0x0c) >> 2 != ((constraint) & 0x03))/* Tokens that match the empty string subject to some constraint actually   work by applying that constraint to determine what may follow them,   taking into account what has gone before.  The following values are   the constraints corresponding to the special tokens previously defined. */#define NO_CONSTRAINT 0xff#define BEGLINE_CONSTRAINT 0xcf#define ENDLINE_CONSTRAINT 0xaf#define BEGWORD_CONSTRAINT 0xf2#define ENDWORD_CONSTRAINT 0xf4#define LIMWORD_CONSTRAINT 0xf6#define NOTLIMWORD_CONSTRAINT 0xf9

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?