From: <bl...@us...> - 2003-08-01 08:25:08
|
Update of /cvsroot/cpptool/rfta/src/pyrfta/test/rfta In directory sc8-pr-cvs1:/tmp/cvs-serv24537/rfta Modified Files: parser.py parsertest.py Log Message: * added subparser support * parse class base classes declaration using a subparser Index: parser.py =================================================================== RCS file: /cvsroot/cpptool/rfta/src/pyrfta/test/rfta/parser.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** parser.py 31 Jul 2003 18:31:50 -0000 1.2 --- parser.py 1 Aug 2003 08:25:05 -0000 1.3 *************** *** 275,278 **** --- 275,281 ---- return [] + def getToken( self ): + return self.token + def isLeaf( self ): return True *************** *** 440,444 **** result = self.parser.parse( scanner ) if result: ! return self.matched( scanner, self.action( result.getValue() ) ) return self.notMatched() --- 443,447 ---- result = self.parser.parse( scanner ) if result: ! return self.action( result.getValue() ) return self.notMatched() *************** *** 446,450 **** return "(%s)[action]" % str(self.parser) ! class NameAction: def __init__( self, name ): self.name = name --- 449,460 ---- return "(%s)[action]" % str(self.parser) ! class Action: # matched & notMatched really need to be moved somewhere else (free function ?) ! def matched( self, node ): ! return Match( True, node ) ! ! def notMatched( self ): ! return Match( False ) ! ! class NameAction(Action): def __init__( self, name ): self.name = name *************** *** 452,456 **** def __call__( self, node ): node.setType( self.name ) ! return node def name_a( name ): --- 462,466 ---- def __call__( self, node ): node.setType( self.name ) ! return self.matched( node ) def name_a( name ): *************** *** 581,585 **** return '0' % str(self.type) ! class InlineChildAction: def __init__( self, node_index ): self.node_index = node_index --- 591,595 ---- return '0' % str(self.type) ! class InlineChildAction(Action): def __init__( self, node_index ): self.node_index = node_index *************** *** 588,594 **** inlined_node = node.getChildren()[ self.node_index ] node.getChildren()[self.node_index : self.node_index+1] = inlined_node.getChildren() ! return node ! class InlineChildrenAction: def __call__( self, node ): new_children = [] --- 598,604 ---- inlined_node = node.getChildren()[ self.node_index ] node.getChildren()[self.node_index : self.node_index+1] = inlined_node.getChildren() ! return self.matched( node ) ! class InlineChildrenAction(Action): def __call__( self, node ): new_children = [] *************** *** 599,603 **** new_children.extend( child.getChildren() ) new_node = Node(node.getType(), new_children) ! return new_node def inline_child_at_a( node_index ): --- 609,624 ---- new_children.extend( child.getChildren() ) new_node = Node(node.getType(), new_children) ! return self.matched( new_node ) ! ! class SubParseAction(Action): ! def __init__( self, subparser ): ! self.subparser = subparser ! ! def __call__( self, node ): ! tokens = [] ! for token_node in node.getChildren(): # all children must be TokenNode => need to test and dump an helpful message ! tokens.append( token_node.getToken() ) ! local_scanner = TokenProvider( tokens ) ! return self.subparser.parse( local_scanner ) def inline_child_at_a( node_index ): *************** *** 624,627 **** --- 645,651 ---- return InlineChildrenAction() + def subparse_a( parser ): + return SubParseAction( make_p( parser ) ) + end_p = TerminalParser( END_STREAM ) *************** *** 709,713 **** | friend_decl_p # enum, nested_class/struct, how ? ! class_inheritance_p = maybe_p( (symbol_p( ":" ) >> anyuntil_p( "{" ))['inheritance'] ) class_inheritance_and_body_decl_p = class_inheritance_p >> "{" >> maybe_p(class_body_statements_p) >> "}" --- 733,745 ---- | friend_decl_p # enum, nested_class/struct, how ? ! # A.8.1, C++PL3 p. 810 ! access_specifier_p = symbol_p('public') | 'protected' | 'private' ! ! base_specifier_p = maybe_p('virtual') >> maybe_p( access_specifier_p ) \ ! >> maybe_p('virtual') >> nested_id_p # not template support in class_name for now ! ! base_clause_subp = list_p( base_specifier_p['base_class'], ',' )['inheritance'] >> end_p ! ! class_inheritance_p = maybe_p( (symbol_p( ":" ) >> anyuntil_p( "{" )[subparse_a( base_clause_subp )]) ) class_inheritance_and_body_decl_p = class_inheritance_p >> "{" >> maybe_p(class_body_statements_p) >> "}" Index: parsertest.py =================================================================== RCS file: /cvsroot/cpptool/rfta/src/pyrfta/test/rfta/parsertest.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** parsertest.py 31 Jul 2003 18:31:50 -0000 1.2 --- parsertest.py 1 Aug 2003 08:25:05 -0000 1.3 *************** *** 128,132 **** 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<MyClass,simple_traits> { };", parser.class_decl_p ) def checkParser( self, text, tested_parser ): --- 128,132 ---- 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 ) def checkParser( self, text, tested_parser ): |