Guido van Rossum | aad6761 | 2000-05-08 17:31:04 +0000 | [diff] [blame^] | 1 | # |
| 2 | # Secret Labs' Regular Expression Engine |
| 3 | # $Id$ |
| 4 | # |
| 5 | # various symbols used by the regular expression engine. |
| 6 | # run this script to update the _sre include files! |
| 7 | # |
| 8 | # Copyright (c) 1998-2000 by Secret Labs AB. All rights reserved. |
| 9 | # |
| 10 | # This code can only be used for 1.6 alpha testing. All other use |
| 11 | # require explicit permission from Secret Labs AB. |
| 12 | # |
| 13 | # Portions of this engine have been developed in cooperation with |
| 14 | # CNRI. Hewlett-Packard provided funding for 1.6 integration and |
| 15 | # other compatibility work. |
| 16 | # |
| 17 | |
| 18 | # operators |
| 19 | |
| 20 | FAILURE = "failure" |
| 21 | SUCCESS = "success" |
| 22 | |
| 23 | ANY = "any" |
| 24 | ASSERT = "assert" |
| 25 | AT = "at" |
| 26 | BRANCH = "branch" |
| 27 | CALL = "call" |
| 28 | CATEGORY = "category" |
| 29 | GROUP = "group" |
| 30 | GROUP_IGNORE = "group_ignore" |
| 31 | IN = "in" |
| 32 | IN_IGNORE = "in_ignore" |
| 33 | JUMP = "jump" |
| 34 | LITERAL = "literal" |
| 35 | LITERAL_IGNORE = "literal_ignore" |
| 36 | MARK = "mark" |
| 37 | MAX_REPEAT = "max_repeat" |
| 38 | MAX_REPEAT_ONE = "max_repeat_one" |
| 39 | MAX_UNTIL = "max_until" |
| 40 | MIN_REPEAT = "min_repeat" |
| 41 | MIN_UNTIL = "min_until" |
| 42 | NEGATE = "negate" |
| 43 | NOT_LITERAL = "not_literal" |
| 44 | NOT_LITERAL_IGNORE = "not_literal_ignore" |
| 45 | RANGE = "range" |
| 46 | REPEAT = "repeat" |
| 47 | SUBPATTERN = "subpattern" |
| 48 | |
| 49 | # positions |
| 50 | AT_BEGINNING = "at_beginning" |
| 51 | AT_BOUNDARY = "at_boundary" |
| 52 | AT_NON_BOUNDARY = "at_non_boundary" |
| 53 | AT_END = "at_end" |
| 54 | |
| 55 | # categories |
| 56 | |
| 57 | CATEGORY_DIGIT = "category_digit" |
| 58 | CATEGORY_NOT_DIGIT = "category_not_digit" |
| 59 | CATEGORY_SPACE = "category_space" |
| 60 | CATEGORY_NOT_SPACE = "category_not_space" |
| 61 | CATEGORY_WORD = "category_word" |
| 62 | CATEGORY_NOT_WORD = "category_not_word" |
| 63 | |
| 64 | CODES = [ |
| 65 | |
| 66 | # failure=0 success=1 (just because it looks better that way :-) |
| 67 | FAILURE, SUCCESS, |
| 68 | |
| 69 | ANY, |
| 70 | ASSERT, |
| 71 | AT, |
| 72 | BRANCH, |
| 73 | CALL, |
| 74 | CATEGORY, |
| 75 | GROUP, GROUP_IGNORE, |
| 76 | IN, IN_IGNORE, |
| 77 | JUMP, |
| 78 | LITERAL, LITERAL_IGNORE, |
| 79 | MARK, |
| 80 | MAX_REPEAT, MAX_UNTIL, |
| 81 | MAX_REPEAT_ONE, |
| 82 | MIN_REPEAT, MIN_UNTIL, |
| 83 | NOT_LITERAL, NOT_LITERAL_IGNORE, |
| 84 | NEGATE, |
| 85 | RANGE, |
| 86 | REPEAT |
| 87 | |
| 88 | ] |
| 89 | |
| 90 | # convert to dictionary |
| 91 | c = {} |
| 92 | i = 0 |
| 93 | for code in CODES: |
| 94 | c[code] = i |
| 95 | i = i + 1 |
| 96 | CODES = c |
| 97 | |
| 98 | # replacement operations for "ignore case" mode |
| 99 | MAP_IGNORE = { |
| 100 | GROUP: GROUP_IGNORE, |
| 101 | IN: IN_IGNORE, |
| 102 | LITERAL: LITERAL_IGNORE, |
| 103 | NOT_LITERAL: NOT_LITERAL_IGNORE |
| 104 | } |
| 105 | |
| 106 | POSITIONS = { |
| 107 | AT_BEGINNING: ord("a"), |
| 108 | AT_BOUNDARY: ord("b"), |
| 109 | AT_NON_BOUNDARY: ord("B"), |
| 110 | AT_END: ord("z"), |
| 111 | } |
| 112 | |
| 113 | CATEGORIES = { |
| 114 | CATEGORY_DIGIT: ord("d"), |
| 115 | CATEGORY_NOT_DIGIT: ord("D"), |
| 116 | CATEGORY_SPACE: ord("s"), |
| 117 | CATEGORY_NOT_SPACE: ord("S"), |
| 118 | CATEGORY_WORD: ord("w"), |
| 119 | CATEGORY_NOT_WORD: ord("W"), |
| 120 | } |
| 121 | |
| 122 | if __name__ == "__main__": |
| 123 | import string |
| 124 | items = CODES.items() |
| 125 | items.sort(lambda a, b: cmp(a[1], b[1])) |
| 126 | f = open("sre_constants.h", "w") |
| 127 | f.write("/* generated by sre_constants.py */\n") |
| 128 | for k, v in items: |
| 129 | f.write("#define SRE_OP_" + string.upper(k) + " " + str(v) + "\n") |
| 130 | f.close() |
| 131 | print "done" |