Googlecode issue #87: improve error reporting for parse errors to contain
columns.
diff --git a/CHANGES b/CHANGES
index 7e72527..866e76a 100644
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,7 @@
- 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)
diff --git a/pycparser/c_lexer.py b/pycparser/c_lexer.py
index 7770ac5..07752a5 100644
--- a/pycparser/c_lexer.py
+++ b/pycparser/c_lexer.py
@@ -68,6 +68,15 @@
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 --######################
##
@@ -78,15 +87,8 @@
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
diff --git a/pycparser/c_parser.py b/pycparser/c_parser.py
index ddca893..6c17971 100644
--- a/pycparser/c_parser.py
+++ b/pycparser/c_parser.py
@@ -1419,7 +1419,8 @@
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', '')
diff --git a/z_test.py b/z_test.py
index 57c1a19..a87a9ae 100644
--- a/z_test.py
+++ b/z_test.py
@@ -96,7 +96,7 @@
#--------------- Parsing
source_code = r'''
typedef int int8_t;
- typedef signed char int8_t;
+ kw*
'''