PythonTreeMaker { public AssignmentStatement assignment(StatementWithSeparator statementWithSeparator) { AstNode astNode = statementWithSeparator.statement(); Separators separators = statementWithSeparator.separator(); List<Token> assignTokens = new ArrayList<>(); List<ExpressionList> lhsExpressions = new ArrayList<>(); List<AstNode> assignNodes = astNode.getChildren(PythonPunctuator.ASSIGN); for (AstNode assignNode : assignNodes) { assignTokens.add(toPyToken(assignNode.getToken())); lhsExpressions.add(expressionList(assignNode.getPreviousSibling())); } AstNode assignedValueNode = assignNodes.get(assignNodes.size() - 1).getNextSibling(); Expression assignedValue = assignedValueNode.is(PythonGrammar.YIELD_EXPR) ? yieldExpression(assignedValueNode) : exprListOrTestList(assignedValueNode); return new AssignmentStatementImpl(assignTokens, lhsExpressions, assignedValue, separators); }  FileInput fileInput(AstNode astNode); void setParents(Tree root); AnnotatedAssignment annotatedAssignment(StatementWithSeparator statementWithSeparator); PrintStatement printStatement(StatementWithSeparator statementWithSeparator); ExecStatement execStatement(StatementWithSeparator statementWithSeparator); AssertStatement assertStatement(StatementWithSeparator statementWithSeparator); PassStatement passStatement(StatementWithSeparator statementWithSeparator); DelStatement delStatement(StatementWithSeparator statementWithSeparator); ReturnStatement returnStatement(StatementWithSeparator statementWithSeparator); YieldStatement yieldStatement(StatementWithSeparator statementWithSeparator); YieldExpression yieldExpression(AstNode astNode); RaiseStatement raiseStatement(StatementWithSeparator statementWithSeparator); BreakStatement breakStatement(StatementWithSeparator statementWithSeparator); ContinueStatement continueStatement(StatementWithSeparator statementWithSeparator); ImportStatement importStatement(StatementWithSeparator statementWithSeparator); GlobalStatement globalStatement(StatementWithSeparator statementWithSeparator); NonlocalStatement nonlocalStatement(StatementWithSeparator statementWithSeparator); IfStatement ifStatement(AstNode astNode); FunctionDef funcDefStatement(AstNode astNode); ClassDef classDefStatement(AstNode astNode); ForStatement forStatement(AstNode astNode); WhileStatementImpl whileStatement(AstNode astNode); ExpressionStatement expressionStatement(StatementWithSeparator statementWithSeparator); AssignmentStatement assignment(StatementWithSeparator statementWithSeparator); CompoundAssignmentStatement compoundAssignment(StatementWithSeparator statementWithSeparator); TryStatement tryStatement(AstNode astNode); WithStatement withStatement(AstNode astNode); Expression expression(AstNode astNode); Argument argument(AstNode astNode); LambdaExpression lambdaExpression(AstNode astNode);  }
@Test public void tuples() { Tuple empty = parseTuple("()"); assertThat(empty.getKind()).isEqualTo(Tree.Kind.TUPLE); assertThat(empty.firstToken().value()).isEqualTo("("); assertThat(empty.lastToken().value()).isEqualTo(")"); assertThat(empty.elements()).isEmpty(); assertThat(empty.commas()).isEmpty(); assertThat(empty.leftParenthesis().value()).isEqualTo("("); assertThat(empty.rightParenthesis().value()).isEqualTo(")"); assertThat(empty.children()).hasSize(2); Tuple singleValue = parseTuple("(a,)"); assertThat(singleValue.firstToken().value()).isEqualTo("("); assertThat(singleValue.lastToken().value()).isEqualTo(")"); assertThat(singleValue.elements()).extracting(Tree::getKind).containsExactly(Tree.Kind.NAME); assertThat(singleValue.commas()).extracting(Token::value).containsExactly(","); assertThat(singleValue.children()).hasSize(4); Tuple tuple = parseTuple("(a,b)"); assertThat(tuple.firstToken().value()).isEqualTo("("); assertThat(tuple.lastToken().value()).isEqualTo(")"); assertThat(tuple.elements()).hasSize(2); assertThat(tuple.children()).hasSize(5); assertThat(tuple.children()).containsExactly(tuple.leftParenthesis(), tuple.elements().get(0), tuple.commas().get(0), tuple.elements().get(1), tuple.rightParenthesis()); setRootRule(PythonGrammar.EXPRESSION_STMT); AstNode astNode = p.parse("x = a,b"); StatementWithSeparator statementWithSeparator = new StatementWithSeparator(astNode, null); AssignmentStatement assignementstatement = treeMaker.assignment(statementWithSeparator); assertThat(assignementstatement.assignedValue().getKind()).isEqualTo(Tree.Kind.TUPLE); Tuple assignedTuple = (Tuple) assignementstatement.assignedValue(); assertThat(assignedTuple.leftParenthesis()).isNull(); assertThat(assignedTuple.rightParenthesis()).isNull(); assertThat(assignedTuple.children()).doesNotContainNull(); }