Ejemplo n.º 1
0
from prestring.go import Module

m = Module()
m.package('main')
with m.import_group() as im:
    pass

with m.func('main'):
    im.import_('log')
    m.stmt('log.Println("hmm")')

print(m)
Ejemplo n.º 2
0
from prestring.go import Module

m = Module()
m.package("main")

with m.import_group() as im:
    im.import_("fmt")

with m.func("main"):
    m.stmt("fmt.Println(`hello world`)")

print(m)
Ejemplo n.º 3
0
from prestring.go import Module
m = Module()
m.package('main')

with m.import_group() as im:
    im.import_("fmt")

with m.func('Fizzbuzz', 'v int', return_='(string, error)'):
    with m.if_("v == 1"):
        m.return_('"1", nil')
    for i in range(2, 101):
        with m.elif_("v == {}".format(i)):
            if i % 15 == 0:
                m.return_('"fizzbuzz", nil')
            elif i % 3 == 0:
                m.return_('"fizz", nil')
            elif i % 5 == 0:
                m.return_('"buzz", nil')
            else:
                m.return_('"{}", nil'.format(i))
    with m.else_():
        m.return_('"", fmt.Errorf("unsupported value: %q", v)')

print(m)