aboutsummaryrefslogtreecommitdiff
path: root/pycparser
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2013-07-13 06:40:36 -0700
committerEli Bendersky <eliben@gmail.com>2013-07-13 06:40:36 -0700
commit2a826bcffe76422a7c576f12640a1202b1f7e88b (patch)
treefb0f47dd2ad42f2477b1545ccf37b29c431921d7 /pycparser
parentffa18094fe6c76ea6bc864b442f65b3668406289 (diff)
downloadpycparser-2a826bcffe76422a7c576f12640a1202b1f7e88b.tar.gz
Remember last_token in the lexer, instead of using tokenfunc
Diffstat (limited to 'pycparser')
-rw-r--r--pycparser/c_lexer.py7
-rw-r--r--pycparser/c_parser.py13
2 files changed, 9 insertions, 11 deletions
diff --git a/pycparser/c_lexer.py b/pycparser/c_lexer.py
index 8a4a0b1..393f0a8 100644
--- a/pycparser/c_lexer.py
+++ b/pycparser/c_lexer.py
@@ -46,6 +46,9 @@ class CLexer(object):
self.type_lookup_func = type_lookup_func
self.filename = ''
+ # Keeps track of the last token returned from self.token()
+ self.last_token = None
+
# Allow either "# line" or "# <num>" to support GCC's
# cpp output
#
@@ -71,8 +74,8 @@ class CLexer(object):
self.lexer.input(text)
def token(self):
- g = self.lexer.token()
- return g
+ self.last_token = self.lexer.token()
+ return self.last_token
def find_tok_column(self, token):
""" Find the column of the token in its line.
diff --git a/pycparser/c_parser.py b/pycparser/c_parser.py
index 4a33057..e67c27f 100644
--- a/pycparser/c_parser.py
+++ b/pycparser/c_parser.py
@@ -135,7 +135,6 @@ class CParser(PLYParser):
return self.cparser.parse(
input=text,
lexer=self.clex,
- tokenfunc=self._yacc_tokenfunc,
debug=debuglevel)
######################-- PRIVATE --######################
@@ -194,16 +193,12 @@ class CParser(PLYParser):
is_type = self._is_type_in_scope(name)
return is_type
- def _yacc_tokenfunc(self):
- self._last_yielded_token = self.clex.token()
- return self._last_yielded_token
-
def _get_yacc_lookahead_token(self):
- """ We need access to yacc.py's lookahead token in certain cases. We
- keep track of the last token read by yacc, which is lookahead
- unless some sort of error recovery was attempted.
+ """ We need access to yacc's lookahead token in certain cases.
+ This is the last token yacc requested from the lexer, so we
+ ask the lexer.
"""
- return self._last_yielded_token
+ return self.clex.last_token
# To understand what's going on here, read sections A.8.5 and
# A.8.6 of K&R2 very carefully.