[Idle-dev] CVS: idle PyParse.py,1.4,1.5

Kurt B. Kaiser kbk@users.sourceforge.net
Mon, 16 Sep 2002 20:55:15 -0700


Update of /cvsroot/idlefork/idle
In directory usw-pr-cvs1:/tmp/cvs-serv16222

Modified Files:
	PyParse.py 
Log Message:
Merge Py Idle changes:
Rev 1.10 doerwalter
(string methods)


Index: PyParse.py
===================================================================
RCS file: /cvsroot/idlefork/idle/PyParse.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** PyParse.py	14 Jul 2001 04:59:24 -0000	1.4
--- PyParse.py	17 Sep 2002 03:55:13 -0000	1.5
***************
*** 1,3 ****
- import string
  import re
  import sys
--- 1,2 ----
***************
*** 8,12 ****
  if 0:   # for throwaway debugging output
      def dump(*stuff):
!         sys.__stdout__.write(string.join(map(str, stuff), " ") + "\n")
  
  # Find what looks like the start of a popular stmt.
--- 7,11 ----
  if 0:   # for throwaway debugging output
      def dump(*stuff):
!         sys.__stdout__.write(" ".join(map(str, stuff)) + "\n")
  
  # Find what looks like the start of a popular stmt.
***************
*** 104,108 ****
  for ch in "\"'\\\n#":
      _tran[ord(ch)] = ch
! _tran = string.join(_tran, '')
  del ch
  
--- 103,107 ----
  for ch in "\"'\\\n#":
      _tran[ord(ch)] = ch
! _tran = ''.join(_tran)
  del ch
  
***************
*** 154,158 ****
  
      def find_good_parse_start(self, use_ps1, is_char_in_string=None,
-                               _rfind=string.rfind,
                                _synchre=_synchre):
          str, pos = self.str, None
--- 153,156 ----
***************
*** 160,164 ****
              # shell window
              ps1 = '\n' + sys.ps1
!             i = _rfind(str, ps1)
              if i >= 0:
                  pos = i + len(ps1)
--- 158,162 ----
              # shell window
              ps1 = '\n' + sys.ps1
!             i = str.rfind(ps1)
              if i >= 0:
                  pos = i + len(ps1)
***************
*** 179,186 ****
          limit = len(str)
          for tries in range(5):
!             i = _rfind(str, ":\n", 0, limit)
              if i < 0:
                  break
!             i = _rfind(str, '\n', 0, i) + 1  # start of colon line
              m = _synchre(str, i, limit)
              if m and not is_char_in_string(m.start()):
--- 177,184 ----
          limit = len(str)
          for tries in range(5):
!             i = str.rfind(":\n", 0, limit)
              if i < 0:
                  break
!             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()):
***************
*** 227,231 ****
      # Creates self.{goodlines, continuation}.
  
!     def _study1(self, _replace=string.replace, _find=string.find):
          if self.study_level >= 1:
              return
--- 225,229 ----
      # Creates self.{goodlines, continuation}.
  
!     def _study1(self):
          if self.study_level >= 1:
              return
***************
*** 237,246 ****
          # by a factor of 10-40, and so greatly speed the following loop.
          str = self.str
!         str = string.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, '\nx', '\n')
          # note that replacing x\n with \n would be incorrect, because
          # x may be preceded by a backslash
--- 235,244 ----
          # by a factor of 10-40, and so greatly speed the following loop.
          str = self.str
!         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('\nx', '\n')
          # note that replacing x\n with \n would be incorrect, because
          # x may be preceded by a backslash
***************
*** 323,327 ****
              if ch == '#':
                  # consume the comment
!                 i = _find(str, '\n', i)
                  assert i >= 0
                  continue
--- 321,325 ----
              if ch == '#':
                  # consume the comment
!                 i = str.find('\n', i)
                  assert i >= 0
                  continue
***************
*** 364,369 ****
      #         if continuation is C_BRACKET, index of last open bracket
  
!     def _study2(self, _rfind=string.rfind, _find=string.find,
!                       _ws=string.whitespace):
          if self.study_level >= 2:
              return
--- 362,366 ----
      #         if continuation is C_BRACKET, index of last open bracket
  
!     def _study2(self):
          if self.study_level >= 2:
              return
***************
*** 382,386 ****
              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
              # The stmt str[p:q] isn't a continuation, but may be blank
              # or a non-indenting comment line.
--- 379,383 ----
              for nothing in range(goodlines[i-1], goodlines[i]):
                  # tricky: sets p to 0 if no preceding newline
!                 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.
***************
*** 445,449 ****
              if ch == '#':
                  # consume comment and trailing newline
!                 p = _find(str, '\n', p, q) + 1
                  assert p > 0
                  continue
--- 442,446 ----
              if ch == '#':
                  # consume comment and trailing newline
!                 p = str.find('\n', p, q) + 1
                  assert p > 0
                  continue
***************
*** 466,470 ****
      # of spaces the next line should be indented.
  
!     def compute_bracket_indent(self, _find=string.find):
          self._study2()
          assert self.continuation == C_BRACKET
--- 463,467 ----
      # of spaces the next line should be indented.
  
!     def compute_bracket_indent(self):
          self._study2()
          assert self.continuation == C_BRACKET
***************
*** 472,476 ****
          str = self.str
          n = len(str)
!         origi = i = string.rfind(str, '\n', 0, j) + 1
          j = j+1     # one beyond open bracket
          # find first list item; set i to start of its line
--- 469,473 ----
          str = self.str
          n = len(str)
!         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
***************
*** 483,487 ****
              else:
                  # this line is junk; advance to next line
!                 i = j = _find(str, '\n', j) + 1
          else:
              # nothing interesting follows the bracket;
--- 480,484 ----
              else:
                  # this line is junk; advance to next line
!                 i = j = str.find('\n', j) + 1
          else:
              # nothing interesting follows the bracket;
***************
*** 491,496 ****
                  j = j+1
              extra = self.indentwidth
!         return len(string.expandtabs(str[i:j],
!                                      self.tabwidth)) + extra
  
      # Return number of physical lines in last stmt (whether or not
--- 488,492 ----
                  j = j+1
              extra = self.indentwidth
!         return len(str[i:j].expandtabs(self.tabwidth)) + extra
  
      # Return number of physical lines in last stmt (whether or not
***************
*** 518,522 ****
          # See whether the initial line starts an assignment stmt; i.e.,
          # look for an = operator
!         endpos = string.find(str, '\n', startpos) + 1
          found = level = 0
          while i < endpos:
--- 514,518 ----
          # See whether the initial line starts an assignment stmt; i.e.,
          # look for an = operator
!         endpos = str.find('\n', startpos) + 1
          found = level = 0
          while i < endpos:
***************
*** 554,559 ****
                  i = i+1
  
!         return len(string.expandtabs(str[self.stmt_start :
!                                          i],
                                       self.tabwidth)) + 1
  
--- 550,554 ----
                  i = i+1
  
!         return len(str[self.stmt_start:i].expandtabs(\
                                       self.tabwidth)) + 1