Commits

Georg Brandl committed 7f4fa60

Fix a few problems.

Comments (0)

Files changed (1)

scripts/find_error.py

     text = file(fn, 'U').read()
     text = text.strip('\n') + '\n'
     text = text.decode('latin1')
-    ntext = []
+    tokens = []
     states = []
 
-    def show_token(tok):
+    def show_token(tok, state):
         reprs = map(repr, tok)
         print '   ' + reprs[1] + ' ' + ' ' * (29-len(reprs[1])) + reprs[0],
         if debug_lexer:
-            print ' ' + ' ' * (29-len(reprs[0])) + repr(states[i]),
+            print ' ' + ' ' * (29-len(reprs[0])) + repr(state),
         print
 
     for type, val in lx.get_tokens(text):
         if type == Error:
             print 'Error parsing', fn, 'on line', lno
             print 'Previous tokens' + (debug_lexer and ' and states' or '') + ':'
-            for i in range(len(ntext) - num, len(ntext)):
-                show_token(ntext[i])
+            if showall:
+                for tok, state in zip(tokens, states):
+                    show_token(tok, state)
+            else:
+                for i in range(len(tokens) - num, len(tokens)):
+                    show_token(tokens[i], states[i])
             print 'Error token:'
             l = len(repr(val))
             print '   ' + repr(val),
-            if debug_lexer:
+            if debug_lexer and hasattr(lx, 'statestack'):
                 print ' ' * (60-l) + repr(lx.statestack),
             print
             print
             return 1
-        ntext.append((type,val))
+        tokens.append((type,val))
         if debug_lexer:
-            states.append(lx.statestack[:])
+            if hasattr(lx, 'statestack'):
+                states.append(lx.statestack[:])
+            else:
+                states.append(None)
     if showall:
-        for tok in ntext:
-            show_token(tok)
+        for tok, state in zip(tokens, states):
+            show_token(tok, state)
     return 0
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.