예제 #1
0
 def runner(self, cmd, mode, out):
     import pytuga
     import tugalib
     tuganames = {k: getattr(tugalib, k) for k in dir(tugalib)}
     self.console_namespace = {**tuganames, **self.console_namespace}
     pycmd = pytuga.transpile(cmd)
     self.runner_(pycmd, mode, out)
예제 #2
0
def main():
    """Executes the main pytuga program in the console."""

    if len(sys.argv) <= 1:
        return start_interactive()

    # Process arguments
    parser = argparse.ArgumentParser(description='Executa código Pytuguês')
    parser.add_argument(
        'arquivo', help='nome do arquivo a ser executado')
    parser.add_argument(
        '--mostre-python', '-P',
        help='mostra conversão do arquivo para Python na tela',
        action='store_const', const=True)
    parser.add_argument(
        '--python', '-p',
        metavar='ARQUIVO',
        help='salva conversão para Python no caminho especificado')
    parser.add_argument(
        '--versão', '-v',
        help='mostra a versão do interpretador de pytuguês',
        action='version', version='Pytuga %s' % version)
    # parser.add_argument('--warning', '-w', action='store_const',
    #                   help='ativa avisos de compatibilidade com o python')
    args = parser.parse_args()

    # Process errors
    if os.path.splitext(args.arquivo)[1] != '.pytg':
        print('Aviso: Pytuga deve processar apenas arquivos .pytg!')
    if not os.path.exists(args.arquivo):
        raise SystemExit('O arquivo %s não existe!' % args.arquivo)

    # Process file
    if args.mostre_python:
        with open(args.arquivo) as F:
            print(transpile(F.read()))
    elif args.python:
        with open(args.arquivo) as source:
            with open(args.python, 'w') as dest:
                dest.write(transpile(source.read()))
    else:
        with open(args.arquivo) as F:
            console = PyTugaConsole(filename=args.arquivo)
            console.runcode(F.read())
예제 #3
0
def pytg(src):
    return [repr(x) for x in tokenize(transpile(src))]
예제 #4
0
def test_transpile():
    py = transpile('enquanto verdadeiro ou falso: prosseguir')
    assert py == 'while True or False: pass'
예제 #5
0
def to_python(src):
    """
    Convert script from pytugues to python.
    """

    return 'from pytuga.lib import *\n' + transpile(src)
예제 #6
0
 def build(self):
     super().build()
     self.is_built = False
     self.transpiled = pytuga.transpile(self.source)
     self.is_built = True
예제 #7
0
 def ev(self, cmd):
     return super().ev(pytuga.transpile(cmd))
예제 #8
0
 def do_is_complete(self, code):
     return super().do_is_complete(pytuga.transpile(code))