blob: af883094d40398cd68ac8746fd311dcffc22484f [file] [log] [blame]
Guido van Rossum7627c0d2000-03-31 14:58:54 +00001#
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
20FAILURE = "failure"
21SUCCESS = "success"
22
23ANY = "any"
24ASSERT = "assert"
25AT = "at"
26BRANCH = "branch"
27CALL = "call"
28CATEGORY = "category"
29GROUP = "group"
30GROUP_IGNORE = "group_ignore"
31IN = "in"
32IN_IGNORE = "in_ignore"
33JUMP = "jump"
34LITERAL = "literal"
35LITERAL_IGNORE = "literal_ignore"
36MARK = "mark"
37MAX_REPEAT = "max_repeat"
38MAX_REPEAT_ONE = "max_repeat_one"
39MAX_UNTIL = "max_until"
40MIN_REPEAT = "min_repeat"
41MIN_UNTIL = "min_until"
42NEGATE = "negate"
43NOT_LITERAL = "not_literal"
44NOT_LITERAL_IGNORE = "not_literal_ignore"
45RANGE = "range"
46REPEAT = "repeat"
47SUBPATTERN = "subpattern"
48
49# positions
50AT_BEGINNING = "at_beginning"
51AT_BOUNDARY = "at_boundary"
52AT_NON_BOUNDARY = "at_non_boundary"
53AT_END = "at_end"
54
55# categories
56
57CATEGORY_DIGIT = "category_digit"
58CATEGORY_NOT_DIGIT = "category_not_digit"
59CATEGORY_SPACE = "category_space"
60CATEGORY_NOT_SPACE = "category_not_space"
61CATEGORY_WORD = "category_word"
62CATEGORY_NOT_WORD = "category_not_word"
63
64CODES = [
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
91c = {}
92i = 0
93for code in CODES:
94 c[code] = i
95 i = i + 1
96CODES = c
97
98# replacement operations for "ignore case" mode
99MAP_IGNORE = {
100 GROUP: GROUP_IGNORE,
101 IN: IN_IGNORE,
102 LITERAL: LITERAL_IGNORE,
103 NOT_LITERAL: NOT_LITERAL_IGNORE
104}
105
106POSITIONS = {
107 AT_BEGINNING: ord("a"),
108 AT_BOUNDARY: ord("b"),
109 AT_NON_BOUNDARY: ord("B"),
110 AT_END: ord("z"),
111}
112
113CATEGORIES = {
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
122if __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:
Guido van Rossumb81e70e2000-04-10 17:10:48 +0000129 f.write("#define SRE_OP_" + string.upper(k) + " " + str(v) + "\n")
Guido van Rossum7627c0d2000-03-31 14:58:54 +0000130 f.close()
131 print "done"