PythonTreeMaker { public Argument argument(AstNode astNode) { AstNode compFor = astNode.getFirstChild(PythonGrammar.COMP_FOR); if (compFor != null) { Expression expression = expression(astNode.getFirstChild()); ComprehensionExpression comprehension = new ComprehensionExpressionImpl(Tree.Kind.GENERATOR_EXPR, null, expression, compFor(compFor), null); return new RegularArgumentImpl(comprehension); } AstNode walrusOperator = astNode.getFirstChild(PythonPunctuator.WALRUS_OPERATOR); if (walrusOperator != null) { AssignmentExpression assignmentExpression = (AssignmentExpression) assignmentExpression(astNode); return new RegularArgumentImpl(assignmentExpression); } AstNode assign = astNode.getFirstChild(PythonPunctuator.ASSIGN); Token star = astNode.getFirstChild(PythonPunctuator.MUL) == null ? null : toPyToken(astNode.getFirstChild(PythonPunctuator.MUL).getToken()); if (star == null) { star = astNode.getFirstChild(PythonPunctuator.MUL_MUL) == null ? null : toPyToken(astNode.getFirstChild(PythonPunctuator.MUL_MUL).getToken()); } Expression arg = expression(astNode.getLastChild(PythonGrammar.TEST)); if (assign != null) { AstNode nameNode = astNode.getFirstChild(PythonGrammar.TEST).getFirstChild(PythonGrammar.ATOM).getFirstChild(PythonGrammar.NAME); return new RegularArgumentImpl(name(nameNode), toPyToken(assign.getToken()), arg); } return star == null ? new RegularArgumentImpl(arg) : new UnpackingExpressionImpl(star, arg); }  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 argument() { setRootRule(PythonGrammar.ARGUMENT); RegularArgument argumentTree = (RegularArgument) parse("foo", treeMaker::argument); assertThat(argumentTree.equalToken()).isNull(); assertThat(argumentTree.keywordArgument()).isNull(); Name name = (Name) argumentTree.expression(); assertThat(name.name()).isEqualTo("foo"); assertThat(argumentTree.children()).hasSize(1); UnpackingExpression iterableUnpacking = (UnpackingExpression) parse("*foo", treeMaker::argument); name = (Name) iterableUnpacking.expression(); assertThat(name.name()).isEqualTo("foo"); assertThat(iterableUnpacking.children()).hasSize(2); UnpackingExpression dictionaryUnpacking = (UnpackingExpression) parse("**foo", treeMaker::argument); name = (Name) dictionaryUnpacking.expression(); assertThat(name.name()).isEqualTo("foo"); assertThat(dictionaryUnpacking.starToken()).isNotNull(); assertThat(dictionaryUnpacking.children()).hasSize(2); argumentTree = (RegularArgument) parse("bar=foo", treeMaker::argument); assertThat(argumentTree.equalToken()).isNotNull(); Name keywordArgument = argumentTree.keywordArgument(); assertThat(keywordArgument.name()).isEqualTo("bar"); name = (Name) argumentTree.expression(); assertThat(name.name()).isEqualTo("foo"); assertThat(argumentTree.children()).hasSize(3).containsExactly(argumentTree.keywordArgument(), argumentTree.equalToken(), argumentTree.expression()); }