<s> """<STR_LIT>""" <EOL> import py <EOL> from pypy . rlib . parsing . lexer import Lexer , SourcePos , Token <EOL> from pypy . rlib . parsing . deterministic import LexerError <EOL> from pypy . rlib . parsing . tree import Nonterminal , Symbol , RPythonVisitor <EOL> from pypy . rlib . parsing . parsing import PackratParser , Symbol , ParseError , Rule <EOL> from pypy . rlib . parsing . ebnfparse import parse_ebnf , make_parse_function <EOL> grammar = py . magic . autopath ( ) . dirpath ( ) . join ( "<STR_LIT>" ) . read ( mode = '<STR_LIT>' ) <EOL> def test_parse_grammar ( ) : <EOL> _ , rules , ToAST = parse_ebnf ( grammar ) <EOL> def test_parse_python_args ( ) : <EOL> regexs , rules , ToAST = parse_ebnf ( """<STR_LIT>""" ) <EOL> parse = make_parse_function ( regexs , rules ) <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> def test_parse_funcdef ( ) : <EOL> regexs , rules , ToAST = parse_ebnf ( """<STR_LIT>""" ) <EOL> parse = make_parse_function ( regexs , rules ) <EOL> t = parse ( "<STR_LIT>" ) . visit ( ToAST ( ) ) [ <NUM_LIT:0> ] <EOL> class TestParser ( object ) : <EOL> def setup_class ( cls ) : <EOL> from pypy . rlib . parsing . parsing import PackratParser <EOL> regexs , rules , ToAST = parse_ebnf ( grammar ) <EOL> cls . ToAST = ToAST ( ) <EOL> cls . parser = PackratParser ( rules , rules [ <NUM_LIT:0> ] . nonterminal ) <EOL> cls . regexs = regexs <EOL> names , regexs = zip ( * regexs ) <EOL> cls . lexer = Lexer ( list ( regexs ) , list ( names ) ) <EOL> def parse ( self , source ) : <EOL> tokens = list ( self . tokenize ( source ) ) <EOL> s = self . parser . parse ( tokens ) <EOL> return s <EOL> def tokenize ( self , source ) : <EOL> import tokenize , cStringIO <EOL> pos = <NUM_LIT:0> <EOL> readline = cStringIO . StringIO ( source ) . readline <EOL> for token in tokenize . generate_tokens ( readline ) : <EOL> typ , s , ( row , col ) , _ , line = token <EOL> row -= <NUM_LIT:1> <EOL> pos += len ( s ) <EOL> typ = tokenize . tok_name [ typ ] <EOL> if typ == "<STR_LIT>" : <EOL> typ = s = "<STR_LIT>" <EOL> elif typ == "<STR_LIT>" : <EOL> continue <EOL> elif typ == "<STR_LIT>" : <EOL> continue <EOL> try : <EOL> tokens = self . lexer . tokenize ( s , eof = False ) <EOL> if len ( tokens ) == <NUM_LIT:1> : <EOL> yield tokens [ <NUM_LIT:0> ] <EOL> continue <EOL> except LexerError : <EOL> pass <EOL> yield Token ( typ , s , SourcePos ( pos , row , col ) ) <EOL> def test_simple ( self ) : <EOL> t = self . parse ( """<STR_LIT>""" ) <EOL> t = self . ToAST . transform ( t ) <EOL> def test_class ( self ) : <EOL> t = self . parse ( """<STR_LIT>""" ) <EOL> t = self . ToAST . transform ( t ) <EOL> def test_while ( self ) : <EOL> t = self . parse ( """<STR_LIT>""" ) <EOL> t = self . ToAST . transform ( t ) <EOL> def test_comment ( self ) : <EOL> t = self . parse ( """<STR_LIT>""" ) <EOL> t = self . ToAST . transform ( t ) <EOL> def test_parse_print ( self ) : <EOL> t = self . parse ( """<STR_LIT>""" ) <EOL> t = self . ToAST . transform ( t ) <EOL> def test_assignment ( self ) : <EOL> t = self . parse ( """<STR_LIT>""" ) <EOL> t = self . ToAST . transform ( t ) <EOL> def test_lists ( self ) : <EOL> t = self . parse ( """<STR_LIT>""" ) <EOL> t = self . ToAST . transform ( t ) <EOL> def test_dicts ( self ) : <EOL> t = self . parse ( """<STR_LIT>""" ) <EOL> t = self . ToAST . transform ( t ) <EOL> def test_calls ( self ) : <EOL> t = self . parse ( """<STR_LIT>""" ) <EOL> t = self . ToAST . transform ( t ) <EOL> def test_trailers ( self ) : <EOL> py . test . skip ( "<STR_LIT>" ) <EOL> t = self . parse ( """<STR_LIT>""" ) <EOL> t = self . ToAST . transform ( t ) <EOL> def test_errors ( self ) : <EOL> source = """<STR_LIT>""" <EOL> excinfo = py . test . raises ( ParseError , self . parse , source ) <EOL> error = excinfo . value . errorinformation <EOL> msg = excinfo . value . nice_error_message ( "<STR_LIT>" , source ) <EOL> def test_precedence ( self ) : <EOL> source = """<STR_LIT>""" <EOL> t = self . parse ( source ) <EOL> t = self . ToAST . transform ( t ) <EOL> def test_parse_this ( self ) : <EOL> s = py . magic . autopath ( ) . read ( ) <EOL> t = self . parse ( s ) <EOL> t = self . ToAST . transform ( t ) <EOL> def test_parsing ( self ) : <EOL> s = py . magic . autopath ( ) . dirpath ( ) . dirpath ( ) . join ( "<STR_LIT>" ) . read ( ) <EOL> t = self . parse ( s ) <EOL> t = self . ToAST . transform ( t ) </s>
