2.7 grammar bug workaround. Fix docstring bug

This commit is contained in:
rocky
2016-11-24 21:41:23 -05:00
parent 8be6369bdf
commit abecb21671
8 changed files with 19 additions and 10 deletions

Binary file not shown.

View File

@@ -49,7 +49,10 @@ class Python27Parser(Python2Parser):
def p_jump27(self, args):
"""
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD COME_FROM
come_froms ::= come_froms COME_FROM
come_froms ::= COME_FROM
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD come_froms
bp_come_from ::= POP_BLOCK COME_FROM
# FIXME: Common with 3.0+

View File

@@ -160,7 +160,11 @@ class Scanner2(scan.Scanner):
# we sort them). That way, specific COME_FROM tags will match up
# properly. For example, a "loop" with an "if" nested in it should have the
# "loop" tag last so the grammar rule matches that properly.
# last_offset = -1
for jump_offset in sorted(jump_targets[offset], reverse=True):
# if jump_offset == last_offset:
# continue
# last_offset = jump_offset
come_from_name = 'COME_FROM'
opname = self.opc.opname[self.code[jump_offset]]
if opname.startswith('SETUP_') and self.version == 2.7:

View File

@@ -8,12 +8,13 @@ else:
maxint = sys.maxint
def print_docstring(self, indent, docstring):
## FIXME: put this into a testable function.
if docstring.find('"""') == -1:
quote = '"""'
else:
quote = "'''"
try:
if docstring.find('"""') == -1:
quote = '"""'
else:
quote = "'''"
except:
return False
self.write(indent)
if not PYTHON3 and not isinstance(docstring, str):
# Must be unicode in Python2
@@ -73,6 +74,7 @@ def print_docstring(self, indent, docstring):
for line in trimmed[1:-1]:
self.println( indent, line )
self.println(indent, trimmed[-1], quote)
return True
# if __name__ == '__main__':
# if PYTHON3:

View File

@@ -2120,9 +2120,9 @@ class SourceWalker(GenericASTTraversal, object):
docstring = ast[i][0][0][0][0].pattr
except:
docstring = code.co_consts[0]
print_docstring(self, indent, docstring)
self.println()
del ast[i]
if print_docstring(self, indent, docstring):
self.println()
del ast[i]
# the function defining a class normally returns locals(); we