From numpy-svn at scipy.org Wed Nov 1 05:09:57 2006 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Wed, 1 Nov 2006 04:09:57 -0600 (CST) Subject: [Numpy-svn] r3423 - trunk/numpy/f2py/lib/parser Message-ID: <20061101100957.09A063A0017@new.scipy.org> Author: pearu Date: 2006-11-01 04:09:49 -0600 (Wed, 01 Nov 2006) New Revision: 3423 Added: trunk/numpy/f2py/lib/parser/test_Fortran2003.py Modified: trunk/numpy/f2py/lib/parser/Fortran2003.py trunk/numpy/f2py/lib/parser/pattern_tools.py Log: F2PY G3: Cont impl F2003 parser; defined all syntax rules. Modified: trunk/numpy/f2py/lib/parser/Fortran2003.py =================================================================== --- trunk/numpy/f2py/lib/parser/Fortran2003.py 2006-10-31 14:58:19 UTC (rev 3422) +++ trunk/numpy/f2py/lib/parser/Fortran2003.py 2006-11-01 10:09:49 UTC (rev 3423) @@ -31,7 +31,9 @@ def __new__(cls, string): #print '__new__:',cls.__name__,`string` - if isinstance(string, FortranReaderBase) and not issubclass(cls, BlockBase): + match = cls.__dict__.get('match', None) + if isinstance(string, FortranReaderBase) and not issubclass(cls, BlockBase) \ + and match is not None: reader = string item = reader.get_item() if item is None: return @@ -44,7 +46,6 @@ return obj._item = item return obj - match = cls.__dict__.get('match', None) if match is not None: result = cls.match(string) else: @@ -109,6 +110,7 @@ [ ] """ def match(startcls, subclasses, endcls, reader): + assert isinstance(reader,FortranReaderBase),`reader` content = [] if startcls is not None: try: @@ -157,9 +159,12 @@ start_stmt = content[0] end_stmt = content[-1] if isinstance(end_stmt, endcls) and hasattr(end_stmt, 'name'): - if end_stmt.name is not None and start_stmt.name != end_stmt.name: - end_stmt._item.reader.error('expected <%s-name> is %s but got %s. Ignoring.'\ - % (end_stmt.type.lower(), start_stmt.name, end_stmt.name)) + if end_stmt.name is not None: + if start_stmt.name != end_stmt.name: + end_stmt._item.reader.error('expected <%s-name> is %s but got %s. Ignoring.'\ + % (end_stmt.type.lower(), start_stmt.name, end_stmt.name)) + else: + end_stmt.name = start_stmt.name return content, match = staticmethod(match) @@ -432,13 +437,16 @@ ############################### SECTION 2 #################################### ############################################################################### -class Program(Base): # R201 +class Program(BlockBase): # R201 """ = [ ] ... """ subclass_names = [] use_names = ['Program_Unit'] + def match(reader): + return BlockBase.match(Program_Unit, [Program_Unit], None, reader) + match = staticmethod(match) class Program_Unit(Base): # R202 """ @@ -684,10 +692,17 @@ subclass_names = ['Constant'] #R310: = | | | | | | | | -#R311: = | | +#R311: = | | #R312: = -#R313: