Python: добавлена ф-ция append
Этот коммит содержится в:
родитель
433dde73b0
коммит
c9d3b90caa
2 изменённых файлов: 39 добавлений и 7 удалений
|
@ -160,14 +160,29 @@ func handleBinaryExpr(expr ast.Expr) string {
|
|||
}
|
||||
|
||||
func handleCallExpr(expr *ast.CallExpr) string {
|
||||
code := handleExpr(expr.Fun)
|
||||
code += "("
|
||||
args := make([]string, 0)
|
||||
for _, arg := range expr.Args {
|
||||
args = append(args, handleExpr(arg))
|
||||
func_name := handleExpr(expr.Fun)
|
||||
code := ""
|
||||
switch func_name {
|
||||
case "append":
|
||||
code = handleExpr(expr.Args[0])
|
||||
code += ".append("
|
||||
args := make([]string, 0)
|
||||
for _, arg := range expr.Args[1:] {
|
||||
args = append(args, handleExpr(arg))
|
||||
}
|
||||
code += strings.Join(args, ",")
|
||||
code += ")"
|
||||
return code
|
||||
default:
|
||||
code = func_name
|
||||
code += "("
|
||||
args := make([]string, 0)
|
||||
for _, arg := range expr.Args {
|
||||
args = append(args, handleExpr(arg))
|
||||
}
|
||||
code += strings.Join(args, ",")
|
||||
code += ")"
|
||||
}
|
||||
code += strings.Join(args, ",")
|
||||
code += ")"
|
||||
return code
|
||||
}
|
||||
|
||||
|
|
|
@ -117,6 +117,23 @@ main()
|
|||
Compare(source, expected)
|
||||
})
|
||||
|
||||
It("Array append", func() {
|
||||
source := `package test
|
||||
import "skidl"
|
||||
|
||||
func main() {
|
||||
append(a, 1)
|
||||
}
|
||||
`
|
||||
expected := `from skidl import *
|
||||
|
||||
def main():
|
||||
a.append(1)
|
||||
main()
|
||||
`
|
||||
Compare(source, expected)
|
||||
})
|
||||
|
||||
It("Function Declaration", func() {
|
||||
source := `package test
|
||||
import "skidl"
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче