Exemple #1
0
def source(value):
    from yalix.utils import highlight_syntax
    from yalix.source_view import source_view
    src = source_view(value)
    if src:
        print('-----------------')
        print(highlight_syntax(source_view(value)))
Exemple #2
0
def source(value):
    from yalix.utils import highlight_syntax
    from yalix.source_view import source_view
    src = source_view(value)
    if src:
        print('-----------------')
        print(highlight_syntax(source_view(value)))
Exemple #3
0
 def test_syntax_highligher(self):
     import hashlib
     sample_code = "(define (identity x) x)"
     output = utils.highlight_syntax(sample_code)
     if output != sample_code:
         # Pygments in action
         m = hashlib.sha224(output.encode('utf-8'))
         self.assertEquals('7ec4fce8a935c23538e701e1da3dfc6ce124ee5555cd90e7b5cd877e', m.hexdigest())
Exemple #4
0
def repl(inprompt=stdin_read, outprompt=stdout_prn):

    try:
        env = create_initial_env()
    except EvaluationError as ex:
        log("{0}: {1}", red(type(ex).__name__, style='bold'), ex)
        log(highlight_syntax(source_view(ex.primitive)))
        sys.exit()

    env['copyright'] = left_margin(copyright())
    env['license'] = left_margin(license())
    env['help'] = left_margin(help())
    env['credits'] = left_margin(credits())

    init_readline(env)
    ready()

    parser = scheme_parser()
    count = 1
    while True:
        try:
            text = next(inprompt(count))
            for ast in parser.parseString(text, parseAll=True).asList():
                result = ast.eval(env)
                # Evaluate lazy list representations
                result = Repr(result).eval(env)
                outprompt(result, count)

            if text.strip() != '':
                print('')

        except EOFError:
            log(blue('\nBye!', style='bold'))
            break

        except KeyboardInterrupt:
            log(red('\nKeyboardInterrupt', style='bold'))

        except EvaluationError as ex:
            log("{0}: {1}", red(type(ex).__name__, style='bold'), ex)
            log(highlight_syntax(source_view(ex.primitive)))

        except ParseException as ex:
            log("{0}: {1}", red(type(ex).__name__, style='bold'), ex)

        count += 1
Exemple #5
0
 def test_syntax_highligher(self):
     import hashlib
     sample_code = "(define (identity x) x)"
     output = utils.highlight_syntax(sample_code)
     if output != sample_code:
         # Pygments in action
         m = hashlib.sha224(output.encode('utf-8'))
         self.assertEquals('505d8372212855be0fc387e2367b1a82ff322e2dcdf07a7a83ebc8f6', m.hexdigest())
Exemple #6
0
 def test_syntax_highligher(self):
     import hashlib
     sample_code = "(define (identity x) x)"
     output = utils.highlight_syntax(sample_code)
     if output != sample_code:
         # Pygments in action
         m = hashlib.sha224(output.encode('utf-8'))
         self.assertEquals(
             '505d8372212855be0fc387e2367b1a82ff322e2dcdf07a7a83ebc8f6',
             m.hexdigest())