fparser Reference Guide
0.0.14
|
Public Member Functions | |
def | __init__ (self, source, mode, ignore_comments) |
def | __repr__ (self) |
def | find_module_source_file (self, mod_name) |
def | set_format (self, mode) |
def | format (self) |
def | name (self) |
def | close_source (self) |
def | put_single_line (self, line) |
def | get_single_line (self, ignore_empty=False, ignore_comments=None) |
def | get_next_line (self, ignore_empty=False, ignore_comments=None) |
def | get_item (self, ignore_comments=None) |
def | put_item (self, item) |
def | __iter__ (self) |
def | __next__ (self) |
def | next (self, ignore_comments=None) |
def | line_item (self, line, startlineno, endlineno, label, name, errmessage=None) |
def | multiline_item (self, prefix, lines, suffix, startlineno, endlineno, errmessage=None) |
def | comment_item (self, comment, startlineno, endlineno) |
def | cpp_directive_item (self, line, startlineno, endlineno) |
def | format_message (self, kind, message, startlineno, endlineno, startcolno=0, endcolno=-1) |
def | format_error_message (self, message, startlineno, endlineno, startcolno=0, endcolno=-1) |
def | format_warning_message (self, message, startlineno, endlineno, startcolno=0, endcolno=-1) |
def | info (self, message, item=None) |
def | error (self, message, item=None) |
def | warning (self, message, item=None) |
def | handle_cpp_directive (self, line) |
def | handle_cf2py_start (self, line) |
def | handle_inline_comment (self, line, lineno, quotechar=None) |
def | handle_multilines (self, line, startlineno, mlstr) |
def | get_source_item (self) |
Public Attributes | |
source | |
linecount | |
isclosed | |
filo_line | |
fifo_item | |
source_lines | |
f2py_comment_lines | |
reader | |
include_dirs | |
source_only | |
exit_on_error | |
restore_cache | |
Base class for reading Fortran sources. A Fortran source must be a file-like object (have a ``.next()`` method) and it may hold Fortran 77 code, fixed format Fortran code, free format Fortran code, or PYF signatures (with extended free format Fortran syntax). :param source: a file-like object with .next() method used to \ retrive a line. :type source: :py:class:`StringIO` or a file handle :param mode: a FortranFormat object as returned by \ `sourceinfo.get_source_info()` :type mode: :py:class:`fparser.common.sourceinfo.Format` :param bool isstrict: whether we are strictly enforcing fixed format. :param bool ignore_comments: whether or not to discard comments. The Fortran source is iterated by `get_single_line`, `get_next_line`, `put_single_line` methods.
Definition at line 545 of file readfortran.py.
def fparser.common.readfortran.FortranReaderBase.__iter__ | ( | self | ) |
Make FortranReader an iterator.
Definition at line 763 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase.next().
def fparser.common.readfortran.FortranReaderBase.close_source | ( | self | ) |
Called when self.source.next() raises StopIteration.
Definition at line 644 of file readfortran.py.
def fparser.common.readfortran.FortranReaderBase.comment_item | ( | self, | |
comment, | |||
startlineno, | |||
endlineno | |||
) |
Construct Comment item.
Definition at line 956 of file readfortran.py.
def fparser.common.readfortran.FortranReaderBase.cpp_directive_item | ( | self, | |
line, | |||
startlineno, | |||
endlineno | |||
) |
Construct :py:class:`fparser.common.readfortran.CppDirective` item. :param str line: string containing the text of a single or \ multi-line preprocessor directive. :param int startlineno: start line number of the directive from \ the input source. :param int endlineno: end line number of the directive from \ the input source.
Definition at line 960 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase.format_message().
def fparser.common.readfortran.FortranReaderBase.error | ( | self, | |
message, | |||
item = None |
|||
) |
Logs an error message.
Definition at line 1037 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase.exit_on_error, fparser.common.readfortran.FortranReaderBase.format_error_message(), and fparser.common.readfortran.FortranReaderBase.source_lines.
def fparser.common.readfortran.FortranReaderBase.find_module_source_file | ( | self, | |
mod_name | |||
) |
Scans registered dependees for a named module.
Definition at line 602 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase.include_dirs, and fparser.common.readfortran.FortranReaderBase.source_only.
def fparser.common.readfortran.FortranReaderBase.format | ( | self | ) |
:returns: the currently applicable format. :rtype: :py:class:`fparser.sourceinfo.FortranFormat`
Definition at line 629 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase._format.
def fparser.common.readfortran.FortranReaderBase.format_error_message | ( | self, | |
message, | |||
startlineno, | |||
endlineno, | |||
startcolno = 0 , |
|||
endcolno = -1 |
|||
) |
Create a string with an error message.
Definition at line 1008 of file readfortran.py.
References fparser.common.base_classes.Statement.format_message(), fparser.common.readfortran.FortranReaderBase.format_message(), and fparser.common.readfortran.FortranReaderBase.format_warning_message().
def fparser.common.readfortran.FortranReaderBase.format_message | ( | self, | |
kind, | |||
message, | |||
startlineno, | |||
endlineno, | |||
startcolno = 0 , |
|||
endcolno = -1 |
|||
) |
Prepares a string for logging.
Definition at line 978 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase._format, fparser.common.readfortran.FortranReaderBase.format_error_message(), fparser.common.readfortran.FortranFileReader.id, fparser.common.readfortran.FortranStringReader.id, and fparser.common.readfortran.FortranReaderBase.source_lines.
def fparser.common.readfortran.FortranReaderBase.format_warning_message | ( | self, | |
message, | |||
startlineno, | |||
endlineno, | |||
startcolno = 0 , |
|||
endcolno = -1 |
|||
) |
Create a string with a warning message.
Definition at line 1016 of file readfortran.py.
References fparser.common.base_classes.Statement.format_message(), and fparser.common.readfortran.FortranReaderBase.format_message().
def fparser.common.readfortran.FortranReaderBase.get_item | ( | self, | |
ignore_comments = None |
|||
) |
Return next item.
Definition at line 746 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase._ignore_comments, and fparser.common.readfortran.FortranReaderBase.next().
def fparser.common.readfortran.FortranReaderBase.get_next_line | ( | self, | |
ignore_empty = False , |
|||
ignore_comments = None |
|||
) |
Return next non-empty line from FILO line buffer or from source. The line will be put to FILO line buffer. So, this method can be used for looking forward lines without consuming them. See also -------- get_single_line, put_single_line
Definition at line 726 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase._ignore_comments, fparser.common.readfortran.FortranReaderBase.get_single_line(), and fparser.common.readfortran.FortranReaderBase.put_single_line().
def fparser.common.readfortran.FortranReaderBase.get_single_line | ( | self, | |
ignore_empty = False , |
|||
ignore_comments = None |
|||
) |
Return line from FILO line buffer or from source. First try getting the line from FILO line buffer. If FILO line buffer is empty then get the next line from source. Tabs in source line are expanded, ending blank and new line characters will be removed. The source line will be added to ``source_lines`` list. If source line is empty then recursively get next non-empty line. In both situations ``linecount`` will be incremented, that is, the line will be consumed. :param bool ignore_empty: if True then ignore empty lines. :param bool ignore_comments: if True then ignore comments (overrides \ self._ignore_comments) See also -------- put_single_line, get_next_line
Definition at line 664 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase._format, fparser.common.readfortran.FortranReaderBase._ignore_comments, fparser.common.readfortran.FortranReaderBase.close_source(), fparser.common.readfortran.FortranReaderBase.filo_line, fparser.common.readfortran.FortranReaderBase.get_single_line(), fparser.common.readfortran.FortranReaderBase.isclosed, fparser.common.readfortran.FortranReaderBase.linecount, fparser.common.readfortran.FortranReaderBase.next(), fparser.common.readfortran.FortranReaderBase.source, and fparser.common.readfortran.FortranReaderBase.source_lines.
def fparser.common.readfortran.FortranReaderBase.get_source_item | ( | self | ) |
Return the next source item. A source item is .. - a fortran line - a list of continued fortran lines - a multiline - lines inside triple-quotes, only when in ispyf mode - a comment line - a preprocessor directive line :returns: the next source item. :rtype: :py:class:`fparser.common.readfortran.Line` or \ :py:class:`fparser.common.readfortran.MultiLine` or \ :py:class:`fparser.common.readfortran.Comment` or \ :py:class:`fparser.common.readfortran.CppDirective` or \ :py:class:`fparser.common.readfortran.SyntaxErrorLine` or \ :py:class:`fparser.common.readfortran.SyntaxErrorMultiLine`
Definition at line 1257 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase._format, fparser.common.readfortran.FortranReaderBase.comment_item(), fparser.common.readfortran.FortranReaderBase.cpp_directive_item(), fparser.common.base_classes.Variable.error(), fparser.common.base_classes.Statement.error(), fparser.common.readfortran.FortranReaderBase.error(), fparser.common.readfortran.FortranReaderBase.f2py_comment_lines, fparser.common.readfortran.FortranReaderBase.fifo_item, fparser.common.readfortran.FortranReaderBase.format_error_message(), fparser.common.base_classes.Statement.format_message(), fparser.common.readfortran.FortranReaderBase.format_message(), fparser.common.readfortran.FortranReaderBase.format_warning_message(), fparser.common.readfortran.FortranReaderBase.get_next_line(), fparser.common.readfortran.FortranReaderBase.get_single_line(), fparser.common.readfortran.FortranReaderBase.handle_cf2py_start(), fparser.common.readfortran.FortranReaderBase.handle_cpp_directive(), fparser.common.readfortran.FortranReaderBase.handle_inline_comment(), fparser.common.readfortran.FortranReaderBase.handle_multilines(), fparser.common.readfortran.FortranReaderBase.line_item(), fparser.common.readfortran.FortranReaderBase.linecount, fparser.common.readfortran.FortranReaderBase.put_item(), fparser.common.readfortran.FortranReaderBase.set_format(), fparser.common.base_classes.Variable.warning(), fparser.common.base_classes.Statement.warning(), and fparser.common.readfortran.FortranReaderBase.warning().
def fparser.common.readfortran.FortranReaderBase.handle_cf2py_start | ( | self, | |
line | |||
) |
Process any f2py directives contained in the supplied line. If support for such directives has been disabled then the line is returned unchanged. F2py directives are specified in the beginning of the line. f2py directives can be used only in Fortran codes. They are ignored when used inside PYF files. :param str line: the line to check for f2py directives. :returns: the line with any f2py directives applied (if they are \ enabled in the reader). :rtype: str
Definition at line 1089 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase._format, fparser.common.readfortran.FortranReaderBase.f2py_comment_lines, and fparser.common.readfortran.FortranReaderBase.linecount.
def fparser.common.readfortran.FortranReaderBase.handle_cpp_directive | ( | self, | |
line | |||
) |
Determine whether the current line is likely to hold C preprocessor directive. If the first non whitespace character of a line is the symbol ``#`` it is assumed this is a preprocessor directive. Preprocessor directives can be used only in Fortran codes. They are ignored when used inside PYF files. The actual line content is not altered. :param str line: the line to be tested for directives. :return: a tuple containing the line and True/False depending on \ whether it holds a C preprocessor directive. :rtype: (str, bool)
Definition at line 1065 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase._format.
def fparser.common.readfortran.FortranReaderBase.handle_inline_comment | ( | self, | |
line, | |||
lineno, | |||
quotechar = None |
|||
) |
Any in-line comment is extracted from the line. If keep_inline_comments==True then the extracted comments are put back into the fifo sequence where they will subsequently be processed as a comment line. :param str line: line of code from which to remove in-line comment :param int lineno: line-no. in orig. file :param quotechar: String to use as character-string delimiter :type quotechar: {None, str} :return: line_with_no_comments, quotechar, had_comment :rtype: 3-tuple of str, str, bool
Definition at line 1124 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase._format, fparser.common.readfortran.FortranReaderBase.comment_item(), fparser.common.readfortran.FortranReaderBase.f2py_comment_lines, fparser.common.readfortran.FortranReaderBase.fifo_item, fparser.one.statements.Print.format, fparser.one.statements.Read1.format, fparser.common.readfortran.FortranReaderBase.format(), fparser.common.readfortran.FortranReaderBase.handle_inline_comment(), and fparser.common.readfortran.FortranReaderBase.put_item().
def fparser.common.readfortran.FortranReaderBase.handle_multilines | ( | self, | |
line, | |||
startlineno, | |||
mlstr | |||
) |
Examines line for Python triple quote strings (f2py feature). :param str line: line of Fortran source text :param int startlineno: the number of the line on which this multi-line string began. :param list mlstr: list of delimiters for a multi-line string (e.g. '"""')
Definition at line 1185 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase.format(), fparser.common.readfortran.FortranReaderBase.format_error_message(), fparser.common.base_classes.Statement.format_message(), fparser.common.readfortran.FortranReaderBase.format_message(), fparser.common.readfortran.FortranReaderBase.format_warning_message(), fparser.common.readfortran.FortranReaderBase.get_single_line(), fparser.common.readfortran.FortranReaderBase.handle_inline_comment(), fparser.common.readfortran.FortranReaderBase.linecount, fparser.common.readfortran.FortranReaderBase.multiline_item(), and fparser.common.readfortran.FortranReaderBase.warning().
def fparser.common.readfortran.FortranReaderBase.info | ( | self, | |
message, | |||
item = None |
|||
) |
Logs an information message.
Definition at line 1022 of file readfortran.py.
References fparser.common.base_classes.Statement.format_message(), fparser.common.readfortran.FortranReaderBase.format_message(), and fparser.common.readfortran.FortranReaderBase.source_lines.
def fparser.common.readfortran.FortranReaderBase.line_item | ( | self, | |
line, | |||
startlineno, | |||
endlineno, | |||
label, | |||
name, | |||
errmessage = None |
|||
) |
Construct Line item.
Definition at line 938 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase.multiline_item().
def fparser.common.readfortran.FortranReaderBase.multiline_item | ( | self, | |
prefix, | |||
lines, | |||
suffix, | |||
startlineno, | |||
endlineno, | |||
errmessage = None |
|||
) |
Construct MultiLine item.
Definition at line 948 of file readfortran.py.
def fparser.common.readfortran.FortranReaderBase.name | ( | self | ) |
:returns: the name of this reader. :rtype: str
Definition at line 637 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase._format, fparser.common.readfortran.FortranReaderBase.format(), and fparser.common.readfortran.FortranReaderBase.source.
def fparser.common.readfortran.FortranReaderBase.next | ( | self, | |
ignore_comments = None |
|||
) |
Return the next Fortran code item. Include statements are dealt with here. :param bool ignore_comments: When True then act as if Fortran \ code does not contain any comments or blank lines. if this \ optional arguement is not provided then use the default \ value. :returns: the next line item. This can be from a local fifo \ buffer, from an include reader or from this reader. :rtype: py:class:`fparser.common.readfortran.Line` :raises StopIteration: if no more lines are found. :raises StopIteration: if a general error has occured.
Definition at line 770 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase._format, fparser.common.readfortran.FortranReaderBase._ignore_comments, fparser.common.readfortran.FortranReaderBase._next(), fparser.common.readfortran.FortranReaderBase.fifo_item, fparser.common.base_classes.Statement.format_message(), fparser.common.readfortran.FortranReaderBase.format_message(), fparser.common.readfortran.FortranReaderBase.get_source_item(), fparser.common.readfortran.FortranReaderBase.include_dirs, fparser.common.readfortran.FortranReaderBase.linecount, fparser.common.readfortran.Line.reader, fparser.common.readfortran.Comment.reader, fparser.common.readfortran.MultiLine.reader, fparser.common.readfortran.FortranReaderBase.reader, and fparser.common.base_classes.Statement.reader.
def fparser.common.readfortran.FortranReaderBase.put_item | ( | self, | |
item | |||
) |
Insert item to FIFO item buffer.
Definition at line 757 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase.fifo_item.
def fparser.common.readfortran.FortranReaderBase.put_single_line | ( | self, | |
line | |||
) |
Put single line to FILO line buffer. ``linecount`` will be decremented, that is, the line was returned by ``get_single_line`` call then it will be un-consumed. See also -------- get_single_line, get_next_line
Definition at line 650 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase.filo_line, and fparser.common.readfortran.FortranReaderBase.linecount.
def fparser.common.readfortran.FortranReaderBase.set_format | ( | self, | |
mode | |||
) |
Set Fortran code mode (fixed/free format etc). :param mode: Object describing the desired mode for the reader :type mode: :py:class:`fparser.common.sourceinfo.FortranFormat`
Definition at line 619 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase._format.
def fparser.common.readfortran.FortranReaderBase.warning | ( | self, | |
message, | |||
item = None |
|||
) |
Logs a warning message.
Definition at line 1051 of file readfortran.py.
References fparser.common.readfortran.FortranReaderBase.format_warning_message(), and fparser.common.readfortran.FortranReaderBase.source_lines.