How to use the fparser.parsefortran.FortranParser function in fparser

To help you get started, we’ve selected a few fparser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stfc / PSyclone / src / parse.py View on Github external
>>> from parse import parse
    >>> ast,info=parse("argspec.F90")

    '''
    if api=="":
        from config import DEFAULTAPI
        api=DEFAULTAPI
    else:
        from config import SUPPORTEDAPIS
        if api not in SUPPORTEDAPIS:
            raise ParseError("parse: Unsupported API '{0}' specified. Supported types are {1}.".format(api, SUPPORTEDAPIS))

    from pyparsing import ParseException

    # drop cache
    fparser.parsefortran.FortranParser.cache.clear()
    fparser.logging.disable('CRITICAL')
    if not os.path.isfile(alg_filename):
        raise IOError("File %s not found" % alg_filename)
    try:
        ast = fpapi.parse(alg_filename, ignore_comments = False, analyze = False)
        # ast includes an extra comment line which contains file
        # details. This line can be long which can cause line length
        # issues. Therefore set the information (name) to be empty.
        ast.name = ""
    except:
        import traceback
        traceback.print_exc()
	raise ParseError("Fatal error in external fparser tool")
    if line_length:
        fll = FortLineLength()
        with open (alg_filename, "r") as myfile:
github pearu / f2py / fparser / parsefortran.py View on Github external
call smth
    end if
    aaa : if (.false.) then
    else if (a) then aaa
    else aaa
    end if aaa
    hey = 1
    end subroutine bar
    abstract interface

    end interface

end module foo
"""
    reader = FortranStringReader(string, True, False)
    parser = FortranParser(reader)
    block = parser.parse()
    print(block)
github stfc / PSyclone / f2py_93 / fparser / scripts / parse.py View on Github external
def runner (parser, options, args):
    from fparser.readfortran import  FortranFileReader
    from fparser.parsefortran import  FortranParser
    for filename in args:
        reader = FortranFileReader(filename)
        if options.mode != 'auto':
            reader.set_mode_from_str(options.mode)
        parser = FortranParser(reader)
        parser.parse()
        parser.analyze()
        if options.task=='show':
            print parser.block.torepr(4)
        elif options.task == 'none':
            pass
        else:
            raise NotImplementedError(`options.task`)
github pearu / f2py / fparser / api.py View on Github external
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
github pearu / f2py / fparser / parsefortran.py View on Github external
def parse_all_f():
    for filename in open('opt_all_f.txt'):
        filename = filename.strip()
        reader = FortranFileReader(filename)
        print(yellow_text('Processing '+filename+' (mode=%r)' % (reader.mode)))
        parser = FortranParser(reader)
        block = parser.parse()
        print(block)
github pearu / f2py / fparser / parsefortran.py View on Github external
def test_f77():
    string = """\
      program foo
      a = 3
      end
      subroutine bar
      end
      pure function foo(a)
      end
      pure real*4 recursive function bar()
      end
"""
    reader = FortranStringReader(string, False, True)
    parser = FortranParser(reader)
    block = parser.parse()
    print(block)
github stfc / PSyclone / src / genkernelstub.py View on Github external
format.
    '''
    if api == "":
        api = DEFAULTSTUBAPI
    if api not in SUPPORTEDSTUBAPIS:
        print "Unsupported API '{0}' specified. Supported API's are {1}.".\
              format(api, SUPPORTEDSTUBAPIS)
        raise GenerationError(
            "generate: Unsupported API '{0}' specified. Supported types are "
            "{1}.".format(api, SUPPORTEDSTUBAPIS))

    if not os.path.isfile(filename):
        raise IOError("file '{0}' not found".format(filename))

    # drop cache
    fparser.parsefortran.FortranParser.cache.clear()
    fparser.logging.disable('CRITICAL')
    try:
        ast = fpapi.parse(filename, ignore_comments=False)
    except AttributeError:
        raise ParseError("Code appears to be invalid Fortran")

    metadata = DynKernMetadata(ast)
    kernel = DynKern()
    kernel.load_meta(metadata)
    return kernel.gen_stub