mirror of
https://github.com/python/cpython.git
synced 2025-10-17 12:18:23 +00:00
Add Yield() statement handler
Fix Module() handler to avoid including the doc string in the AST
This commit is contained in:
parent
9fa96bed6f
commit
ec927348c2
2 changed files with 22 additions and 2 deletions
|
@ -153,8 +153,12 @@ class Transformer:
|
||||||
|
|
||||||
def file_input(self, nodelist):
|
def file_input(self, nodelist):
|
||||||
doc = self.get_docstring(nodelist, symbol.file_input)
|
doc = self.get_docstring(nodelist, symbol.file_input)
|
||||||
|
if doc is not None:
|
||||||
|
i = 1
|
||||||
|
else:
|
||||||
|
i = 0
|
||||||
stmts = []
|
stmts = []
|
||||||
for node in nodelist:
|
for node in nodelist[i:]:
|
||||||
if node[0] != token.ENDMARKER and node[0] != token.NEWLINE:
|
if node[0] != token.ENDMARKER and node[0] != token.NEWLINE:
|
||||||
self.com_append_stmt(stmts, node)
|
self.com_append_stmt(stmts, node)
|
||||||
return Module(doc, Stmt(stmts))
|
return Module(doc, Stmt(stmts))
|
||||||
|
@ -340,6 +344,11 @@ class Transformer:
|
||||||
n.lineno = nodelist[0][2]
|
n.lineno = nodelist[0][2]
|
||||||
return n
|
return n
|
||||||
|
|
||||||
|
def yield_stmt(self, nodelist):
|
||||||
|
n = Yield(self.com_node(nodelist[1]))
|
||||||
|
n.lineno = nodelist[0][2]
|
||||||
|
return n
|
||||||
|
|
||||||
def raise_stmt(self, nodelist):
|
def raise_stmt(self, nodelist):
|
||||||
# raise: [test [',' test [',' test]]]
|
# raise: [test [',' test [',' test]]]
|
||||||
if len(nodelist) > 5:
|
if len(nodelist) > 5:
|
||||||
|
@ -1245,6 +1254,7 @@ _legal_node_types = [
|
||||||
symbol.continue_stmt,
|
symbol.continue_stmt,
|
||||||
symbol.return_stmt,
|
symbol.return_stmt,
|
||||||
symbol.raise_stmt,
|
symbol.raise_stmt,
|
||||||
|
symbol.yield_stmt,
|
||||||
symbol.import_stmt,
|
symbol.import_stmt,
|
||||||
symbol.global_stmt,
|
symbol.global_stmt,
|
||||||
symbol.exec_stmt,
|
symbol.exec_stmt,
|
||||||
|
|
|
@ -153,8 +153,12 @@ class Transformer:
|
||||||
|
|
||||||
def file_input(self, nodelist):
|
def file_input(self, nodelist):
|
||||||
doc = self.get_docstring(nodelist, symbol.file_input)
|
doc = self.get_docstring(nodelist, symbol.file_input)
|
||||||
|
if doc is not None:
|
||||||
|
i = 1
|
||||||
|
else:
|
||||||
|
i = 0
|
||||||
stmts = []
|
stmts = []
|
||||||
for node in nodelist:
|
for node in nodelist[i:]:
|
||||||
if node[0] != token.ENDMARKER and node[0] != token.NEWLINE:
|
if node[0] != token.ENDMARKER and node[0] != token.NEWLINE:
|
||||||
self.com_append_stmt(stmts, node)
|
self.com_append_stmt(stmts, node)
|
||||||
return Module(doc, Stmt(stmts))
|
return Module(doc, Stmt(stmts))
|
||||||
|
@ -340,6 +344,11 @@ class Transformer:
|
||||||
n.lineno = nodelist[0][2]
|
n.lineno = nodelist[0][2]
|
||||||
return n
|
return n
|
||||||
|
|
||||||
|
def yield_stmt(self, nodelist):
|
||||||
|
n = Yield(self.com_node(nodelist[1]))
|
||||||
|
n.lineno = nodelist[0][2]
|
||||||
|
return n
|
||||||
|
|
||||||
def raise_stmt(self, nodelist):
|
def raise_stmt(self, nodelist):
|
||||||
# raise: [test [',' test [',' test]]]
|
# raise: [test [',' test [',' test]]]
|
||||||
if len(nodelist) > 5:
|
if len(nodelist) > 5:
|
||||||
|
@ -1245,6 +1254,7 @@ _legal_node_types = [
|
||||||
symbol.continue_stmt,
|
symbol.continue_stmt,
|
||||||
symbol.return_stmt,
|
symbol.return_stmt,
|
||||||
symbol.raise_stmt,
|
symbol.raise_stmt,
|
||||||
|
symbol.yield_stmt,
|
||||||
symbol.import_stmt,
|
symbol.import_stmt,
|
||||||
symbol.global_stmt,
|
symbol.global_stmt,
|
||||||
symbol.exec_stmt,
|
symbol.exec_stmt,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue