mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
- fixed some re usage, partly so it'll still work when re uses pre instead
of sre, and partly fixing re -> regex porting oversights - fixed PyFontify.py so it actually *works* again..
This commit is contained in:
parent
353ae58964
commit
3eec7620be
4 changed files with 38 additions and 43 deletions
|
@ -13,7 +13,7 @@ opensolidid = struct.pack('h', 471)
|
||||||
|
|
||||||
arrows = (nullid, closedid, openid, closedsolidid, opensolidid)
|
arrows = (nullid, closedid, openid, closedsolidid, opensolidid)
|
||||||
|
|
||||||
has_ctlcharsRE = re.compile('[\000-\037\177-\377]')
|
has_ctlcharsRE = re.compile(r'[\000-\037\177-\377]')
|
||||||
def ctlcharsREsearch(str):
|
def ctlcharsREsearch(str):
|
||||||
if has_ctlcharsRE.search(str) is None:
|
if has_ctlcharsRE.search(str) is None:
|
||||||
return -1
|
return -1
|
||||||
|
|
|
@ -790,7 +790,7 @@ def _escape(where, what) :
|
||||||
|
|
||||||
def _makewholewordpattern(word):
|
def _makewholewordpattern(word):
|
||||||
# first, escape special regex chars
|
# first, escape special regex chars
|
||||||
for esc in "\\[]().*^+$?":
|
for esc in "\\[]()|.*^+$?":
|
||||||
word = _escape(word, esc)
|
word = _escape(word, esc)
|
||||||
notwordcharspat = '[^' + _wordchars + ']'
|
notwordcharspat = '[^' + _wordchars + ']'
|
||||||
pattern = '(' + word + ')'
|
pattern = '(' + word + ')'
|
||||||
|
@ -1166,7 +1166,7 @@ def execstring(pytext, globals, locals, filename="<string>", debugging=0,
|
||||||
PyDebugger.stop()
|
PyDebugger.stop()
|
||||||
|
|
||||||
|
|
||||||
_identifieRE = re.compile("[A-Za-z_][A-Za-z_0-9]*")
|
_identifieRE = re.compile(r"[A-Za-z_][A-Za-z_0-9]*")
|
||||||
|
|
||||||
def identifieRE_match(str):
|
def identifieRE_match(str):
|
||||||
match = _identifieRE.match(str)
|
match = _identifieRE.match(str)
|
||||||
|
|
|
@ -19,15 +19,16 @@ sublist is not used, hence always None.
|
||||||
# Many thanks for regular expression debugging & authoring are due to:
|
# Many thanks for regular expression debugging & authoring are due to:
|
||||||
# Tim (the-incredib-ly y'rs) Peters and Cristian Tismer
|
# Tim (the-incredib-ly y'rs) Peters and Cristian Tismer
|
||||||
# So, who owns the copyright? ;-) How about this:
|
# So, who owns the copyright? ;-) How about this:
|
||||||
# Copyright 1996-2000:
|
# Copyright 1996-2001:
|
||||||
# Mitchell S. Chapman,
|
# Mitchell S. Chapman,
|
||||||
# Zachary Roadhouse,
|
# Zachary Roadhouse,
|
||||||
# Tim Peters,
|
# Tim Peters,
|
||||||
# Just van Rossum
|
# Just van Rossum
|
||||||
|
|
||||||
__version__ = "0.3.3"
|
__version__ = "0.4"
|
||||||
|
|
||||||
import string, re
|
import string
|
||||||
|
import re
|
||||||
|
|
||||||
# First a little helper, since I don't like to repeat things. (Tismer speaking)
|
# First a little helper, since I don't like to repeat things. (Tismer speaking)
|
||||||
import string
|
import string
|
||||||
|
@ -43,50 +44,47 @@ keywordsList = [
|
||||||
"break", "else", "if", "or", "while",
|
"break", "else", "if", "or", "while",
|
||||||
"class", "except", "import", "pass",
|
"class", "except", "import", "pass",
|
||||||
"continue", "finally", "in", "print",
|
"continue", "finally", "in", "print",
|
||||||
"def", "for", "is", "raise"]
|
"def", "for", "is", "raise", "yield"]
|
||||||
|
|
||||||
# Build up a regular expression which will match anything
|
# Build up a regular expression which will match anything
|
||||||
# interesting, including multi-line triple-quoted strings.
|
# interesting, including multi-line triple-quoted strings.
|
||||||
commentPat = "#.*"
|
commentPat = r"#[^\n]*"
|
||||||
|
|
||||||
pat = "q[^\q\n]*\(\\\\[\000-\377][^\q\n]*\)*q"
|
pat = r"q[^\\q\n]*(\\[\000-\377][^\\q\n]*)*q"
|
||||||
quotePat = replace(pat, "q", "'") + "\|" + replace(pat, 'q', '"')
|
quotePat = replace(pat, "q", "'") + "|" + replace(pat, 'q', '"')
|
||||||
|
|
||||||
# Way to go, Tim!
|
# Way to go, Tim!
|
||||||
pat = """
|
pat = r"""
|
||||||
qqq
|
qqq
|
||||||
[^\\q]*
|
[^\\q]*
|
||||||
\(
|
(
|
||||||
\( \\\\[\000-\377]
|
( \\[\000-\377]
|
||||||
\| q
|
| q
|
||||||
\( \\\\[\000-\377]
|
( \\[\000-\377]
|
||||||
\| [^\\q]
|
| [^\q]
|
||||||
\| q
|
| q
|
||||||
\( \\\\[\000-\377]
|
( \\[\000-\377]
|
||||||
\| [^\\q]
|
| [^\\q]
|
||||||
\)
|
)
|
||||||
\)
|
)
|
||||||
\)
|
)
|
||||||
[^\\q]*
|
[^\\q]*
|
||||||
\)*
|
)*
|
||||||
qqq
|
qqq
|
||||||
"""
|
"""
|
||||||
pat = string.join(string.split(pat), '') # get rid of whitespace
|
pat = string.join(string.split(pat), '') # get rid of whitespace
|
||||||
tripleQuotePat = replace(pat, "q", "'") + "\|" + replace(pat, 'q', '"')
|
tripleQuotePat = replace(pat, "q", "'") + "|" + replace(pat, 'q', '"')
|
||||||
|
|
||||||
# Build up a regular expression which matches all and only
|
# Build up a regular expression which matches all and only
|
||||||
# Python keywords. This will let us skip the uninteresting
|
# Python keywords. This will let us skip the uninteresting
|
||||||
# identifier references.
|
# identifier references.
|
||||||
# nonKeyPat identifies characters which may legally precede
|
# nonKeyPat identifies characters which may legally precede
|
||||||
# a keyword pattern.
|
# a keyword pattern.
|
||||||
nonKeyPat = "\(^\|[^a-zA-Z0-9_.\"']\)"
|
nonKeyPat = r"(^|[^a-zA-Z0-9_.\"'])"
|
||||||
|
|
||||||
keyPat = nonKeyPat + "\("
|
keyPat = nonKeyPat + "(" + "|".join(keywordsList) + ")" + nonKeyPat
|
||||||
for keyword in keywordsList:
|
|
||||||
keyPat = keyPat + keyword + "\|"
|
|
||||||
keyPat = keyPat[:-2] + "\)" + nonKeyPat
|
|
||||||
|
|
||||||
matchPat = commentPat + "\|" + keyPat + "\|" + tripleQuotePat + "\|" + quotePat
|
matchPat = commentPat + "|" + keyPat + "|" + tripleQuotePat + "|" + quotePat
|
||||||
matchRE = re.compile(matchPat)
|
matchRE = re.compile(matchPat)
|
||||||
|
|
||||||
idKeyPat = "[ \t]*[A-Za-z_][A-Za-z_0-9.]*" # Ident w. leading whitespace.
|
idKeyPat = "[ \t]*[A-Za-z_][A-Za-z_0-9.]*" # Ident w. leading whitespace.
|
||||||
|
@ -111,7 +109,10 @@ def fontify(pytext, searchfrom = 0, searchto = None):
|
||||||
end = searchfrom
|
end = searchfrom
|
||||||
while 1:
|
while 1:
|
||||||
m = search(pytext, end)
|
m = search(pytext, end)
|
||||||
if not m or m.start() >= searchto:
|
if m is None:
|
||||||
|
break # EXIT LOOP
|
||||||
|
start = m.start()
|
||||||
|
if start >= searchto:
|
||||||
break # EXIT LOOP
|
break # EXIT LOOP
|
||||||
match = m.group(0)
|
match = m.group(0)
|
||||||
end = start + len(match)
|
end = start + len(match)
|
||||||
|
@ -132,10 +133,12 @@ def fontify(pytext, searchfrom = 0, searchto = None):
|
||||||
# following identifier.
|
# following identifier.
|
||||||
if match in ["def", "class"]:
|
if match in ["def", "class"]:
|
||||||
m = idSearch(pytext, end)
|
m = idSearch(pytext, end)
|
||||||
if m and m.start() == end:
|
if m is not None:
|
||||||
match = m.group(0)
|
start = m.start()
|
||||||
end = start + len(match)
|
if start == end:
|
||||||
tags_append((identifierTag, start, end, None))
|
match = m.group(0)
|
||||||
|
end = start + len(match)
|
||||||
|
tags_append((identifierTag, start, end, None))
|
||||||
elif c == "#":
|
elif c == "#":
|
||||||
tags_append((commentTag, start, end, None))
|
tags_append((commentTag, start, end, None))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -381,14 +381,6 @@ class Scrollbar(ControlWidget):
|
||||||
return self._value
|
return self._value
|
||||||
|
|
||||||
|
|
||||||
class __xxxx_PopupControl(ControlWidget):
|
|
||||||
|
|
||||||
def __init__(self, possize, title = "Button", callback = None):
|
|
||||||
procID = Controls.popupMenuProc # | Controls.useWFont
|
|
||||||
ControlWidget.__init__(self, possize, title, procID, callback, 0, 0, 1)
|
|
||||||
self._isdefault = 0
|
|
||||||
|
|
||||||
|
|
||||||
def _scalebarvalue(absmin, absmax, curmin, curmax):
|
def _scalebarvalue(absmin, absmax, curmin, curmax):
|
||||||
if curmin <= absmin and curmax >= absmax:
|
if curmin <= absmin and curmax >= absmax:
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue