コード例 #1
0
def test_bad_input(bad_input, diag):
    code, desc = bad_input

    token_stream = tokenize(code)
    parser = Parser(token_stream, diag)
    parse_method = getattr(parser, desc['hook'])

    with pytest.raises(DumbSyntaxError):
        parse_method()
コード例 #2
0
def test_eof_handling(diag):
    code = ''
    token_stream = tokenize(code)
    parser = Parser(token_stream, diag)

    # Current token is EOF, so the next advance() method call
    # should cause an error.
    with pytest.raises(DumbEOFError):
        parser.advance()
コード例 #3
0
def test_output_ast(good_input, diag):
    code, desc = good_input
    token_stream = tokenize(code)
    parser = Parser(token_stream, diag)
    parse_method = getattr(parser, desc['hook'])

    ast = parse_method()

    if 'root' in desc:
        tree_desc = desc['root']
        verify_tree(ast, tree_desc)
    else:
        forest_desc = desc['forest']
        verify_forest(ast, forest_desc)
コード例 #4
0
def get_loc_list(code):
    tokens = tokenize(code)
    t1, t2 = itertools.tee(tokens, 2)
    loc = extract_field(t1, 'loc')
    return list(loc)
コード例 #5
0
def get_kind_list(code):
    tokens = tokenize(code)
    return list(extract_field(tokens, 'kind'))