Python: селекторы (через точку .) выдаются на новой строке

Этот коммит содержится в:
Softonik 2022-12-11 01:04:59 +03:00 коммит произвёл Nikolay Kopitonenko
родитель 3fe7d47388
коммит 686ef65fd7
2 изменённых файлов: 39 добавлений и 12 удалений

Просмотреть файл

@ -48,7 +48,6 @@ func (s *defaultService) Start() error {
if s.out == nil { if s.out == nil {
return fmt.Errorf("Error: %s", ErrorWorkerWriterIsNil) return fmt.Errorf("Error: %s", ErrorWorkerWriterIsNil)
} }
ind = 0
main_func_declared = false main_func_declared = false
// Read tokens from file by using Go's parser. // Read tokens from file by using Go's parser.
fset := token.NewFileSet() fset := token.NewFileSet()
@ -71,6 +70,7 @@ func (s *defaultService) Start() error {
// Start a transpile with an individual channel for each declaration in the source file. // Start a transpile with an individual channel for each declaration in the source file.
go func() { go func() {
for i, decl := range file.Decls { for i, decl := range file.Decls {
ind = 0
handleDecl(i, decl, dst[i], done) handleDecl(i, decl, dst[i], done)
} }
}() }()
@ -112,6 +112,11 @@ func indSpaces() string {
} }
return res return res
} }
func indSpacesPlus() string {
increaseInd()
defer decreaseInd()
return indSpaces()
}
func handleAssignStmt(as *ast.AssignStmt) string { func handleAssignStmt(as *ast.AssignStmt) string {
code := handleAssignStmtExpr(as.Lhs) code := handleAssignStmtExpr(as.Lhs)
@ -488,7 +493,8 @@ func handleSelectorExpr(expr ast.Expr) string {
spew.Dump(s) spew.Dump(s)
code += "unknown handleSelectorExpr" code += "unknown handleSelectorExpr"
} }
code += "." code += ".\\\n"
code += indSpacesPlus()
code += handleIdent(s.Sel) code += handleIdent(s.Sel)
if val, ok := mapping[code]; ok { if val, ok := mapping[code]; ok {
code = val code = val

Просмотреть файл

@ -179,13 +179,23 @@ main()
import . "skidl" import . "skidl"
func main() { func main() {
a.b.c = 1 a.b.c.d.e = 1
x = a.b.c.d.e
} }
` `
expected := `from skidl import * expected := `from skidl import *
def main(): def main():
a.b.c = 1 a.\
b.\
c.\
d.\
e = 1
x = a.\
b.\
c.\
d.\
e
main() main()
` `
Compare(source, expected) Compare(source, expected)
@ -248,7 +258,11 @@ main()
expected := `from skidl import * expected := `from skidl import *
def main(): def main():
a.b().c(1).d(2).e(3) a.\
b().\
c(1).\
d(2).\
e(3)
main() main()
` `
Compare(source, expected) Compare(source, expected)
@ -476,10 +490,14 @@ main()
expected := `from skidl import * expected := `from skidl import *
def main(): def main():
vkl_iface.value = "k vkl" vkl_iface.\
vkl_iface.value = 19 value = "k vkl"
vkl_iface.value = 19 / 3 vkl_iface.\
vkl_iface.value = 19 * 2 value = 19
vkl_iface.\
value = 19 / 3
vkl_iface.\
value = 19 * 2
main() main()
` `
Compare(source, expected) Compare(source, expected)
@ -701,9 +719,12 @@ main()
@subcircuit @subcircuit
def mem_module(intfc): def mem_module(intfc):
ram = Part("Memory_RAM","AS6C1616") ram = Part("Memory_RAM","AS6C1616")
ram["A[0:19]"] += intfc.addr ram["A[0:19]"] += intfc.\
ram["DQ[0:15]"] += intfc.data addr
ram["WE#"] += intfc.wr ram["DQ[0:15]"] += intfc.\
data
ram["WE#"] += intfc.\
wr
ram["OE#"] += intfc["rd"] ram["OE#"] += intfc["rd"]
def main(): def main():
rd = Net("MEM_RD#") rd = Net("MEM_RD#")