From d54d93ef2f480bc7609bd35afce9f76dd1ef2b1a Mon Sep 17 00:00:00 2001 From: Kevin Date: Sun, 10 May 2020 12:42:22 -0400 Subject: [PATCH] Initial support for if blocks This currently only supports tests which are a simple condition and do not span multiple sides of a comparison. --- new_parser.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/new_parser.py b/new_parser.py index 56a7fe44..3bfedb36 100644 --- a/new_parser.py +++ b/new_parser.py @@ -45,6 +45,9 @@ def parse_block_pair(ast): if block_name == 'for': return parse_block_for(ast) + if block_name == 'if': + return parse_block_if(ast) + if block_name == 'with': return parse_block_with(ast) @@ -100,6 +103,20 @@ def parse_block_from(ast): return from_import +def parse_block_if(ast): + test = parse_conditional_expression(ast['start']['parameters'][0]['value']) + body = parse(ast['contents']) + elif_ = None + else_ = None + + return nodes.If( + test, + body, + elif_, + else_, + lineno=lineno_from_parseinfo(ast['parseinfo']) + ) + def parse_block_with(ast): with_node = nodes.With( lineno=lineno_from_parseinfo(ast['parseinfo']) @@ -122,6 +139,12 @@ def parse_block_with(ast): return with_node def parse_comment(ast): + return + +def parse_conditional_expression(ast): + if 'variable' in ast: + return parse_variable(ast) + return None def parse_literal(ast): -- 2.47.3