2
0

regexport.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*-------------------------------------------------------------------------
  2. *
  3. * regexport.h
  4. * Declarations for exporting info about a regex's NFA (nondeterministic
  5. * finite automaton)
  6. *
  7. * The functions declared here provide accessors to extract the NFA state
  8. * graph and color character sets of a successfully-compiled regex.
  9. *
  10. * An NFA contains one or more states, numbered 0..N-1. There is an initial
  11. * state, as well as a final state --- reaching the final state denotes
  12. * successful matching of an input string. Each state except the final one
  13. * has some out-arcs that lead to successor states, each arc being labeled
  14. * with a color that represents one or more concrete character codes.
  15. * (The colors of a state's out-arcs need not be distinct, since this is an
  16. * NFA not a DFA.) There are also "pseudocolors" representing start/end of
  17. * line and start/end of string. Colors are numbered 0..C-1, but note that
  18. * color 0 is "white" (all unused characters) and can generally be ignored.
  19. *
  20. * Portions Copyright (c) 2013-2022, PostgreSQL Global Development Group
  21. * Portions Copyright (c) 1998, 1999 Henry Spencer
  22. *
  23. * IDENTIFICATION
  24. * src/include/regex/regexport.h
  25. *
  26. *-------------------------------------------------------------------------
  27. */
  28. #ifndef _REGEXPORT_H_
  29. #define _REGEXPORT_H_
  30. #include "regex/regex.h"
  31. /* These macros must match corresponding ones in regguts.h: */
  32. #define COLOR_WHITE 0 /* color for chars not appearing in regex */
  33. #define COLOR_RAINBOW (-2) /* represents all colors except pseudocolors */
  34. /* information about one arc of a regex's NFA */
  35. typedef struct
  36. {
  37. int co; /* label (character-set color) of arc */
  38. int to; /* next state number */
  39. } regex_arc_t;
  40. /* Functions for gathering information about NFA states and arcs */
  41. extern int pg_reg_getnumstates(const regex_t *regex);
  42. extern int pg_reg_getinitialstate(const regex_t *regex);
  43. extern int pg_reg_getfinalstate(const regex_t *regex);
  44. extern int pg_reg_getnumoutarcs(const regex_t *regex, int st);
  45. extern void pg_reg_getoutarcs(const regex_t *regex, int st,
  46. regex_arc_t *arcs, int arcs_len);
  47. /* Functions for gathering information about colors */
  48. extern int pg_reg_getnumcolors(const regex_t *regex);
  49. extern int pg_reg_colorisbegin(const regex_t *regex, int co);
  50. extern int pg_reg_colorisend(const regex_t *regex, int co);
  51. extern int pg_reg_getnumcharacters(const regex_t *regex, int co);
  52. extern void pg_reg_getcharacters(const regex_t *regex, int co,
  53. pg_wchar *chars, int chars_len);
  54. #endif /* _REGEXPORT_H_ */