# Path: fparser/api.py
# def parse(input, isfree=None, isstrict=None, include_dirs = None, source_only = None,
#           ignore_comments = True, analyze=True):
#     """ Parse input and return Statement tree.
# 
#     Parameters
#     ----------
#     input : str
#       Specify a string or filename containing Fortran code.
#     isfree, isstrict : {None, bool}
#       Specify input Fortran format. The values are determined from the
#       input. If that fails then isfree=True and isstrict=False is assumed.
#     include_dirs : {None, list}
#       Specify a list of include directories. The default list (when
#       include_dirs=None) contains the current working directory and
#       the directory of ``filename``.
#     source_only : {None, list}
#       Specify a list of Fortran file names that are searched when the
#       ``USE`` statement is encountered.
#     ignore_comments : bool
#       When True then discard all comment lines in the Fortran code.
#     analyze : bool
#       When True then apply run analyze method on the Fortran code tree.
# 
#     Returns
#     -------
#     block : `fparser.api.BeginSource`
# 
#     Examples
#     --------
# 
#         >>> code = '''
#         ... c comment
#         ...       subroutine foo(a)
#         ...         integer a
#         ...         print*, "a=",a
#         ...       end
#         ... '''
#         >>> tree = parse(code,isfree=False)
#         >>> print tree
#               !BEGINSOURCE <cStringIO.StringI object at 0x1798030> mode=fix90
#                 SUBROUTINE foo(a)
#                   INTEGER a
#                   PRINT *, "a=", a
#                 END SUBROUTINE foo
#         >>> print `tree`
#               BeginSource
#                 blocktype='beginsource'
#                 name='<cStringIO.StringI object at 0x1798030> mode=fix90'
#                 a=AttributeHolder:
#               external_subprogram=<dict with keys ['foo']>
#                 content:
#                   Subroutine
#                     args=['a']
#                     item=Line('subroutine foo(a)',(3, 3),'')
#                     a=AttributeHolder:
#                 variables=<dict with keys ['a']>
#                     content:
#                       Integer
#                         selector=('', '')
#                         entity_decls=['a']
#                         item=Line('integer a',(4, 4),'')
#                       Print
#                         item=Line('print*, "a=",a',(5, 5),'')
#                   EndSubroutine
#                     blocktype='subroutine'
#                     name='foo'
#             item=Line('end',(6, 6),'')
# 
#     See also
#     --------
#     get_reader
#     """
#     from .parsefortran import FortranParser
#     reader = get_reader(input, isfree, isstrict, include_dirs, source_only)
#     parser = FortranParser(reader, ignore_comments = ignore_comments)
#     parser.parse()
#     if analyze:
#         parser.analyze()
#     return parser.block


from fparser.api import parse
    tree = parse(source_str, isfree=True, isstrict=False,
                 ignore_comments=False)
    assert str(tree).strip().split('\n')[1:]=='''
!BEGINSOURCE <cStringIO.StringI object at 0x2952e70> mode=free90
  SUBROUTINE foo()
    REAL a
    ! Valid code:
100 a = 3
    l: DO
    END DO l
200 a = 4
    ! haa
300 l1: DO
    END DO l1
  END SUBROUTINE foo
'''.strip().split('\n')[1:]

    source_str = '''\
      subroutine foo
      real a
      ! Valid code:
  100 a = 3
      l: do
      end do l
  200 ! haa
     &a=4
  300 l1: do
      end do l1
      end subroutine foo
'''

# Path: fparser/api.py
# def parse(input, isfree=None, isstrict=None, include_dirs = None, source_only = None,
#           ignore_comments = True, analyze=True):
#     """ Parse input and return Statement tree.
# 
#     Parameters
#     ----------
#     input : str
#       Specify a string or filename containing Fortran code.
#     isfree, isstrict : {None, bool}
#       Specify input Fortran format. The values are determined from the
#       input. If that fails then isfree=True and isstrict=False is assumed.
#     include_dirs : {None, list}
#       Specify a list of include directories. The default list (when
#       include_dirs=None) contains the current working directory and
#       the directory of ``filename``.
#     source_only : {None, list}
#       Specify a list of Fortran file names that are searched when the
#       ``USE`` statement is encountered.
#     ignore_comments : bool
#       When True then discard all comment lines in the Fortran code.
#     analyze : bool
#       When True then apply run analyze method on the Fortran code tree.
# 
#     Returns
#     -------
#     block : `fparser.api.BeginSource`
# 
#     Examples
#     --------
# 
#         >>> code = '''
#         ... c comment
#         ...       subroutine foo(a)
#         ...         integer a
#         ...         print*, "a=",a
#         ...       end
#         ... '''
#         >>> tree = parse(code,isfree=False)
#         >>> print tree
#               !BEGINSOURCE <cStringIO.StringI object at 0x1798030> mode=fix90
#                 SUBROUTINE foo(a)
#                   INTEGER a
#                   PRINT *, "a=", a
#                 END SUBROUTINE foo
#         >>> print `tree`
#               BeginSource
#                 blocktype='beginsource'
#                 name='<cStringIO.StringI object at 0x1798030> mode=fix90'
#                 a=AttributeHolder:
#               external_subprogram=<dict with keys ['foo']>
#                 content:
#                   Subroutine
#                     args=['a']
#                     item=Line('subroutine foo(a)',(3, 3),'')
#                     a=AttributeHolder:
#                 variables=<dict with keys ['a']>
#                     content:
#                       Integer
#                         selector=('', '')
#                         entity_decls=['a']
#                         item=Line('integer a',(4, 4),'')
#                       Print
#                         item=Line('print*, "a=",a',(5, 5),'')
#                   EndSubroutine
#                     blocktype='subroutine'
#                     name='foo'
#             item=Line('end',(6, 6),'')
# 
#     See also
#     --------
#     get_reader
#     """
#     from .parsefortran import FortranParser
#     reader = get_reader(input, isfree, isstrict, include_dirs, source_only)
#     parser = FortranParser(reader, ignore_comments = ignore_comments)
#     parser.parse()
#     if analyze:
#         parser.analyze()
#     return parser.block


# Path: fparser/tests/test_comment.py
from fparser.api import parse

    tree = parse(source_str, isfree=True, isstrict=False,
                 ignore_comments=False)
    assert str(tree).strip().split('\n')[1:]=='''
!BEGINSOURCE <cStringIO.StringI object at 0x2952e70> mode=free90
  SUBROUTINE foo()
    REAL a
    ! Valid code:
100 a = 3
    l: DO
    END DO l
200 a = 4
    ! haa
300 l1: DO
    END DO l1
  END SUBROUTINE foo
'''.strip().split('\n')[1:]

    source_str = '''\
      subroutine foo
      real a
      ! Valid code:
  100 a = 3
      l: do
      end do l
  200 ! haa
     &a=4
  300 l1: do
      end do l1
      end subroutine foo
'''

    tree = parse(source_str, isfree=False, isstrict=False,