Commits

Eli Bendersky  committed 7cead7e

Googlecode issue #87: improve error reporting for parse errors to contain
columns.

  • Participants
  • Parent commits 3174be7

Comments (0)

Files changed (4)

   - pycparser now carries its PLY dependency along. The pycparser/ply directory
     contains the source of PLY for the currently supported version. This makes
     distribution and testing easier.
+  - The pycparser project has moved to Bitbucket.
 
 + Version 2.08 (10.08.2012)
 

File pycparser/c_lexer.py

         g = self.lexer.token()
         return g
 
+    def find_tok_column(self, token):
+        """ Find the column of the token in its line.
+        """
+        i = token.lexpos
+        while i > 0:
+            if self.lexer.lexdata[i] == '\n': break
+            i -= 1
+        return (token.lexpos - i) + 1
+
     ######################--   PRIVATE   --######################
     
     ##
         self.error_func(msg, location[0], location[1])
         self.lexer.skip(1)
     
-    def _find_tok_column(self, token):
-        i = token.lexpos
-        while i > 0:
-            if self.lexer.lexdata[i] == '\n': break
-            i -= 1
-        return (token.lexpos - i) + 1
-    
     def _make_tok_location(self, token):
-        return (token.lineno, self._find_tok_column(token))
+        return (token.lineno, self.find_tok_column(token))
     
     ##
     ## Reserved keywords

File pycparser/c_parser.py

         if p:
             self._parse_error(
                 'before: %s' % p.value, 
-                self._coord(p.lineno))
+                self._coord(lineno=p.lineno,
+                            column=self.clex.find_tok_column(p)))
         else:
             self._parse_error('At end of input', '')
 
     #--------------- Parsing
     source_code = r'''
     typedef int int8_t;
-    typedef signed char int8_t;
+    kw*
     
     
     '''