scripts/hapy_cli.py
def repl(ctx, english):
    """the Hapy REPL (interactive programming environment)"""

    prompt = f"hapy>"

    lcls = {"sys": sys, "__name__": "__repl__"}
    runner = InteractiveConsole(locals=lcls)

    # join all the arguments
    all_args = " ".join(ctx.args)
    # only match arguments ending in '.hapy' for now
    # thank you Jesus!
    matched = re.findall(r'([a-zA-Z\./]*\.hapy)', all_args)
    # actually, loop through the args and find all applicable arguments/options
    if len(list(matched)) > 0:
        filename = ""
        compile_only = False
        save = False
        for a in ctx.args:
            if a.endswith(".hapy"):
                filename = a
            elif a == "-c" or a == "--compile-only":
                compile_only = True
            elif a == "-s" or a == "--save":
                save = True

        ctx.invoke(run,
                   filename=filename,
                   compile_only=compile_only,
                   save=save)
        return

    click.secho("Welcome to the Hapy REPL!", fg="green")

    if (english):
        # tell Hapy compiler that it should listen for English vocabulary
        # one way to do that is to change the ENV_VAR
        os.environ["HAPY_LANG"] = "eng"
        click.secho("-- Language is ENGLISH --")
    else:
        os.environ["HAPY_LANG"] = "hausa"
        # TODO: write this is HAUSA
        click.secho("-- Language is HAUSA --")

    click.echo(
        "\nType a command and just dey go!\nUse exit() or Ctrl+C to close")
    click.secho("\n- Type 'show modules' to list all modules you can use.\n",
                fg="blue")

    try:
        while True:
            try:
                _in = input(f'{prompt} ')
                # check for REPL commands...
                # How do we support block statements?
                # check if the last character is { then
                # ask for more input...
                try:
                    result = False
                    code = _in
                    open_brackets = 0
                    closing_brackets = 0

                    if code.endswith("{"):
                        # do procedure
                        # get the line, ask for more input
                        # when the number of open brackets
                        # equal the number of closing,
                        # then finish loop and return
                        # code += _in
                        code += "\n"  # add this to make it if cond {\n
                        open_brackets += 1
                        # closing_brackets = 0

                        while open_brackets != closing_brackets:
                            in_2 = input("... ")
                            # TODO: find a better way of checking if line ends in
                            # "}" or "};"

                            if "{" in in_2 or "}" in in_2:
                                code += "\n"
                                closing_brackets += in_2.count("}")
                                open_brackets += in_2.count("{")

                            code += in_2

                            # check if code ends in 2 \n line brakes

                        result = False
                    result = check_commands(code)
                    # print('code => ', repr(code))

                    if not result:
                        code_2_run = transpile(code)

                        runner.push(code_2_run)
                except Exception as e:
                    # NOTE: I'm not sure if this is still useful...

                    # I stopped using eval/exec because of scope and shii
                    # the variables I defined were not staying
                    print(e)

                    # code_2_run = transpile(code)
                    # # print(code)
                    # # exec(code_2_run)
                    # runner.runcode(code_2_run)
                    # # if out is not None:
                    # #     click.echo(out)
            except Exception as e:
                click.echo(f"Error: {e}")
    except KeyboardInterrupt as e:
        click.echo('\nBye! Exiting Hapy...')
the Hapy REPL (interactive programming environment)
the Hapy REPL (interactive programming environment)
the Hapy REPL ( interactive programming environment )
def repl(ctx, english):
    prompt = f"hapy>"
    lcls = {"sys": sys, "__name__": "__repl__"}
    runner = InteractiveConsole(locals=lcls)
    all_args = " ".join(ctx.args)
    matched = re.findall(r'([a-zA-Z\./]*\.hapy)', all_args)
    if len(list(matched)) > 0:
        filename = ""
        compile_only = False
        save = False
        for a in ctx.args:
            if a.endswith(".hapy"):
                filename = a
            elif a == "-c" or a == "--compile-only":
                compile_only = True
            elif a == "-s" or a == "--save":
                save = True
        ctx.invoke(run,
                   filename=filename,
                   compile_only=compile_only,
                   save=save)
        return
    click.secho("Welcome to the Hapy REPL!", fg="green")
    if (english):
        os.environ["HAPY_LANG"] = "eng"
        click.secho("-- Language is ENGLISH --")
    else:
        os.environ["HAPY_LANG"] = "hausa"
        click.secho("-- Language is HAUSA --")
    click.echo(
        "\nType a command and just dey go!\nUse exit() or Ctrl+C to close")
    click.secho("\n- Type 'show modules' to list all modules you can use.\n",
                fg="blue")
    try:
        while True:
            try:
                _in = input(f'{prompt} ')
                try:
                    result = False
                    code = _in
                    open_brackets = 0
                    closing_brackets = 0
                    if code.endswith("{"):
                        code += "\n"  
                        open_brackets += 1
                        while open_brackets != closing_brackets:
                            in_2 = input("... ")
                            if "{" in in_2 or "}" in in_2:
                                code += "\n"
                                closing_brackets += in_2.count("}")
                                open_brackets += in_2.count("{")
                            code += in_2
                        result = False
                    result = check_commands(code)
                    if not result:
                        code_2_run = transpile(code)
                        runner.push(code_2_run)
                except Exception as e:
                    print(e)
            except Exception as e:
                click.echo(f"Error: {e}")
    except KeyboardInterrupt as e:
        click.echo('\nBye! Exiting Hapy...')
def repl ( ctx , english ) : prompt = f"hapy>" lcls = { "sys" : sys , "__name__" : "__repl__" } runner = InteractiveConsole ( locals = lcls ) all_args = " " . join ( ctx . args ) matched = re . findall ( r'([a-zA-Z\./]*\.hapy)' , all_args ) if len ( list ( matched ) ) > 0 : filename = "" compile_only = False save = False for a in ctx . args : if a . endswith ( ".hapy" ) : filename = a elif a == "-c" or a == "--compile-only" : compile_only = True elif a == "-s" or a == "--save" : save = True ctx . invoke ( run , filename = filename , compile_only = compile_only , save = save ) return click . secho ( "Welcome to the Hapy REPL!" , fg = "green" ) if ( english ) : os . environ [ "HAPY_LANG" ] = "eng" click . secho ( "-- Language is ENGLISH --" ) else : os . environ [ "HAPY_LANG" ] = "hausa" click . secho ( "-- Language is HAUSA --" ) click . echo ( "\nType a command and just dey go!\nUse exit() or Ctrl+C to close" ) click . secho ( "\n- Type 'show modules' to list all modules you can use.\n" , fg = "blue" ) try : while True : try : _in = input ( f'{prompt} ' ) try : result = False code = _in open_brackets = 0 closing_brackets = 0 if code . endswith ( "{" ) : code += "\n" open_brackets += 1 while open_brackets != closing_brackets : in_2 = input ( "... " ) if "{" in in_2 or "}" in in_2 : code += "\n" closing_brackets += in_2 . count ( "}" ) open_brackets += in_2 . count ( "{" ) code += in_2 result = False result = check_commands ( code ) if not result : code_2_run = transpile ( code ) runner . push ( code_2_run ) except Exception as e : print ( e ) except Exception as e : click . echo ( f"Error: {e}" ) except KeyboardInterrupt as e : click . echo ( '\nBye! Exiting Hapy...' )
the Hapy REPL (interactive programming environment)
the Hapy REPL ( interactive programming environment )
"""the Hapy REPL (interactive programming environment)""" # join all the arguments # only match arguments ending in '.hapy' for now # thank you Jesus! # actually, loop through the args and find all applicable arguments/options # tell Hapy compiler that it should listen for English vocabulary # one way to do that is to change the ENV_VAR # TODO: write this is HAUSA # check for REPL commands... # How do we support block statements? # check if the last character is { then # ask for more input... # do procedure # get the line, ask for more input # when the number of open brackets # equal the number of closing, # then finish loop and return # code += _in # add this to make it if cond {\n # closing_brackets = 0 # TODO: find a better way of checking if line ends in # "}" or "};" # check if code ends in 2 \n line brakes # print('code => ', repr(code)) # NOTE: I'm not sure if this is still useful... # I stopped using eval/exec because of scope and shii # the variables I defined were not staying # code_2_run = transpile(code) # # print(code) # # exec(code_2_run) # runner.runcode(code_2_run) # # if out is not None: # #     click.echo(out)
ctx
english