Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
254eb538
Commit
254eb538
authored
Sep 17, 2002
by
Kurt B. Kaiser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge Py Idle changes:
Rev 1.10 doerwalter (string methods)
parent
d8e20a0e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
27 deletions
+22
-27
Lib/idlelib/PyParse.py
Lib/idlelib/PyParse.py
+22
-27
No files found.
Lib/idlelib/PyParse.py
View file @
254eb538
import
string
import
re
import
sys
...
...
@@ -7,7 +6,7 @@ C_NONE, C_BACKSLASH, C_STRING, C_BRACKET = range(4)
if
0
:
# for throwaway debugging output
def
dump
(
*
stuff
):
sys
.
__stdout__
.
write
(
string
.
join
(
map
(
str
,
stuff
),
" "
)
+
"
\
n
"
)
sys
.
__stdout__
.
write
(
" "
.
join
(
map
(
str
,
stuff
)
)
+
"
\
n
"
)
# Find what looks like the start of a popular stmt.
...
...
@@ -103,7 +102,7 @@ for ch in ")}]":
_tran
[
ord
(
ch
)]
=
')'
for
ch
in
"
\
"
'
\
\
\
n
#"
:
_tran
[
ord
(
ch
)]
=
ch
_tran
=
string
.
join
(
_tran
,
''
)
_tran
=
''
.
join
(
_tran
)
del
ch
try
:
...
...
@@ -153,13 +152,12 @@ class Parser:
# Python 1.5.2 (#0, Apr 13 1999, ...
def
find_good_parse_start
(
self
,
use_ps1
,
is_char_in_string
=
None
,
_rfind
=
string
.
rfind
,
_synchre
=
_synchre
):
str
,
pos
=
self
.
str
,
None
if
use_ps1
:
# shell window
ps1
=
'
\
n
'
+
sys
.
ps1
i
=
_rfind
(
str
,
ps1
)
i
=
str
.
rfind
(
ps1
)
if
i
>=
0
:
pos
=
i
+
len
(
ps1
)
# make it look like there's a newline instead
...
...
@@ -178,10 +176,10 @@ class Parser:
# bumped to a legitimate synch point.
limit
=
len
(
str
)
for
tries
in
range
(
5
):
i
=
_rfind
(
str
,
":
\
n
"
,
0
,
limit
)
i
=
str
.
rfind
(
":
\
n
"
,
0
,
limit
)
if
i
<
0
:
break
i
=
_rfind
(
str
,
'
\
n
'
,
0
,
i
)
+
1
# start of colon line
i
=
str
.
rfind
(
'
\
n
'
,
0
,
i
)
+
1
# start of colon line
m
=
_synchre
(
str
,
i
,
limit
)
if
m
and
not
is_char_in_string
(
m
.
start
()):
pos
=
m
.
start
()
...
...
@@ -226,7 +224,7 @@ class Parser:
# based) of the non-continuation lines.
# Creates self.{goodlines, continuation}.
def
_study1
(
self
,
_replace
=
string
.
replace
,
_find
=
string
.
find
):
def
_study1
(
self
):
if
self
.
study_level
>=
1
:
return
self
.
study_level
=
1
...
...
@@ -236,12 +234,12 @@ class Parser:
# uninteresting characters. This can cut the number of chars
# by a factor of 10-40, and so greatly speed the following loop.
str
=
self
.
str
str
=
str
ing
.
translate
(
str
,
_tran
)
str
=
_replace
(
str
,
'xxxxxxxx'
,
'x'
)
str
=
_replace
(
str
,
'xxxx'
,
'x'
)
str
=
_replace
(
str
,
'xx'
,
'x'
)
str
=
_replace
(
str
,
'xx'
,
'x'
)
str
=
_replace
(
str
,
'
\
n
x'
,
'
\
n
'
)
str
=
str
.
translate
(
_tran
)
str
=
str
.
replace
(
'xxxxxxxx'
,
'x'
)
str
=
str
.
replace
(
'xxxx'
,
'x'
)
str
=
str
.
replace
(
'xx'
,
'x'
)
str
=
str
.
replace
(
'xx'
,
'x'
)
str
=
str
.
replace
(
'
\
n
x'
,
'
\
n
'
)
# note that replacing x\n with \n would be incorrect, because
# x may be preceded by a backslash
...
...
@@ -322,7 +320,7 @@ class Parser:
if
ch
==
'#'
:
# consume the comment
i
=
_find
(
str
,
'
\
n
'
,
i
)
i
=
str
.
find
(
'
\
n
'
,
i
)
assert
i
>=
0
continue
...
...
@@ -363,8 +361,7 @@ class Parser:
# self.lastopenbracketpos
# if continuation is C_BRACKET, index of last open bracket
def
_study2
(
self
,
_rfind
=
string
.
rfind
,
_find
=
string
.
find
,
_ws
=
string
.
whitespace
):
def
_study2
(
self
):
if
self
.
study_level
>=
2
:
return
self
.
_study1
()
...
...
@@ -381,7 +378,7 @@ class Parser:
q
=
p
for
nothing
in
range
(
goodlines
[
i
-
1
],
goodlines
[
i
]):
# tricky: sets p to 0 if no preceding newline
p
=
_rfind
(
str
,
'
\
n
'
,
0
,
p
-
1
)
+
1
p
=
str
.
rfind
(
'
\
n
'
,
0
,
p
-
1
)
+
1
# The stmt str[p:q] isn't a continuation, but may be blank
# or a non-indenting comment line.
if
_junkre
(
str
,
p
):
...
...
@@ -444,7 +441,7 @@ class Parser:
if
ch
==
'#'
:
# consume comment and trailing newline
p
=
_find
(
str
,
'
\
n
'
,
p
,
q
)
+
1
p
=
str
.
find
(
'
\
n
'
,
p
,
q
)
+
1
assert
p
>
0
continue
...
...
@@ -465,13 +462,13 @@ class Parser:
# Assuming continuation is C_BRACKET, return the number
# of spaces the next line should be indented.
def
compute_bracket_indent
(
self
,
_find
=
string
.
find
):
def
compute_bracket_indent
(
self
):
self
.
_study2
()
assert
self
.
continuation
==
C_BRACKET
j
=
self
.
lastopenbracketpos
str
=
self
.
str
n
=
len
(
str
)
origi
=
i
=
str
ing
.
rfind
(
str
,
'
\
n
'
,
0
,
j
)
+
1
origi
=
i
=
str
.
rfind
(
'
\
n
'
,
0
,
j
)
+
1
j
=
j
+
1
# one beyond open bracket
# find first list item; set i to start of its line
while
j
<
n
:
...
...
@@ -482,7 +479,7 @@ class Parser:
break
else
:
# this line is junk; advance to next line
i
=
j
=
_find
(
str
,
'
\
n
'
,
j
)
+
1
i
=
j
=
str
.
find
(
'
\
n
'
,
j
)
+
1
else
:
# nothing interesting follows the bracket;
# reproduce the bracket line's indentation + a level
...
...
@@ -490,8 +487,7 @@ class Parser:
while
str
[
j
]
in
"
\
t
"
:
j
=
j
+
1
extra
=
self
.
indentwidth
return
len
(
string
.
expandtabs
(
str
[
i
:
j
],
self
.
tabwidth
))
+
extra
return
len
(
str
[
i
:
j
].
expandtabs
(
self
.
tabwidth
))
+
extra
# Return number of physical lines in last stmt (whether or not
# it's an interesting stmt! this is intended to be called when
...
...
@@ -517,7 +513,7 @@ class Parser:
# See whether the initial line starts an assignment stmt; i.e.,
# look for an = operator
endpos
=
str
ing
.
find
(
str
,
'
\
n
'
,
startpos
)
+
1
endpos
=
str
.
find
(
'
\
n
'
,
startpos
)
+
1
found
=
level
=
0
while
i
<
endpos
:
ch
=
str
[
i
]
...
...
@@ -553,8 +549,7 @@ class Parser:
while str[i] not in "
\
t
\
n
":
i = i+1
return len(string.expandtabs(str[self.stmt_start :
i],
return len(str[self.stmt_start:i].expandtabs(
\
self.tabwidth)) + 1
# Return the leading whitespace on the initial line of the last
...
...
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