kaist-plrg / python-analyzer

Python analysis framework in Scala
2 stars 0 forks source link

[Beautify] 일부 Stmt 출력 시 newline 생략 #5

Closed yusungsim closed 3 years ago

yusungsim commented 3 years ago

Problem

Test count: 1

Source Text:

import tensor as np

def someFunction(arg):
    print(arg)
    print("hello" + "world")
    print("""asdfasdf""")
    return 42

x = {a : 1}

y = 1
y *= 3
y += 3
z = [1,2,3].merge()
"""hello"""

tokenized result:

import id(tensor) as id(np) \NL
 def id(someFunction) ( id(arg) ) : \NL
 INDENT id(print) ( id(arg) ) \NL
 id(print) ( "hello" + "world" ) \NL
 id(print) ( "asdfasdf" ) \NL
 return 42 \NL
 DEDENT id(x) = { id(a) : 1 } \NL
 id(y) = 1 \NL
 id(y) *= 3 \NL
 id(y) += 3 \NL
 id(z) = [ 1 , 2 , 3 ] . id(merge) ( ) \NL
 "hello" \NL

First ast:

List(ImportStmt(List(Alias(List(Id(tensor)),Some(Id(np))))), FunDef(List(),Id(someFunction),Args(List(),List((Arg(Id(arg),None,None),None)),None,List(),None),None,None,List(ExprStmt(Call(EName(Id(print)),List(EName(Id(arg))),List())), ExprStmt(Call(EName(Id(print)),List(BinaryExpr(OAdd,EConst(StringLiteral(hello)),EConst(StringLiteral(world)))),List())), ExprStmt(Call(EName(Id(print)),List(EConst(StringLiteral(asdfasdf))),List())), ReturnStmt(Some(EConst(IntLiteral(42)))))), AssignStmt(List(EName(Id(x))),DictExpr(List((EName(Id(a)),EConst(IntLiteral(1)))),List()),None), AssignStmt(List(EName(Id(y))),EConst(IntLiteral(1)),None), AugAssign(EName(Id(y)),OMul,EConst(IntLiteral(3))), AugAssign(EName(Id(y)),OAdd,EConst(IntLiteral(3))), AssignStmt(List(EName(Id(z))),Call(Attribute(ListExpr(List(EConst(IntLiteral(1)), EConst(IntLiteral(2)), EConst(IntLiteral(3)))),EName(Id(merge))),List(),List()),None), ExprStmt(EConst(StringLiteral(hello))))

Beautified as:

import tensor as npdef someFunction(arg, ):
  print(arg, )
  print("hello" + "world", )
  print("asdfasdf", )
  return 42
x = {a: 1, } y = 1 y *= 3y += 3z = [1, 2, 3].merge() "hello"