Guido van Rossum | e7b146f | 2000-02-04 15:28:42 +0000 | [diff] [blame] | 1 | """Constants for selecting regexp syntaxes for the obsolete regex module. |
| 2 | |
| 3 | This module is only for backward compatibility. "regex" has now |
| 4 | been replaced by the new regular expression module, "re". |
| 5 | |
| 6 | These bits are passed to regex.set_syntax() to choose among |
| 7 | alternative regexp syntaxes. |
| 8 | """ |
Guido van Rossum | 6c6b78d | 1991-12-30 16:03:05 +0000 | [diff] [blame] | 9 | |
| 10 | # 1 means plain parentheses serve as grouping, and backslash |
| 11 | # parentheses are needed for literal searching. |
| 12 | # 0 means backslash-parentheses are grouping, and plain parentheses |
| 13 | # are for literal searching. |
| 14 | RE_NO_BK_PARENS = 1 |
| 15 | |
| 16 | # 1 means plain | serves as the "or"-operator, and \| is a literal. |
| 17 | # 0 means \| serves as the "or"-operator, and | is a literal. |
| 18 | RE_NO_BK_VBAR = 2 |
| 19 | |
| 20 | # 0 means plain + or ? serves as an operator, and \+, \? are literals. |
| 21 | # 1 means \+, \? are operators and plain +, ? are literals. |
| 22 | RE_BK_PLUS_QM = 4 |
| 23 | |
| 24 | # 1 means | binds tighter than ^ or $. |
| 25 | # 0 means the contrary. |
| 26 | RE_TIGHT_VBAR = 8 |
| 27 | |
| 28 | # 1 means treat \n as an _OR operator |
| 29 | # 0 means treat it as a normal character |
| 30 | RE_NEWLINE_OR = 16 |
| 31 | |
| 32 | # 0 means that a special characters (such as *, ^, and $) always have |
| 33 | # their special meaning regardless of the surrounding context. |
| 34 | # 1 means that special characters may act as normal characters in some |
| 35 | # contexts. Specifically, this applies to: |
Tim Peters | 0c9886d | 2001-01-15 01:18:21 +0000 | [diff] [blame] | 36 | # ^ - only special at the beginning, or after ( or | |
| 37 | # $ - only special at the end, or before ) or | |
| 38 | # *, +, ? - only special when not after the beginning, (, or | |
Guido van Rossum | 6c6b78d | 1991-12-30 16:03:05 +0000 | [diff] [blame] | 39 | RE_CONTEXT_INDEP_OPS = 32 |
| 40 | |
Guido van Rossum | 2498620 | 1997-10-22 16:28:53 +0000 | [diff] [blame] | 41 | # ANSI sequences (\n etc) and \xhh |
| 42 | RE_ANSI_HEX = 64 |
| 43 | |
| 44 | # No GNU extensions |
| 45 | RE_NO_GNU_EXTENSIONS = 128 |
| 46 | |
Guido van Rossum | 6c6b78d | 1991-12-30 16:03:05 +0000 | [diff] [blame] | 47 | # Now define combinations of bits for the standard possibilities. |
| 48 | RE_SYNTAX_AWK = (RE_NO_BK_PARENS | RE_NO_BK_VBAR | RE_CONTEXT_INDEP_OPS) |
| 49 | RE_SYNTAX_EGREP = (RE_SYNTAX_AWK | RE_NEWLINE_OR) |
| 50 | RE_SYNTAX_GREP = (RE_BK_PLUS_QM | RE_NEWLINE_OR) |
| 51 | RE_SYNTAX_EMACS = 0 |
| 52 | |
| 53 | # (Python's obsolete "regexp" module used a syntax similar to awk.) |
Skip Montanaro | 0de6580 | 2001-02-15 22:15:14 +0000 | [diff] [blame^] | 54 | |
| 55 | __all__ = locals().keys() |
| 56 | for _i in range(len(__all__)-1,-1,-1): |
| 57 | if __all__[_i][0] == "_": |
| 58 | del __all__[_i] |
| 59 | del _i |