Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
297d8469
Commit
297d8469
authored
Oct 16, 2014
by
Paul Sokolovsky
Browse files
modure: Update to re1.5 v0.6.1, fixed and extended character class support.
parent
391db866
Changes
6
Hide whitespace changes
Inline
Side-by-side
extmod/re1.5/charclass.c
View file @
297d8469
...
...
@@ -3,9 +3,11 @@
int
_re1_5_classmatch
(
const
char
*
pc
,
const
char
*
sp
)
{
// pc points to "cnt" byte after opcode
int
is_positive
=
(
pc
[
-
1
]
==
Class
);
int
cnt
=
*
pc
++
;
while
(
cnt
--
)
{
if
(
!
(
*
sp
>=
*
pc
&&
*
sp
<=
pc
[
1
]))
return
0
;
if
(
*
sp
>=
*
pc
&&
*
sp
<=
pc
[
1
])
return
is_positive
;
pc
+=
2
;
}
return
1
;
}
\ No newline at end of file
return
!
is_positive
;
}
extmod/re1.5/compilecode.c
View file @
297d8469
...
...
@@ -48,6 +48,7 @@ int re1_5_sizecode(const char *re)
case
'['
:
{
pc
+=
2
;
re
++
;
if
(
*
re
==
'^'
)
re
++
;
while
(
*
re
!=
']'
)
{
if
(
!*
re
)
return
-
1
;
if
(
re
[
1
]
==
'-'
)
{
...
...
@@ -91,10 +92,15 @@ const char *_compilecode(const char *re, ByteProg *prog)
case
'['
:
{
int
cnt
;
term
=
pc
;
EMIT
(
pc
++
,
Class
);
re
++
;
if
(
*
re
==
'^'
)
{
EMIT
(
pc
++
,
ClassNot
);
re
++
;
}
else
{
EMIT
(
pc
++
,
Class
);
}
pc
++
;
// Skip # of pair byte
prog
->
len
++
;
re
++
;
for
(
cnt
=
0
;
*
re
!=
']'
;
re
++
,
cnt
++
)
{
if
(
!*
re
)
return
NULL
;
EMIT
(
pc
++
,
*
re
);
...
...
extmod/re1.5/dumpcode.c
View file @
297d8469
...
...
@@ -32,9 +32,11 @@ void re1_5_dumpcode(ByteProg *prog)
case
Any
:
printf
(
"any
\n
"
);
break
;
case
Class
:
{
int
num
=
code
[
pc
++
];
printf
(
"class %d"
,
num
);
case
Class
:
case
ClassNot
:
{
int
num
=
code
[
pc
];
printf
(
"class%s %d"
,
(
code
[
pc
-
1
]
==
ClassNot
?
"not"
:
""
),
num
);
pc
++
;
while
(
num
--
)
{
printf
(
" 0x%02x-0x%02x"
,
code
[
pc
],
code
[
pc
+
1
]);
pc
+=
2
;
...
...
extmod/re1.5/re1.5.h
View file @
297d8469
...
...
@@ -81,6 +81,7 @@ enum /* Inst.opcode */
Char
=
CONSUMERS
,
Any
,
Class
,
ClassNot
,
ASSERTS
=
0x50
,
Bol
=
ASSERTS
,
...
...
extmod/re1.5/recursiveloop.c
View file @
297d8469
...
...
@@ -24,6 +24,7 @@ recursiveloop(char *pc, const char *sp, Subject *input, const char **subp, int n
sp
++
;
continue
;
case
Class
:
case
ClassNot
:
if
(
!
_re1_5_classmatch
(
pc
,
sp
))
return
0
;
pc
+=
*
(
unsigned
char
*
)
pc
*
2
+
1
;
...
...
tests/extmod/ure1.py
View file @
297d8469
...
...
@@ -20,13 +20,27 @@ try:
except
IndexError
:
print
(
"IndexError"
)
r
=
re
.
compile
(
"[a-c]"
)
r
=
re
.
compile
(
"[a-c
u-z
]"
)
m
=
r
.
match
(
"a"
)
print
(
m
.
group
(
0
))
m
=
r
.
match
(
"z"
)
print
(
m
.
group
(
0
))
m
=
r
.
match
(
"d"
)
print
(
m
)
m
=
r
.
match
(
"A"
)
print
(
m
)
print
(
"==="
)
r
=
re
.
compile
(
"[^a-cu-z]"
)
m
=
r
.
match
(
"a"
)
print
(
m
)
m
=
r
.
match
(
"z"
)
print
(
m
)
m
=
r
.
match
(
"d"
)
print
(
m
.
group
(
0
))
m
=
r
.
match
(
"A"
)
print
(
m
.
group
(
0
))
r
=
re
.
compile
(
"o+"
)
m
=
r
.
search
(
"foobar"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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