From: <bl...@us...> - 2003-08-03 13:58:25
|
Update of /cvsroot/cpptool/rfta/src/pyrfta/test/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv21046/src/pyrfta/test/rfta Modified Files: parser.py parsertest.py Log Message: * started testing expression parsers & fixed a few bug * made debug trace optional * disabled tree node result print Index: parser.py =================================================================== RCS file: /cvsroot/cpptool/rfta/src/pyrfta/test/rfta/parser.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** parser.py 3 Aug 2003 09:24:06 -0000 1.8 --- parser.py 3 Aug 2003 13:58:22 -0000 1.9 *************** *** 299,303 **** class TokenProvider: ! def __init__( self, tokens ): self.tokens = tokens self.index = 0 --- 299,303 ---- class TokenProvider: ! def __init__( self, tokens, debug = False ): self.tokens = tokens [...1181 lines suppressed...] --- 1368,1386 ---- # A.10, C++PL3 p.812 ! throw_expression_p.setParser( symbol_f('throw') >> maybe_f( assignment_expression_p ) ) ! exception_declaration_p = (type_specifier_seq_p >> maybe_f( declarator_p | abstract_declarator_p )) \ | '...' ! handler_p = symbol_f('catch') >> '(' >> exception_declaration_p >> ')' >> compound_statement_p ! handler_seq_p = repeat_f( 1, handler_p ) ! type_id_list_p = list_f( nested_id_p, ',' ) ! exception_specification_p.setParser( symbol_f( 'throw' ) >> '(' >> maybe_f( type_id_list_p ) >> ')' ) ! try_block_p.setParser( symbol_f('try') >> compound_statement_p >> handler_seq_p ) ! function_try_block_p.setParser( symbol_f('try') >> maybe_f(ctor_initializer_p) >> function_body_p >> handler_seq_p ) Index: parsertest.py =================================================================== RCS file: /cvsroot/cpptool/rfta/src/pyrfta/test/rfta/parsertest.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** parsertest.py 3 Aug 2003 08:50:30 -0000 1.6 --- parsertest.py 3 Aug 2003 13:58:22 -0000 1.7 *************** *** 121,149 **** self.scanner = None ! def testParseBasicParsers( self ): ! self.checkParser( "MyClass", parser.id_p ) ! self.checkParser( ",", parser.symbol_p(',') ) ! self.checkParser( "MyClass MyItem", parser.repeat_p( 0, parser.id_p ) ) ! self.checkParser( "v1,v2,v3", parser.list_p( parser.id_p, ',' ) ) ! self.checkParser( "int **myVar[7][12]", parser.type_p >> parser.type_suffix_p >> parser.id_p >> parser.array_type_p ) ! self.checkParser( "::NameSpace::MyClass::myVar", parser.nested_id_p ) ! self.checkParser( "class MyClass : public MyParent, MyParent2 { };", parser.class_decl_p ) ! ! proxy_test_p = parser.proxy_p() ! proxy_test_p.setParser( parser.id_p ) ! self.checkParser( "otot", proxy_test_p ) ! ! self.checkParser( "namespace fs = boost::filesystem;", parser.namespace_alias_definition_p ) ! self.checkParser( "using typename boost::filesystem::path;", parser.using_declaration_p ) ! self.checkParser( "using boost::filesystem::path;", parser.using_declaration_p ) ! self.checkParser( "using namespace boost::filesystem;", parser.using_directive_p ) # self.checkParser( "namespace { } ", parser.namespace_definition_p ) ## self.checkParser( "namespace MyWork { } ", parser.namespace_definition_p ) # self.checkParser( 'extern "C" { }', parser.declaration_p ) ! def checkParser( self, text, tested_parser ): tokens = self.scanner.tokenize( text ) ! scanner = parser.TokenProvider( tokens ) match = tested_parser.parse( scanner ) self.assert_( match, "parser should have matched source" ) --- 121,178 ---- self.scanner = None ! ## def testParseBasicParsers( self ): ! ## self.checkParser( "MyClass", parser.id_p ) ! ## self.checkParser( ",", parser.symbol_p(',') ) ! ## self.checkParser( "MyClass MyItem", parser.repeat_p( 0, parser.id_p ) ) ! ## self.checkParser( "v1,v2,v3", parser.list_p( parser.id_p, ',' ) ) ! ## self.checkParser( "int **myVar[7][12]", parser.type_p >> parser.type_suffix_p >> parser.id_p >> parser.array_type_p ) ! ## self.checkParser( "::NameSpace::MyClass::myVar", parser.nested_id_p ) ! ## self.checkParser( "class MyClass : public MyParent, MyParent2 { };", parser.class_decl_p ) ! ## ! ## proxy_test_p = parser.proxy_p() ! ## proxy_test_p.setParser( parser.id_p ) ! ## self.checkParser( "otot", proxy_test_p ) ! ## ! ## self.checkParser( "namespace fs = boost::filesystem;", parser.namespace_alias_definition_p ) ! ## self.checkParser( "using typename boost::filesystem::path;", parser.using_declaration_p ) ! ## self.checkParser( "using boost::filesystem::path;", parser.using_declaration_p ) ! ## self.checkParser( "using namespace boost::filesystem;", parser.using_directive_p ) # self.checkParser( "namespace { } ", parser.namespace_definition_p ) ## self.checkParser( "namespace MyWork { } ", parser.namespace_definition_p ) # self.checkParser( 'extern "C" { }', parser.declaration_p ) + + def testLiteralExpression( self ): + self.checkParser( '1', parser.literal_expression_p ) + self.checkParser( '1.0', parser.literal_expression_p ) + self.checkParser( '"abc"', parser.literal_expression_p ) + self.checkParser( "'a'", parser.literal_expression_p ) + + def testPrimaryExpression( self ): + # require: literal_expression_p, qualified_id_p, unqualified_id_p, id_expression_p, operator_function_id_p, conversion_function_id_p + self.checkParser( '1', parser.primary_expression_p ) + self.checkParser( 'this', parser.primary_expression_p ) + self.checkParser( '::my_id', parser.primary_expression_p ) + self.checkParser( '::MyNamespace::MyClass::member_', parser.primary_expression_p ) + self.checkParser( '::operator =', parser.primary_expression_p ) + self.checkParser( '(this)', parser.primary_expression_p ) + self.checkParser( 'my_var', parser.primary_expression_p ) + self.checkParser( 'MyNamespace::my_var', parser.primary_expression_p ) + self.checkParser( 'operator =', parser.primary_expression_p ) + self.checkParser( 'operator int', parser.primary_expression_p ) + + def testPostFixExpression( self ): + # require: primary_expression_p + self.checkParser( '(this)', parser.postfix_expression_p ) + self.checkParser( 'my_array', parser.postfix_expression_p ) + # => fail, need to introduce a new 'longuest alternative' parser + # self.checkParser( 'my_array[1]', parser.postfix_expression_p, True ) # also need more complex expression in index ! def testExpressionParsers( self ): ! pass ! ! def checkParser( self, text, tested_parser, debug = False ): tokens = self.scanner.tokenize( text ) ! scanner = parser.TokenProvider( tokens, debug ) match = tested_parser.parse( scanner ) self.assert_( match, "parser should have matched source" ) *************** *** 152,158 **** remaining_tokens.append( scanner.getNextToken() ) self.assertEqual( [], remaining_tokens ) ! if match.getValue(): ! print "Parsing '%s'" % text ! match.getValue().prettyPrint( 4 ) return match.getValue() --- 181,187 ---- remaining_tokens.append( scanner.getNextToken() ) self.assertEqual( [], remaining_tokens ) ! ## if match.getValue(): ! ## print "Parsing '%s'" % text ! ## match.getValue().prettyPrint( 4 ) return match.getValue() |