Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
72b82ba1
Kaydet (Commit)
72b82ba1
authored
Tem 03, 2000
tarafından
Fredrik Lundh
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
- fixed grouping error bug
- changed "group" operator to "groupref"
üst
6f013982
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
55 additions
and
31 deletions
+55
-31
sre_compile.py
Lib/sre_compile.py
+13
-6
sre_constants.py
Lib/sre_constants.py
+4
-4
sre_parse.py
Lib/sre_parse.py
+2
-2
test_sre
Lib/test/output/test_sre
+0
-3
_sre.c
Modules/_sre.c
+33
-16
sre.h
Modules/sre.h
+3
-0
No files found.
Lib/sre_compile.py
Dosyayı görüntüle @
72b82ba1
...
...
@@ -148,18 +148,25 @@ def _compile(code, pattern, flags):
skip
=
len
(
code
);
emit
(
0
)
emit
(
av
[
0
])
emit
(
av
[
1
])
mark
=
MAXCODE
if
av
[
2
][
0
][
0
]
==
SUBPATTERN
:
# repeated subpattern
gid
,
foo
=
av
[
2
][
0
][
1
]
if
gid
:
mark
=
(
gid
-
1
)
*
2
emit
(
mark
)
_compile
(
code
,
av
[
2
],
flags
)
emit
(
OPCODES
[
SUCCESS
])
code
[
skip
]
=
len
(
code
)
-
skip
elif
op
is
SUBPATTERN
:
g
roup
=
av
[
0
]
if
g
roup
:
g
id
=
av
[
0
]
if
g
id
:
emit
(
OPCODES
[
MARK
])
emit
((
g
roup
-
1
)
*
2
)
emit
((
g
id
-
1
)
*
2
)
_compile
(
code
,
av
[
1
],
flags
)
if
g
roup
:
if
g
id
:
emit
(
OPCODES
[
MARK
])
emit
((
g
roup
-
1
)
*
2
+
1
)
emit
((
g
id
-
1
)
*
2
+
1
)
elif
op
in
(
SUCCESS
,
FAILURE
):
emit
(
OPCODES
[
op
])
elif
op
in
(
ASSERT
,
ASSERT_NOT
):
...
...
@@ -207,7 +214,7 @@ def _compile(code, pattern, flags):
emit
(
CHCODES
[
CH_UNICODE
[
av
]])
else
:
emit
(
CHCODES
[
av
])
elif
op
is
GROUP
:
elif
op
is
GROUP
REF
:
if
flags
&
SRE_FLAG_IGNORECASE
:
emit
(
OPCODES
[
OP_IGNORE
[
op
]])
else
:
...
...
Lib/sre_constants.py
Dosyayı görüntüle @
72b82ba1
...
...
@@ -29,8 +29,8 @@ BRANCH = "branch"
CALL
=
"call"
CATEGORY
=
"category"
CHARSET
=
"charset"
GROUP
=
"group
"
GROUP
_IGNORE
=
"group
_ignore"
GROUP
REF
=
"groupref
"
GROUP
REF_IGNORE
=
"groupref
_ignore"
IN
=
"in"
IN_IGNORE
=
"in_ignore"
INDEX
=
"index"
...
...
@@ -90,7 +90,7 @@ OPCODES = [
CALL
,
CATEGORY
,
CHARSET
,
GROUP
,
GROUP
_IGNORE
,
GROUP
REF
,
GROUPREF
_IGNORE
,
INDEX
,
IN
,
IN_IGNORE
,
INFO
,
...
...
@@ -136,7 +136,7 @@ CHCODES = makedict(CHCODES)
# replacement operations for "ignore case" mode
OP_IGNORE
=
{
GROUP
:
GROUP
_IGNORE
,
GROUP
REF
:
GROUPREF
_IGNORE
,
IN
:
IN_IGNORE
,
LITERAL
:
LITERAL_IGNORE
,
NOT_LITERAL
:
NOT_LITERAL_IGNORE
...
...
Lib/sre_parse.py
Dosyayı görüntüle @
72b82ba1
...
...
@@ -241,7 +241,7 @@ def _escape(source, escape, state):
if
group
:
if
(
not
source
.
next
or
not
_group
(
escape
+
source
.
next
,
state
.
groups
)):
return
GROUP
,
group
return
GROUP
REF
,
group
escape
=
escape
+
source
.
get
()
elif
source
.
next
in
OCTDIGITS
:
escape
=
escape
+
source
.
get
()
...
...
@@ -450,7 +450,7 @@ def _parse(source, state):
gid
=
state
.
groupdict
.
get
(
name
)
if
gid
is
None
:
raise
error
,
"unknown group name"
subpattern
.
append
((
GROUP
,
gid
))
subpattern
.
append
((
GROUP
REF
,
gid
))
elif
source
.
match
(
"#"
):
index
=
""
while
1
:
...
...
Lib/test/output/test_sre
Dosyayı görüntüle @
72b82ba1
test_sre
=== Failed incorrectly ('^(.+)?B', 'AB', 0, 'g1', 'A')
=== Failed incorrectly ('(a+)+\\1', 'aa', 0, 'found+"-"+g1', 'aa-a')
=== grouping error ('([^/]*/)*sub1/', 'd:msgs/tdir/sub1/trial/away.cpp', 0, 'found+"-"+g1', 'd:msgs/tdir/sub1/-tdir/') 'd:msgs/tdir/sub1/-trial/' should be 'd:msgs/tdir/sub1/-tdir/'
=== grouping error ('([abc])*bcd', 'abcd', 0, 'found+"-"+g1', 'abcd-a') 'abcd-c' should be 'abcd-a'
=== grouping error ('(?i)([abc])*bcd', 'ABCD', 0, 'found+"-"+g1', 'ABCD-A') 'ABCD-C' should be 'ABCD-A'
=== Failed incorrectly ('^(.+)?B', 'AB', 0, 'g1', 'A')
Modules/_sre.c
Dosyayı görüntüle @
72b82ba1
...
...
@@ -406,6 +406,7 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern)
int
stackbase
;
int
lastmark
;
int
i
,
count
;
SRE_STACK
*
sp
;
/* FIXME: this is a hack! */
void
*
mark_copy
[
SRE_MARK_SIZE
];
...
...
@@ -571,8 +572,8 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern)
/* set mark */
/* args: <mark> */
TRACE
((
"%8d: set mark %d
\n
"
,
PTR
(
ptr
),
pattern
[
0
]));
if
(
state
->
lastmark
<
pattern
[
0
])
state
->
lastmark
=
pattern
[
0
];
if
(
state
->
lastmark
<
pattern
[
0
]
+
1
)
state
->
lastmark
=
pattern
[
0
]
+
1
;
if
(
!
mark
)
{
mark
=
mark_copy
;
memcpy
(
mark
,
state
->
mark
,
state
->
lastmark
*
sizeof
(
void
*
));
...
...
@@ -780,10 +781,8 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern)
#endif
case
SRE_OP_MAX_REPEAT
:
/* match repeated sequence (maximizing regexp). repeated
group should end with a MAX_UNTIL code */
/* args: <skip> <min> <max> <item> */
/* match repeated sequence (maximizing regexp) */
/* args: <skip> <1=min> <2=max> <3=save> <4=item> */
TRACE
((
"%8d: max repeat (%d %d)
\n
"
,
PTR
(
ptr
),
pattern
[
1
],
pattern
[
2
]));
...
...
@@ -793,7 +792,7 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern)
/* match minimum number of items */
while
(
count
<
(
int
)
pattern
[
1
])
{
i
=
SRE_MATCH
(
state
,
pattern
+
3
);
i
=
SRE_MATCH
(
state
,
pattern
+
4
);
if
(
i
<
0
)
return
i
;
if
(
!
i
)
...
...
@@ -817,8 +816,13 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern)
points to the stack */
while
(
pattern
[
2
]
==
65535
||
count
<
(
int
)
pattern
[
2
])
{
void
*
mark0
,
*
mark1
;
if
(
pattern
[
3
]
!=
65535
)
{
mark0
=
state
->
mark
[
pattern
[
3
]];
mark1
=
state
->
mark
[
pattern
[
3
]
+
1
];
}
state
->
stackbase
=
stack
;
i
=
SRE_MATCH
(
state
,
pattern
+
3
);
i
=
SRE_MATCH
(
state
,
pattern
+
4
);
state
->
stackbase
=
stackbase
;
/* rewind */
if
(
i
<
0
)
return
i
;
...
...
@@ -837,8 +841,14 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern)
return
i
;
/* out of memory */
}
TRACE
((
"%8d: stack[%d] = %d
\n
"
,
PTR
(
ptr
),
stack
,
PTR
(
ptr
)));
state
->
stack
[
stack
].
ptr
=
ptr
;
state
->
stack
[
stack
].
pattern
=
pattern
+
pattern
[
0
];
sp
=
state
->
stack
+
stack
;
sp
->
ptr
=
ptr
;
sp
->
pattern
=
pattern
+
pattern
[
0
];
sp
->
mark
=
pattern
[
3
];
if
(
pattern
[
3
]
!=
65535
)
{
sp
->
mark0
=
mark0
;
sp
->
mark1
=
mark1
;
}
stack
++
;
/* move forward */
ptr
=
state
->
ptr
;
...
...
@@ -855,13 +865,15 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern)
case
SRE_OP_MIN_REPEAT
:
/* match repeated sequence (minimizing regexp) */
/* args: <skip> <1=min> <2=max> <3=save> <4=item> */
TRACE
((
"%8d: min repeat %d %d
\n
"
,
PTR
(
ptr
),
pattern
[
1
],
pattern
[
2
]));
count
=
0
;
state
->
ptr
=
ptr
;
/* match minimum number of items */
while
(
count
<
(
int
)
pattern
[
1
])
{
i
=
SRE_MATCH
(
state
,
pattern
+
3
);
i
=
SRE_MATCH
(
state
,
pattern
+
4
);
if
(
i
<
0
)
return
i
;
if
(
!
i
)
...
...
@@ -877,7 +889,7 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern)
goto
success
;
}
state
->
ptr
=
ptr
;
/* backtrack */
i
=
SRE_MATCH
(
state
,
pattern
+
3
);
i
=
SRE_MATCH
(
state
,
pattern
+
4
);
if
(
i
<
0
)
return
i
;
if
(
!
i
)
...
...
@@ -940,15 +952,20 @@ SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern)
}
failure
:
TRACE
((
"%8d: leave (failure)
\n
"
,
PTR
(
ptr
)));
if
(
stack
--
>
stackbase
)
{
ptr
=
state
->
stack
[
stack
].
ptr
;
pattern
=
state
->
stack
[
stack
].
pattern
;
sp
=
state
->
stack
+
stack
;
ptr
=
sp
->
ptr
;
pattern
=
sp
->
pattern
;
if
(
sp
->
mark
!=
65535
)
{
state
->
mark
[
sp
->
mark
]
=
sp
->
mark0
;
state
->
mark
[
sp
->
mark
+
1
]
=
sp
->
mark1
;
}
TRACE
((
"%8d: retry (%d)
\n
"
,
PTR
(
ptr
),
stack
));
goto
retry
;
}
TRACE
((
"%8d: leave (failure)
\n
"
,
PTR
(
ptr
)));
state
->
stackbase
=
stackbase
;
state
->
lastmark
=
lastmark
;
state
->
stackbase
=
stackbase
;
if
(
mark
)
memcpy
(
state
->
mark
,
mark
,
state
->
lastmark
*
sizeof
(
void
*
));
return
0
;
...
...
Modules/sre.h
Dosyayı görüntüle @
72b82ba1
...
...
@@ -46,6 +46,9 @@ typedef struct {
/* stack elements */
SRE_CODE
*
pattern
;
void
*
ptr
;
int
mark
;
void
*
mark0
;
void
*
mark1
;
}
SRE_STACK
;
/* FIXME: <fl> shouldn't be a constant, really... */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment