regularExp.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef _regularExp_h_
  2. #define _regularExp_h_
  3. /*******************************************************************************
  4. * *
  5. * regularExp.h -- Nirvana Editor Regular Expression Package Header File *
  6. * *
  7. * Copyright 2002 The NEdit Developers *
  8. * *
  9. * This is free software; you can redistribute it and/or modify it under the *
  10. * terms of the GNU General Public License as published by the Free Software *
  11. * Foundation; either version 2 of the License, or (at your option) any later *
  12. * version. In addition, you may distribute version of this program linked to *
  13. * Motif or Open Motif. See README for details. *
  14. * *
  15. * This software is distributed in the hope that it will be useful, but WITHOUT *
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
  17. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
  18. * for more details. *
  19. * *
  20. * You should have received a copy of the GNU General Public License along with *
  21. * software; if not, write to the Free Software Foundation, Inc., 59 Temple *
  22. * Place, Suite 330, Boston, MA 02111-1307 USA *
  23. * *
  24. * Nirvana Text Editor *
  25. * July 31, 2001 *
  26. * *
  27. * *
  28. *******************************************************************************/
  29. /*
  30. djmw 20080110 Extra parameter for SubstituteRE to allow error differentiation
  31. */
  32. /* Number of text capturing parentheses allowed. */
  33. #include "melder.h"
  34. #define NSUBEXP 50
  35. /* Structure to contain the compiled form of a regular expression plus
  36. pointers to matched text. `program' is the actual compiled regex code. */
  37. typedef struct regexp {
  38. char32 *startp [NSUBEXP]; /* Captured text starting locations. */
  39. char32 *endp [NSUBEXP]; /* Captured text ending locations. */
  40. char32 *extentpBW; /* Points to the maximum extent of text scanned by
  41. ExecRE in front of the string to achieve a match
  42. (needed because of positive look-behind.) */
  43. char32 *extentpFW; /* Points to the maximum extent of text scanned by
  44. ExecRE to achieve a match (needed because of
  45. positive look-ahead.) */
  46. int top_branch; /* Zero-based index of the top branch that matches.
  47. Used by syntax highlighting only. */
  48. char32 match_start; /* Internal use only. */
  49. char32 anchor; /* Internal use only. */
  50. char32 program [1]; /* Unwarranted chumminess with compiler. */
  51. } regexp;
  52. /* Flags for CompileRE default settings (Markus Schwarzenberg) */
  53. typedef enum {
  54. REDFLT_STANDARD = 0,
  55. REDFLT_CASE_INSENSITIVE = 1
  56. /* REDFLT_MATCH_NEWLINE = 2 Currently not used. */
  57. } RE_DEFAULT_FLAG;
  58. /* Compiles a regular expression into the internal format used by `ExecRE'. */
  59. regexp * CompileRE (
  60. conststring32 exp, /* String containing the regex specification. */
  61. conststring32 *errorText, /* Text of any error message produced. */
  62. int defaultFlags); /* Flags for default RE-operation */
  63. regexp *CompileRE_throwable (conststring32 exp, int defaultFlags);
  64. /* Match a `regexp' structure against a string. */
  65. int ExecRE (
  66. regexp *prog, /* Compiled regex. */
  67. regexp *cross_regex_backref, /* Pointer to a `regexp' that was used in a
  68. previous execution of ExecRE. Used to
  69. implement back references across regular
  70. expressions for use in syntax
  71. highlighting.*/
  72. conststring32 string, /* Text to search within. */
  73. const char32 *end, /* Pointer to the end of `string'. If NULL will
  74. scan from `string' until '\0' is found. */
  75. int reverse, /* Backward search. */
  76. char32 prev_char, /* Character immediately prior to `string'. Set
  77. to '\n' or '\0' if true beginning of text. */
  78. char32 succ_char, /* Character immediately after `end'. Set
  79. to '\n' or '\0' if true beginning of text. */
  80. conststring32 look_behind_to,/* Boundary for look-behind; defaults to
  81. "string" if NULL */
  82. conststring32 match_till); /* Boundary to where match can extend.
  83. \0 is assumed to be the boundary if not
  84. set. Lookahead can cross the boundary. */
  85. /* Perform substitutions after a `regexp' match. */
  86. int SubstituteRE (
  87. const regexp *prog,
  88. conststring32 source,
  89. mutablestring32 dest,
  90. int max,
  91. int *errorType); // djmw 20080110 0: ok; 1: is not enough memory
  92. /* Enable (or disable) brace counting quantifiers, e.g. `(foo){0,3}'. */
  93. void EnableCountingQuantifier (int is_enabled);
  94. #endif /* _regularExp_h_ */