PythonTreeMaker { private ExpressionList expressionList(AstNode astNode) { if (astNode.is(PythonGrammar.TESTLIST_STAR_EXPR, PythonGrammar.TESTLIST_COMP)) { List<Expression> expressions = astNode.getChildren(PythonGrammar.NAMED_EXPR_TEST, PythonGrammar.TEST, PythonGrammar.STAR_EXPR).stream() .map(this::expression) .collect(Collectors.toList()); List<Token> commas = punctuators(astNode, PythonPunctuator.COMMA); return new ExpressionListImpl(expressions, commas); } return new ExpressionListImpl(Collections.singletonList(expression(astNode)), Collections.emptyList()); }  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 repr_expression() { setRootRule(PythonGrammar.ATOM); ReprExpression reprExpressionTree = (ReprExpression) parse("`1`", treeMaker::expression); assertThat(reprExpressionTree.getKind()).isEqualTo(Tree.Kind.REPR); assertThat(reprExpressionTree.firstToken().value()).isEqualTo("`"); assertThat(reprExpressionTree.lastToken().value()).isEqualTo("`"); assertThat(reprExpressionTree.openingBacktick().value()).isEqualTo("`"); assertThat(reprExpressionTree.closingBacktick().value()).isEqualTo("`"); assertThat(reprExpressionTree.expressionList().expressions()).hasSize(1); assertThat(reprExpressionTree.expressionList().expressions().get(0).getKind()).isEqualTo(Tree.Kind.NUMERIC_LITERAL); assertThat(reprExpressionTree.children()).hasSize(3); reprExpressionTree = (ReprExpression) parse("`x, y`", treeMaker::expression); assertThat(reprExpressionTree.getKind()).isEqualTo(Tree.Kind.REPR); assertThat(reprExpressionTree.expressionList().expressions()).hasSize(2); assertThat(reprExpressionTree.expressionList().children()).hasSize(3); assertThat(reprExpressionTree.expressionList().commas()).hasSize(1); assertThat(reprExpressionTree.expressionList().commas().get(0)).isSameAs(reprExpressionTree.expressionList().children().get(1)); assertThat(reprExpressionTree.expressionList().expressions().get(0).getKind()).isEqualTo(Tree.Kind.NAME); assertThat(reprExpressionTree.expressionList().expressions().get(1).getKind()).isEqualTo(Tree.Kind.NAME); }