Добавлен цикл с range
Этот коммит содержится в:
родитель
153c00d0c5
коммит
25a5993b52
2 изменённых файлов: 35 добавлений и 1 удалений
|
@ -497,6 +497,8 @@ func handleStmt(stmt ast.Stmt, standaloneAssignment bool) string {
|
||||||
code += handleExprStmt(s)
|
code += handleExprStmt(s)
|
||||||
case *ast.ForStmt:
|
case *ast.ForStmt:
|
||||||
code += handleForStmt(s)
|
code += handleForStmt(s)
|
||||||
|
case *ast.RangeStmt:
|
||||||
|
code += handleRangeStmt(s)
|
||||||
case *ast.IfStmt:
|
case *ast.IfStmt:
|
||||||
code += handleIfStmt(s)
|
code += handleIfStmt(s)
|
||||||
case *ast.SwitchStmt:
|
case *ast.SwitchStmt:
|
||||||
|
@ -535,6 +537,18 @@ func handleForStmt(stmt *ast.ForStmt) string {
|
||||||
return code
|
return code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleRangeStmt(stmt *ast.RangeStmt) string {
|
||||||
|
code := "for "
|
||||||
|
code += handleIdent(stmt.Key)
|
||||||
|
code += " in "
|
||||||
|
code += handleExpr(stmt.X)
|
||||||
|
code += ":\n"
|
||||||
|
increaseInd()
|
||||||
|
code += handleBlockStmt(stmt.Body)
|
||||||
|
decreaseInd()
|
||||||
|
return code
|
||||||
|
}
|
||||||
|
|
||||||
func handleSwitchStmt(stmt *ast.SwitchStmt) string {
|
func handleSwitchStmt(stmt *ast.SwitchStmt) string {
|
||||||
code := "switch ("
|
code := "switch ("
|
||||||
code += handleExpr(stmt.Tag)
|
code += handleExpr(stmt.Tag)
|
||||||
|
|
|
@ -52,7 +52,7 @@ main()
|
||||||
Compare(source, expected)
|
Compare(source, expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
FIt("Variables declaration", func() {
|
It("Variables declaration", func() {
|
||||||
source := `package test
|
source := `package test
|
||||||
import "skidl"
|
import "skidl"
|
||||||
|
|
||||||
|
@ -403,6 +403,26 @@ main()
|
||||||
Compare(source, expected)
|
Compare(source, expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("For with range", func() {
|
||||||
|
source := `package test
|
||||||
|
import "skidl"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
for v := range list {
|
||||||
|
call(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
expected := `from skidl import *
|
||||||
|
|
||||||
|
def main():
|
||||||
|
for v in list:
|
||||||
|
call(v)
|
||||||
|
main()
|
||||||
|
`
|
||||||
|
Compare(source, expected)
|
||||||
|
})
|
||||||
|
|
||||||
It("Function decl/call", func() {
|
It("Function decl/call", func() {
|
||||||
source := `package test
|
source := `package test
|
||||||
import "skidl"
|
import "skidl"
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче