コード例 #1
0
def run_file(fname):
    reader = FileReader(fname)
    try:
        print parse_skeleton(ReaderLexer(reader)).dump()
    except LexError as e:
        print e.dump()
    except ParseError as e:
        print e.dump()

    return 0
コード例 #2
0
ファイル: target.py プロジェクト: igalic/tulip
def run_file(fname):
    reader = FileReader(fname)
    try:
        print parse_skeleton(ReaderLexer(reader)).dump()
    except LexError as e:
        print u'lex error: %d:%d' % (e.lexer.line, e.lexer.col)
        print u'head: <%s>' % e.lexer.head
    except ParseError as e:
        print e.dump()

    return 0
コード例 #3
0
ファイル: target.py プロジェクト: igalic/tulip
def run_repl():
    print_logo()

    while True:
        try:
            line = readline(': ')
            print parse_skeleton(ReaderLexer(StringReader(u'<repl>', line))).dump()
        except LexError as e:
            print u'lex error: %d:%d' % (e.lexer.line, e.lexer.col)
            print u'head: <%s>' % e.lexer.head
        except ParseError as e:
            print e.dump()
        except EOFError:
            break

    return 0
コード例 #4
0
def run_repl():
    print_logo()

    lines = []
    last_unmatched = None

    while True:
        if last_unmatched is not None:
            prompt = '%s: ' % str(repl_char_map[last_unmatched.tokid])
        else:
            prompt = ' : '

        last_unmatched = None

        try:
            lines.append(readline(prompt))
            code = u'\n'.join(lines)
            ast = compile_base(parse_skeleton(ReaderLexer(StringReader(u'<repl>', code))))
            if ast is None:
                print u'(no input)'
                continue

            print ast.dump()
            try:
                MachineContext(with_prelude(ast)).runVerbose()
            except StandardError as e:
                traceback.print_exc()

            lines = []
        except UnmatchedError as e:
            last_unmatched = e.token
        except LexError as e:
            print e.dump()
        except ParseError as e:
            print e.dump()
        except CompileError as e:
            print e.dump()
        except EOFError:
            break
        # except StandardError as e:
        #     print e
        finally:
            if last_unmatched is None:
                lines = []

    return 0