# Path: fparser/api.py
# def get_reader(input, isfree=None, isstrict=None, include_dirs = None, source_only = None,
#                ignore_comments = True):
#     """ Returns Fortran reader instance.
# 
#     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.
# 
#     Returns
#     -------
#     reader : `FortranReader`
# 
#     Notes
#     -----
#     If ``input`` is a C filename then the functions searches for comment
#     lines starting with ``/*f2py`` and reads following lines as PYF file
#     content until a line ``*/`` is found.
# 
#     See also
#     --------
#     parse
#     """
#     import os
#     import re
#     from .readfortran import FortranFileReader, FortranStringReader
#     if os.path.isfile(input):
#         name,ext = os.path.splitext(input)
#         if ext.lower() in ['.c']:
#             # get signatures from C file comments starting with `/*f2py` and ending with `*/`.
#             # TODO: improve parser to take line number offset making line numbers in
#             #       parser messages correct.
#             f2py_c_comments = re.compile('/[*]\s*f2py\s.*[*]/',re.I | re.M)
#             f = open(filename,'r')
#             c_input = ''
#             for s1 in f2py_c_comments.findall(f.read()):
#                 c_input += s1[2:-2].lstrip()[4:] + '\n'
#             f.close()
#             if isfree is None: isfree = True
#             if isstrict is None: isstrict = True
#             return parse(c_input, isfree, isstrict, include_dirs)
#         reader = FortranFileReader(input, include_dirs = include_dirs, source_only = source_only)
#     elif isinstance(input, str):
#         reader = FortranStringReader(input, include_dirs = include_dirs, source_only = source_only)
#     else:
#         raise TypeError('Expected string or filename input but got %s' % (type(input)))
#     if isfree is None: isfree = reader.isfree
#     if isstrict is None: isstrict = reader.isstrict
#     reader.set_mode(isfree, isstrict)
#     return reader


from fparser.Fortran2003 import *
from fparser.api import get_reader
from nose.tools import assert_equal
else if (expr2) then
  a = 2
else
  a = 3
end if
    '''))
    assert_equal(str(a),'IF (expr) THEN\n  a = 1\nELSE IF (expr2) THEN\n  a = 2\nELSE\n  a = 3\nEND IF')

    a = cls(get_reader('''
named: if (expr) then
  a = 1
else named
  a = 2
end if named
    '''))
    assert_equal(str(a),'named:IF (expr) THEN\n  a = 1\nELSE named\n  a = 2\nEND IF named')

    a = cls(get_reader('''
named: if (expr) then
  a = 1
  named2: if (expr2) then
    a = 2
  end if named2
end if named
'''))
    assert_equal(str(a),'named:IF (expr) THEN\n  a = 1\n  named2:IF (expr2) THEN\n    a = 2\n  END IF named2\nEND IF named')

    a = cls(get_reader('''
if (expr) then
  a = 1

# Path: fparser/api.py
# def get_reader(input, isfree=None, isstrict=None, include_dirs = None, source_only = None,
#                ignore_comments = True):
#     """ Returns Fortran reader instance.
# 
#     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.
# 
#     Returns
#     -------
#     reader : `FortranReader`
# 
#     Notes
#     -----
#     If ``input`` is a C filename then the functions searches for comment
#     lines starting with ``/*f2py`` and reads following lines as PYF file
#     content until a line ``*/`` is found.
# 
#     See also
#     --------
#     parse
#     """
#     import os
#     import re
#     from .readfortran import FortranFileReader, FortranStringReader
#     if os.path.isfile(input):
#         name,ext = os.path.splitext(input)
#         if ext.lower() in ['.c']:
#             # get signatures from C file comments starting with `/*f2py` and ending with `*/`.
#             # TODO: improve parser to take line number offset making line numbers in
#             #       parser messages correct.
#             f2py_c_comments = re.compile('/[*]\s*f2py\s.*[*]/',re.I | re.M)
#             f = open(filename,'r')
#             c_input = ''
#             for s1 in f2py_c_comments.findall(f.read()):
#                 c_input += s1[2:-2].lstrip()[4:] + '\n'
#             f.close()
#             if isfree is None: isfree = True
#             if isstrict is None: isstrict = True
#             return parse(c_input, isfree, isstrict, include_dirs)
#         reader = FortranFileReader(input, include_dirs = include_dirs, source_only = source_only)
#     elif isinstance(input, str):
#         reader = FortranStringReader(input, include_dirs = include_dirs, source_only = source_only)
#     else:
#         raise TypeError('Expected string or filename input but got %s' % (type(input)))
#     if isfree is None: isfree = reader.isfree
#     if isstrict is None: isstrict = reader.isstrict
#     reader.set_mode(isfree, isstrict)
#     return reader


# Path: fparser/tests/test_Fortran2003.py
from fparser.Fortran2003 import *
from fparser.api import get_reader
from nose.tools import assert_equal

else if (expr2) then
  a = 2
else
  a = 3
end if
    '''))
    assert_equal(str(a),'IF (expr) THEN\n  a = 1\nELSE IF (expr2) THEN\n  a = 2\nELSE\n  a = 3\nEND IF')

    a = cls(get_reader('''
named: if (expr) then
  a = 1
else named
  a = 2
end if named
    '''))
    assert_equal(str(a),'named:IF (expr) THEN\n  a = 1\nELSE named\n  a = 2\nEND IF named')

    a = cls(get_reader('''
named: if (expr) then
  a = 1
  named2: if (expr2) then
    a = 2
  end if named2
end if named
'''))
    assert_equal(str(a),'named:IF (expr) THEN\n  a = 1\n  named2:IF (expr2) THEN\n    a = 2\n  END IF named2\nEND IF named')

    a = cls(get_reader('''
if (expr) then
  a = 1

else if (expr2) then