annotate Modules/regexpr.c @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents c569873eeb15
children 0965d9fd1862
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5755
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
1 /*
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
2 * -*- mode: c-mode; c-file-style: python -*-
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
3 */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
4
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
5 /* regexpr.c
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
6 *
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
7 * Author: Tatu Ylonen <ylo@ngs.fi>
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
8 *
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
9 * Copyright (c) 1991 Tatu Ylonen, Espoo, Finland
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
10 *
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
11 * Permission to use, copy, modify, distribute, and sell this software
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
12 * and its documentation for any purpose is hereby granted without
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
13 * fee, provided that the above copyright notice appear in all copies.
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
14 * This software is provided "as is" without express or implied
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
15 * warranty.
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
16 *
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
17 * Created: Thu Sep 26 17:14:05 1991 ylo
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
18 * Last modified: Mon Nov 4 17:06:48 1991 ylo
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
19 * Ported to Think C: 19 Jan 1992 guido@cwi.nl
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
20 *
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
21 * This code draws many ideas from the regular expression packages by
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
22 * Henry Spencer of the University of Toronto and Richard Stallman of
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
23 * the Free Software Foundation.
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
24 *
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
25 * Emacs-specific code and syntax table code is almost directly borrowed
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
26 * from GNU regexp.
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
27 *
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
28 * Bugs fixed and lots of reorganization by Jeffrey C. Ollie, April
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
29 * 1997 Thanks for bug reports and ideas from Andrew Kuchling, Tim
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
30 * Peters, Guido van Rossum, Ka-Ping Yee, Sjoerd Mullender, and
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
31 * probably one or two others that I'm forgetting.
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
32 *
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
33 * $Id$ */
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
34
3977
eaec4f6a8be8 Need config.h (for Win etc.)
Guido van Rossum <guido@python.org>
parents: 3596
diff changeset
35 #include "config.h" /* For Win* specific redefinition of printf c.s. */
eaec4f6a8be8 Need config.h (for Win etc.)
Guido van Rossum <guido@python.org>
parents: 3596
diff changeset
36
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
37 #include "myproto.h" /* For PROTO macro --Guido */
638
9d01e98ed849 Ported to THINK C.
Guido van Rossum <guido@python.org>
parents: 634
diff changeset
38
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 #include <stdio.h>
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
40
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
41 #ifndef NDEBUG
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
42 #define NDEBUG 1
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
43 #endif
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
44
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 #include <assert.h>
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 #include "regexpr.h"
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47
638
9d01e98ed849 Ported to THINK C.
Guido van Rossum <guido@python.org>
parents: 634
diff changeset
48 #ifdef THINK_C
9d01e98ed849 Ported to THINK C.
Guido van Rossum <guido@python.org>
parents: 634
diff changeset
49 /* Think C on the Mac really needs these headers... --Guido */
9d01e98ed849 Ported to THINK C.
Guido van Rossum <guido@python.org>
parents: 634
diff changeset
50 #include <stdlib.h>
9d01e98ed849 Ported to THINK C.
Guido van Rossum <guido@python.org>
parents: 634
diff changeset
51 #include <string.h>
9d01e98ed849 Ported to THINK C.
Guido van Rossum <guido@python.org>
parents: 634
diff changeset
52 #else
3596
8800df366b13 Subtle Windows changes
Guido van Rossum <guido@python.org>
parents: 1760
diff changeset
53 #if defined(__STDC__) || defined(_MSC_VER)
737
8246576ef3f5 Lint fluff
Guido van Rossum <guido@python.org>
parents: 638
diff changeset
54 /* Don't mess around, use the standard headers */
8246576ef3f5 Lint fluff
Guido van Rossum <guido@python.org>
parents: 638
diff changeset
55 #include <stdlib.h>
8246576ef3f5 Lint fluff
Guido van Rossum <guido@python.org>
parents: 638
diff changeset
56 #include <string.h>
8246576ef3f5 Lint fluff
Guido van Rossum <guido@python.org>
parents: 638
diff changeset
57 #else
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 char *malloc();
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 void free();
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 char *realloc();
737
8246576ef3f5 Lint fluff
Guido van Rossum <guido@python.org>
parents: 638
diff changeset
61 #endif /* __STDC__ */
8246576ef3f5 Lint fluff
Guido van Rossum <guido@python.org>
parents: 638
diff changeset
62 #endif /* THINK_C */
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
63
5755
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
64 /* The original code blithely assumed that sizeof(short) == 2. Not
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
65 * always true. Original instances of "(short)x" were replaced by
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
66 * SHORT(x), where SHORT is #defined below. */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
67
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
68 #define SHORT(x) ((x) & 0x8000 ? (x) - 0x10000 : (x))
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
69
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
70 /* The stack implementation is taken from an idea by Andrew Kuchling.
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
71 * It's a doubly linked list of arrays. The advantages of this over a
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
72 * simple linked list are that the number of mallocs required are
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
73 * reduced. It also makes it possible to statically allocate enough
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
74 * space so that small patterns don't ever need to call malloc.
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
75 *
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
76 * The advantages over a single array is that is periodically
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
77 * realloced when more space is needed is that we avoid ever copying
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
78 * the stack. */
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
79
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
80 /* item_t is the basic stack element. Defined as a union of
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
81 * structures so that both registers, failure points, and counters can
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
82 * be pushed/popped from the stack. There's nothing built into the
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
83 * item to keep track of whether a certain stack item is a register, a
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
84 * failure point, or a counter. */
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
85
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
86 typedef union item_t
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
87 {
5755
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
88 struct
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
89 {
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
90 int num;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
91 int level;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
92 char *start;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
93 char *end;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
94 } reg;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
95 struct
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
96 {
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
97 int count;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
98 int level;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
99 int phantom;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
100 char *code;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
101 char *text;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
102 } fail;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
103 struct
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
104 {
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
105 int num;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
106 int level;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
107 int count;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
108 } cntr;
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
109 } item_t;
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
110
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
111 #define STACK_PAGE_SIZE 256
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
112 #define NUM_REGISTERS 256
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
113
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
114 /* A 'page' of stack items. */
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
115
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
116 typedef struct item_page_t
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
117 {
5755
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
118 item_t items[STACK_PAGE_SIZE];
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
119 struct item_page_t *prev;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
120 struct item_page_t *next;
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
121 } item_page_t;
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
122
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
123
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
124 typedef struct match_state
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
125 {
5755
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
126 /* The number of registers that have been pushed onto the stack
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
127 * since the last failure point. */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
128
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
129 int count;
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
130
5755
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
131 /* Used to control when registers need to be pushed onto the
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
132 * stack. */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
133
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
134 int level;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
135
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
136 /* The number of failure points on the stack. */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
137
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
138 int point;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
139
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
140 /* Storage for the registers. Each register consists of two
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
141 * pointers to characters. So register N is represented as
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
142 * start[N] and end[N]. The pointers must be converted to
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
143 * offsets from the beginning of the string before returning the
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
144 * registers to the calling program. */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
145
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
146 char *start[NUM_REGISTERS];
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
147 char *end[NUM_REGISTERS];
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
148
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
149 /* Keeps track of whether a register has changed recently. */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
150
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
151 int changed[NUM_REGISTERS];
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
152
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
153 /* Structure to encapsulate the stack. */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
154 struct
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
155 {
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
156 /* index into the curent page. If index == 0 and you need
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
157 * to pop an item, move to the previous page and set index
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
158 * = STACK_PAGE_SIZE - 1. Otherwise decrement index to
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
159 * push a page. If index == STACK_PAGE_SIZE and you need
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
160 * to push a page move to the next page and set index =
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
161 * 0. If there is no new next page, allocate a new page
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
162 * and link it in. Otherwise, increment index to push a
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
163 * page. */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
164
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
165 int index;
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
166 item_page_t *current; /* Pointer to the current page. */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
167 item_page_t first; /* First page is statically allocated. */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
168 } stack;
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
169 } match_state;
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
170
5755
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
171 /* Initialize a state object */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
172
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
173 /* #define NEW_STATE(state) \ */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
174 /* memset(&state, 0, (void *)(&state.stack) - (void *)(&state)); \ */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
175 /* state.stack.current = &state.stack.first; \ */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
176 /* state.stack.first.prev = NULL; \ */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
177 /* state.stack.first.next = NULL; \ */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
178 /* state.stack.index = 0; \ */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
179 /* state.level = 1 */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
180
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
181 #define NEW_STATE(state, nregs) \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
182 { \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
183 int i; \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
184 for (i = 0; i < nregs; i++) \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
185 { \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
186 state.start[i] = NULL; \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
187 state.end[i] = NULL; \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
188 state.changed[i] = 0; \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
189 } \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
190 state.stack.current = &state.stack.first; \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
191 state.stack.first.prev = NULL; \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
192 state.stack.first.next = NULL; \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
193 state.stack.index = 0; \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
194 state.level = 1; \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
195 state.count = 0; \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
196 state.level = 0; \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
197 state.point = 0; \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
198 }
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
199
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
200 /* Free any memory that might have been malloc'd */
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
201
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
202 #define FREE_STATE(state) \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
203 while(state.stack.first.next != NULL) \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
204 { \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
205 state.stack.current = state.stack.first.next; \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
206 state.stack.first.next = state.stack.current->next; \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
207 free(state.stack.current); \
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
208 }
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
209
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
210 /* Discard the top 'count' stack items. */
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
211
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
212 #define STACK_DISCARD(stack, count, on_error) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
213 stack.index -= count; \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
214 while (stack.index < 0) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
215 { \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
216 if (stack.current->prev == NULL) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
217 on_error; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
218 stack.current = stack.current->prev; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
219 stack.index += STACK_PAGE_SIZE; \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
220 }
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
221
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
222 /* Store a pointer to the previous item on the stack. Used to pop an
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
223 * item off of the stack. */
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
224
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
225 #define STACK_PREV(stack, top, on_error) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
226 if (stack.index == 0) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
227 { \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
228 if (stack.current->prev == NULL) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
229 on_error; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
230 stack.current = stack.current->prev; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
231 stack.index = STACK_PAGE_SIZE - 1; \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
232 } \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
233 else \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
234 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
235 stack.index--; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
236 } \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
237 top = &(stack.current->items[stack.index])
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
238
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
239 /* Store a pointer to the next item on the stack. Used to push an item
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
240 * on to the stack. */
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
241
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
242 #define STACK_NEXT(stack, top, on_error) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
243 if (stack.index == STACK_PAGE_SIZE) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
244 { \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
245 if (stack.current->next == NULL) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
246 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
247 stack.current->next = (item_page_t *)malloc(sizeof(item_page_t)); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
248 if (stack.current->next == NULL) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
249 on_error; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
250 stack.current->next->prev = stack.current; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
251 stack.current->next->next = NULL; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
252 } \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
253 stack.current = stack.current->next; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
254 stack.index = 0; \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
255 } \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
256 top = &(stack.current->items[stack.index++])
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
257
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
258 /* Store a pointer to the item that is 'count' items back in the
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
259 * stack. STACK_BACK(stack, top, 1, on_error) is equivalent to
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
260 * STACK_TOP(stack, top, on_error). */
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
261
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
262 #define STACK_BACK(stack, top, count, on_error) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
263 { \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
264 int index; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
265 item_page_t *current; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
266 current = stack.current; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
267 index = stack.index - (count); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
268 while (index < 0) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
269 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
270 if (current->prev == NULL) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
271 on_error; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
272 current = current->prev; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
273 index += STACK_PAGE_SIZE; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
274 } \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
275 top = &(current->items[index]); \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
276 }
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
277
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
278 /* Store a pointer to the top item on the stack. Execute the
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
279 * 'on_error' code if there are no items on the stack. */
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
280
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
281 #define STACK_TOP(stack, top, on_error) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
282 if (stack.index == 0) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
283 { \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
284 if (stack.current->prev == NULL) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
285 on_error; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
286 top = &(stack.current->prev->items[STACK_PAGE_SIZE - 1]); \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
287 } \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
288 else \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
289 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
290 top = &(stack.current->items[stack.index - 1]); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
291 }
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
292
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
293 /* Test to see if the stack is empty */
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
294
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
295 #define STACK_EMPTY(stack) ((stack.index == 0) && \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
296 (stack.current->prev == NULL))
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
297
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
298 /* Return the start of register 'reg' */
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
299
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
300 #define GET_REG_START(state, reg) (state.start[reg])
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
301
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
302 /* Return the end of register 'reg' */
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
303
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
304 #define GET_REG_END(state, reg) (state.end[reg])
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
305
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
306 /* Set the start of register 'reg'. If the state of the register needs
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
307 * saving, push it on the stack. */
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
308
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
309 #define SET_REG_START(state, reg, text, on_error) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
310 if(state.changed[reg] < state.level) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
311 { \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
312 item_t *item; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
313 STACK_NEXT(state.stack, item, on_error); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
314 item->reg.num = reg; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
315 item->reg.start = state.start[reg]; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
316 item->reg.end = state.end[reg]; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
317 item->reg.level = state.changed[reg]; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
318 state.changed[reg] = state.level; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
319 state.count++; \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
320 } \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
321 state.start[reg] = text
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
322
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
323 /* Set the end of register 'reg'. If the state of the register needs
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
324 * saving, push it on the stack. */
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
325
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
326 #define SET_REG_END(state, reg, text, on_error) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
327 if(state.changed[reg] < state.level) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
328 { \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
329 item_t *item; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
330 STACK_NEXT(state.stack, item, on_error); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
331 item->reg.num = reg; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
332 item->reg.start = state.start[reg]; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
333 item->reg.end = state.end[reg]; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
334 item->reg.level = state.changed[reg]; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
335 state.changed[reg] = state.level; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
336 state.count++; \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
337 } \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
338 state.end[reg] = text
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
339
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
340 #define PUSH_FAILURE(state, xcode, xtext, on_error) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
341 { \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
342 item_t *item; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
343 STACK_NEXT(state.stack, item, on_error); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
344 item->fail.code = xcode; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
345 item->fail.text = xtext; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
346 item->fail.count = state.count; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
347 item->fail.level = state.level; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
348 item->fail.phantom = 0; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
349 state.count = 0; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
350 state.level++; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
351 state.point++; \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
352 }
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
353
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
354 /* Update the last failure point with a new position in the text. */
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
355
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
356 #define UPDATE_FAILURE(state, xtext, on_error) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
357 { \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
358 item_t *item; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
359 STACK_BACK(state.stack, item, state.count + 1, on_error); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
360 if (!item->fail.phantom) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
361 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
362 item_t *item2; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
363 STACK_NEXT(state.stack, item2, on_error); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
364 item2->fail.code = item->fail.code; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
365 item2->fail.text = xtext; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
366 item2->fail.count = state.count; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
367 item2->fail.level = state.level; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
368 item2->fail.phantom = 1; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
369 state.count = 0; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
370 state.level++; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
371 state.point++; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
372 } \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
373 else \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
374 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
375 STACK_DISCARD(state.stack, state.count, on_error); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
376 STACK_TOP(state.stack, item, on_error); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
377 item->fail.text = xtext; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
378 state.count = 0; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
379 state.level++; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
380 } \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
381 }
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
382
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
383 #define POP_FAILURE(state, xcode, xtext, on_empty, on_error) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
384 { \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
385 item_t *item; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
386 do \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
387 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
388 while(state.count > 0) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
389 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
390 STACK_PREV(state.stack, item, on_error); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
391 state.start[item->reg.num] = item->reg.start; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
392 state.end[item->reg.num] = item->reg.end; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
393 state.changed[item->reg.num] = item->reg.level; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
394 state.count--; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
395 } \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
396 STACK_PREV(state.stack, item, on_empty); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
397 xcode = item->fail.code; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
398 xtext = item->fail.text; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
399 state.count = item->fail.count; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
400 state.level = item->fail.level; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
401 state.point--; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
402 } \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
403 while (item->fail.text == NULL); \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
404 }
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
405
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
406 enum regexp_compiled_ops /* opcodes for compiled regexp */
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
407 {
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
408 Cend, /* end of pattern reached */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
409 Cbol, /* beginning of line */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
410 Ceol, /* end of line */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
411 Cset, /* character set. Followed by 32 bytes of set. */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
412 Cexact, /* followed by a byte to match */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
413 Canychar, /* matches any character except newline */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
414 Cstart_memory, /* set register start addr (followed by reg number) */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
415 Cend_memory, /* set register end addr (followed by reg number) */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
416 Cmatch_memory, /* match a duplicate of reg contents (regnum follows)*/
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
417 Cjump, /* followed by two bytes (lsb,msb) of displacement. */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
418 Cstar_jump, /* will change to jump/update_failure_jump at runtime */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
419 Cfailure_jump, /* jump to addr on failure */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
420 Cupdate_failure_jump, /* update topmost failure point and jump */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
421 Cdummy_failure_jump, /* push a dummy failure point and jump */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
422 Cbegbuf, /* match at beginning of buffer */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
423 Cendbuf, /* match at end of buffer */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
424 Cwordbeg, /* match at beginning of word */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
425 Cwordend, /* match at end of word */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
426 Cwordbound, /* match if at word boundary */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
427 Cnotwordbound, /* match if not at word boundary */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
428 Csyntaxspec, /* matches syntax code (1 byte follows) */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
429 Cnotsyntaxspec, /* matches if syntax code does not match (1 byte foll)*/
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
430 Crepeat1
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
431 };
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
432
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
433 enum regexp_syntax_op /* syntax codes for plain and quoted characters */
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
434 {
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
435 Rend, /* special code for end of regexp */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
436 Rnormal, /* normal character */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
437 Ranychar, /* any character except newline */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
438 Rquote, /* the quote character */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
439 Rbol, /* match beginning of line */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
440 Reol, /* match end of line */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
441 Roptional, /* match preceding expression optionally */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
442 Rstar, /* match preceding expr zero or more times */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
443 Rplus, /* match preceding expr one or more times */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
444 Ror, /* match either of alternatives */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
445 Ropenpar, /* opening parenthesis */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
446 Rclosepar, /* closing parenthesis */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
447 Rmemory, /* match memory register */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
448 Rextended_memory, /* \vnn to match registers 10-99 */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
449 Ropenset, /* open set. Internal syntax hard-coded below. */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
450 /* the following are gnu extensions to "normal" regexp syntax */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
451 Rbegbuf, /* beginning of buffer */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
452 Rendbuf, /* end of buffer */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
453 Rwordchar, /* word character */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
454 Rnotwordchar, /* not word character */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
455 Rwordbeg, /* beginning of word */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
456 Rwordend, /* end of word */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
457 Rwordbound, /* word bound */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
458 Rnotwordbound, /* not word bound */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
459 Rnum_ops
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
460 };
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
461
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
462 static int re_compile_initialized = 0;
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
463 static int regexp_syntax = 0;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 737
diff changeset
464 int re_syntax = 0; /* Exported copy of regexp_syntax */
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
465 static unsigned char regexp_plain_ops[256];
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
466 static unsigned char regexp_quoted_ops[256];
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
467 static unsigned char regexp_precedences[Rnum_ops];
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
468 static int regexp_context_indep_ops;
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
469 static int regexp_ansi_sequences;
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
470
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
471 #define NUM_LEVELS 5 /* number of precedence levels in use */
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
472 #define MAX_NESTING 100 /* max nesting level of operators */
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
473
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
474 #define SYNTAX(ch) re_syntax_table[(unsigned char)(ch)]
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
475 #define Sword 1
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
476
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
477 static char re_syntax_table[256];
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
478
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
479 static void re_compile_initialize(void)
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
480 {
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
481 int a;
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
482
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
483 static int syntax_table_inited = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
484
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
485 if (!syntax_table_inited)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
486 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
487 syntax_table_inited = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
488 memset(re_syntax_table, 0, 256);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
489 for (a = 'a'; a <= 'z'; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
490 re_syntax_table[a] = Sword;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
491 for (a = 'A'; a <= 'Z'; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
492 re_syntax_table[a] = Sword;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
493 for (a = '0'; a <= '9'; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
494 re_syntax_table[a] = Sword;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
495 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
496 re_compile_initialized = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
497 for (a = 0; a < 256; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
498 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
499 regexp_plain_ops[a] = Rnormal;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
500 regexp_quoted_ops[a] = Rnormal;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
501 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
502 for (a = '0'; a <= '9'; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
503 regexp_quoted_ops[a] = Rmemory;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
504 regexp_plain_ops['\134'] = Rquote;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
505 if (regexp_syntax & RE_NO_BK_PARENS)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
506 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
507 regexp_plain_ops['('] = Ropenpar;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
508 regexp_plain_ops[')'] = Rclosepar;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
509 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
510 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
511 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
512 regexp_quoted_ops['('] = Ropenpar;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
513 regexp_quoted_ops[')'] = Rclosepar;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
514 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
515 if (regexp_syntax & RE_NO_BK_VBAR)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
516 regexp_plain_ops['\174'] = Ror;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
517 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
518 regexp_quoted_ops['\174'] = Ror;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
519 regexp_plain_ops['*'] = Rstar;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
520 if (regexp_syntax & RE_BK_PLUS_QM)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
521 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
522 regexp_quoted_ops['+'] = Rplus;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
523 regexp_quoted_ops['?'] = Roptional;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
524 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
525 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
526 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
527 regexp_plain_ops['+'] = Rplus;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
528 regexp_plain_ops['?'] = Roptional;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
529 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
530 if (regexp_syntax & RE_NEWLINE_OR)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
531 regexp_plain_ops['\n'] = Ror;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
532 regexp_plain_ops['\133'] = Ropenset;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
533 regexp_plain_ops['\136'] = Rbol;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
534 regexp_plain_ops['$'] = Reol;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
535 regexp_plain_ops['.'] = Ranychar;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
536 if (!(regexp_syntax & RE_NO_GNU_EXTENSIONS))
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
537 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
538 regexp_quoted_ops['w'] = Rwordchar;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
539 regexp_quoted_ops['W'] = Rnotwordchar;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
540 regexp_quoted_ops['<'] = Rwordbeg;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
541 regexp_quoted_ops['>'] = Rwordend;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
542 regexp_quoted_ops['b'] = Rwordbound;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
543 regexp_quoted_ops['B'] = Rnotwordbound;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
544 regexp_quoted_ops['`'] = Rbegbuf;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
545 regexp_quoted_ops['\''] = Rendbuf;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
546 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
547 if (regexp_syntax & RE_ANSI_HEX)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
548 regexp_quoted_ops['v'] = Rextended_memory;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
549 for (a = 0; a < Rnum_ops; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
550 regexp_precedences[a] = 4;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
551 if (regexp_syntax & RE_TIGHT_VBAR)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
552 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
553 regexp_precedences[Ror] = 3;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
554 regexp_precedences[Rbol] = 2;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
555 regexp_precedences[Reol] = 2;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
556 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
557 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
558 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
559 regexp_precedences[Ror] = 2;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
560 regexp_precedences[Rbol] = 3;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
561 regexp_precedences[Reol] = 3;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
562 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
563 regexp_precedences[Rclosepar] = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
564 regexp_precedences[Rend] = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
565 regexp_context_indep_ops = (regexp_syntax & RE_CONTEXT_INDEP_OPS) != 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
566 regexp_ansi_sequences = (regexp_syntax & RE_ANSI_HEX) != 0;
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
567 }
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
568
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
569 int re_set_syntax(int syntax)
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
570 {
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
571 int ret;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
572
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
573 ret = regexp_syntax;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
574 regexp_syntax = syntax;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
575 re_syntax = syntax; /* Exported copy */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
576 re_compile_initialize();
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
577 return ret;
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
578 }
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
579
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
580 static int hex_char_to_decimal(int ch)
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
581 {
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
582 if (ch >= '0' && ch <= '9')
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
583 return ch - '0';
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
584 if (ch >= 'a' && ch <= 'f')
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
585 return ch - 'a' + 10;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
586 if (ch >= 'A' && ch <= 'F')
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
587 return ch - 'A' + 10;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
588 return 16;
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
589 }
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
590
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
591 static void re_compile_fastmap_aux(char *code,
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
592 int pos,
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
593 char *visited,
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
594 char *can_be_null,
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
595 char *fastmap)
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
596 {
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
597 int a;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
598 int b;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
599 int syntaxcode;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
600
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
601 if (visited[pos])
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
602 return; /* we have already been here */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
603 visited[pos] = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
604 for (;;)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
605 switch (code[pos++])
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
606 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
607 case Cend:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
608 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
609 *can_be_null = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
610 return;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
611 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
612 case Cbol:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
613 case Cbegbuf:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
614 case Cendbuf:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
615 case Cwordbeg:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
616 case Cwordend:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
617 case Cwordbound:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
618 case Cnotwordbound:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
619 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
620 for (a = 0; a < 256; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
621 fastmap[a] = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
622 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
623 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
624 case Csyntaxspec:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
625 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
626 syntaxcode = code[pos++];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
627 for (a = 0; a < 256; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
628 if (SYNTAX(a) == syntaxcode)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
629 fastmap[a] = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
630 return;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
631 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
632 case Cnotsyntaxspec:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
633 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
634 syntaxcode = code[pos++];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
635 for (a = 0; a < 256; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
636 if (SYNTAX(a) != syntaxcode)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
637 fastmap[a] = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
638 return;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
639 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
640 case Ceol:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
641 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
642 fastmap['\n'] = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
643 if (*can_be_null == 0)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
644 *can_be_null = 2; /* can match null, but only at end of buffer*/
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
645 return;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
646 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
647 case Cset:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
648 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
649 for (a = 0; a < 256/8; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
650 if (code[pos + a] != 0)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
651 for (b = 0; b < 8; b++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
652 if (code[pos + a] & (1 << b))
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
653 fastmap[(a << 3) + b] = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
654 pos += 256/8;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
655 return;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
656 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
657 case Cexact:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
658 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
659 fastmap[(unsigned char)code[pos]] = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
660 return;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
661 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
662 case Canychar:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
663 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
664 for (a = 0; a < 256; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
665 if (a != '\n')
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
666 fastmap[a] = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
667 return;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
668 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
669 case Cstart_memory:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
670 case Cend_memory:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
671 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
672 pos++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
673 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
674 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
675 case Cmatch_memory:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
676 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
677 for (a = 0; a < 256; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
678 fastmap[a] = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
679 *can_be_null = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
680 return;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
681 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
682 case Cjump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
683 case Cdummy_failure_jump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
684 case Cupdate_failure_jump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
685 case Cstar_jump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
686 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
687 a = (unsigned char)code[pos++];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
688 a |= (unsigned char)code[pos++] << 8;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
689 pos += (int)SHORT(a);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
690 if (visited[pos])
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
691 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
692 /* argh... the regexp contains empty loops. This is not
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
693 good, as this may cause a failure stack overflow when
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
694 matching. Oh well. */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
695 /* this path leads nowhere; pursue other paths. */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
696 return;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
697 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
698 visited[pos] = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
699 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
700 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
701 case Cfailure_jump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
702 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
703 a = (unsigned char)code[pos++];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
704 a |= (unsigned char)code[pos++] << 8;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
705 a = pos + (int)SHORT(a);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
706 re_compile_fastmap_aux(code, a, visited, can_be_null, fastmap);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
707 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
708 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
709 case Crepeat1:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
710 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
711 pos += 2;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
712 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
713 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
714 default:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
715 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
716 abort(); /* probably some opcode is missing from this switch */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
717 /*NOTREACHED*/
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
718 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
719 }
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
720 }
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
721
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
722 static int re_do_compile_fastmap(char *buffer,
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
723 int used,
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
724 int pos,
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
725 char *can_be_null,
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
726 char *fastmap)
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
727 {
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
728 char small_visited[512], *visited;
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
729
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
730 if (used <= sizeof(small_visited))
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
731 visited = small_visited;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
732 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
733 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
734 visited = malloc(used);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
735 if (!visited)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
736 return 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
737 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
738 *can_be_null = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
739 memset(fastmap, 0, 256);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
740 memset(visited, 0, used);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
741 re_compile_fastmap_aux(buffer, pos, visited, can_be_null, fastmap);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
742 if (visited != small_visited)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
743 free(visited);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
744 return 1;
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
745 }
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
746
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
747 void re_compile_fastmap(regexp_t bufp)
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
748 {
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
749 if (!bufp->fastmap || bufp->fastmap_accurate)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
750 return;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
751 assert(bufp->used > 0);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
752 if (!re_do_compile_fastmap(bufp->buffer,
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
753 bufp->used,
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
754 0,
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
755 &bufp->can_be_null,
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
756 bufp->fastmap))
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
757 return;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
758 if (bufp->buffer[0] == Cbol)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
759 bufp->anchor = 1; /* begline */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
760 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
761 if (bufp->buffer[0] == Cbegbuf)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
762 bufp->anchor = 2; /* begbuf */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
763 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
764 bufp->anchor = 0; /* none */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
765 bufp->fastmap_accurate = 1;
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
766 }
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
767
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
768 /*
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
769 * star is coded as:
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
770 * 1: failure_jump 2
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
771 * ... code for operand of star
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
772 * star_jump 1
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
773 * 2: ... code after star
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
774 *
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
775 * We change the star_jump to update_failure_jump if we can determine
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
776 * that it is safe to do so; otherwise we change it to an ordinary
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
777 * jump.
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
778 *
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
779 * plus is coded as
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
780 *
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
781 * jump 2
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
782 * 1: failure_jump 3
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
783 * 2: ... code for operand of plus
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
784 * star_jump 1
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
785 * 3: ... code after plus
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
786 *
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
787 * For star_jump considerations this is processed identically to star.
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
788 *
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
789 */
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
790
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
791 static int re_optimize_star_jump(regexp_t bufp, char *code)
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
792 {
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
793 char map[256];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
794 char can_be_null;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
795 char *p1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
796 char *p2;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
797 char ch;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
798 int a;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
799 int b;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
800 int num_instructions = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
801
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
802 a = (unsigned char)*code++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
803 a |= (unsigned char)*code++ << 8;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
804 a = (int)SHORT(a);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
805
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
806 p1 = code + a + 3; /* skip the failure_jump */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
807 assert(p1[-3] == Cfailure_jump);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
808 p2 = code;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
809 /* p1 points inside loop, p2 points to after loop */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
810 if (!re_do_compile_fastmap(bufp->buffer, bufp->used,
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
811 p2 - bufp->buffer, &can_be_null, map))
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
812 goto make_normal_jump;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
813
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
814 /* If we might introduce a new update point inside the
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
815 * loop, we can't optimize because then update_jump would
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
816 * update a wrong failure point. Thus we have to be
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
817 * quite careful here.
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
818 */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
819
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
820 /* loop until we find something that consumes a character */
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
821 loop_p1:
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
822 num_instructions++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
823 switch (*p1++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
824 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
825 case Cbol:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
826 case Ceol:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
827 case Cbegbuf:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
828 case Cendbuf:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
829 case Cwordbeg:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
830 case Cwordend:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
831 case Cwordbound:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
832 case Cnotwordbound:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
833 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
834 goto loop_p1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
835 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
836 case Cstart_memory:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
837 case Cend_memory:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
838 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
839 p1++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
840 goto loop_p1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
841 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
842 case Cexact:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
843 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
844 ch = (unsigned char)*p1++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
845 if (map[(int)ch])
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
846 goto make_normal_jump;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
847 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
848 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
849 case Canychar:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
850 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
851 for (b = 0; b < 256; b++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
852 if (b != '\n' && map[b])
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
853 goto make_normal_jump;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
854 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
855 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
856 case Cset:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
857 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
858 for (b = 0; b < 256; b++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
859 if ((p1[b >> 3] & (1 << (b & 7))) && map[b])
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
860 goto make_normal_jump;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
861 p1 += 256/8;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
862 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
863 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
864 default:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
865 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
866 goto make_normal_jump;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
867 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
868 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
869 /* now we know that we can't backtrack. */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
870 while (p1 != p2 - 3)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
871 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
872 num_instructions++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
873 switch (*p1++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
874 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
875 case Cend:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
876 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
877 return 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
878 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
879 case Cbol:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
880 case Ceol:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
881 case Canychar:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
882 case Cbegbuf:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
883 case Cendbuf:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
884 case Cwordbeg:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
885 case Cwordend:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
886 case Cwordbound:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
887 case Cnotwordbound:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
888 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
889 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
890 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
891 case Cset:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
892 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
893 p1 += 256/8;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
894 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
895 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
896 case Cexact:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
897 case Cstart_memory:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
898 case Cend_memory:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
899 case Cmatch_memory:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
900 case Csyntaxspec:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
901 case Cnotsyntaxspec:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
902 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
903 p1++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
904 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
905 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
906 case Cjump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
907 case Cstar_jump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
908 case Cfailure_jump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
909 case Cupdate_failure_jump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
910 case Cdummy_failure_jump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
911 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
912 goto make_normal_jump;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
913 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
914 default:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
915 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
916 return 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
917 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
918 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
919 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
920 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
921
5755
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
922 make_update_jump:
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
923 code -= 3;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
924 a += 3; /* jump to after the Cfailure_jump */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
925 code[0] = Cupdate_failure_jump;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
926 code[1] = a & 0xff;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
927 code[2] = a >> 8;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
928 if (num_instructions > 1)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
929 return 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
930 assert(num_instructions == 1);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
931 /* if the only instruction matches a single character, we can do
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
932 * better */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
933 p1 = code + 3 + a; /* start of sole instruction */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
934 if (*p1 == Cset || *p1 == Cexact || *p1 == Canychar ||
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
935 *p1 == Csyntaxspec || *p1 == Cnotsyntaxspec)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
936 code[0] = Crepeat1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
937 return 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
938
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
939 make_normal_jump:
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
940 code -= 3;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
941 *code = Cjump;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
942 return 1;
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
943 }
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
944
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
945 static int re_optimize(regexp_t bufp)
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
946 {
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
947 char *code;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
948
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
949 code = bufp->buffer;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
950
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
951 while(1)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
952 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
953 switch (*code++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
954 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
955 case Cend:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
956 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
957 return 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
958 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
959 case Canychar:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
960 case Cbol:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
961 case Ceol:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
962 case Cbegbuf:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
963 case Cendbuf:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
964 case Cwordbeg:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
965 case Cwordend:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
966 case Cwordbound:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
967 case Cnotwordbound:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
968 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
969 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
970 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
971 case Cset:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
972 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
973 code += 256/8;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
974 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
975 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
976 case Cexact:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
977 case Cstart_memory:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
978 case Cend_memory:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
979 case Cmatch_memory:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
980 case Csyntaxspec:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
981 case Cnotsyntaxspec:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
982 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
983 code++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
984 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
985 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
986 case Cstar_jump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
987 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
988 if (!re_optimize_star_jump(bufp, code))
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
989 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
990 return 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
991 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
992 /* fall through */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
993 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
994 case Cupdate_failure_jump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
995 case Cjump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
996 case Cdummy_failure_jump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
997 case Cfailure_jump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
998 case Crepeat1:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
999 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1000 code += 2;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1001 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1002 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1003 default:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1004 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1005 return 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1006 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1007 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1008 }
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1009 }
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1010
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1011 #define NEXTCHAR(var) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1012 { \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1013 if (pos >= size) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1014 goto ends_prematurely; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1015 (var) = regex[pos]; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1016 pos++; \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1017 }
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1018
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1019 #define ALLOC(amount) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1020 { \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1021 if (pattern_offset+(amount) > alloc) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1022 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1023 alloc += 256 + (amount); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1024 pattern = realloc(pattern, alloc); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1025 if (!pattern) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1026 goto out_of_memory; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1027 } \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1028 }
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1029
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1030 #define STORE(ch) pattern[pattern_offset++] = (ch)
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1031
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1032 #define CURRENT_LEVEL_START (starts[starts_base + current_level])
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1033
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1034 #define SET_LEVEL_START starts[starts_base + current_level] = pattern_offset
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1035
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1036 #define PUSH_LEVEL_STARTS \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1037 if (starts_base < (MAX_NESTING-1)*NUM_LEVELS) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1038 starts_base += NUM_LEVELS; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1039 else \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1040 goto too_complex \
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1041
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1042 #define POP_LEVEL_STARTS starts_base -= NUM_LEVELS
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1043
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1044 #define PUT_ADDR(offset,addr) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1045 { \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1046 int disp = (addr) - (offset) - 2; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1047 pattern[(offset)] = disp & 0xff; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1048 pattern[(offset)+1] = (disp>>8) & 0xff; \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1049 }
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1050
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1051 #define INSERT_JUMP(pos,type,addr) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1052 { \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1053 int a, p = (pos), t = (type), ad = (addr); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1054 for (a = pattern_offset - 1; a >= p; a--) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1055 pattern[a + 3] = pattern[a]; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1056 pattern[p] = t; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1057 PUT_ADDR(p+1,ad); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1058 pattern_offset += 3; \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1059 }
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1060
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1061 #define SETBIT(buf,offset,bit) (buf)[(offset)+(bit)/8] |= (1<<((bit) & 7))
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1062
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1063 #define SET_FIELDS \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1064 { \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1065 bufp->allocated = alloc; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1066 bufp->buffer = pattern; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1067 bufp->used = pattern_offset; \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1068 }
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1069
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1070 #define GETHEX(var) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1071 { \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1072 char gethex_ch, gethex_value; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1073 NEXTCHAR(gethex_ch); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1074 gethex_value = hex_char_to_decimal(gethex_ch); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1075 if (gethex_value == 16) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1076 goto hex_error; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1077 NEXTCHAR(gethex_ch); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1078 gethex_ch = hex_char_to_decimal(gethex_ch); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1079 if (gethex_ch == 16) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1080 goto hex_error; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1081 (var) = gethex_value * 16 + gethex_ch; \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1082 }
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1083
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1084 #define ANSI_TRANSLATE(ch) \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1085 { \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1086 switch (ch) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1087 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1088 case 'a': \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1089 case 'A': \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1090 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1091 ch = 7; /* audible bell */ \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1092 break; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1093 } \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1094 case 'b': \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1095 case 'B': \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1096 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1097 ch = 8; /* backspace */ \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1098 break; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1099 } \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1100 case 'f': \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1101 case 'F': \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1102 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1103 ch = 12; /* form feed */ \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1104 break; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1105 } \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1106 case 'n': \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1107 case 'N': \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1108 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1109 ch = 10; /* line feed */ \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1110 break; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1111 } \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1112 case 'r': \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1113 case 'R': \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1114 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1115 ch = 13; /* carriage return */ \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1116 break; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1117 } \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1118 case 't': \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1119 case 'T': \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1120 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1121 ch = 9; /* tab */ \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1122 break; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1123 } \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1124 case 'v': \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1125 case 'V': \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1126 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1127 ch = 11; /* vertical tab */ \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1128 break; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1129 } \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1130 case 'x': /* hex code */ \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1131 case 'X': \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1132 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1133 GETHEX(ch); \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1134 break; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1135 } \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1136 default: \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1137 { \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1138 /* other characters passed through */ \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1139 if (translate) \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1140 ch = translate[(unsigned char)ch]; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1141 break; \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1142 } \
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1143 } \
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1144 }
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1145
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1146 char *re_compile_pattern(char *regex, int size, regexp_t bufp)
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1147 {
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1148 int a;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1149 int pos;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1150 int op;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1151 int current_level;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1152 int level;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1153 int opcode;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1154 int pattern_offset = 0, alloc;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1155 int starts[NUM_LEVELS * MAX_NESTING];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1156 int starts_base;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1157 int future_jumps[MAX_NESTING];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1158 int num_jumps;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1159 unsigned char ch = '\0';
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1160 char *pattern;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1161 char *translate;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1162 int next_register;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1163 int paren_depth;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1164 int num_open_registers;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1165 int open_registers[RE_NREGS];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1166 int beginning_context;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1167
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1168 if (!re_compile_initialized)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1169 re_compile_initialize();
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1170 bufp->used = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1171 bufp->fastmap_accurate = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1172 bufp->uses_registers = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1173 bufp->num_registers = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1174 translate = bufp->translate;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1175 pattern = bufp->buffer;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1176 alloc = bufp->allocated;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1177 if (alloc == 0 || pattern == NULL)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1178 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1179 alloc = 256;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1180 pattern = malloc(alloc);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1181 if (!pattern)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1182 goto out_of_memory;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1183 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1184 pattern_offset = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1185 starts_base = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1186 num_jumps = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1187 current_level = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1188 SET_LEVEL_START;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1189 num_open_registers = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1190 next_register = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1191 paren_depth = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1192 beginning_context = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1193 op = -1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1194 /* we use Rend dummy to ensure that pending jumps are updated
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1195 (due to low priority of Rend) before exiting the loop. */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1196 pos = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1197 while (op != Rend)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1198 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1199 if (pos >= size)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1200 op = Rend;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1201 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1202 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1203 NEXTCHAR(ch);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1204 if (translate)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1205 ch = translate[(unsigned char)ch];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1206 op = regexp_plain_ops[(unsigned char)ch];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1207 if (op == Rquote)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1208 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1209 NEXTCHAR(ch);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1210 op = regexp_quoted_ops[(unsigned char)ch];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1211 if (op == Rnormal && regexp_ansi_sequences)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1212 ANSI_TRANSLATE(ch);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1213 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1214 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1215 level = regexp_precedences[op];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1216 /* printf("ch='%c' op=%d level=%d current_level=%d
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1217 curlevstart=%d\n", ch, op, level, current_level,
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1218 CURRENT_LEVEL_START); */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1219 if (level > current_level)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1220 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1221 for (current_level++; current_level < level; current_level++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1222 SET_LEVEL_START;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1223 SET_LEVEL_START;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1224 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1225 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1226 if (level < current_level)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1227 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1228 current_level = level;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1229 for (;num_jumps > 0 &&
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1230 future_jumps[num_jumps-1] >= CURRENT_LEVEL_START;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1231 num_jumps--)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1232 PUT_ADDR(future_jumps[num_jumps-1], pattern_offset);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1233 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1234 switch (op)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1235 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1236 case Rend:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1237 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1238 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1239 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1240 case Rnormal:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1241 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1242 normal_char:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1243 opcode = Cexact;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1244 store_opcode_and_arg: /* opcode & ch must be set */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1245 SET_LEVEL_START;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1246 ALLOC(2);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1247 STORE(opcode);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1248 STORE(ch);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1249 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1250 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1251 case Ranychar:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1252 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1253 opcode = Canychar;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1254 store_opcode:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1255 SET_LEVEL_START;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1256 ALLOC(1);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1257 STORE(opcode);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1258 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1259 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1260 case Rquote:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1261 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1262 abort();
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1263 /*NOTREACHED*/
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1264 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1265 case Rbol:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1266 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1267 if (!beginning_context)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1268 if (regexp_context_indep_ops)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1269 goto op_error;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1270 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1271 goto normal_char;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1272 opcode = Cbol;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1273 goto store_opcode;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1274 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1275 case Reol:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1276 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1277 if (!((pos >= size) ||
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1278 ((regexp_syntax & RE_NO_BK_VBAR) ?
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1279 (regex[pos] == '\174') :
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1280 (pos+1 < size && regex[pos] == '\134' &&
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1281 regex[pos+1] == '\174')) ||
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1282 ((regexp_syntax & RE_NO_BK_PARENS)?
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1283 (regex[pos] == ')'):
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1284 (pos+1 < size && regex[pos] == '\134' &&
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1285 regex[pos+1] == ')'))))
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1286 if (regexp_context_indep_ops)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1287 goto op_error;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1288 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1289 goto normal_char;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1290 opcode = Ceol;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1291 goto store_opcode;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1292 /* NOTREACHED */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1293 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1294 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1295 case Roptional:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1296 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1297 if (beginning_context)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1298 if (regexp_context_indep_ops)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1299 goto op_error;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1300 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1301 goto normal_char;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1302 if (CURRENT_LEVEL_START == pattern_offset)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1303 break; /* ignore empty patterns for ? */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1304 ALLOC(3);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1305 INSERT_JUMP(CURRENT_LEVEL_START, Cfailure_jump,
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1306 pattern_offset + 3);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1307 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1308 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1309 case Rstar:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1310 case Rplus:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1311 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1312 if (beginning_context)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1313 if (regexp_context_indep_ops)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1314 goto op_error;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1315 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1316 goto normal_char;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1317 if (CURRENT_LEVEL_START == pattern_offset)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1318 break; /* ignore empty patterns for + and * */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1319 ALLOC(9);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1320 INSERT_JUMP(CURRENT_LEVEL_START, Cfailure_jump,
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1321 pattern_offset + 6);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1322 INSERT_JUMP(pattern_offset, Cstar_jump, CURRENT_LEVEL_START);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1323 if (op == Rplus) /* jump over initial failure_jump */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1324 INSERT_JUMP(CURRENT_LEVEL_START, Cdummy_failure_jump,
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1325 CURRENT_LEVEL_START + 6);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1326 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1327 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1328 case Ror:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1329 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1330 ALLOC(6);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1331 INSERT_JUMP(CURRENT_LEVEL_START, Cfailure_jump,
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1332 pattern_offset + 6);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1333 if (num_jumps >= MAX_NESTING)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1334 goto too_complex;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1335 STORE(Cjump);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1336 future_jumps[num_jumps++] = pattern_offset;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1337 STORE(0);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1338 STORE(0);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1339 SET_LEVEL_START;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1340 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1341 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1342 case Ropenpar:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1343 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1344 SET_LEVEL_START;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1345 if (next_register < RE_NREGS)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1346 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1347 bufp->uses_registers = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1348 ALLOC(2);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1349 STORE(Cstart_memory);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1350 STORE(next_register);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1351 open_registers[num_open_registers++] = next_register;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1352 bufp->num_registers++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1353 next_register++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1354 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1355 paren_depth++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1356 PUSH_LEVEL_STARTS;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1357 current_level = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1358 SET_LEVEL_START;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1359 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1360 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1361 case Rclosepar:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1362 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1363 if (paren_depth <= 0)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1364 goto parenthesis_error;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1365 POP_LEVEL_STARTS;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1366 current_level = regexp_precedences[Ropenpar];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1367 paren_depth--;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1368 if (paren_depth < num_open_registers)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1369 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1370 bufp->uses_registers = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1371 ALLOC(2);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1372 STORE(Cend_memory);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1373 num_open_registers--;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1374 STORE(open_registers[num_open_registers]);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1375 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1376 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1377 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1378 case Rmemory:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1379 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1380 if (ch == '0')
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1381 goto bad_match_register;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1382 assert(ch >= '0' && ch <= '9');
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1383 bufp->uses_registers = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1384 opcode = Cmatch_memory;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1385 ch -= '0';
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1386 goto store_opcode_and_arg;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1387 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1388 case Rextended_memory:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1389 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1390 NEXTCHAR(ch);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1391 if (ch < '0' || ch > '9')
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1392 goto bad_match_register;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1393 NEXTCHAR(a);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1394 if (a < '0' || a > '9')
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1395 goto bad_match_register;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1396 ch = 10 * (a - '0') + ch - '0';
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1397 if (ch <= 0 || ch >= RE_NREGS)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1398 goto bad_match_register;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1399 bufp->uses_registers = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1400 opcode = Cmatch_memory;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1401 goto store_opcode_and_arg;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1402 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1403 case Ropenset:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1404 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1405 int complement;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1406 int prev;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1407 int offset;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1408 int range;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1409 int firstchar;
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1410
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1411 SET_LEVEL_START;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1412 ALLOC(1+256/8);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1413 STORE(Cset);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1414 offset = pattern_offset;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1415 for (a = 0; a < 256/8; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1416 STORE(0);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1417 NEXTCHAR(ch);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1418 if (translate)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1419 ch = translate[(unsigned char)ch];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1420 if (ch == '\136')
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1421 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1422 complement = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1423 NEXTCHAR(ch);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1424 if (translate)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1425 ch = translate[(unsigned char)ch];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1426 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1427 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1428 complement = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1429 prev = -1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1430 range = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1431 firstchar = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1432 while (ch != '\135' || firstchar)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1433 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1434 firstchar = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1435 if (regexp_ansi_sequences && ch == '\134')
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1436 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1437 NEXTCHAR(ch);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1438 ANSI_TRANSLATE(ch);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1439 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1440 if (range)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1441 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1442 for (a = prev; a <= (int)ch; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1443 SETBIT(pattern, offset, a);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1444 prev = -1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1445 range = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1446 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1447 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1448 if (prev != -1 && ch == '-')
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1449 range = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1450 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1451 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1452 SETBIT(pattern, offset, ch);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1453 prev = ch;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1454 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1455 NEXTCHAR(ch);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1456 if (translate)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1457 ch = translate[(unsigned char)ch];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1458 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1459 if (range)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1460 SETBIT(pattern, offset, '-');
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1461 if (complement)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1462 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1463 for (a = 0; a < 256/8; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1464 pattern[offset+a] ^= 0xff;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1465 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1466 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1467 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1468 case Rbegbuf:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1469 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1470 opcode = Cbegbuf;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1471 goto store_opcode;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1472 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1473 case Rendbuf:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1474 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1475 opcode = Cendbuf;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1476 goto store_opcode;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1477 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1478 case Rwordchar:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1479 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1480 opcode = Csyntaxspec;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1481 ch = Sword;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1482 goto store_opcode_and_arg;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1483 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1484 case Rnotwordchar:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1485 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1486 opcode = Cnotsyntaxspec;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1487 ch = Sword;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1488 goto store_opcode_and_arg;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1489 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1490 case Rwordbeg:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1491 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1492 opcode = Cwordbeg;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1493 goto store_opcode;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1494 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1495 case Rwordend:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1496 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1497 opcode = Cwordend;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1498 goto store_opcode;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1499 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1500 case Rwordbound:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1501 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1502 opcode = Cwordbound;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1503 goto store_opcode;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1504 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1505 case Rnotwordbound:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1506 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1507 opcode = Cnotwordbound;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1508 goto store_opcode;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1509 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1510 default:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1511 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1512 abort();
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1513 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1514 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1515 beginning_context = (op == Ropenpar || op == Ror);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1516 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1517 if (starts_base != 0)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1518 goto parenthesis_error;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1519 assert(num_jumps == 0);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1520 ALLOC(1);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1521 STORE(Cend);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1522 SET_FIELDS;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1523 if(!re_optimize(bufp))
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1524 return "Optimization error";
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1525 return NULL;
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1526
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1527 op_error:
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1528 SET_FIELDS;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1529 return "Badly placed special character";
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1530
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1531 bad_match_register:
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1532 SET_FIELDS;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1533 return "Bad match register number";
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1534
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1535 hex_error:
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1536 SET_FIELDS;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1537 return "Bad hexadecimal number";
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1538
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1539 parenthesis_error:
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1540 SET_FIELDS;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1541 return "Badly placed parenthesis";
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1542
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1543 out_of_memory:
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1544 SET_FIELDS;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1545 return "Out of memory";
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1546
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1547 ends_prematurely:
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1548 SET_FIELDS;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1549 return "Regular expression ends prematurely";
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1550
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1551 too_complex:
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1552 SET_FIELDS;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1553 return "Regular expression too complex";
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1554 }
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1555
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1556 #undef CHARAT
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1557 #undef NEXTCHAR
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1558 #undef GETHEX
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1559 #undef ALLOC
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1560 #undef STORE
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1561 #undef CURRENT_LEVEL_START
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1562 #undef SET_LEVEL_START
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1563 #undef PUSH_LEVEL_STARTS
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1564 #undef POP_LEVEL_STARTS
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1565 #undef PUT_ADDR
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1566 #undef INSERT_JUMP
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1567 #undef SETBIT
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1568 #undef SET_FIELDS
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1569
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1570 #define PREFETCH if (text == textend) goto fail
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1571
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1572 #define NEXTCHAR(var) \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1573 PREFETCH; \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1574 var = (unsigned char)*text++; \
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1575 if (translate) \
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1576 var = translate[var]
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1577
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1578 int re_match(regexp_t bufp,
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1579 char *string,
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1580 int size,
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1581 int pos,
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1582 regexp_registers_t old_regs)
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1583 {
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1584 char *code;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1585 char *translate;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1586 char *text;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1587 char *textstart;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1588 char *textend;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1589 int a;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1590 int b;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1591 int ch;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1592 int reg;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1593 int match_end;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1594 char *regstart;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1595 char *regend;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1596 int regsize;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1597 match_state state;
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1598
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1599 assert(pos >= 0 && size >= 0);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1600 assert(pos <= size);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1601
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1602 text = string + pos;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1603 textstart = string;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1604 textend = string + size;
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1605
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1606 code = bufp->buffer;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1607
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1608 translate = bufp->translate;
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1609
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1610 NEW_STATE(state, bufp->num_registers);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1611
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1612 if (!re_compile_initialized)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1613 re_compile_initialize();
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1614
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1615 continue_matching:
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1616 switch (*code++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1617 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1618 case Cend:
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1619 {
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1620 match_end = text - textstart;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1621 if (old_regs)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1622 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1623 old_regs->start[0] = pos;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1624 old_regs->end[0] = match_end;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1625 if (!bufp->uses_registers)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1626 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1627 for (a = 1; a < RE_NREGS; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1628 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1629 old_regs->start[a] = -1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1630 old_regs->end[a] = -1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1631 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1632 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1633 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1634 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1635 for (a = 1; a < bufp->num_registers; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1636 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1637 if ((GET_REG_START(state, a) == NULL) ||
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1638 (GET_REG_END(state, a) == NULL))
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1639 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1640 old_regs->start[a] = -1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1641 old_regs->end[a] = -1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1642 continue;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1643 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1644 old_regs->start[a] = GET_REG_START(state, a) - textstart;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1645 old_regs->end[a] = GET_REG_END(state, a) - textstart;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1646 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1647 for (; a < RE_NREGS; a++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1648 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1649 old_regs->start[a] = -1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1650 old_regs->end[a] = -1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1651 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1652 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1653 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1654 FREE_STATE(state);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1655 return match_end - pos;
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1656 }
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1657 case Cbol:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1658 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1659 if (text == textstart || text[-1] == '\n')
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1660 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1661 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1662 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1663 case Ceol:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1664 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1665 if (text == textend || *text == '\n')
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1666 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1667 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1668 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1669 case Cset:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1670 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1671 NEXTCHAR(ch);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1672 if (code[ch/8] & (1<<(ch & 7)))
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1673 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1674 code += 256/8;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1675 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1676 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1677 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1678 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1679 case Cexact:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1680 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1681 NEXTCHAR(ch);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1682 if (ch != (unsigned char)*code++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1683 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1684 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1685 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1686 case Canychar:
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1687 {
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1688 NEXTCHAR(ch);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1689 if (ch == '\n')
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1690 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1691 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1692 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1693 case Cstart_memory:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1694 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1695 reg = *code++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1696 SET_REG_START(state, reg, text, goto error);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1697 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1698 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1699 case Cend_memory:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1700 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1701 reg = *code++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1702 SET_REG_END(state, reg, text, goto error);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1703 goto continue_matching;
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1704 }
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1705 case Cmatch_memory:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1706 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1707 reg = *code++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1708 regstart = GET_REG_START(state, reg);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1709 regend = GET_REG_END(state, reg);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1710 if ((regstart == NULL) || (regend == NULL))
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1711 goto fail; /* or should we just match nothing? */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1712 regsize = regend - regstart;
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1713
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1714 if (regsize > (textend - text))
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1715 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1716 if(translate)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1717 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1718 for (; regstart < regend; regstart++, text++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1719 if (translate[*regstart] != translate[*text])
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1720 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1721 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1722 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1723 for (; regstart < regend; regstart++, text++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1724 if (*regstart != *text)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1725 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1726 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1727 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1728 case Cupdate_failure_jump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1729 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1730 UPDATE_FAILURE(state, text, goto error);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1731 /* fall to next case */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1732 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1733 /* treat Cstar_jump just like Cjump if it hasn't been optimized */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1734 case Cstar_jump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1735 case Cjump:
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1736 {
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1737 a = (unsigned char)*code++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1738 a |= (unsigned char)*code++ << 8;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1739 code += (int)SHORT(a);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1740 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1741 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1742 case Cdummy_failure_jump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1743 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1744 a = (unsigned char)*code++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1745 a |= (unsigned char)*code++ << 8;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1746 a = (int)SHORT(a);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1747 assert(*code == Cfailure_jump);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1748 b = (unsigned char)code[1];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1749 b |= (unsigned char)code[2] << 8;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1750 PUSH_FAILURE(state, code + (int)SHORT(b) + 3, NULL, goto error);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1751 code += a;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1752 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1753 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1754 case Cfailure_jump:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1755 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1756 a = (unsigned char)*code++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1757 a |= (unsigned char)*code++ << 8;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1758 a = (int)SHORT(a);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1759 PUSH_FAILURE(state, code + a, text, goto error);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1760 goto continue_matching;
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1761 }
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1762 case Crepeat1:
5755
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
1763 {
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1764 char *pinst;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1765 a = (unsigned char)*code++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1766 a |= (unsigned char)*code++ << 8;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1767 a = (int)SHORT(a);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1768 pinst = code + a;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1769 /* pinst is sole instruction in loop, and it matches a
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1770 * single character. Since Crepeat1 was originally a
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1771 * Cupdate_failure_jump, we also know that backtracking
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1772 * is useless: so long as the single-character
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1773 * expression matches, it must be used. Also, in the
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1774 * case of +, we've already matched one character, so +
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1775 * can't fail: nothing here can cause a failure. */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1776 switch (*pinst++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1777 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1778 case Cset:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1779 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1780 if (translate)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1781 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1782 while (text < textend)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1783 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1784 ch = translate[(unsigned char)*text];
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1785 if (pinst[ch/8] & (1<<(ch & 7)))
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1786 text++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1787 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1788 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1789 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1790 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1791 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1792 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1793 while (text < textend)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1794 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1795 ch = (unsigned char)*text;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1796 if (pinst[ch/8] & (1<<(ch & 7)))
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1797 text++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1798 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1799 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1800 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1801 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1802 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1803 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1804 case Cexact:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1805 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1806 ch = (unsigned char)*pinst;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1807 if (translate)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1808 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1809 while (text < textend &&
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1810 translate[(unsigned char)*text] == ch)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1811 text++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1812 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1813 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1814 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1815 while (text < textend && (unsigned char)*text == ch)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1816 text++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1817 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1818 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1819 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1820 case Canychar:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1821 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1822 while (text < textend && (unsigned char)*text != '\n')
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1823 text++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1824 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1825 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1826 case Csyntaxspec:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1827 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1828 a = (unsigned char)*pinst;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1829 if (translate)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1830 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1831 while (text < textend &&
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1832 translate[SYNTAX(*text)] == a)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1833 text++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1834 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1835 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1836 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1837 while (text < textend && SYNTAX(*text) == a)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1838 text++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1839 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1840 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1841 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1842 case Cnotsyntaxspec:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1843 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1844 a = (unsigned char)*pinst;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1845 if (translate)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1846 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1847 while (text < textend &&
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1848 translate[SYNTAX(*text)] != a)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1849 text++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1850 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1851 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1852 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1853 while (text < textend && SYNTAX(*text) != a)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1854 text++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1855 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1856 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1857 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1858 default:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1859 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1860 abort();
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1861 /*NOTREACHED*/
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1862 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1863 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1864 /* due to the funky way + and * are compiled, the top
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1865 * failure- stack entry at this point is actually a
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1866 * success entry -- update it & pop it */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1867 UPDATE_FAILURE(state, text, goto error);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1868 goto fail; /* i.e., succeed <wink/sigh> */
5755
18a639db048c New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents: 5513
diff changeset
1869 }
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1870 case Cbegbuf:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1871 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1872 if (text == textstart)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1873 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1874 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1875 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1876 case Cendbuf:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1877 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1878 if (text == textend)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1879 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1880 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1881 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1882 case Cwordbeg:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1883 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1884 if (text == textend)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1885 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1886 if (SYNTAX(*text) != Sword)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1887 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1888 if (text == textstart)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1889 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1890 if (SYNTAX(text[-1]) != Sword)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1891 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1892 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1893 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1894 case Cwordend:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1895 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1896 if (text == textstart)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1897 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1898 if (SYNTAX(text[-1]) != Sword)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1899 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1900 if (text == textend)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1901 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1902 if (SYNTAX(*text) == Sword)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1903 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1904 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1905 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1906 case Cwordbound:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1907 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1908 /* Note: as in gnu regexp, this also matches at the
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1909 * beginning and end of buffer. */
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1910
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1911 if (text == textstart || text == textend)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1912 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1913 if ((SYNTAX(text[-1]) == Sword) ^ (SYNTAX(*text) == Sword))
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1914 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1915 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1916 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1917 case Cnotwordbound:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1918 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1919 /* Note: as in gnu regexp, this never matches at the
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1920 * beginning and end of buffer. */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1921 if (text == textstart || text == textend)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1922 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1923 if (!((SYNTAX(text[-1]) == Sword) ^ (SYNTAX(*text) == Sword)))
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1924 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1925 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1926 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1927 case Csyntaxspec:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1928 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1929 NEXTCHAR(ch);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1930 if (SYNTAX(ch) != (unsigned char)*code++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1931 goto fail;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1932 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1933 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1934 case Cnotsyntaxspec:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1935 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1936 NEXTCHAR(ch);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1937 if (SYNTAX(ch) != (unsigned char)*code++)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1938 break;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1939 goto continue_matching;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1940 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1941 default:
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1942 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1943 abort();
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1944 /*NOTREACHED*/
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1945 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1946 }
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1947
638
9d01e98ed849 Ported to THINK C.
Guido van Rossum <guido@python.org>
parents: 634
diff changeset
1948 #if 0 /* This line is never reached --Guido */
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1949 abort();
619
ac7d64453aa9 #ifdef'ed an unreachable line out.
Guido van Rossum <guido@python.org>
parents: 616
diff changeset
1950 #endif
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1951 /*
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1952 *NOTREACHED
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1953 */
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1954
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1955 fail:
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1956 POP_FAILURE(state, code, text, goto done_matching, goto error);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1957 goto continue_matching;
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1958
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1959 done_matching:
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1960 /* if(translated != NULL) */
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1961 /* free(translated); */
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1962 FREE_STATE(state);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1963 return -1;
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1964
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1965 error:
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1966 /* if (translated != NULL) */
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1967 /* free(translated); */
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1968 FREE_STATE(state);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1969 return -2;
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1970 }
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1971
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1972 #undef PREFETCH
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1973 #undef NEXTCHAR
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1974
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1975 int re_search(regexp_t bufp,
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1976 char *string,
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1977 int size,
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1978 int pos,
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1979 int range,
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
1980 regexp_registers_t regs)
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1981 {
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1982 char *fastmap;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1983 char *translate;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1984 char *text;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1985 char *partstart;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1986 char *partend;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1987 int dir;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1988 int ret;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1989 char anchor;
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1990
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1991 assert(size >= 0 && pos >= 0);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1992 assert(pos + range >= 0 && pos + range <= size); /* Bugfix by ylo */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1993
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1994 fastmap = bufp->fastmap;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1995 translate = bufp->translate;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1996 if (fastmap && !bufp->fastmap_accurate)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1997 re_compile_fastmap(bufp);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1998 anchor = bufp->anchor;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
1999 if (bufp->can_be_null == 1) /* can_be_null == 2: can match null at eob */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2000 fastmap = NULL;
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
2001
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2002 if (range < 0)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2003 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2004 dir = -1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2005 range = -range;
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2006 }
5465
09e6b4e34523 Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents: 5440
diff changeset
2007 else
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2008 dir = 1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2009
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2010 if (anchor == 2)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2011 if (pos != 0)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2012 return -1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2013 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2014 range = 0;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2015
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2016 for (; range >= 0; range--, pos += dir)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2017 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2018 if (fastmap)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2019 {
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2020 if (dir == 1)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2021 { /* searching forwards */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2022
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2023 text = string + pos;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2024 partend = string + size;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2025 partstart = text;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2026 if (translate)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2027 while (text != partend &&
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2028 !fastmap[(unsigned char) translate[(unsigned char)*text]])
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2029 text++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2030 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2031 while (text != partend && !fastmap[(unsigned char)*text])
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2032 text++;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2033 pos += text - partstart;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2034 range -= text - partstart;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2035 if (pos == size && bufp->can_be_null == 0)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2036 return -1;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2037 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2038 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2039 { /* searching backwards */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2040 text = string + pos;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2041 partstart = string + pos - range;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2042 partend = text;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2043 if (translate)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2044 while (text != partstart &&
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2045 !fastmap[(unsigned char)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2046 translate[(unsigned char)*text]])
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2047 text--;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2048 else
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2049 while (text != partstart &&
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2050 !fastmap[(unsigned char)*text])
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2051 text--;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2052 pos -= partend - text;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2053 range -= partend - text;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2054 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2055 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2056 if (anchor == 1)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2057 { /* anchored to begline */
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2058 if (pos > 0 && (string[pos - 1] != '\n'))
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2059 continue;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2060 }
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2061 assert(pos >= 0 && pos <= size);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2062 ret = re_match(bufp, string, size, pos, regs);
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2063 if (ret >= 0)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2064 return pos;
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2065 if (ret == -2)
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2066 return -2;
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2067 }
5786
c569873eeb15 Reformatted.
Guido van Rossum <guido@python.org>
parents: 5755
diff changeset
2068 return -1;
616
8d5725494ede Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2069 }