fparser.two.Fortran2003
Fortran 2003 Syntax Rules.
Module Contents
Classes
Represents a Fortran Comment. |
|
Fortran 2003 rule R201: |
|
Implements the matching of a filename from an include statement. |
|
Implements the matching of a Fortran include statement. There is no |
|
Fortran 2003 Rule R202: |
|
Fortran2003 Rule R203: |
|
Fortran2003 Rule R204: |
|
Fortran2003 Rule R205: |
|
Fortran2003 Rule R206: |
|
Fortran 2003 rule R207: |
|
Fortran2003 Rule R208: |
|
Base class for Fortran 2003 syntax rules. |
|
Fortran 2003 rule R213: |
|
Base class for Fortran 2003 syntax rules. |
|
Fortran 2003 rule R304: |
|
Fortran 2003 rule R311: |
|
Fortran 2003 rule R312: |
|
Fortran 2003 Rule 402: |
|
Fortran 2003 rule R404: |
|
Fortran 2003 rule R427: |
|
Fortran 2003 rule R430: |
|
Fortran 2003 rule 440: |
|
Fortran2003 Rule R447: |
|
Fortran 2003 rule R448. |
|
Fortran2003 Rule R449: |
|
Fortran2003 Rule R450: |
|
Fortran2003 Rule R451: |
|
Fortran 2003 helper rule (for R453): |
|
Fortran2003 Rule R452: |
|
Fortran2003 Rule R453: |
|
Fortran2003 Rule R454: |
|
Fortran2003 rule R470. |
|
Fortran2003 rule R471. |
|
Fortran2003 rule R472. |
|
Fortran 2003 rule 501: |
|
Fortran2003 Rule R508: |
|
Fortran2003 Rule R509: |
|
Fortran2003 Rule R510: |
|
Fortran2003 Rule R514: |
|
Fortran2003 Rule R515: |
|
Fortran2003 Rule R516: |
|
Fortran2003 Rule R518: |
|
Fortran2003 Rule R519: |
|
Fortran2003 Rule R520: |
|
Fortran2003 Rule R521: |
|
Fortran2003 Rule R522: |
|
Fortran 2003 Rule R524: |
|
Fortran2003 Rule R525: |
|
Fortran 2003 Rule R526: |
|
Fortran 2003 Rule R527: |
|
Fortran 2003 Rule R532: |
|
Fortran 2003 Rule R533: |
|
Fortran 2003 Rule R534: |
|
Fortran 2003 Rule R535: |
|
Fortran 2003 rule R552: |
|
Fortran 2003 rule R603: |
|
Fortran 2003 Rule R612: |
|
Fortran2003 rule R623: |
|
Base class for Fortran 2003 syntax rules. |
|
Fortran 2003 rule R701: |
|
Part of Fortran 2003 rule R701: |
|
Fortran 2003 rule R703: |
|
Utility class that Implements the functionality of rules R703 and |
|
Fortran 2003 rule R705: |
|
Fortran 2003 rule R723: |
|
Fortran 2003 rule R724: |
|
Fortran 2003 rule R725: |
|
Fortran 2003 rule R726: |
|
Fortran 2003 rule R727: |
|
Fortran 2003 rule R728: |
|
<mask-expr> = <logical-expr> |
|
<elsewhere-stmt> = ELSEWHERE [ <where-construct-name> ] |
|
<end-where-stmt> = END WHERE [ <where-construct-name> ] |
|
Fortran 2003 rule R754: |
|
<end-forall-stmt> = END FORALL [ <forall-construct-name> ] |
|
Fortran 2003 rule R759: |
|
<block> = [ <execution-part-construct> ]... |
|
<else-stmt> = ELSE [ <if-construct-name> ] |
|
<end-if-stmt> = END IF [ <if-construct-name> ] |
|
Fortran 2003 rule R807: |
|
<case-stmt> = CASE <case-selector> [ <case-construct-name> ] |
|
<end-select-stmt> = END SELECT [ <case-construct-name> ] |
|
<association> = <associate-name> => <selector> |
|
<end-associate-stmt> = END ASSOCIATE [ <associate-construct-name> ] |
|
<end-select-type-stmt> = END SELECT [ <select-construct-name> ] |
|
R825: |
|
R826: |
|
R826_1: |
|
R826_2: |
|
R827: |
|
R828: |
|
R829: |
|
Fortran 2003 rule R830 |
|
R831: |
|
R832: |
|
R833: |
|
R834: |
|
R835: |
|
<do-body> = [ <execution-part-construct> ]... |
|
<cycle-stmt> = CYCLE [ <do-construct-name> ] |
|
<exit-stmt> = EXIT [ <do-construct-name> ] |
|
<goto-stmt> = GO TO <label> |
|
<computed-goto-stmt> = GO TO ( <label-list> ) [ , ] <scalar-int-expr> |
|
<continue-stmt> = CONTINUE |
|
<stop-stmt> = STOP [ <stop-code> ] |
|
<file-unit-number> = <scalar-int-expr> |
|
R904 is: |
|
R905 is: |
|
<file-name-expr> = <scalar-default-char-expr> |
|
<iomsg-variable> = <scalar-default-char-variable> |
|
<close-stmt> = CLOSE ( <close-spec-list> ) |
|
Fortran2003 Rule R910: |
|
Fortran 2003 rule R911. |
|
Fortran2003 Rule R912: |
|
Rule 913 - Control information list: |
|
This class implements partial support for Rule 913: |
|
<wait-stmt> = WAIT ( <wait-spec-list> ) |
|
Fortran2003 Rule R923: |
|
Fortran2003 Rule R924: |
|
Fortran2003 Rule R925: |
|
Fortran2003 Rule R927: |
|
Fortran2003 Rule R928: |
|
Fortran2003 Rule R929: |
|
Fortran2003 Rule R930: |
|
<format-stmt> = FORMAT <format-specification> |
|
This class replaces the one generated by fparser. This class is |
|
Fortran 2003 rule R1002: |
|
Fortran 2003 constraint C1002: |
|
Hollerith strings take the form nHx, where n is an integer and |
|
Fortran 2003 rule R1003: |
|
This class helps implement the matching for the first part of the |
|
Fortran 2003 rule R1011: |
|
Fortran 2003 rule R1013: |
|
<decimal-edit-desc> = DC |
|
<char-string-edit-desc> = <char-literal-constant> |
|
Fortran 2003 rule R1101: |
|
Rule 1101 specifies that the opening 'program-stmt' is optional. This |
|
Fortran 2003 rule R1102: |
|
<end-program-stmt> = END [ PROGRAM [ <program-name> ] ] |
|
<module-stmt> = MODULE <module-name> |
|
<end-module-stmt> = END [ MODULE [ <module-name> ] ] |
|
Fortran 2003 rule R1109: |
|
R1110: |
|
Class defining Rule #R1111: |
|
Fortran 2003 rule R1209: |
|
<interface-name> = <name> |
|
<function-reference> = <procedure-designator> |
|
Represents the name of a Fortran intrinsic function. |
|
Represents Fortran intrinsics: |
|
<actual-arg-spec> = [ <keyword> = ] <actual-arg> |
|
<proc-language-binding-spec> = <language-binding-spec> |
|
<dummy-arg-name> = <name> |
|
Fortran2003 rule R1227: |
|
<end-function-stmt> = END [ FUNCTION [ <function-name> ] ] |
|
Fortran2003 rule R1232: |
|
<end-subroutine-stmt> = END [ SUBROUTINE [ <subroutine-name> ] ] |
|
<return-stmt> = RETURN [ <scalar-int-expr> ] |
|
<contains-stmt> = CONTAINS |
|
Functions
|
Creates a comment or include object from the current line. |
|
Creates comment, include, and/or cpp directive objects and adds them to |
|
Skips over any potential digits (including spaces) to the next |
|
If prefix and binding-spec exist then check whether they conform to |
Attributes
- class fparser.two.Fortran2003.Comment(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Represents a Fortran Comment.
- fparser.two.Fortran2003.match_comment_or_include(reader)[source]
Creates a comment or include object from the current line.
- Parameters:
reader (
fparser.common.readfortran.FortranFileReader
orfparser.common.readfortran.FortranStringReader
) – the fortran file reader containing the line of code that we are trying to match- Returns:
a comment or include object if found, otherwise None.
- Return type:
fparser.two.Fortran2003.Comment
orfparser.two.Fortran2003.Include_Stmt
- fparser.two.Fortran2003.add_comments_includes_directives(content, reader)[source]
Creates comment, include, and/or cpp directive objects and adds them to the content list. Comment, include, and/or directive objects are added until a line that is not a comment, include, or directive is found.
- Parameters:
content (
list
) – a list of matched objects. Any matched comments, includes, or directives in this routine are added to this list.reader (
fparser.common.readfortran.FortranFileReader
orfparser.common.readfortran.FortranStringReader
) – the fortran file reader containing the line(s) of code that we are trying to match
- class fparser.two.Fortran2003.Program(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
Fortran 2003 rule R201:
program is program-unit [ program-unit ] ...
- static match(reader)[source]
Implements the matching for a Program. Whilst the rule looks like it could make use of BlockBase, the parser must not match if an optional program_unit has a syntax error, which the BlockBase match implementation does not do.
- Parameters:
reader (
fparser.common.readfortran.FortranFileReader
orfparser.common.readfortran.FortranStringReader
) – the fortran file reader containing the line(s) of code that we are trying to match- Returns:
tuple containing a single list which contains instance of the classes that have matched if there is a match or None if there is no match
- class fparser.two.Fortran2003.Include_Filename(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StringBase
Implements the matching of a filename from an include statement.
- class fparser.two.Fortran2003.Include_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Implements the matching of a Fortran include statement. There is no rule for this as the compiler is expected to inline any content from an include statement when one is found. However, for a parser it can make sense to represent an include statement in a parse tree:
include-stmt is INCLUDE ['filename' or "filename"]
- static match(string)[source]
Implements the matching for an include statement.
- Parameters:
string (str) – the string to match with as an include statement.
- Returns:
a tuple of size 1 containing an Include_Filename object with the matched filename if there is a match, or None if there is not.
- Return type:
(
fparser.two.Fortran2003.Include_Filename
) or NoneType
- class fparser.two.Fortran2003.Program_Unit(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 Rule R202:
<program-unit> = <main-program> | <external-subprogram> | <module> | <block-data>
- class fparser.two.Fortran2003.External_Subprogram(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran2003 Rule R203:
<external-subprogram> = <function-subprogram> | <subroutine-subprogram>
- class fparser.two.Fortran2003.Specification_Part(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
Fortran2003 Rule R204:
<specification-part> = [ <use-stmt> ]... [ <import-stmt> ]... [ <implicit-part> ] [ <declaration-construct> ]...
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Implicit_Part(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
Fortran2003 Rule R205:
<implicit-part> = [ <implicit-part-stmt> ]... <implicit-stmt>
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Implicit_Part_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran2003 Rule R206:
<implicit-part-stmt> = <implicit-stmt> | <parameter-stmt> | <format-stmt> | <entry-stmt>
- class fparser.two.Fortran2003.Declaration_Construct(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R207:
declaration-construct is derived-type-def or entry-stmt or enum-def or format-stmt or interface-block or parameter-stmt or procedure-declaration-stmt or specification-stmt or type-declaration-stmt or stmt-function-stmt
Note, stmt-function-stmt is not currently matched.
- class fparser.two.Fortran2003.Execution_Part(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
Fortran2003 Rule R208:
<execution-part> = <executable-construct>
[ <execution-part-construct> ]…<execution-part> shall not contain <end-function-stmt>, <end-program-stmt>, <end-subroutine-stmt>
- static match(string)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Execution_Part_Construct(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<execution-part-construct> = <executable-construct> | <format-stmt> | <entry-stmt> | <data-stmt>
- class fparser.two.Fortran2003.Execution_Part_Construct_C201(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Base class for Fortran 2003 syntax rules.
All Base classes have the following attributes:
self.string - original argument to construct a class instance, its type is either str or FortranReaderBase. self.item - Line instance (holds label) or None.
- Parameters:
cls (type) – the class of object to create.
string (str |
fparser.common.readfortran.FortranReaderBase
) – (source of) Fortran string to parse.parent_cls (type) – the parent class of this object.
- class fparser.two.Fortran2003.Internal_Subprogram_Part(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<internal-subprogram-part> = <contains-stmt> <internal-subprogram> [ <internal-subprogram> ]...
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Internal_Subprogram(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<internal-subprogram> = <function-subprogram> | <subroutine-subprogram>
- class fparser.two.Fortran2003.Specification_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<specification-stmt> = <access-stmt> | <allocatable-stmt> | <asynchronous-stmt> | <bind-stmt> | <common-stmt> | <data-stmt> | <dimension-stmt> | <equivalence-stmt> | <external-stmt> | <intent-stmt> | <intrinsic-stmt> | <namelist-stmt> | <optional-stmt> | <pointer-stmt> | <protected-stmt> | <save-stmt> | <target-stmt> | <volatile-stmt> | <value-stmt>
- class fparser.two.Fortran2003.Executable_Construct(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R213:
executable-construct is action-stmt or associate-construct or case-construct or do-construct or forall-construct or if-construct or select-type-construct or where-construct
- class fparser.two.Fortran2003.Executable_Construct_C201(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Base class for Fortran 2003 syntax rules.
All Base classes have the following attributes:
self.string - original argument to construct a class instance, its type is either str or FortranReaderBase. self.item - Line instance (holds label) or None.
- Parameters:
cls (type) – the class of object to create.
string (str |
fparser.common.readfortran.FortranReaderBase
) – (source of) Fortran string to parse.parent_cls (type) – the parent class of this object.
- class fparser.two.Fortran2003.Action_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<action-stmt> = <allocate-stmt> | <assignment-stmt> | <backspace-stmt> | <call-stmt> | <close-stmt> | <continue-stmt> | <cycle-stmt> | <deallocate-stmt> | <endfile-stmt> | <end-function-stmt> | <end-program-stmt> | <end-subroutine-stmt> | <exit-stmt> | <flush-stmt> | <forall-stmt> | <goto-stmt> | <if-stmt> | <inquire-stmt> | <nullify-stmt> | <open-stmt> | <pointer-assignment-stmt> | <print-stmt> | <read-stmt> | <return-stmt> | <rewind-stmt> | <stop-stmt> | <wait-stmt> | <where-stmt> | <write-stmt> | <arithmetic-if-stmt> | <computed-goto-stmt>
- class fparser.two.Fortran2003.Action_Stmt_C201(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<action-stmt-c201> = <action-stmt>
C201 is applied.
- class fparser.two.Fortran2003.Action_Stmt_C802(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<action-stmt-c802> = <action-stmt>
C802 is applied.
- class fparser.two.Fortran2003.Action_Stmt_C824(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<action-stmt-c824> = <action-stmt>
C824 is applied.
- class fparser.two.Fortran2003.Keyword(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<keyword> = <name>
- class fparser.two.Fortran2003.Name(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StringBase
Fortran 2003 rule R304:
name is letter [ alphanumeric_character ]...
- class fparser.two.Fortran2003.Constant(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<constant> = <literal-constant> | <named-constant>
- class fparser.two.Fortran2003.Literal_Constant(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<literal-constant> = <int-literal-constant> | <real-literal-constant> | <complex-literal-constant> | <logical-literal-constant> | <char-literal-constant> | <boz-literal-constant>
- class fparser.two.Fortran2003.Named_Constant(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
- ::
<named-constant> = <name>
- class fparser.two.Fortran2003.Int_Constant(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<int-constant> = <constant>
- class fparser.two.Fortran2003.Char_Constant(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<char-constant> = <constant>
- class fparser.two.Fortran2003.Defined_Operator(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R311:
defined-operator is defined-unary-op or defined-binary-op or extended-intrinsic-op
Note, defined-operator is defined in pattern_tools.py so could be called directly via a stringbase match. However, the defined unary and binary op rules have constraints which would not be checked if we did this.
Note, whilst we subclass for both Defined Unary and Binary ops, the match is the same so we will only ever match with the first (so the second is not really necessary here). This is OK from a parsing point of view as they both return a Defined_Op class, so are identical from the parsers point of view.
- class fparser.two.Fortran2003.Extended_Intrinsic_Op(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StringBase
Fortran 2003 rule R312:
extended-intrinsic-op is intrinsic-operator
Note, extended-intrinsic-op is only ever used by R311 and is defined in pattern_tools.py so could be matched directly in the Defined_Operator class (by changing it to STRINGBase and moving the match in this class into the Defined_Operator class). This would mean that this class would not be required. However, the parse tree would then not have the concept of an Extended_Intrinsic_Op which might be useful for code manipulation tools.
- class fparser.two.Fortran2003.Label(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StringBase
<label> = <digit> [ <digit> [ <digit> [ <digit> [ <digit> ] ] ] ]
Has attributes:
string : str
- class fparser.two.Fortran2003.Type_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
- ::
- <type-spec> = <intrinsic-type-spec>
- <derived-type-spec>
- class fparser.two.Fortran2003.Type_Param_Value(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StringBase
Fortran 2003 Rule 402:
<type-param-value> = <scalar-int-expr> | * | :
- class fparser.two.Fortran2003.Intrinsic_Type_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.WORDClsBase
<intrinsic-type-spec> = INTEGER [ <kind-selector> ] | REAL [ <kind-selector> ] | DOUBLE COMPLEX | COMPLEX [ <kind-selector> ] | CHARACTER [ <char-selector> ] | LOGICAL [ <kind-selector> ] Extensions: | DOUBLE PRECISION | BYTE
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Kind_Selector(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R404:
kind-selector is ( [ KIND = ] scalar-int-initialization-expr ) A non-standard extension is also supported here: | * char-length
There is an associated constraint that we can’t enforce in fparser:
C404 (R404) The value of scalar-int-initialization-expr shall be nonnegative and shall specify a representation method that exists on the processor.
- static match(string)[source]
Implements the matching for a Kind_Selector.
- Parameters:
string (str) – a string containing the code to match
- Returns:
None if there is no match, otherwise a tuple of size 3 containing a ‘(’, a single list which contains an instance of classes that have matched and a ‘)’, or a tuple of size 2 containing a ‘*’ and an instance of classes that have matched.
- Return type:
NoneType or ( str, [ MatchedClasses ], str) or ( str,
fparser.two.Fortran2003.Char_Length
)- Raises:
InternalError – if None is passed instead of a string. The parent rule should not pass None and the logic in this routine relies on a valid string.
InternalError – if the string passed is <=1 characters long. The parent rule passing this string should ensure the string is at least 2 characters long and the logic in this routine relies on this. The reason there is a minimum of two is that the pattern ‘*n’ where ‘n’ is a number is the smallest valid pattern. The other valid pattern must have at least a name with one character surrounded by brackets e.g. ‘(x)’ so should be at least 3 characters long.
- class fparser.two.Fortran2003.Signed_Int_Literal_Constant(string, parent_cls=None)[source]
Bases:
fparser.two.utils.NumberBase
- ::
<signed-int-literal-constant> = [ <sign> ] <int-literal-constant>
- class fparser.two.Fortran2003.Int_Literal_Constant(string, parent_cls=None)[source]
Bases:
fparser.two.utils.NumberBase
- ::
<int-literal-constant> = <digit-string> [ _ <kind-param> ]
- class fparser.two.Fortran2003.Digit_String(string, parent_cls=None)[source]
Bases:
fparser.two.utils.NumberBase
<digit-string> = <digit> [ <digit> ]...
- class fparser.two.Fortran2003.Boz_Literal_Constant(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<boz-literal-constant> = <binary-constant> | <octal-constant> | <hex-constant>
- class fparser.two.Fortran2003.Binary_Constant(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
<binary-constant> = B ' <digit> [ <digit> ]... ' | B " <digit> [ <digit> ]... "
- static match(string)[source]
Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.
The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:
from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)
- Parameters:
pattern (list, tuple, str or an re expression) – the pattern to match
string (str) – the string to match with the pattern
- Returns:
None if there is no match, or a tuple containing the matched string in upper case.
- Return type:
NoneType or ( str )
- class fparser.two.Fortran2003.Octal_Constant(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
<octal-constant> = O ' <digit> [ <digit> ]... ' | O " <digit> [ <digit> ]... "
- static match(string)[source]
Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.
The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:
from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)
- Parameters:
pattern (list, tuple, str or an re expression) – the pattern to match
string (str) – the string to match with the pattern
- Returns:
None if there is no match, or a tuple containing the matched string in upper case.
- Return type:
NoneType or ( str )
- class fparser.two.Fortran2003.Hex_Constant(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
<hex-constant> = Z ' <digit> [ <digit> ]... ' | Z " <digit> [ <digit> ]... "
- static match(string)[source]
Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.
The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:
from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)
- Parameters:
pattern (list, tuple, str or an re expression) – the pattern to match
string (str) – the string to match with the pattern
- Returns:
None if there is no match, or a tuple containing the matched string in upper case.
- Return type:
NoneType or ( str )
- class fparser.two.Fortran2003.Signed_Real_Literal_Constant(string, parent_cls=None)[source]
Bases:
fparser.two.utils.NumberBase
<signed-real-literal-constant> = [ <sign> ] <real-literal-constant>
- class fparser.two.Fortran2003.Real_Literal_Constant(string, parent_cls=None)[source]
Bases:
fparser.two.utils.NumberBase
- class fparser.two.Fortran2003.Complex_Literal_Constant(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<complex-literal-constant> = ( <real-part>, <imag-part> )
- class fparser.two.Fortran2003.Real_Part(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<real-part> = <signed-int-literal-constant> | <signed-real-literal-constant> | <named-constant>
- class fparser.two.Fortran2003.Imag_Part(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<imag-part> = <real-part>
- class fparser.two.Fortran2003.Char_Selector(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<char-selector> = <length-selector> | ( LEN = <type-param-value> , KIND = <scalar-int-initialization-expr> ) | ( <type-param-value> , [ KIND = ] <scalar-int-initialization-expr> ) | ( KIND = <scalar-int-initialization-expr> [ , LEN = <type-param-value> ] )
- class fparser.two.Fortran2003.Length_Selector(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<length -selector> = ( [ LEN = ] <type-param-value> ) | * <char-length> [ , ]
- class fparser.two.Fortran2003.Char_Length(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BracketBase
<char-length> = ( <type-param-value> ) | <scalar-int-literal-constant>
- static match(string)[source]
A generic match method for all types of bracketed expressions.
- Parameters:
brackets (str) – the format of the left and right brackets provided as a string, for example ‘()’
cls – the class to match the content within the brackets :type cls: subclass of
fparser.two.utils.Base
string (str) – the content to match
require_cls (bool) – whether the class and associated content is mandatory (True) or optional (False). The default is True.
- Returns:
None if there is no match, otherwise a tuple with the first and third entries being strings containing the left and right brackets respectively and the second entry being either None or an instance of the class provided as the second argument (cls).
- Return type:
‘NoneType’, ( str, NoneType, str) or ( str, cls, str )
- class fparser.two.Fortran2003.Char_Literal_Constant(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R427:
char-literal-constant is [ kind-param _ ] ' rep-char ' or [ kind-param _ ] " rep-char "
- static match(string)[source]
Implements the matching for a Char_Literal_Constant. For example:
"hello" 'hello' nondefaultcharset_"nondefaultchars"
There is an associated constraint C422: “The value of kind-param shall specify a representation method that exists on the processor.” However, this cannot be validated by fparser so no checks are performed.
- Parameters:
string (str) – a string containing the code to match.
- Returns:
None if there is no match, otherwise a tuple of size 2 containing the character constant and the kind value as strings.
- Return type:
NoneType or (str, NoneType) or (str, str)
- tostr()[source]
- Returns:
this Char_Literal_Constant as a string.
- Return type:
- Raises:
InternalError – if the internal items list variable is not the expected size.
InternalError – if the first element of the internal items list is None or is an empty string.
- class fparser.two.Fortran2003.Logical_Literal_Constant(string, parent_cls=None)[source]
Bases:
fparser.two.utils.NumberBase
<logical-literal-constant> = .TRUE. [ _ <kind-param> ] | .FALSE. [ _ <kind-param> ]
- class fparser.two.Fortran2003.Derived_Type_Def(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<derived-type-def> = <derived-type-stmt> [ <type-param-def-stmt> ]... [ <private-or-sequence> ]... [ <component-part> ] [ <type-bound-procedure-part> ] <end-type-stmt>
- use_names = ['Derived_Type_Stmt', 'Type_Param_Def_Stmt', 'Private_Or_Sequence', 'Component_Part',...[source]
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Derived_Type_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran 2003 rule R430:
derived-type-stmt is TYPE [ [ , type-attr-spec-list ] :: ] type-name [ ( type-param-name-list ) ]
- static match(string)[source]
Implements the matching for a Derived Type Statement.
- Parameters:
string (str) – a string containing the code to match
- Returns:
None if there is no match, otherwise a tuple of size 3 containing an Attribute_Spec_List (or None if there isn’t one), the name of the type (in a Name class) and a Parameter_Name_List (or None is there isn’t one).
- Return type:
( Type_Attr_Spec_List or None, Name, Type_Param_Name_List or None ) or None
- tostr()[source]
- Returns:
this derived type statement as a string
- Return type:
- Raises:
InternalError – if items array is not the expected size
InternalError – if items array[1] has no content
- class fparser.two.Fortran2003.Type_Name(string, parent_cls=None)[source]
Bases:
Name
<type-name> = <name> <type-name> shall not be DOUBLEPRECISION or the name of intrinsic type
- class fparser.two.Fortran2003.Type_Attr_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<type-attr-spec> = <access-spec> | EXTENDS ( <parent-type-name> ) | ABSTRACT | BIND (C)
- class fparser.two.Fortran2003.Private_Or_Sequence(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<private-or-sequence> = <private-components-stmt> | <sequence-stmt>
- class fparser.two.Fortran2003.End_Type_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.EndStmtBase
<end-type-stmt> = END TYPE [ <type-name> ]
- static match(string)[source]
Attempts to match the supplied string as a form of ‘END xxx’ statement.
- Parameters:
stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.
stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).
string (str) – the string to attempt to match.
require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.
- Returns:
2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.
- Return type:
Optional[ Tuple[Optional[str],
Optional[
fparser.two.Fortran2003.Name
]]]
- class fparser.two.Fortran2003.Sequence_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
<sequence-stmt> = SEQUENCE
- static match(string)[source]
Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.
The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:
from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)
- Parameters:
pattern (list, tuple, str or an re expression) – the pattern to match
string (str) – the string to match with the pattern
- Returns:
None if there is no match, or a tuple containing the matched string in upper case.
- Return type:
NoneType or ( str )
- class fparser.two.Fortran2003.Type_Param_Def_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<type-param-def-stmt> = INTEGER [ <kind-selector> ] , <type-param-attr-spec> :: <type-param-decl-list>
- class fparser.two.Fortran2003.Type_Param_Decl(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BinaryOpBase
- ::
- <type-param-decl> = <type-param-name>
[ = <scalar-int-initialization-expr> ]
- static match(string)[source]
Matches the binary-op-base rule.
If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.
If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.
if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.
- Parameters:
lhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the lhs text.op_pattern (str or
fparser.two.pattern_tools.Pattern
) – the pattern to match.rhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the rhs text.string (str) – the string to match with the pattern and lhs and rhs rules.
right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).
exclude_op_pattern (
fparser.two.pattern_tools.Pattern
) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.
- Returns:
a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.
- Return type:
(
fparser.two.utils.Base
, str,fparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.Type_Param_Attr_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
<type-param-attr-spec> = KIND | LEN
- static match(string)[source]
Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.
The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:
from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)
- Parameters:
pattern (list, tuple, str or an re expression) – the pattern to match
string (str) – the string to match with the pattern
- Returns:
None if there is no match, or a tuple containing the matched string in upper case.
- Return type:
NoneType or ( str )
- class fparser.two.Fortran2003.Component_Part(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<component-part> is [ <component-def-stmt> ]...
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Component_Def_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<component-def-stmt> is <data-component-def-stmt> or <proc-component-def-stmt>
- class fparser.two.Fortran2003.Data_Component_Def_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Type_Declaration_StmtBase
Fortran 2003 rule 440:
<data-component-def-stmt> is <declaration-type-spec> [ [ , <component-attr-spec-list> ] :: ] <component-decl-list>
Associated constraints are:
C436 (R440) No component-attr-spec shall appear more than once in a given component-def-stmt. C437 (R440) A component declared with the CLASS keyword shall have the ALLOCATABLE or POINTER attribute. C438 (R440) If the POINTER attribute is not specified for a component, the declaration-type-spec in the component-def-stmt shall be CLASS(*) or shall specify an intrinsic type or a previously defined derived type. C439 (R440) If the POINTER attribute is specified for a component, the declaration-type-spec in the component-def-stmt shall be CLASS(*) or shall specify an intrinsic type or any accessible derived type including the type being defined. C440 (R440) If the POINTER or ALLOCATABLE attribute is specified, each component-array-spec shall be a deferred-shape-spec-list. C441 (R440) If neither the POINTER attribute nor the ALLOCATABLE attribute is specified, each component-array-spec shall be an explicit-shape-spec-list. C443 (R440) A component shall not have both the ALLOCATABLE and the POINTER attribute. C446 (R440) If component-initialization appears, a double-colon separator shall appear before the component-decl-list. C447 (R440) If => appears in component-initialization, POINTER shall appear in the component-attr-spec-list. If = appears in component-initialization, POINTER or ALLOCATABLE shall not appear in the component-attr-spec-list.
C436-C441, C443, C446-C447 are currently not checked - issue #258.
- class fparser.two.Fortran2003.Dimension_Component_Attr_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CALLBase
<dimension-component-attr-spec> = DIMENSION ( <component-array-spec> )
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Component_Attr_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
<component-attr-spec> = POINTER | DIMENSION ( <component-array-spec> ) | ALLOCATABLE | <access-spec>
- classmethod match(string)[source]
Implements the matching for component attribute specifications.
Note that this is implemented as a classmethod (not a staticmethod), using attribute keywords from the list provided as a class property. This allows expanding this list for Fortran 2008 without having to reimplement the matching.
- class fparser.two.Fortran2003.Component_Decl(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<component-decl> = <component-name> [ ( <component-array-spec> ) ] [ * <char-length> ] [ <component-initialization> ]
- class fparser.two.Fortran2003.Component_Array_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<component-array-spec> = <explicit-shape-spec-list> | <deferred-shape-spec-list>
- class fparser.two.Fortran2003.Component_Initialization(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<component-initialization> = = <initialization-expr> | => <null-init>
- class fparser.two.Fortran2003.Proc_Component_Def_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<proc-component-def-stmt> is PROCEDURE ( [ <proc-interface> ] ) , <proc-component-attr-spec-list> :: <proc-decl-list>
where:
proc-component-attr-spec is POINTER or PASS [ (arg-name) ] or NOPASS or access-spec
The standard specifies the following constraints:
C448 The same proc-component-attr-spec shall not appear more than once in a given proc-component-def-stmt. Not checked by fparser - #232. C449 POINTER shall appear in each proc-component-attr-spec-list. C450 If the procedure pointer component has an implicit interface or has no arguments, NOPASS shall be specified. Not checked by fparser - #232. C451 If PASS (arg-name) appears, the interface shall have a dummy argument named arg-name. Not checked by fparser - #232. C452 PASS and NOPASS shall not both appear in the same proc-component-attr-spec-list. Not checked by fparser - #232.
- static match(string)[source]
Attempts to match the supplied string with the pattern for a declaration of a procedure part of a component.
- Parameters:
string (str) – the string to test for a match.
- Returns:
None (if no match) or a tuple consisting of the procedure interface, the list of attributes and a list of procedure names or None.
- Return type:
NoneType or (
fparser.two.Fortran2003.Proc_Interface
,fparser.two.Fortran2003.Proc_Component_Attr_Spec_List
,fparser.two.Fortran2003.Proc_Decl_List
)
- class fparser.two.Fortran2003.Proc_Component_PASS_Arg_Name(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CALLBase
<proc-component-PASS-arg-name> = PASS ( <arg-name> )
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Proc_Component_Attr_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
<proc-component-attr-spec> = POINTER | PASS [ ( <arg-name> ) ] | NOPASS | <access-spec>
- static match(string)[source]
Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.
The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:
from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)
- Parameters:
pattern (list, tuple, str or an re expression) – the pattern to match
string (str) – the string to match with the pattern
- Returns:
None if there is no match, or a tuple containing the matched string in upper case.
- Return type:
NoneType or ( str )
- class fparser.two.Fortran2003.Private_Components_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
Fortran2003 Rule R447:
<private-components-stmt> = PRIVATE
Specifies support for private components statement within a derived type.
- class fparser.two.Fortran2003.Type_Bound_Procedure_Part(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
Fortran 2003 rule R448.
Specifies the type-bound procedure part of a derived type:
type-bound-procedure-part is contains-stmt [ binding-private-stmt ] proc-binding-stmt [ proc-binding-stmt ]...
- static match(reader)[source]
- Parameters:
reader (
fparser.common.readfortran.FortranReaderBase
) – the Fortran reader containing the line(s) of code that we are trying to match- Returns:
code block containing instances of the classes that match the syntax of the type-bound procedure part of a derived type.
- Return type:
([Contains_Stmt, Specific_Binding, str, Name, Name]) or None
- class fparser.two.Fortran2003.Binding_Private_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.STRINGBase
Fortran2003 Rule R449:
<binding-private-stmt> = PRIVATE
For binding private statement within the type-bound procedure part of a derived type.
- class fparser.two.Fortran2003.Proc_Binding_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran2003 Rule R450:
<proc-binding-stmt> = <specific-binding> | <generic-binding> | <final-binding>
Specifies the procedure binding for the type-bound procedures within a derived type.
- class fparser.two.Fortran2003.Specific_Binding(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran2003 Rule R451:
<specific-binding> = PROCEDURE [ ( <interface-name> ) ] [ [ , <binding-attr-list> ] :: ] <binding-name> [ => <procedure-name> ]
Specifies the syntax of specific binding for a type-bound procedure within a derived type.
The following are associated constraints:
C456 (R451) If => procedure-name appears, the double-colon separator shall appear. C457 (R451) If => procedure-name appears, interface-name shall not appear. C458 (R451) The procedure-name shall be the name of an accessible module procedure or an external procedure that has an explicit interface. Note, this is not checked by fparser.
- static match(string)[source]
- Parameters:
string (str) – Fortran code to check for a match
- Returns:
5-tuple containing strings and instances of the classes describing a specific type-bound procedure (optional interface name, optional binding attribute list, optional double colon delimiter, mandatory binding name and optional procedure name)
- Return type:
5-tuple of objects (1 mandatory and 4 optional)
- class fparser.two.Fortran2003.Binding_PASS_Arg_Name(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CALLBase
Fortran 2003 helper rule (for R453):
<binding-PASS-arg-name> = PASS ( <arg-name> )
Specifies the syntax of passed-object dummy argument for a specific type-bound procedure.
- class fparser.two.Fortran2003.Generic_Binding(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran2003 Rule R452:
<generic-binding> = GENERIC [ , <access-spec> ] :: <generic-spec> => <binding-name-list>
Specifies the syntax of generic binding for a type-bound procedure within a derived type.
- static match(string)[source]
- Parameters:
string (str) – Fortran code to check for a match
- Returns:
3-tuple containing strings and instances of the classes describing a generic type-bound procedure (optional access specifier, mandatory generic identifier and mandatory binding name list)
- Return type:
3-tuple of objects (2 mandatory and 1 optional)
- class fparser.two.Fortran2003.Binding_Attr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
Fortran2003 Rule R453:
<binding-attr> = PASS [ ( <arg-name> ) ] | NOPASS | NON_OVERRIDABLE | DEFERRED | <access-spec>
Specifies syntax of allowed binding attributes for a specific type-bound procedure binding.
- class fparser.two.Fortran2003.Final_Binding(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
Fortran2003 Rule R454:
<final-binding> = FINAL [ :: ] <final-subroutine-name-list>
Specifies the syntax of final binding for a type-bound procedure within a derived type.
- class fparser.two.Fortran2003.Derived_Type_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CallBase
<derived-type-spec> = <type-name> [ ( <type-param-spec-list> ) ]
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Type_Param_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.KeywordValueBase
<type-param-spec> = [ <keyword> = ] <type-param-value>
- static match(string)[source]
Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.
- Parameters:
lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.
rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.
string (str) – text to be matched.
require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.
upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.
- Returns:
instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.
- Return type:
2-tuple of objects or NoneType
- class fparser.two.Fortran2003.Structure_Constructor(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CallBase
<structure-constructor> = <derived-type-spec> ( [ <component-spec-list> ] )
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Component_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.KeywordValueBase
<component-spec> = [ <keyword> = ] <component-data-source>
- static match(string)[source]
Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.
- Parameters:
lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.
rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.
string (str) – text to be matched.
require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.
upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.
- Returns:
instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.
- Return type:
2-tuple of objects or NoneType
- class fparser.two.Fortran2003.Component_Data_Source(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<component-data-source> = <expr> | <data-target> | <proc-target>
- class fparser.two.Fortran2003.Enum_Def(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<enum-def> = <enum-def-stmt> <enumerator-def-stmt> [ <enumerator-def-stmt> ]... <end-enum-stmt>
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Enum_Def_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<enum-def-stmt> = ENUM, BIND(C)
- class fparser.two.Fortran2003.Enumerator_Def_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
<enumerator-def-stmt> = ENUMERATOR [ :: ] <enumerator-list>
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Enumerator(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BinaryOpBase
<enumerator> = <named-constant> [ = <scalar-int-initialization-expr> ]
- static match(string)[source]
Matches the binary-op-base rule.
If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.
If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.
if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.
- Parameters:
lhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the lhs text.op_pattern (str or
fparser.two.pattern_tools.Pattern
) – the pattern to match.rhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the rhs text.string (str) – the string to match with the pattern and lhs and rhs rules.
right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).
exclude_op_pattern (
fparser.two.pattern_tools.Pattern
) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.
- Returns:
a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.
- Return type:
(
fparser.two.utils.Base
, str,fparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.End_Enum_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.EndStmtBase
<end-enum-stmt> = END ENUM
- static match(string)[source]
Attempts to match the supplied string as a form of ‘END xxx’ statement.
- Parameters:
stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.
stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).
string (str) – the string to attempt to match.
require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.
- Returns:
2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.
- Return type:
Optional[ Tuple[Optional[str],
Optional[
fparser.two.Fortran2003.Name
]]]
- class fparser.two.Fortran2003.Array_Constructor(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BracketBase
<array-constructor> = (/ <ac-spec> /) | <left-square-bracket> <ac-spec> <right-square-bracket>
- static match(string)[source]
A generic match method for all types of bracketed expressions.
- Parameters:
brackets (str) – the format of the left and right brackets provided as a string, for example ‘()’
cls – the class to match the content within the brackets :type cls: subclass of
fparser.two.utils.Base
string (str) – the content to match
require_cls (bool) – whether the class and associated content is mandatory (True) or optional (False). The default is True.
- Returns:
None if there is no match, otherwise a tuple with the first and third entries being strings containing the left and right brackets respectively and the second entry being either None or an instance of the class provided as the second argument (cls).
- Return type:
‘NoneType’, ( str, NoneType, str) or ( str, cls, str )
- class fparser.two.Fortran2003.Ac_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<ac-spec> = <type-spec> :: | [ <type-spec> :: ] <ac-value-list>
- class fparser.two.Fortran2003.Ac_Value(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<ac-value> = <expr> | <ac-implied-do>
- class fparser.two.Fortran2003.Ac_Implied_Do(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran2003 rule R470. Describes the form of implicit do loop used within an array constructor:
ac-implied-do is ( ac-value-list , ac-implied-do-control )
Subject to the following constraint:
C497 (R470) The ac-do-variable of an ac-implied-do that is in another ac-implied-do shall not appear as the ac-do-variable of the containing ac-implied-do.
C497 is currently not checked - issue #257.
- class fparser.two.Fortran2003.Ac_Implied_Do_Control(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran2003 rule R471. Specifies the syntax for the control of an implicit loop within an array constructor:
ac-implied-do-control is ac-do-variable = scalar-int-expr, scalar-int-expr [ , scalar-int-expr ]
where (R472) ac-do-variable is scalar-int-variable
- static match(string)[source]
Attempts to match the supplied string with the pattern for implied-do control.
- Parameters:
string (str) – the string to test for a match.
- Returns:
None if there is no match or a 2-tuple containing the do-variable name and the list of integer expressions (for start, stop [, step]).
- Return type:
NoneType or (
fparser.two.Fortran2003.Ac_Do_Variable
, list)
- class fparser.two.Fortran2003.Ac_Do_Variable(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran2003 rule R472. Specifies the permitted form of an implicit do-loop variable within an array constructor:
ac-do-variable is scalar-int-variable ac-do-variable shall be a named variable
Subject to the following constraint:
C493 (R472) ac-do-variable shall be a named variable.
C493 is currently not checked - issue #257.
- class fparser.two.Fortran2003.Type_Declaration_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Type_Declaration_StmtBase
Fortran 2003 rule 501:
type-declaration-stmt is declaration-type-spec [ [ , attr-spec ]... :: ] entity-decl-list
Associated constraints are:
C507 (R501) The same attr-spec shall not appear more than once in a given type-declaration-stmt. C509 (R501) An entity declared with the CLASS keyword shall be a dummy argument or have the ALLOCATABLE or POINTER attribute. C510 (R501) An array that has the POINTER or ALLOCATABLE attribute shall be specified with an array-spec that is a deferred-shape-spec-list. C511 (R501) An array-spec for an object-name that is a function result that does not have the ALLOCATABLE or POINTER attribute shall be an explicit-shape-spec-list. C512 (R501) If the POINTER attribute is specified, the ALLOCATABLE, TARGET, EXTERNAL, or INTRINSIC attribute shall not be specified. C513 (R501) If the TARGET attribute is specified, the POINTER, EXTERNAL, INTRINSIC, or PARAMETER attribute shall not be specified. C514 (R501) The PARAMETER attribute shall not be specified for a dummy argument, a pointer, an allocatable entity, a function, or an object in a common block. C515 (R501) The INTENT, VALUE, and OPTIONAL attributes may be specified only for dummy arguments. C516 (R501) The INTENT attribute shall not be specified for a dummy procedure without the POINTER attribute. C517 (R501) The SAVE attribute shall not be specified for an object that is in a common block, a dummy argument, a procedure, a function result, an automatic data object, or an object with the PARAMETER attribute. C519 (R501) An entity in an entity-decl-list shall not have the EXTERNAL or INTRINSIC attribute specified unless it is a function. C522 (R501) The initialization shall appear if the statement contains a PARAMETER attribute. C523 (R501) If initialization appears, a double-colon separator shall appear before the entity-decl-list. C526 (R501) If the VOLATILE attribute is specified, the PARAMETER, INTRINSIC, EXTERNAL, or INTENT(IN) attribute shall not be specified. C527 (R501) If the VALUE attribute is specified, the PARAMETER, EXTERNAL, POINTER, ALLOCATABLE, DIMENSION, VOLATILE, INTENT(INOUT), or INTENT(OUT) attribute shall not be specified. C528 (R501) If the VALUE attribute is specified, the length type parameter values shall be omitted or specified by initialization expressions. C529 (R501) The VALUE attribute shall not be specified for a dummy procedure. C530 (R501) The ALLOCATABLE, POINTER, or OPTIONAL attribute shall not be specified for adummy argument of a procedure that has aproc-language-binding-spec. C532 (R501) If a language-binding-spec is specified, the entity declared shall be an interoperable variable. C533 (R501) If a language-binding-spec with a NAME= specifier appears, the entity-decl-list shall consist of a single entity-decl. C534 (R503) The PROTECTED attribute is permitted only in the specification part of a module. C535 (R501) The PROTECTED attribute is permitted only for a procedure pointer or named variable that is not in a common block. C536 (R501) If the PROTECTED attribute is specified, the EXTERNAL, INTRINSIC, or PARAMETER attribute shall not be specified.
C507, C509-C517, C519, C522-C523, C526-C530, C532-C533, C535-C536 are currently not checked - issue #259.
- static get_attr_spec_list_cls()[source]
Return the type used to match the attr-spec-list
This method allows to overwrite the type used in
match()
in derived classes (e.g.,fparser.two.Fortran2008.Type_Declaration_Stmt
).This cannot be implemented as an attribute because the relevant type
Attr_Spec_List
is auto-generated at the end of the file using theuse_names
property of the class.
- static add_to_symbol_table(result)[source]
Capture the declared symbols in the symbol table of the current scoping region
- Parameters:
result (NoneType or (Declaration_Type_Spec, Attr_Spec_List or NoneType, Entity_Decl_List)) – the declared type, attributes and entities or None
- classmethod match(string)[source]
Attempts to match the supplied string as a type declaration. If the match is successful the declared symbols are added to the symbol table of the current scope (if there is one).
Note that this is implemented as a class method to allow parameterizing the type used to match attr-spec-list via
get_attr_spec_list_cls()
.- Parameters:
string (str) – the string to match.
- Returns:
3-tuple containing the matched declaration.
- Return type:
(Declaration_Type_Spec, Attr_Spec_List or NoneType, Entity_Decl_List)
- class fparser.two.Fortran2003.Declaration_Type_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<declaration-type-spec> = <intrinsic-type-spec> | TYPE ( <derived-type-spec> ) | CLASS ( <derived-type-spec> ) | CLASS ( * )
- static match(string)[source]
Implements the matching of a declaration type specification.
- Parameters:
string (str) – the reader or string to match as a declaration type specification.
- Returns:
A tuple of size 2 containing a string with the value ‘TYPE’ or ‘CLASS’ and a ‘Derived_Type_Spec’ instance if there is a match or None if not.
- Return type:
Optional[Tuple[Str, py:class:fparser.two.Fortran2003.Derived_Type_Spec]
- class fparser.two.Fortran2003.Dimension_Attr_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CALLBase
<dimension-attr-spec> = DIMENSION ( <array-spec> )
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Intent_Attr_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CALLBase
<intent-attr-spec> = INTENT ( <intent-spec> )
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Attr_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
<attr-spec> = <access-spec> | ALLOCATABLE | ASYNCHRONOUS | DIMENSION ( <array-spec> ) | EXTERNAL | INTENT ( <intent-spec> ) | INTRINSIC | <language-binding-spec> | OPTIONAL | PARAMETER | POINTER | PROTECTED | SAVE | TARGET | VALUE | VOLATILE
- subclass_names = ['Access_Spec', 'Language_Binding_Spec', 'Dimension_Attr_Spec', 'Intent_Attr_Spec'][source]
- static match(string)[source]
Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.
The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:
from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)
- Parameters:
pattern (list, tuple, str or an re expression) – the pattern to match
string (str) – the string to match with the pattern
- Returns:
None if there is no match, or a tuple containing the matched string in upper case.
- Return type:
NoneType or ( str )
- class fparser.two.Fortran2003.Entity_Decl(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<entity-decl> = <object-name> [ ( <array-spec> ) ] [ * <char-length> ] [ <initialization> ] | <function-name> [ * <char-length> ]
- class fparser.two.Fortran2003.Object_Name(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<object-name> = <name>
- class fparser.two.Fortran2003.Initialization(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<initialization> = = <initialization-expr> | => <null-init>
- class fparser.two.Fortran2003.Null_Init(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
null-init is function-reference
where:
function-reference shall be a reference to the NULL intrinsic function with no arguments.
- static match(string)[source]
Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.
The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:
from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)
- Parameters:
pattern (list, tuple, str or an re expression) – the pattern to match
string (str) – the string to match with the pattern
- Returns:
None if there is no match, or a tuple containing the matched string in upper case.
- Return type:
NoneType or ( str )
- class fparser.two.Fortran2003.Access_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
Fortran2003 Rule R508:
<access-spec> = PUBLIC | PRIVATE
- static match(string)[source]
Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.
The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:
from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)
- Parameters:
pattern (list, tuple, str or an re expression) – the pattern to match
string (str) – the string to match with the pattern
- Returns:
None if there is no match, or a tuple containing the matched string in upper case.
- Return type:
NoneType or ( str )
- class fparser.two.Fortran2003.Language_Binding_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran2003 Rule R509:
<language-binding-spec> = BIND ( C [ , NAME = <scalar-char-initialization-expr> ] )
- class fparser.two.Fortran2003.Array_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran2003 Rule R510:
<array-spec> = <explicit-shape-spec-list> | <assumed-shape-spec-list> | <deferred-shape-spec-list> | <assumed-size-spec>
- class fparser.two.Fortran2003.Explicit_Shape_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.SeparatorBase
<explicit-shape-spec> = [ <lower-bound> : ] <upper-bound>
- class fparser.two.Fortran2003.Lower_Bound(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<lower-bound> = <specification-expr>
- class fparser.two.Fortran2003.Upper_Bound(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<upper-bound> = <specification-expr>
- class fparser.two.Fortran2003.Assumed_Shape_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.SeparatorBase
Fortran2003 Rule R514:
<assumed-shape-spec> = [ <lower-bound> ] :
- class fparser.two.Fortran2003.Deferred_Shape_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.SeparatorBase
Fortran2003 Rule R515:
<deferred_shape_spec> = :
- class fparser.two.Fortran2003.Assumed_Size_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran2003 Rule R516:
<assumed-size-spec> = [ <explicit-shape-spec-list> , ] [ <lower-bound> : ] *
- class fparser.two.Fortran2003.Intent_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
<intent-spec> = IN | OUT | INOUT
- static match(string)[source]
Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.
The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:
from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)
- Parameters:
pattern (list, tuple, str or an re expression) – the pattern to match
string (str) – the string to match with the pattern
- Returns:
None if there is no match, or a tuple containing the matched string in upper case.
- Return type:
NoneType or ( str )
- class fparser.two.Fortran2003.Access_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
Fortran2003 Rule R518:
<access-stmt> = <access-spec> [ [ :: ] <access-id-list> ]
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Access_Id(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran2003 Rule R519:
<access-id> = <use-name> | <generic-spec>
- class fparser.two.Fortran2003.Object_Name_Deferred_Shape_Spec_List_Item(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CallBase
<..> = <object-name> [ ( <deferred-shape-spec-list> ) ]
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Allocatable_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
Fortran2003 Rule R520:
<allocateble-stmt> = ALLOCATABLE [ :: ] <object-name> [ ( <deferred-shape-spec-list> ) ] [ , <object-name> [ ( <deferred-shape-spec-list> ) ] ]...
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Asynchronous_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
Fortran2003 Rule R521:
<asynchronous-stmt> = ASYNCHRONOUS [ :: ] <object-name-list>
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Bind_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran2003 Rule R522:
<bind-stmt> = <language-binding-spec> [ :: ] <bind-entity-list>
- class fparser.two.Fortran2003.Bind_Entity(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BracketBase
<bind-entity> = <entity-name> | / <common-block-name> /
- static match(string)[source]
A generic match method for all types of bracketed expressions.
- Parameters:
brackets (str) – the format of the left and right brackets provided as a string, for example ‘()’
cls – the class to match the content within the brackets :type cls: subclass of
fparser.two.utils.Base
string (str) – the content to match
require_cls (bool) – whether the class and associated content is mandatory (True) or optional (False). The default is True.
- Returns:
None if there is no match, otherwise a tuple with the first and third entries being strings containing the left and right brackets respectively and the second entry being either None or an instance of the class provided as the second argument (cls).
- Return type:
‘NoneType’, ( str, NoneType, str) or ( str, cls, str )
- class fparser.two.Fortran2003.Data_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran 2003 Rule R524:
<data-stmt> = DATA <data-stmt-set> [ [ , ] <data-stmt-set> ]...
- class fparser.two.Fortran2003.Data_Stmt_Set(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran2003 Rule R525:
<data-stmt-set> = <data-stmt-object-list> / <data-stmt-value-list> /
- class fparser.two.Fortran2003.Data_Stmt_Object(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 Rule R526:
<data-stmt-object> = <variable> | <data-implied-do>
- class fparser.two.Fortran2003.Data_Implied_Do(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 Rule R527:
<data-implied-do> = ( <data-i-do-object-list> , <data-i-do-variable> = <scalar-int-expr > , <scalar-int-expr> [ , <scalar-int-expr> ] )
- class fparser.two.Fortran2003.Data_I_Do_Object(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<data-i-do-object> = <array-element> | <scalar-structure-component> | <data-implied-do>
- class fparser.two.Fortran2003.Data_I_Do_Variable(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<data-i-do-variable> = <scalar-int-variable>
- class fparser.two.Fortran2003.Data_Stmt_Value(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<data-stmt-value> = [ <data-stmt-repeat> * ] <data-stmt-constant>
- class fparser.two.Fortran2003.Data_Stmt_Repeat(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<data-stmt-repeat> = <scalar-int-constant> | <scalar-int-constant-subobject>
- class fparser.two.Fortran2003.Data_Stmt_Constant(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 Rule R532:
<data-stmt-constant> = <scalar-constant> | <scalar-constant-subobject> | <signed-int-literal-constant> | <signed-real-literal-constant> | <null-init> | <structure-constructor>
- class fparser.two.Fortran2003.Int_Constant_Subobject(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 Rule R533:
<int-constant-subobject> = <constant-subobject>
- class fparser.two.Fortran2003.Constant_Subobject(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 Rule R534:
<constant-subobject> = <designator>
- class fparser.two.Fortran2003.Dimension_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran 2003 Rule R535:
<dimension-stmt> = DIMENSION [ :: ] <array-name> ( <array-spec> ) [ , <array-name> ( <array-spec> ) ]...
- class fparser.two.Fortran2003.Intent_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<intent-stmt> = INTENT ( <intent-spec> ) [ :: ] <dummy-arg-name-list>
- class fparser.two.Fortran2003.Optional_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
<optional-stmt> = OPTIONAL [ :: ] <dummy-arg-name-list>
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Parameter_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.CALLBase
<parameter-stmt> = PARAMETER ( <named-constant-def-list> )
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Named_Constant_Def(string, parent_cls=None)[source]
Bases:
fparser.two.utils.KeywordValueBase
<named-constant-def> = <named-constant> = <initialization-expr>
- static match(string)[source]
Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.
- Parameters:
lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.
rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.
string (str) – text to be matched.
require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.
upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.
- Returns:
instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.
- Return type:
2-tuple of objects or NoneType
- class fparser.two.Fortran2003.Cray_Pointer_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
cray-pointer-stmt is POINTER cray-pointer-decl-list
- static match(string)[source]
Implements the matching for a Cray-pointer statement.
- Parameters:
string (
fparser.common.readfortran.FortranReaderBase
or str) – the reader or string to match as a Cray-pointer statement.- Returns:
a tuple of size 2 containing a string with the name “POINTER” and a cray-pointer-decl-list, if there is a match, or None if there is not.
- Return type:
(str, Cray_Pointer_Decl_List) or None
- class fparser.two.Fortran2003.Cray_Pointer_Decl(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
cray-pointer-decl is ( cray-pointer-name, cray-pointee-decl )
- static match(string)[source]
Implements the matching for a Cray-pointer declaration.
- Parameters:
string (str) – the string to match as a Cray-pointer declaration.
- Returns:
None if there is no match, otherwise a tuple of size 2 containing the name of the pointer as the first argument and either the name of the pointee as the second argument or a Cray-pointee declaration.
- Return type:
None, (Name, Name) or (Name, Cray_Pointee_Decl)
- tostr()[source]
- Returns:
this Cray-pointee declaration as a string
- Return type:
- Raises:
InternalError – if the internal items list variable is not the expected size.
InternalError – if the first element of the internal items list is None or is empty.
InternalError – if the second element of the internal items list is None or is empty.
- class fparser.two.Fortran2003.Cray_Pointee_Decl(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CallBase
cray-pointee-decl is cray-pointee-name ( cray-pointee-array-spec )
- static match(string)[source]
Implements the matching for a Cray-pointee declaration.
- Parameters:
string (str) – the string to match as a Cray-pointee declaration.
- Returns:
None if there is no match, otherwise a tuple of size 2 containing the name of the pointee as the first argument and a Cray-pointee array spec as the second argument.
- Return type:
None or (Name, Cray_Pointee_Array_Spec)
- class fparser.two.Fortran2003.Cray_Pointee_Array_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
cray-pointee-array-spec is explicit-shape-spec-list or assumed-size-spec
The above two forms of declaration are the only ones allowed according to http://pubs.cray.com/content/S-3901/8.6/cray-fortran-reference-manual-s-3901-86/types or https://docs.oracle.com/cd/E19957-01/805-4941/z40000a54ba7/index.html
- class fparser.two.Fortran2003.Pointer_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
<pointer-stmt> = POINTER [ :: ] <pointer-decl-list>
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Pointer_Decl(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CallBase
<pointer-decl> = <object-name> [ ( <deferred-shape-spec-list> ) ] | <proc-entity-name>
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Protected_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
<protected-stmt> = PROTECTED [ :: ] <entity-name-list>
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Save_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
<save-stmt> = SAVE [ [ :: ] <saved-entity-list> ]
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Saved_Entity(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BracketBase
<saved-entity> = <object-name> | <proc-pointer-name> | / <common-block-name> /
- static match(string)[source]
A generic match method for all types of bracketed expressions.
- Parameters:
brackets (str) – the format of the left and right brackets provided as a string, for example ‘()’
cls – the class to match the content within the brackets :type cls: subclass of
fparser.two.utils.Base
string (str) – the content to match
require_cls (bool) – whether the class and associated content is mandatory (True) or optional (False). The default is True.
- Returns:
None if there is no match, otherwise a tuple with the first and third entries being strings containing the left and right brackets respectively and the second entry being either None or an instance of the class provided as the second argument (cls).
- Return type:
‘NoneType’, ( str, NoneType, str) or ( str, cls, str )
- class fparser.two.Fortran2003.Proc_Pointer_Name(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<proc-pointer-name> = <name>
- class fparser.two.Fortran2003.Target_Entity_Decl(string, parent_cls=None)[source]
Bases:
Entity_Decl
<target-entity-decl> = <object-name> [ ( <array-spec> ) ]
- class fparser.two.Fortran2003.Target_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<target-stmt> = TARGET [ :: ] <target-entity-decl-list>
- class fparser.two.Fortran2003.Value_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
<value-stmt> = VALUE [ :: ] <dummy-arg-name-list>
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Volatile_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
<volatile-stmt> = VOLATILE [ :: ] <object-name-list>
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Implicit_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<implicit-stmt> = IMPLICIT <implicit-spec-list> | IMPLICIT NONE
Has attributes:
items : ({'NONE', Implicit_Spec_List},)
- class fparser.two.Fortran2003.Implicit_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CallBase
<implicit-spec> = <declaration-type-spec> ( <letter-spec-list> )
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Letter_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<letter-spec> = <letter> [ - <letter> ]
- class fparser.two.Fortran2003.Namelist_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran 2003 rule R552:
namelist-stmt is NAMELIST / namelist-group-name / namelist-group-object-list [ [,] / namelist-group-name / namelist-group-object-list ] ...
- static match(string)[source]
Implements the matching for a Namelist_Stmt.
- Parameters:
string (str) – a string containing the code to match.
- Returns:
None if there is no match, otherwise a tuple containing 2-tuples with a namelist name and a namelist object list.
- Return type:
Optional[Tuple[Tuple[ fparser.two.Fortran2003.Namelist_Group_Name, fparser.two.Fortran2003.Namelist_Group_Object_List]]]
- class fparser.two.Fortran2003.Namelist_Group_Object(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<namelist-group-object> = <variable-name>
- class fparser.two.Fortran2003.Equivalence_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
<equivalence-stmt> = EQUIVALENCE <equivalence-set-list>
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Equivalence_Set(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<equivalence-set> = ( <equivalence-object> , <equivalence-object-list> )
- class fparser.two.Fortran2003.Equivalence_Object(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<equivalence-object> = <variable-name> | <array-element> | <substring>
- class fparser.two.Fortran2003.Common_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<common-stmt> = COMMON [ / [ <common-block-name> ] / ] <common-block-object-list> [ [ , ] / [ <common-block-name> ] / <common-block-object-list> ]...
- class fparser.two.Fortran2003.Common_Block_Object(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CallBase
<common-block-object> = <variable-name> [ ( <explicit-shape-spec-list> ) ] | <proc-pointer-name>
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Variable(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<variable> = <designator>
- class fparser.two.Fortran2003.Variable_Name(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<variable-name> = <name>
- class fparser.two.Fortran2003.Designator(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R603:
designator is object-name or array-element or array-section or structure-component or substring
- class fparser.two.Fortran2003.Logical_Variable(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<logical-variable> = <variable>
- class fparser.two.Fortran2003.Default_Logical_Variable(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<default-logical-variable> = <variable>
- class fparser.two.Fortran2003.Char_Variable(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<char-variable> = <variable>
- class fparser.two.Fortran2003.Default_Char_Variable(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<default-char-variable> = <variable>
- class fparser.two.Fortran2003.Int_Variable(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<int-variable> = <variable>
- class fparser.two.Fortran2003.Substring(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CallBase
<substring> = <parent-string> ( <substring-range> )
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Parent_String(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<parent-string> = <scalar-variable-name> | <array-element> | <scalar-structure-component> | <scalar-constant>
- class fparser.two.Fortran2003.Substring_Range(string, parent_cls=None)[source]
Bases:
fparser.two.utils.SeparatorBase
<substring-range> = [ <scalar-int-expr> ] : [ <scalar-int-expr> ]
- class fparser.two.Fortran2003.Data_Ref(string, parent_cls=None)[source]
Bases:
fparser.two.utils.SequenceBase
Fortran 2003 Rule R612:
data-ref is part-ref [ % part-ref ] ...
If there is only one part-ref then return a ‘Part_Ref’ object (or another object from a matching sub-rule). If there is more than one part-ref then return a ‘Data_Ref’ object containing the part-ref’s.
- class fparser.two.Fortran2003.Part_Ref(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CallBase
<part-ref> = <part-name> [ ( <section-subscript-list> ) ]
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Structure_Component(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<structure-component> = <data-ref>
- class fparser.two.Fortran2003.Type_Param_Inquiry(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BinaryOpBase
<type-param-inquiry> = <designator> % <type-param-name>
- static match(string)[source]
Matches the binary-op-base rule.
If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.
If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.
if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.
- Parameters:
lhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the lhs text.op_pattern (str or
fparser.two.pattern_tools.Pattern
) – the pattern to match.rhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the rhs text.string (str) – the string to match with the pattern and lhs and rhs rules.
right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).
exclude_op_pattern (
fparser.two.pattern_tools.Pattern
) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.
- Returns:
a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.
- Return type:
(
fparser.two.utils.Base
, str,fparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.Array_Element(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<array-element> = <data-ref>
- class fparser.two.Fortran2003.Array_Section(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CallBase
<array-section> = <data-ref> [ ( <substring-range> ) ]
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Subscript(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<subscript> = <scalar-int-expr>
- class fparser.two.Fortran2003.Section_Subscript(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<section-subscript> = <subscript> | <subscript-triplet> | <vector-subscript>
- class fparser.two.Fortran2003.Subscript_Triplet(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<subscript-triplet> = [ <subscript> ] : [ <subscript> ] [ : <stride> ]
- class fparser.two.Fortran2003.Stride(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<stride> = <scalar-int-expr>
- class fparser.two.Fortran2003.Vector_Subscript(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<vector-subscript> = <int-expr>
- class fparser.two.Fortran2003.Allocate_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran2003 rule R623:
allocate-stmt is ALLOCATE ( [ type-spec :: ] allocation-list [, alloc-opt-list ] )
Subject to the following constraints:
- C622 (R629) Each allocate-object shall be a nonprocedure pointer or an
allocatable variable.
- C623 (R623) If any allocate-object in the statement has a deferred type
parameter, either type-spec or SOURCE= shall appear.
- C624 (R623) If a type-spec appears, it shall specify a type with which
each allocate-object is type compatible.
- C625 (R623) If any allocate-object is unlimited polymorphic, either
type-spec or SOURCE= shall appear.
- C626 (R623) A type-param-value in a type-spec shall be an asterisk if and
only if each allocate-object is a dummy argument for which the corresponding type parameter is assumed.
- C627 (R623) If a type-spec appears, the kind type parameter values of each
allocate-object shall be the same as the corresponding type parameter values of the type-spec.
- C628 (R628) An allocate-shape-spec-list shall appear if and only if the
allocate-object is an array.
- C629 (R628) The number of allocate-shape-specs in an
allocate-shape-spec-list shall be the same as the rank of the allocate-object.
- C630 (R624) No alloc-opt shall appear more than once in a given
alloc-opt-list.
- C631 (R623) If SOURCE= appears, type-spec shall not appear and
allocation-list shall contain only one allocate-object, which shall be type compatible (5.1.1.2) with source-expr.
- C632 (R623) The source-expr shall be a scalar or have the same rank as
allocate-object.
- C633 (R623) Corresponding kind type parameters of allocate-object and
source-expr shall have the same values.
None of these constraints are currently applied - issue #355.
- classmethod match(string)[source]
Attempts to match the supplied string as an Allocate_Stmt.
- Parameters:
string (str) – the string to attempt to match.
- Returns:
A 2-tuple giving the Type_Spec and Allocation_List if the match is successful, None otherwise.
- Return type:
Optional[ Tuple[Optional[
fparser.two.Fortran2003.Type_Spec
],fparser.two.Fortran2003.Allocation_List
]]
- class fparser.two.Fortran2003.Stat_Variable(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<stat-variable> = <scalar-int-variable>
- class fparser.two.Fortran2003.Errmsg_Variable(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<errmsg-variable> = <scalar-default-char-variable>
- class fparser.two.Fortran2003.Source_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<source-expr> = <expr>
- class fparser.two.Fortran2003.Alloc_Opt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.KeywordValueBase
<alloc-opt> = STAT = <stat-variable> | ERRMSG = <errmsg-variable> | SOURCE = <source-expr>
- classmethod match(string)[source]
Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.
- Parameters:
lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.
rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.
string (str) – text to be matched.
require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.
upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.
- Returns:
instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.
- Return type:
2-tuple of objects or NoneType
- class fparser.two.Fortran2003.Allocation(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CallBase
<allocation> = <allocate-object> [ ( <allocate-shape-spec-list> ) ] | <variable-name>
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Allocate_Object(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<allocate-object> = <variable-name> | <structure-component>
- class fparser.two.Fortran2003.Allocate_Shape_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.SeparatorBase
<allocate-shape-spec> = [ <lower-bound-expr> : ] <upper-bound-expr>
- class fparser.two.Fortran2003.Lower_Bound_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<lower-bound-expr> = <scalar-int-expr>
- class fparser.two.Fortran2003.Upper_Bound_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<upper-bound-expr> = <scalar-int-expr>
- class fparser.two.Fortran2003.Nullify_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.CALLBase
<nullify-stmt> = NULLIFY ( <pointer-object-list> )
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Pointer_Object(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<pointer-object> = <variable-name> | <structure-component> | <proc-pointer-name>
- class fparser.two.Fortran2003.Deallocate_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<deallocate-stmt> = DEALLOCATE ( <allocate-object-list> [ , <dealloc-opt-list> ] )
- class fparser.two.Fortran2003.Dealloc_Opt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.KeywordValueBase
<dealloc-opt> = STAT = <stat-variable> | ERRMSG = <errmsg-variable>
- static match(string)[source]
Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.
- Parameters:
lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.
rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.
string (str) – text to be matched.
require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.
upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.
- Returns:
instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.
- Return type:
2-tuple of objects or NoneType
- class fparser.two.Fortran2003.Scalar_Char_Initialization_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Base class for Fortran 2003 syntax rules.
All Base classes have the following attributes:
self.string - original argument to construct a class instance, its type is either str or FortranReaderBase. self.item - Line instance (holds label) or None.
- Parameters:
cls (type) – the class of object to create.
string (str |
fparser.common.readfortran.FortranReaderBase
) – (source of) Fortran string to parse.parent_cls (type) – the parent class of this object.
- class fparser.two.Fortran2003.Primary(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R701:
primary is intrinsic_function_reference or constant or designator or array-constructor or structure-constructor or function-reference or type-param-inquiry or type-param-name or ( expr )
intrinsic_function_reference is not part of rule R701 but is required for fparser to recognise intrinsic functions. This is placed before array-constructor in the subclass_names list so that an intrinsic is not (incorrectly) matched as an array (as class Base matches rules in list order).
Note, ( expr ) is implemented in the Parenthesis subclass.
- class fparser.two.Fortran2003.Parenthesis(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BracketBase
Part of Fortran 2003 rule R701:
parenthesis = ( expr )
- static match(string)[source]
Implements the matching of round brackets surrounding an expression which is specified as one of the matches in R701.
- Parameters:
string (str) – Fortran code to check for a match.
- Returns:
None if there is no match, or a 3-tuple containing the left bracket, the matched expression and the right bracket.
- Return type:
NoneType or (str, subclass of
fparser.two.utils.Base
, str)
- class fparser.two.Fortran2003.Level_1_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.UnaryOpBase
<level-1-expr> = [ <defined-unary-op> ] <primary> <defined-unary-op> = . <letter> [ <letter> ]... .
- class fparser.two.Fortran2003.Defined_Unary_Op(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R703:
defined-unary-op is . letter [ letter ]... .
C704 (R703) A defined-unary-op shall not contain more than 63 letters and shall not be the same as any intrinsic-operator or logical-literal-constant.
Implemented in Defined_Op class.
- class fparser.two.Fortran2003.Defined_Op(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
Utility class that Implements the functionality of rules R703 and R723 (as the rules are the same):
defined-op is . letter [ letter ]... .
C704 (R723) A defined-binary-op shall not contain more than 63 letters and shall not be the same as any intrinsic-operator or logical-literal-constant.
C704 (R703) A defined-unary-op shall not contain more than 63 letters and shall not be the same as any intrinsic-operator or logical-literal-constant.
- class fparser.two.Fortran2003.Mult_Operand(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BinaryOpBase
<mult-operand> = <level-1-expr> [ <power-op> <mult-operand> ] <power-op> = **
- static match(string)[source]
Matches the binary-op-base rule.
If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.
If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.
if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.
- Parameters:
lhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the lhs text.op_pattern (str or
fparser.two.pattern_tools.Pattern
) – the pattern to match.rhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the rhs text.string (str) – the string to match with the pattern and lhs and rhs rules.
right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).
exclude_op_pattern (
fparser.two.pattern_tools.Pattern
) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.
- Returns:
a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.
- Return type:
(
fparser.two.utils.Base
, str,fparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.Add_Operand(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BinaryOpBase
Fortran 2003 rule R705:
add-operand is [ add-operand mult-op ] mult-operand
Rule R705 is implemented in two parts, the first with the optional part included (in the match method for this class) and the second without the optional part (specified in subclass_names).
Note rule R708 (mult-op is * or /) is implemented directly here as the mult_op pattern.
There is potential to accidentally match a sign in an exponent as the plus/minus sign in a level-2-expr. If this were to happen then it is possible to end up matching a * or / (a level 1 expression) before matching a valid + or - which would normally result in no match overall as * or / are matched after + or -. This situation is avoided by tokenising the string before performing the match so that any numerical constants involving exponents are replaced by simple symbols. (The tokenisation is performed by fparser.common.splitline.string_replace_map.)
- static match(string)[source]
Implement the matching for the add-operand rule. Makes use of the pre-defined mult_op pattern and the BinaryOpBase baseclass.
- Parameters:
string (str) – the string to match.
- Returns:
a tuple of size 3 containing an fparser2 class instance matching a level-2-expr expression, a string containing the matched operator and an fparser2 class instance matching a mult-operand if there is a match, or None if there is not.
- Return type:
(subclass of
fparser.two.utils.Base
, str, subclass offparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.Level_2_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BinaryOpBase
<level-2-expr> = [ [ <level-2-expr> ] <add-op> ] <add-operand> <level-2-expr> = [ <level-2-expr> <add-op> ] <add-operand> | <level-2-unary-expr> <add-op> = + | -
- static match(string)[source]
Matches the binary-op-base rule.
If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.
If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.
if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.
- Parameters:
lhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the lhs text.op_pattern (str or
fparser.two.pattern_tools.Pattern
) – the pattern to match.rhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the rhs text.string (str) – the string to match with the pattern and lhs and rhs rules.
right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).
exclude_op_pattern (
fparser.two.pattern_tools.Pattern
) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.
- Returns:
a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.
- Return type:
(
fparser.two.utils.Base
, str,fparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.Level_2_Unary_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.UnaryOpBase
<level-2-unary-expr> = [ <add-op> ] <add-operand>
- class fparser.two.Fortran2003.Level_3_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BinaryOpBase
<level-3-expr> = [ <level-3-expr> <concat-op> ] <level-2-expr> <concat-op> = //
- static match(string)[source]
Matches the binary-op-base rule.
If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.
If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.
if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.
- Parameters:
lhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the lhs text.op_pattern (str or
fparser.two.pattern_tools.Pattern
) – the pattern to match.rhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the rhs text.string (str) – the string to match with the pattern and lhs and rhs rules.
right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).
exclude_op_pattern (
fparser.two.pattern_tools.Pattern
) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.
- Returns:
a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.
- Return type:
(
fparser.two.utils.Base
, str,fparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.Level_4_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BinaryOpBase
<level-4-expr> = [ <level-3-expr> <rel-op> ] <level-3-expr> <rel-op> = .EQ. | .NE. | .LT. | .LE. | .GT. | .GE. | == | /= | < | <= | > | >=
- static match(string)[source]
Matches the binary-op-base rule.
If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.
If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.
if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.
- Parameters:
lhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the lhs text.op_pattern (str or
fparser.two.pattern_tools.Pattern
) – the pattern to match.rhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the rhs text.string (str) – the string to match with the pattern and lhs and rhs rules.
right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).
exclude_op_pattern (
fparser.two.pattern_tools.Pattern
) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.
- Returns:
a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.
- Return type:
(
fparser.two.utils.Base
, str,fparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.And_Operand(string, parent_cls=None)[source]
Bases:
fparser.two.utils.UnaryOpBase
<and-operand> = [ <not-op> ] <level-4-expr> <not-op> = .NOT.
- class fparser.two.Fortran2003.Or_Operand(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BinaryOpBase
<or-operand> = [ <or-operand> <and-op> ] <and-operand> <and-op> = .AND.
- static match(string)[source]
Matches the binary-op-base rule.
If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.
If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.
if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.
- Parameters:
lhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the lhs text.op_pattern (str or
fparser.two.pattern_tools.Pattern
) – the pattern to match.rhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the rhs text.string (str) – the string to match with the pattern and lhs and rhs rules.
right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).
exclude_op_pattern (
fparser.two.pattern_tools.Pattern
) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.
- Returns:
a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.
- Return type:
(
fparser.two.utils.Base
, str,fparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.Equiv_Operand(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BinaryOpBase
<equiv-operand> = [ <equiv-operand> <or-op> ] <or-operand> <or-op> = .OR.
- static match(string)[source]
Matches the binary-op-base rule.
If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.
If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.
if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.
- Parameters:
lhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the lhs text.op_pattern (str or
fparser.two.pattern_tools.Pattern
) – the pattern to match.rhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the rhs text.string (str) – the string to match with the pattern and lhs and rhs rules.
right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).
exclude_op_pattern (
fparser.two.pattern_tools.Pattern
) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.
- Returns:
a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.
- Return type:
(
fparser.two.utils.Base
, str,fparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.Level_5_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BinaryOpBase
<level-5-expr> = [ <level-5-expr> <equiv-op> ] <equiv-operand> <equiv-op> = .EQV. | .NEQV.
- static match(string)[source]
Matches the binary-op-base rule.
If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.
If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.
if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.
- Parameters:
lhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the lhs text.op_pattern (str or
fparser.two.pattern_tools.Pattern
) – the pattern to match.rhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the rhs text.string (str) – the string to match with the pattern and lhs and rhs rules.
right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).
exclude_op_pattern (
fparser.two.pattern_tools.Pattern
) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.
- Returns:
a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.
- Return type:
(
fparser.two.utils.Base
, str,fparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BinaryOpBase
<expr> = [ <expr> <defined-binary-op> ] <level-5-expr> <defined-binary-op> = . <letter> [ <letter> ]... .
- static match(string)[source]
Matches the binary-op-base rule.
If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.
If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.
if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.
- Parameters:
lhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the lhs text.op_pattern (str or
fparser.two.pattern_tools.Pattern
) – the pattern to match.rhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the rhs text.string (str) – the string to match with the pattern and lhs and rhs rules.
right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).
exclude_op_pattern (
fparser.two.pattern_tools.Pattern
) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.
- Returns:
a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.
- Return type:
(
fparser.two.utils.Base
, str,fparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.Defined_Binary_Op(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R723:
defined-binary-op is . letter [ letter ]... .
C704 (R723) A defined-binary-op shall not contain more than 63 letters and shall not be the same as any intrinsic-operator or logical-literal-constant.
Implemented in Defined_Op class.
- class fparser.two.Fortran2003.Logical_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R724:
logical-expr is expr
C705 logical-expr shall be of type logical.
- static match(string)[source]
Implements the matching for a logical expression.
Note, whilst we exclude Signed_Int_Literal_Constant and Signed_Real_Literal_Constant, it seems that it is not possible to create these from code as a “-” sign is treated as a unary operator.
- Parameters:
string (str) – Fortran code to check for a match.
- Returns:
None if there is no match, or an fparser2 class instance containing the matched expression.
- Return type:
NoneType or
fparser.two.utils.Base
- class fparser.two.Fortran2003.Char_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R725:
char-expr is expr
C706 char-expr shall be of type character.
- static match(string)[source]
Implements the matching for a character expression.
- Parameters:
string (str) – Fortran code to check for a match.
- Returns:
None if there is no match, or an fparser2 class instance containing the matched expression.
- Return type:
NoneType or
fparser.two.utils.Base
- class fparser.two.Fortran2003.Default_Char_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R726:
default-char-expr is expr
C707 default-char-expr shall be of type default character.
- static match(string)[source]
Implements the matching for a default character expression.
- Parameters:
string (str) – Fortran code to check for a match.
- Returns:
None if there is no match, or an fparser2 class instance containing the matched expression.
- Return type:
NoneType or
fparser.two.utils.Base
- class fparser.two.Fortran2003.Int_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R727:
int-expr is expr
C708 int-expr shall be of type integer.
- static match(string)[source]
Implements the matching for an integer expression.
- Parameters:
string (str) – Fortran code to check for a match.
- Returns:
None if there is no match, or an fparser2 class instance containing the matched expression.
- Return type:
NoneType or
fparser.two.utils.Base
- class fparser.two.Fortran2003.Numeric_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R728:
numeric-expr is expr
C709 numeric-expr shall be of type integer, real or complex.
- static match(string)[source]
Implements the matching for a numeric expression.
- Parameters:
string (str) – Fortran code to check for a match.
- Returns:
None if there is no match, or an fparser2 class instance containing the matched expression.
- Return type:
NoneType or
fparser.two.utils.Base
- class fparser.two.Fortran2003.Specification_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<specification-expr> = <scalar-int-expr>
- class fparser.two.Fortran2003.Initialization_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<initialization-expr> = <expr>
- class fparser.two.Fortran2003.Char_Initialization_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<char-initialization-expr> = <char-expr>
- class fparser.two.Fortran2003.Int_Initialization_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<int-initialization-expr> = <int-expr>
- class fparser.two.Fortran2003.Logical_Initialization_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<logical-initialization-expr> = <logical-expr>
- class fparser.two.Fortran2003.Assignment_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.BinaryOpBase
<assignment-stmt> = <variable> = <expr>
- static match(string)[source]
Matches the binary-op-base rule.
If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.
If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.
if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.
- Parameters:
lhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the lhs text.op_pattern (str or
fparser.two.pattern_tools.Pattern
) – the pattern to match.rhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the rhs text.string (str) – the string to match with the pattern and lhs and rhs rules.
right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).
exclude_op_pattern (
fparser.two.pattern_tools.Pattern
) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.
- Returns:
a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.
- Return type:
(
fparser.two.utils.Base
, str,fparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.Pointer_Assignment_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<pointer-assignment-stmt> = <data-pointer-object> [ ( <bounds-spec-list> ) ] => <data-target> | <data-pointer-object> ( <bounds-remapping-list> ) => <data-target> | <proc-pointer-object> => <proc-target>
- class fparser.two.Fortran2003.Data_Pointer_Object(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BinaryOpBase
<data-pointer-object> = <variable-name> | <variable> % <data-pointer-component-name>
- static match(string)[source]
Matches the binary-op-base rule.
If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.
If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.
if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.
- Parameters:
lhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the lhs text.op_pattern (str or
fparser.two.pattern_tools.Pattern
) – the pattern to match.rhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the rhs text.string (str) – the string to match with the pattern and lhs and rhs rules.
right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).
exclude_op_pattern (
fparser.two.pattern_tools.Pattern
) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.
- Returns:
a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.
- Return type:
(
fparser.two.utils.Base
, str,fparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.Bounds_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.SeparatorBase
<bounds-spec> = <lower-bound-expr> :
- class fparser.two.Fortran2003.Bounds_Remapping(string, parent_cls=None)[source]
Bases:
fparser.two.utils.SeparatorBase
<bounds-remapping> = <lower-bound-expr> : <upper-bound-expr>
- class fparser.two.Fortran2003.Data_Target(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<data-target> = <variable> | <expr>
- class fparser.two.Fortran2003.Proc_Pointer_Object(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<proc-pointer-object> = <proc-pointer-name> | <proc-component-ref>
- class fparser.two.Fortran2003.Proc_Component_Ref(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BinaryOpBase
<proc-component-ref> = <variable> % <procedure-component-name>
- static match(string)[source]
Matches the binary-op-base rule.
If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.
If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.
if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.
- Parameters:
lhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the lhs text.op_pattern (str or
fparser.two.pattern_tools.Pattern
) – the pattern to match.rhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the rhs text.string (str) – the string to match with the pattern and lhs and rhs rules.
right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).
exclude_op_pattern (
fparser.two.pattern_tools.Pattern
) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.
- Returns:
a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.
- Return type:
(
fparser.two.utils.Base
, str,fparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.Proc_Target(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<proc-target> = <expr> | <procedure-name> | <proc-component-ref>
- class fparser.two.Fortran2003.Where_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<where-stmt> = WHERE ( <mask-expr> ) <where-assignment-stmt>
- class fparser.two.Fortran2003.Where_Construct(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<where-construct> = <where-construct-stmt> [ <where-body-construct> ]... [ <masked-elsewhere-stmt> [ <where-body-construct> ]... ]... [ <elsewhere-stmt> [ <where-body-construct> ]... ] <end-where-stmt>
- use_names = ['Where_Construct_Stmt', 'Where_Body_Construct', 'Masked_Elsewhere_Stmt', 'Elsewhere_Stmt',...[source]
- static match(string)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Where_Construct_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<where-construct-stmt> = [ <where-construct-name> : ] WHERE ( <mask-expr> )
- class fparser.two.Fortran2003.Where_Body_Construct(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<where-body-construct> = <where-assignment-stmt> | <where-stmt> | <where-construct>
- class fparser.two.Fortran2003.Where_Assignment_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<where-assignment-stmt> = <assignment-stmt>
- class fparser.two.Fortran2003.Mask_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<mask-expr> = <logical-expr>
- class fparser.two.Fortran2003.Masked_Elsewhere_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<masked-elsewhere-stmt> = ELSEWHERE ( <mask-expr> ) [ <where-construct-name> ]
- class fparser.two.Fortran2003.Elsewhere_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
<elsewhere-stmt> = ELSEWHERE [ <where-construct-name> ]
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.End_Where_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.EndStmtBase
<end-where-stmt> = END WHERE [ <where-construct-name> ]
- static match(string)[source]
Attempts to match the supplied string as a form of ‘END xxx’ statement.
- Parameters:
stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.
stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).
string (str) – the string to attempt to match.
require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.
- Returns:
2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.
- Return type:
Optional[ Tuple[Optional[str],
Optional[
fparser.two.Fortran2003.Name
]]]
- class fparser.two.Fortran2003.Forall_Construct(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<forall-construct> = <forall-construct-stmt> [ <forall-body-construct> ]... <end-forall-stmt>
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Forall_Construct_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
<forall-construct-stmt> = [ <forall-construct-name> : ] FORALL <forall-header>
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Forall_Header(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R754:
forall-header is ( forall-triplet-spec-list [, scalar-mask-expr ] )
- static match(string)[source]
Implements the matching for a Forall_Header.
- Parameters:
string (str) – A string containing the code to match.
- Returns:
None if there is no match, otherwise a tuple of size 2 containing a class of type Forall_Triplet_Spec_List and a class of type Scalar_Mask_Expr if there is a scalar mask expresssion and None if not.
- Return type:
(Forall_Triplet_Spec_List, Scalar_Mask_Expr) or (Forall_Triplet_Spec_List, None) or None
- tostr()[source]
- Returns:
this Forall Header as a string
- Return type:
- Raises:
InternalError – if the length of the internal items list is not 2.
InternalError – if the first entry of the internal items list has no content, as a Forall_Triplet_List is expected.
- class fparser.two.Fortran2003.Forall_Triplet_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<forall-triplet-spec> = <index-name> = <subscript> : <subscript> [ : <stride> ]
- class fparser.two.Fortran2003.Forall_Body_Construct(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<forall-body-construct> = <forall-assignment-stmt> | <where-stmt> | <where-construct> | <forall-construct> | <forall-stmt>
- class fparser.two.Fortran2003.Forall_Assignment_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<forall-assignment-stmt> = <assignment-stmt> | <pointer-assignment-stmt>
- class fparser.two.Fortran2003.End_Forall_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.EndStmtBase
<end-forall-stmt> = END FORALL [ <forall-construct-name> ]
- static match(string)[source]
Attempts to match the supplied string as a form of ‘END xxx’ statement.
- Parameters:
stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.
stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).
string (str) – the string to attempt to match.
require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.
- Returns:
2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.
- Return type:
Optional[ Tuple[Optional[str],
Optional[
fparser.two.Fortran2003.Name
]]]
- class fparser.two.Fortran2003.Forall_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran 2003 rule R759:
forall-stmt is FORALL forall-header forall-assignment-stmt
- static match(string)[source]
Implements the matching for a forall statement.
- Parameters:
string (str or
fparser.common.readfortran.FortranReader
) – A string or the fortran reader containing the line of code that we are trying to match.- Returns:
None if there is no match or a tuple of size 2 containing an instance of the Forall_Header class followed by an instance of the Forall_Assignment_Stmt class.
- Return type:
None or (
fparser.two.Fortran2003.Forall_Header
,fparser.two.Fortran2003.Forall_Assignment_Stmt
)
- tostr()[source]
- Returns:
this forall statement as a string
- Return type:
- Raises:
InternalError – if the internal items list variable is not the expected size.
InternalError – if the first element of the internal items list is None or is an empty string.
InternalError – if the second element of the internal items list is None or is an empty string.
- class fparser.two.Fortran2003.Block(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<block> = [ <execution-part-construct> ]…
- static match(string)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.If_Construct(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<if-construct> = <if-then-stmt> <block> [ <else-if-stmt> <block> ]... [ <else-stmt> <block> ] <end-if-stmt>
- use_names = ['If_Then_Stmt', 'Execution_Part_Construct', 'Else_If_Stmt', 'Else_Stmt', 'End_If_Stmt'][source]
- static match(string)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.If_Then_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<if-then-stmt> = [ <if-construct-name> : ] IF ( <scalar-logical-expr> ) THEN
- class fparser.two.Fortran2003.Else_If_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<else-if-stmt> = ELSE IF ( <scalar-logical-expr> ) THEN [ <if-construct-name> ]
- class fparser.two.Fortran2003.Else_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<else-stmt> = ELSE [ <if-construct-name> ]
- class fparser.two.Fortran2003.End_If_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.EndStmtBase
<end-if-stmt> = END IF [ <if-construct-name> ]
- static match(string)[source]
Attempts to match the supplied string as a form of ‘END xxx’ statement.
- Parameters:
stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.
stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).
string (str) – the string to attempt to match.
require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.
- Returns:
2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.
- Return type:
Optional[ Tuple[Optional[str],
Optional[
fparser.two.Fortran2003.Name
]]]
- class fparser.two.Fortran2003.If_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran 2003 rule R807:
if-stmt is IF ( scalar-logical-expr ) action-stmt
C802 (R807) The action-stmt in the if-stmt shall not be an if-stmt, end-program-stmt, end-function-stmt, or end-subroutine-stmt.
- classmethod match(string)[source]
Implements the matching for an if statement that controls a single action statement
This is implemented as a class method to allow parameterizing the type that is used to match the action-stmt. It is specified by the attribute
action_stmt_cls
, which can be overwritten in derived classes to specify an updated version, so done for example in the Fortran 2008 versionfparser.two.Fortran2008.If_Stmt
.- Parameters:
string (str) – Text that we are trying to match.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing the logical expression as an object matched by
fparser.two.Fortran2003.Scalar_Logical_Expr
and the action statement as an object matchingcls.action_stmt_cls
.- Return type:
(
fparser.two.Fortran2003.Scalar_Logical_Expr
,fparser.two.Fortran2003.Action_Stmt_C802
) or NoneType
- class fparser.two.Fortran2003.Case_Construct(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<case-construct> = <select-case-stmt> [ <case-stmt> <block> == [<execution-part-construct>].. ].. <end-select-stmt>
- use_names = ['Select_Case_Stmt', 'Case_Stmt', 'End_Select_Stmt', 'Execution_Part_Construct'][source]
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Select_Case_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.CALLBase
<select-case-stmt> = [ <case-construct-name> : ] SELECT CASE ( <case-expr> )
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Case_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<case-stmt> = CASE <case-selector> [ <case-construct-name> ]
- class fparser.two.Fortran2003.End_Select_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.EndStmtBase
<end-select-stmt> = END SELECT [ <case-construct-name> ]
- static match(string)[source]
Attempts to match the supplied string as a form of ‘END xxx’ statement.
- Parameters:
stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.
stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).
string (str) – the string to attempt to match.
require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.
- Returns:
2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.
- Return type:
Optional[ Tuple[Optional[str],
Optional[
fparser.two.Fortran2003.Name
]]]
- class fparser.two.Fortran2003.Case_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<case-expr> = <scalar-int-expr> | <scalar-char-expr> | <scalar-logical-expr>
- class fparser.two.Fortran2003.Case_Selector(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<case-selector> = ( <case-value-range-list> ) | DEFAULT
- class fparser.two.Fortran2003.Case_Value_Range(string, parent_cls=None)[source]
Bases:
fparser.two.utils.SeparatorBase
<case-value-range> = <case-value> | <case-value> : | : <case-value> | <case-value> : <case-value>
- class fparser.two.Fortran2003.Case_Value(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<case-value> = <scalar-int-initialization-expr> | <scalar-char-initialization-expr> | <scalar-logical-initialization-expr>
- class fparser.two.Fortran2003.Associate_Construct(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<associate-construct> = <associate-stmt> <block> == [ <execution-part-construct> ]... <end-associate-stmt>
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Associate_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.CALLBase
<associate-stmt> = [ <associate-construct-name> : ] ASSOCIATE ( <association-list> )
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Association(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BinaryOpBase
<association> = <associate-name> => <selector>
- static match(string)[source]
Matches the binary-op-base rule.
If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.
If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.
if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.
- Parameters:
lhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the lhs text.op_pattern (str or
fparser.two.pattern_tools.Pattern
) – the pattern to match.rhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the rhs text.string (str) – the string to match with the pattern and lhs and rhs rules.
right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).
exclude_op_pattern (
fparser.two.pattern_tools.Pattern
) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.
- Returns:
a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.
- Return type:
(
fparser.two.utils.Base
, str,fparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.Selector(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<selector> = <expr> | <variable>
- class fparser.two.Fortran2003.End_Associate_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.EndStmtBase
<end-associate-stmt> = END ASSOCIATE [ <associate-construct-name> ]
- static match(string)[source]
Attempts to match the supplied string as a form of ‘END xxx’ statement.
- Parameters:
stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.
stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).
string (str) – the string to attempt to match.
require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.
- Returns:
2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.
- Return type:
Optional[ Tuple[Optional[str],
Optional[
fparser.two.Fortran2003.Name
]]]
- class fparser.two.Fortran2003.Select_Type_Construct(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<select-type-construct> = <select-type-stmt> [ <type-guard-stmt> <block> == [<execution-part-construct>].. ]... <end-select-type-stmt>
- use_names = ['Select_Type_Stmt', 'Type_Guard_Stmt', 'Execution_Part_Construct', 'End_Select_Type_Stmt'][source]
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Select_Type_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<select-type-stmt> = [ <select-construct-name> : ] SELECT TYPE ( [ <associate-name> => ] <selector> )
- class fparser.two.Fortran2003.Type_Guard_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<type-guard-stmt> = TYPE IS ( <type-spec> ) [ <select-construct-name> ] | CLASS IS ( <type-spec> ) [ <select-construct-name> ] | CLASS DEFAULT [ <select-construct-name> ]
The items attribute for this class will contain:
({'TYPE IS', 'CLASS IS', 'CLASS DEFAULT'}, Type_Spec, Select_Construct_Name)
- class fparser.two.Fortran2003.End_Select_Type_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.EndStmtBase
<end-select-type-stmt> = END SELECT [ <select-construct-name> ]
- static match(string)[source]
Attempts to match the supplied string as a form of ‘END xxx’ statement.
- Parameters:
stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.
stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).
string (str) – the string to attempt to match.
require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.
- Returns:
2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.
- Return type:
Optional[ Tuple[Optional[str],
Optional[
fparser.two.Fortran2003.Name
]]]
- class fparser.two.Fortran2003.Do_Construct(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
R825:
<do-construct> = <block-do-construct> | <nonblock-do-construct>
- class fparser.two.Fortran2003.Block_Do_Construct(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
R826:
<block-do-construct> = <block-label-do-construct> | <block-nonlabel-do-construct>
- class fparser.two.Fortran2003.Block_Label_Do_Construct(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
R826_1:
<block-label-do-construct> = <label-do-stmt> [ <execution-part-construct> ]... <end-do>
- classmethod match(reader)[source]
- Parameters:
reader (
FortranReaderBase
) – instance of FortranReaderBase class- Returns:
code block matching the labeled “DO” construct
- Return type:
string
- class fparser.two.Fortran2003.Block_Nonlabel_Do_Construct(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
R826_2:
<block-nonlabel-do-construct> = <nonlabel-do-stmt> [ <execution-part-construct> ]... <end-do-stmt>
- classmethod match(reader)[source]
- Parameters:
reader (
FortranReaderBase
) – instance of FortranReaderBase class- Returns:
code block matching the nonlabeled “DO” construct
- Return type:
string
- class fparser.two.Fortran2003.Do_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
R827:
<do-stmt> = <label-do-stmt> | <nonlabel-do-stmt>
- class fparser.two.Fortran2003.Label_Do_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
R828:
<label-do-stmt> = [ <do-construct-name> : ] DO <label> [ <loop-control> ]
- classmethod match(string)[source]
- Parameters:
string (str or
FortranReaderBase
) – (source of) Fortran string to parse- Returns:
3-tuple containing strings and instances of the classes determining labeled “DO” statement (optional statement name, label and loop control expression if present)
- Return type:
3-tuple of objects
- class fparser.two.Fortran2003.Nonlabel_Do_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
R829:
<nonlabel-do-stmt> = [ <do-construct-name> : ] DO [ <loop-control> ]
- class fparser.two.Fortran2003.Loop_Control(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R830
- loop-control is [ , ] do-variable = scalar-int-expr , scalar-int-expr
[ , scalar-int-expr ]
or [ , ] WHILE ( scalar-logical-expr )
This class would be better and more extensible if it called 2 classes, one for each of the above expressions. Something like the suggestion below. However, this would result in a different fparser tree, see issue #416.
F2003: While_Loop_Cntl: scalar-logical-expression, delim F2003: Counter_Loop_Cntl: var, lower, upper, [step], delim F2008: Concurrent_Loop_Cntl: conc_expr, delim F2018: Concurrent_Loop_Cntl: conc_expr, local_x, delim
- static match(string)[source]
Attempts to match the supplied text with this rule.
- Parameters:
string (str) – Fortran code to check for a match.
- Returns:
None if there is no match, a 3-tuple with the first entry providing the result of matching the ‘WHILE’ part of the rule if there is a match, the second entry providing the result of matching the ‘COUNTER’ part of the rule if there is a match and the third entry indicating whether there is an optional preceding ‘,’.
- Return type:
Optional[Tuple[ Optional[
fparser.two.Fortran2003.Scalar_Logical_Expr
], Optional[Tuple[fparser.two.Fortran2003.Do_Variable
, List[str]]], Optional[str]]]
- class fparser.two.Fortran2003.Do_Variable(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
R831:
<do-variable> = <scalar-int-variable>
- class fparser.two.Fortran2003.Do_Block(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
R832:
<do-block> = [ <execution-part-construct> ]...
- class fparser.two.Fortran2003.End_Do(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
R833:
<end-do> = <end-do-stmt> | <continue-stmt>
- class fparser.two.Fortran2003.End_Do_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.EndStmtBase
R834:
<end-do-stmt> = END DO [ <do-construct-name> ]
- class fparser.two.Fortran2003.Nonblock_Do_Construct(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
R835:
<nonblock-do-stmt> = <action-term-do-construct> | <outer-shared-do-construct>
- class fparser.two.Fortran2003.Action_Term_Do_Construct(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<action-term-do-construct> = <label-do-stmt> <do-body> <do-term-action-stmt> <action-term-do-construct> = <label-do-stmt> [ <execution-part-construct> ]... <do-term-action-stmt>
- classmethod match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Do_Body(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<do-body> = [ <execution-part-construct> ]…
- static match(string)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Do_Term_Action_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<do-term-action-stmt> = <action-stmt>
Notes:
C824 - <do-term-action-stmt> shall not be <continue-stmt>, <goto-stmt>, <return-stmt>, <stop-stmt>, <exit-stmt>, <cycle-stmt>, <end-function-stmt>, <end-subroutine-stmt>, <end-program-stmt>, <arithmetic-if-stmt>
Bases:
fparser.two.utils.BlockBase
<outer-shared-do-construct> = <label-do-stmt> <do-body> <shared-term-do-construct>
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
Bases:
fparser.two.utils.Base
<shared-term-do-construct> = <outer-shared-do-construct> | <inner-shared-do-construct>
Bases:
fparser.two.utils.BlockBase
<inner-shared-do-construct> = <label-do-stmt> <do-body> <do-term-shared-stmt>
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
Bases:
fparser.two.utils.StmtBase
<do-term-shared-stmt> = <action-stmt>
C826 - see C824 above.
- class fparser.two.Fortran2003.Cycle_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
<cycle-stmt> = CYCLE [ <do-construct-name> ]
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Exit_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
<exit-stmt> = EXIT [ <do-construct-name> ]
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Goto_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<goto-stmt> = GO TO <label>
- class fparser.two.Fortran2003.Computed_Goto_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<computed-goto-stmt> = GO TO ( <label-list> ) [ , ] <scalar-int-expr>
- class fparser.two.Fortran2003.Arithmetic_If_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<arithmetic-if-stmt> = IF ( <scalar-numeric-expr> ) <label> , <label> , <label>
- class fparser.two.Fortran2003.Continue_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.STRINGBase
<continue-stmt> = CONTINUE
- static match(string)[source]
Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.
The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:
from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)
- Parameters:
pattern (list, tuple, str or an re expression) – the pattern to match
string (str) – the string to match with the pattern
- Returns:
None if there is no match, or a tuple containing the matched string in upper case.
- Return type:
NoneType or ( str )
- class fparser.two.Fortran2003.Stop_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
<stop-stmt> = STOP [ <stop-code> ]
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Stop_Code(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StringBase
<stop-code> = <scalar-char-constant> | <digit> [ <digit> [ <digit> [ <digit> [ <digit> ] ] ] ]
- class fparser.two.Fortran2003.Io_Unit(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StringBase
<io-unit> = <file-unit-number> | * | <internal-file-variable>
- class fparser.two.Fortran2003.File_Unit_Number(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<file-unit-number> = <scalar-int-expr>
- class fparser.two.Fortran2003.Internal_File_Variable(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<internal-file-variable> = <char-variable>
C901 - <char-variable> shall not be an array section with a vector subscript.
- class fparser.two.Fortran2003.Open_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.CALLBase
R904 is:
open-stmt is OPEN ( connect-spec-list )
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Connect_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.KeywordValueBase
R905 is:
- connect-spec is [ UNIT = ] file-unit-number
or ACCESS = scalar-default-char-expr or ACTION = scalar-default-char-expr or ASYNCHRONOUS = scalar-default-char-expr or BLANK = scalar-default-char-expr [ or CONVERT = scalar-default-char-expr ] or DECIMAL = scalar-default-char-expr or DELIM = scalar-default-char-expr or ENCODING = scalar-default-char-expr or ERR = label or FILE = file-name-expr or FORM = scalar-default-char-expr or IOMSG = iomsg-variable or IOSTAT = scalar-int-variable or PAD = scalar-default-char-expr or POSITION = scalar-default-char-expr or RECL = scalar-int-expr or ROUND = scalar-default-char-expr or SIGN = scalar-default-char-expr or STATUS = scalar-default-char-expr
Note that CONVERT is not a part of the Fortran standard but is supported by several major compilers (Gnu, Intel, Cray etc.) and thus is matched by fparser if the utils.EXTENSIONS() list includes the string ‘open-convert’.
- use_names = ['File_Unit_Number', 'Scalar_Default_Char_Expr', 'Label', 'File_Name_Expr', 'Iomsg_Variable',...[source]
- classmethod _keyword_value_list()[source]
Defines the valid keywords and corresponding classes to match against. This has to be a method rather than a class property as those classes are generated after this class has been created.
- classmethod match(string)[source]
Implements the matching for connect-spec.
Note that this is implemented as a classmethod (not a staticmethod), using attribute keywords from the list provided as a class method. This allows expanding this list for Fortran 2008 without having to reimplement the matching.
- Parameters:
string (str) – Fortran code to check for a match
- Returns:
2-tuple containing the keyword and value or None if the supplied string is not a match
- Return type:
2-tuple containing keyword (e.g. “UNIT”) and associated value
- class fparser.two.Fortran2003.File_Name_Expr(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<file-name-expr> = <scalar-default-char-expr>
- class fparser.two.Fortran2003.Iomsg_Variable(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<iomsg-variable> = <scalar-default-char-variable>
- class fparser.two.Fortran2003.Close_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.CALLBase
<close-stmt> = CLOSE ( <close-spec-list> )
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Close_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.KeywordValueBase
<close-spec> = [ UNIT = ] <file-unit-number> | IOSTAT = <scalar-int-variable> | IOMSG = <iomsg-variable> | ERR = <label> | STATUS = <scalar-default-char-expr>
- use_names = ['File_Unit_Number', 'Scalar_Default_Char_Expr', 'Label', 'Iomsg_Variable', 'Scalar_Int_Variable'][source]
- static match(string)[source]
Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.
- Parameters:
lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.
rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.
string (str) – text to be matched.
require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.
upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.
- Returns:
instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.
- Return type:
2-tuple of objects or NoneType
- class fparser.two.Fortran2003.Read_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran2003 Rule R910:
<read-stmt> = READ ( <io-control-spec-list> ) [ <input-item-list> ] | READ <format> [ , <input-item-list> ]
Attributes:
items : (Io_Control_Spec_List, Format, Input_Item_List)
- class fparser.two.Fortran2003.Write_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran 2003 rule R911.
Specifies the syntax of a “WRITE” statement:
write-stmt is WRITE ( io-control-spec-list ) [ output-item-list ]
- static match(string)[source]
- Parameters:
string (str) – Fortran code to check for a match
- Returns:
2-tuple containing strings and instances of the classes describing “WRITE” statement (mandatory IO control specification list and optional output item list.
- Return type:
2-tuple of objects (1 mandatory and 1 optional)
- class fparser.two.Fortran2003.Print_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran2003 Rule R912:
<print-stmt> = PRINT <format> [ , <output-item-list> ]
Parameters:
items : (Format, Output_Item_List)
- class fparser.two.Fortran2003.Io_Control_Spec_List(string, parent_cls=None)[source]
Bases:
fparser.two.utils.SequenceBase
Rule 913 - Control information list:
io-control-spec-list is a list of io-control-spec items.
Subject to the following constraints:
C909 No specifier shall appear more than once in a given io-control-spec-list. C910 An io-unit shall be specified; if the optional characters UNIT= are omitted, the io-unit shall be the first item in the io-control-spec-list. C911 A DELIM= or SIGN= specifier shall not appear in a read-stmt. C912 A BLANK=, PAD=, END=, EOR=, or SIZE=specifier shall not appear in a write-stmt. C913 The label in the ERR=, EOR=, or END= specifier shall be the statement label of a branch target statement that appears in the same scoping unit as the data transfer statement. C914 A namelist-group-name shall be the name of a namelist group. C915 A namelist-group-name shall not appear if an input-item-list or an output-item-list appears in the data transfer statement. C916 An io-control-spec-list shall not contain both a format and a namelist-group-name. C917 If format appears without a preceding FMT=, it shall be the second item in the iocontrol-spec-list and the first item shall be io-unit. C918 If namelist-group-name appears without a preceding NML=, it shall be the second item in the io-control-spec-list and the first item shall be io-unit. C919 If io-unit is not a file-unit-number, the io-control-spec-list shall not contain a REC= specifier or a POS= specifier. C920 If the REC= specifier appears, an END= specifier shall not appear, a namelist-groupname shall not appear, and the format, if any, shall not be an asterisk. C921 An ADVANCE= specifier may appear only in a formatted sequential or stream input/output statement with explicit format specification (10.1) whose control information list does not contain an internal-file-variable as the io-unit. C922 If an EOR= specifier appears, an ADVANCE= specifier also shall appear. C923 If a SIZE= specifier appears, an ADVANCE= specifier also shall appear. C924 The scalar-char-initialization-expr in an ASYNCHRONOUS= specifier shall be of type default character and shall have the value YES or NO. C925 An ASYNCHRONOUS= specifier with a value YES shall not appear unless io-unit is a file-unit-number. C926 If an ID= specifier appears, an ASYNCHRONOUS= specifier with the value YES shall also appear. C927 If a POS= specifier appears, the io-control-spec-list shall not contain a REC= specifier. C928 If a DECIMAL=, BLANK=, PAD=, SIGN=, or ROUND= specifier appears, a format or namelist-group-name shall also appear. C929 If a DELIM= specifier appears, either format shall be an asterisk or namelist-group-name shall appear.
TODO #267. Of these constraints, only C910 & C916-918 are currently enforced.
- static match(string)[source]
Attempts to match the supplied string with a list of Io_Control_Spec items. We have to override the base implementation because the first two items in the list have specific meanings if they are not explictly named: the first must be the unit number and the second may be either a format specifier or a namelist-group-name.
- Parameters:
string (str) – the string that is checked for a match.
- Returns:
a tuple of Io_Control_Spec objects if the match is successful, None otherwise.
- Return type:
tuple of
fparser.two.Fortran2003.Io_Control_Spec
objects or NoneType
- class fparser.two.Fortran2003.Io_Control_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.KeywordValueBase
This class implements partial support for Rule 913:
<io-control-spec> is [UNIT = ] <io-unit> | [ FMT = ] <format> | [ NML = ] <namelist-group-name> | ADVANCE = <scalar-default-char-expr> | ASYNCHRONOUS = <scalar-char-initialization-expr> | BLANK = <scalar-default-char-expr> | DECIMAL = <scalar-default-char-expr> | DELIM = <scalar-default-char-expr> | END = <label> | EOR = <label> | ERR = <label> | ID = <scalar-int-variable> | IOMSG = <iomsg-variable> | IOSTAT = <scalar-int-variable> | PAD = <scalar-default-char-expr> | POS = <scalar-int-expr> | REC = <scalar-int-expr> | ROUND = <scalar-default-char-expr> | SIGN = <scalar-default-char-expr> | SIZE = <scalar-int-variable>
The support is partial because this class requires that every spec be named. The specs that may not be named are explicitly handled in Io_Control_Spec_List.match().
- static match(string)[source]
Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.
- Parameters:
lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.
rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.
string (str) – text to be matched.
require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.
upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.
- Returns:
instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.
- Return type:
2-tuple of objects or NoneType
- class fparser.two.Fortran2003.Format(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StringBase
<format> = <default-char-expr> | <label> | *
- class fparser.two.Fortran2003.Input_Item(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<input-item> = <variable> | <io-implied-do>
- class fparser.two.Fortran2003.Output_Item(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<output-item> = <expr> | <io-implied-do>
- class fparser.two.Fortran2003.Io_Implied_Do(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<io-implied-do> = ( <io-implied-do-object-list> , <io-implied-do-control> )
- class fparser.two.Fortran2003.Io_Implied_Do_Object(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<io-implied-do-object> = <input-item> | <output-item>
- class fparser.two.Fortran2003.Io_Implied_Do_Control(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<io-implied-do-control> = <do-variable> = <scalar-int-expr> , <scalar-int-expr> [ , <scalar-int-expr> ]
- class fparser.two.Fortran2003.Dtv_Type_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CALLBase
<dtv-type-spec> = TYPE ( <derived-type-spec> ) | CLASS ( <derived-type-spec> )
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Wait_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.CALLBase
<wait-stmt> = WAIT ( <wait-spec-list> )
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Wait_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.KeywordValueBase
<wait-spec> = [ UNIT = ] <file-unit-number> | END = <label> | EOR = <label> | ERR = <label> | ID = <scalar-int-expr> | IOMSG = <iomsg-variable> | IOSTAT = <scalar-int-variable>
- use_names = ['File_Unit_Number', 'Label', 'Scalar_Int_Expr', 'Iomsg_Variable', 'Scalar_Int_Variable'][source]
- static match(string)[source]
Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.
- Parameters:
lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.
rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.
string (str) – text to be matched.
require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.
upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.
- Returns:
instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.
- Return type:
2-tuple of objects or NoneType
- class fparser.two.Fortran2003.Backspace_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran2003 Rule R923:
<backspace-stmt> = BACKSPACE <file-unit-number> | BACKSPACE ( <position-spec-list> )
Attributes:
items : (File_Unit_Number, Position_Spec_List)
- class fparser.two.Fortran2003.Endfile_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran2003 Rule R924:
<endfile-stmt> = ENDFILE <file-unit-number> | ENDFILE ( <position-spec-list> )
Attributes:
items : (File_Unit_Number, Position_Spec_List)
- class fparser.two.Fortran2003.Rewind_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran2003 Rule R925:
<rewind-stmt> = REWIND <file-unit-number> | REWIND ( <position-spec-list> )
Attributes:
items : (File_Unit_Number, Position_Spec_List)
- class fparser.two.Fortran2003.Position_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.KeywordValueBase
<position-spec> = [ UNIT = ] <file-unit-number> | IOMSG = <iomsg-variable> | IOSTAT = <scalar-int-variable> | ERR = <label>
- static match(string)[source]
Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.
- Parameters:
lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.
rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.
string (str) – text to be matched.
require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.
upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.
- Returns:
instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.
- Return type:
2-tuple of objects or NoneType
- class fparser.two.Fortran2003.Flush_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran2003 Rule R927:
<flush-stmt> = FLUSH <file-unit-number> | FLUSH ( <position-spec-list> )
Attributes:
items : (File_Unit_Number, Position_Spec_List)
- class fparser.two.Fortran2003.Flush_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.KeywordValueBase
Fortran2003 Rule R928:
<flush-spec> = [ UNIT = ] <file-unit-number> | IOMSG = <iomsg-variable> | IOSTAT = <scalar-int-variable> | ERR = <label>
Attributes:
items : ({'UNIT', 'IOMSG', 'IOSTAT', 'ERR'}, {File_Unit_Number, Iomsg_Variable, Scalar_Int_Variable, Label})
- static match(string)[source]
Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.
- Parameters:
lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.
rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.
string (str) – text to be matched.
require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.
upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.
- Returns:
instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.
- Return type:
2-tuple of objects or NoneType
- class fparser.two.Fortran2003.Inquire_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran2003 Rule R929:
<inquire-stmt> = INQUIRE ( <inquire-spec-list> ) | INQUIRE ( IOLENGTH = <scalar-int-variable> ) <output-item-list>
Attributes:
items : (Inquire_Spec_List, Scalar_Int_Variable, Output_Item_List)
- class fparser.two.Fortran2003.Inquire_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.KeywordValueBase
Fortran2003 Rule R930:
<inquire-spec> = [ UNIT = ] <file-unit-number> | FILE = <file-name-expr> | ACCESS = <scalar-default-char-variable> | ACTION = <scalar-default-char-variable> | ASYNCHRONOUS = <scalar-default-char-variable> | BLANK = <scalar-default-char-variable> | DECIMAL = <scalar-default-char-variable> | DELIM = <scalar-default-char-variable> | DIRECT = <scalar-default-char-variable> | ENCODING = <scalar-default-char-variable> | ERR = <label> | EXIST = <scalar-default-logical-variable> | FORM = <scalar-default-char-variable> | FORMATTED = <scalar-default-char-variable> | ID = <scalar-int-expr> | IOMSG = <iomsg-variable> | IOSTAT = <scalar-int-variable> | NAME = <scalar-default-char-variable> | NAMED = <scalar-default-logical-variable> | NEXTREC = <scalar-int-variable> | NUMBER = <scalar-int-variable> | OPENED = <scalar-default-logical-variable> | PAD = <scalar-default-char-variable> | PENDING = <scalar-default-logical-variable> | POS = <scalar-int-variable> | POSITION = <scalar-default-char-variable> | READ = <scalar-default-char-variable> | READWRITE = <scalar-default-char-variable> | RECL = <scalar-int-variable> | ROUND = <scalar-default-char-variable> | SEQUENTIAL = <scalar-default-char-variable> | SIGN = <scalar-default-char-variable> | SIZE = <scalar-int-variable> | STREAM = <scalar-default-char-variable> | UNFORMATTED = <scalar-default-char-variable> | WRITE = <scalar-default-char-variable>
The items attribute for this class contains (str, instance).
- class fparser.two.Fortran2003.Format_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
<format-stmt> = FORMAT <format-specification>
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Format_Item_List(string, parent_cls=None)[source]
Bases:
fparser.two.utils.SequenceBase
This class replaces the one generated by fparser. This class is required as support for hollerith strings makes matching more complicated.
- static match(string)[source]
Implements the matching for a list of format items.
Supporting Hollerith strings makes it very difficult to correctly split the input string into items a-priori. The reason for this can be seen in the following example:
2H,x,e2.2 is 2H,x and e2.2 but when split with commas incorrectly gives 2H, x and e2.2.
Further, hollerith strings could also confuse any code that tried to determine whether code was inside quotes or not. For example:
`2H"x,2H"x` does not mean that `x,2H` is part of a string.
The solution chosen is to match one item at a time, first checking for a valid Hollerith string and then checking for any other valid input.
- Parameters:
string (str) – the string to match as a Format List.
- Returns:
None if there is no match or a tuple of size 2 containing a string with a comma followed by a tuple containing a list which itself contains the matched format items.
- Return type:
(str, ([
fparser.two.Fortran2003.Format_Item`s])) or `NoneType
- class fparser.two.Fortran2003.Format_Specification(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BracketBase
Fortran 2003 rule R1002:
format-specification = ( [ format-item-list ] )
C1002 is implemented in a separate class Format_Item_C1002
C1002 (R1002) The comma used to separate format-items in a format-item-list may be omitted
(1) Between a P edit descriptor and an immediately following F, E, EN, ES, D, or G edit descriptor, possibly preceded by a repeat specifier,
(2) Before a slash edit descriptor when the optional repeat specification is not present,
After a slash edit descriptor, or
Before or after a colon edit descriptor.
- static match(string)[source]
Implements the matching for a format specification.
- Parameters:
string (str) – The string to check for conformance with a format specification.
- Returns:
None if there is no match, otherwise a tuple of size three, the first entry being a string containing a left bracket and the third being a string containing a right bracket. The second entry is either a Format_Item or a Format_Item_List.
- Return type:
NoneType or ( str,
fparser.two.Fortran2003.Format_Item
orfparser.two.Fortran2003.Format_Item_List
, str )
- fparser.two.Fortran2003.skip_digits(string)[source]
Skips over any potential digits (including spaces) to the next non-digit character and return its index. If no such character is found or if the first character in the string is not a digit then specify that the skip has failed.
- class fparser.two.Fortran2003.Format_Item_C1002(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 constraint C1002:
format-item-c1002 is kP [,] (F|D)w.d | (E|EN|ES|G)w.d[Ee] or [r]/ [,] format-item or : [,] format-item or format-item [,] / [[,] format-item] or format-item [,] : [[,] format-item]
C1002 (R1002) The comma used to separate format-items in a format-item-list may be omitted
(1) Between a P edit descriptor and an immediately following F, E, EN, ES, D, or G edit descriptor, possibly preceded by a repeat specifier,
(2) Before a slash edit descriptor when the optional repeat specification is not present (10.7.2),
After a slash edit descriptor, or
Before or after a colon edit descriptor.
- static match(string)[source]
Implements the matching for the C1002 Format Item constraint. The constraints specify certain combinations of format items that do not need a comma to separate them. Rather than sorting this out when parsing the list, it was decided to treat these separately and match them in this class. As a result the generated class hierarchy is a little more complicated.
- Parameters:
string (str) – The string to check for conformance with a C1002 format item constraint.
- Returns:
None if there is no match, otherwise a tuple of size 2 containing a mixture of Control_Edit_Descriptor and Format_Item classes depending on what has been matched.
- Return type:
NoneType or (
fparser.two.Control_Edit_Desc
,fparser.two.Format_Item
) or (fparser.two.Format_Item
,fparser.two.Control_Edit_Desc
) or (fparser.two.Format_Item
,fparser.two.Format_Item
)
- tostr()[source]
- Returns:
Parsed representation of two format items
- Return type:
- Raises:
InternalError – if the length of the internal items list is not 2.
InternalError – if the first entry of the internal items list has no content.
InternalError – if the second entry of the internal items list has no content.
- class fparser.two.Fortran2003.Hollerith_Item(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Hollerith strings take the form nHx, where n is an integer and x is a sequence of characters of length n.
Note, the Hollerith format was deprecated in Fortran77 and removed in Fortran95. However, Fortran compilers still support it. See, for example https://gcc.gnu.org/onlinedocs/gcc-4.8.2/gfortran/Hollerith-constants-support.html
- tostr()[source]
- Returns:
Parsed representation of a Hollerith String.
- Return type:
- Raises:
InternalError – if the length of the internal items list is not 1.
InternalError – if the first entry of the internal items list has no content.
- class fparser.two.Fortran2003.Format_Item(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R1003:
format-item is [ r ] data-edit-desc or control-edit-desc or char-string-edit-desc or [ r ] ( format-item-list ) or format-item-c1002 or hollerith-item
- subclass_names = ['Hollerith_Item', 'Control_Edit_Desc', 'Char_String_Edit_Desc', 'Format_Item_C1002'][source]
- static match(string)[source]
Implements the matching of a Format Item. This method matches ‘[ r ] data-edit-desc’ and ‘[ r ] ( format-item-list )’. The remaining options are matched via subclasses specified in the subclass_names variable.
- Parameters:
string (str) – A string or the Fortran reader containing the line of code that we are trying to match.
- Returns:
None if there is no match or a tuple of size 2 containing an instance of the R class followed by an instance of either the Format_Item_List or the Data_Edit_Desc class.
- Return type:
None or (
fparser.two.Fortran2003.R
,fparser.two.Fortran2003.Format_Item_List
orfparser.two.Fortran2003.Data_Edit_Desc
)
- tostr()[source]
- Returns:
Parsed representation of a Format Item.
- Return type:
- Raises:
InternalError – if the length of the internal items list is not 2.
InternalError – if the first entry of the internal items list has no content.
- class fparser.two.Fortran2003.R(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<r> = <int-literal-constant>
Notes:
C1003, C1004: <r> shall be positive and without kind parameter specified.
- class fparser.two.Fortran2003.Data_Edit_Desc_C1002(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
This class helps implement the matching for the first part of the Fortran 2003 Constraint C1002 which constrains rule R1002. In particular it matches with the subset of edit descriptors that can follow a P edit descriptor without needing a comma, see below.
C1002 (applied to R1002) The comma used to separate format-items in a format-item-list may be omitted
(1) Between a P edit descriptor and an immediately following F, E, EN, ES, D, or G edit descriptor, possibly preceded by a repeat specifier.
[Remaining constraint clauses ommitted as they are not relevant here.]
data-edit-desc is F w . d or E w . d [ E e ] or EN w . d [ E e ] or ES w . d [ E e] or G w . d [ E e ] or D w . d
- static match(string)[source]
Check whether the input matches the rule.
param str string: contains the Fortran that we are trying to match. :return: None if there is no match, otherwise a tuple of size 4, the first entry containing a string with one of [‘F’, ‘E’, ‘EN’, ‘ES’, ‘G’, ‘D’], the second entry containing a W class instance, the third entry containing D class instance and the fourth entry containing either None or an E class instance. :rtype: NoneType, (str,
fparser.two.W
,fparser.two.D
, NoneType) or, (str,fparser.two.W
,fparser.two.D
,fparser.two.E
)
- tostr()[source]
- Returns:
parsed representation of a Data Edit Descriptor conforming to constraint C1002.
- Return type:
- Raises:
InternalError – if the length of the internal items list is not 4.
InternalError – if the first, second or third entry of the internal items list has no content.
InternalError – if the value of the first entry is unsupported.
InternalError – if the value of the first entry is ‘F’ or ‘D’ and the fourth entry has content.
InternalError – if the value of the first entry is ‘E’, ‘EN’, ‘ES’ or ‘G’ and the fourth entry is empty or None.
- class fparser.two.Fortran2003.Data_Edit_Desc(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<data-edit-desc> = I <w> [ . <m> ] | B <w> [ . <m> ] | O <w> [ . <m> ] | Z <w> [ . <m> ] | L <w> | A [ <w> ] | DT [ <char-literal-constant> ] [ ( <v-list> ) ] | <data-edit-desc-c1002>
- class fparser.two.Fortran2003.W(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
w is int-literal-constant == digit-string
Subject to constraints:
C1006, C1007: w is zero or postive and without kind parameters.
- class fparser.two.Fortran2003.M(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
m = int-literal-constant
Subject to the constraint:
C1007: m is without kind parameters.
- class fparser.two.Fortran2003.D(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
d = int-literal-constant
Subject to the constraint:
C1007: d is without kind parameters.
- class fparser.two.Fortran2003.E(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
e is int-literal-constant
Subject to the constraints:
C1005, C1007: e is postive and without kind parameters.
- class fparser.two.Fortran2003.V(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
v is signed-int-literal-constant
Subject to the constraint:
C1007: w is without kind parameters.
- class fparser.two.Fortran2003.Control_Edit_Desc(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R1011:
control-edit-desc is position-edit-desc or [ r ] / or : or sign-edit-desc or k P or blank-interp-edit-desc or round-edit-desc or decimal-edit-desc or $
‘$’ is used to suppress the carriage return on output. Note that this is an extension to the Fortran standard.
- subclass_names = ['Position_Edit_Desc', 'Sign_Edit_Desc', 'Blank_Interp_Edit_Desc', 'Round_Edit_Desc',...[source]
- static match(string)[source]
Check whether the input matches the rule.
param str string: contains the Fortran that we are trying to match. :return: None if there is no match, otherwise a tuple of size 2 containing, None and a string with one of ‘/’, ‘:’, or ‘$’, an R class and a string containing ‘/’ or a K class and a string containing ‘P’. :rtype: NoneType, (NoneType, str), (
fparser.two.Fortran2003.R
, str), or (fparser.two.Fortran2003.K
, str)
- tostr()[source]
- Returns:
parsed representation of a Control Edit Descriptor
- Return type:
- Raises:
InternalError – if the length of the internal items list is not 2.
InternalError – if the second entry of the internal items list has no content.
- class fparser.two.Fortran2003.K(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<k> = <signed-int-literal-constant>
Notes:
C1009: <k> is without kind parameters.
- class fparser.two.Fortran2003.Position_Edit_Desc(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Fortran 2003 rule R1013:
position-edit-desc is T n or TL n or TR n or n X
where n is a positive integer.
If the extensions list includes the string ‘x-format’ then ‘X’ without a preceeding integer is also matched. This is a common extension in Fortran compilers.
- static match(string)[source]
Check whether the input matches the rule.
param str string: contains the Fortran that we are trying to match. :return: None if there is no match, otherwise a tuple of size 2 either containing a string which is one of “T”, “TL” or “TR”, followed by an N class, or containing an N class, or None, followed by an “X”. :rtype: NoneType, (str,
fparser.two.Fortran2003.N
), (fparser.two.Fortran2003.N
, str) or (NoneType, str)
- tostr()[source]
- Returns:
parsed representation of a Position Edit Descriptor
- Return type:
- Raises:
InternalError – if the length of the internal items list is not 2.
InternalError – if the second entry of the internal items list has no content.
- class fparser.two.Fortran2003.N(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<n> = <int-literal-constant> == <digit-string>
Subject to:
C1010, C1011: <n> is positive and without kind parameter.
- class fparser.two.Fortran2003.Sign_Edit_Desc(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
<sign-edit-desc> = SS | SP | S
- static match(string)[source]
Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.
The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:
from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)
- Parameters:
pattern (list, tuple, str or an re expression) – the pattern to match
string (str) – the string to match with the pattern
- Returns:
None if there is no match, or a tuple containing the matched string in upper case.
- Return type:
NoneType or ( str )
- class fparser.two.Fortran2003.Blank_Interp_Edit_Desc(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
<blank-interp-edit-desc> = BN | BZ
- static match(string)[source]
Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.
The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:
from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)
- Parameters:
pattern (list, tuple, str or an re expression) – the pattern to match
string (str) – the string to match with the pattern
- Returns:
None if there is no match, or a tuple containing the matched string in upper case.
- Return type:
NoneType or ( str )
- class fparser.two.Fortran2003.Round_Edit_Desc(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
<round-edit-desc> = RU | RD | RZ | RN | RC | RP
- static match(string)[source]
Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.
The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:
from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)
- Parameters:
pattern (list, tuple, str or an re expression) – the pattern to match
string (str) – the string to match with the pattern
- Returns:
None if there is no match, or a tuple containing the matched string in upper case.
- Return type:
NoneType or ( str )
- class fparser.two.Fortran2003.Decimal_Edit_Desc(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
- <decimal-edit-desc> = DC
- DP
- static match(string)[source]
Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.
The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:
from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)
- Parameters:
pattern (list, tuple, str or an re expression) – the pattern to match
string (str) – the string to match with the pattern
- Returns:
None if there is no match, or a tuple containing the matched string in upper case.
- Return type:
NoneType or ( str )
- class fparser.two.Fortran2003.Char_String_Edit_Desc(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<char-string-edit-desc> = <char-literal-constant>
- class fparser.two.Fortran2003.Main_Program(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
Fortran 2003 rule R1101:
main-program is program-stmt [ specification-part ] [ execution-part ] [ internal-subprogram-part ] end-program-stmt
This class does not cater for the case where there is no program-stmt. The separate Main_Program0() class matches this situation. See Class Program() method match() for how this is implemented.
C1101 In a main-program, the execution-part shall not contain a RETURN statement or an ENTRY statement. This is currently not checked, see issue #140.
C1102 The program-name may be included in the end-program-stmt only if the optional program-stmt is used and, if included, shall be identical to the program-name specified in the program-stmt.
C1103 An automatic object shall not appear in the specification-part (R204) of a main program. This is currently not checked, see issue #140.
- use_names = ['Program_Stmt', 'Specification_Part', 'Execution_Part', 'Internal_Subprogram_Part', 'End_Program_Stmt'][source]
- static match(reader)[source]
Implements the matching of a main program which has a Program statement. See class Main_Program0 for matching without a Program Statement. Matching uses BlockBase as it conforms to the start/end with optional content pattern. match_names is set to True so that different names e.g. program x and end program y will not match.
- Parameters:
reader (
fparser.common.readfortran.FortranReaderBase
) – the Fortran reader containing the line(s) of code that we are trying to match- Returns:
None if there is not match or, if there is a match, a tuple containing a single list, with minimum size 2 and maximum size 5, which contains instances of the classes that have matched. The first entry in the list will be a Program_Stmt and the last entry in the list will be an End_Program_Stmt. In-between these two instances will be an optional Specification_Part followed by an optional Execution_Part followed by an optional Internal_Subprogram_Part.
- Return type:
NoneType or ([
fparser.two.Fortran2003.Program_Stmt
, optionalfparser.two.Fortran2003.Specification_Part
, optionalfparser.two.Fortran2003.Execution_Part
, optionalfparser.two.Fortran2003.Internal_Subprogram_Part
,fparser.two.Fortran2003.End_Program_Stmt
])
- class fparser.two.Fortran2003.Main_Program0(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
Rule 1101 specifies that the opening ‘program-stmt’ is optional. This class handles the special case when it is not supplied and thus matches on:
<main-program> = [ <specification-part> ] [ <execution-part> ] [ <internal-subprogram-part> ] <end-program-stmt>
C1102 The program-name may be included in the end-program-stmt only if the optional program-stmt is used and, if included, shall be identical to the program-name specified in the program-stmt.
In this class an end program name is not allowed due to C1102.
- use_names = ['Program_Stmt', 'Specification_Part', 'Execution_Part', 'Internal_Subprogram_Part', 'End_Program_Stmt'][source]
- static match(reader)[source]
Attempts to match the content in the reader with a program that is missing the optional opening program-stmt (R1101). If the match is successful, a symbol table named “fparser2:main_program” is also created.
- Parameters:
reader (str or instance of
FortranReaderBase
) – Content to check for match- Returns:
2-tuple of (list of matched classes, None) or None if no match is found.
- Return type:
(list of matched classes, None) or NoneType
- class fparser.two.Fortran2003.Program_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
,fparser.two.utils.ScopingRegionMixin
Fortran 2003 rule R1102:
program-stmt is PROGRAM program-name
- static match(string)[source]
Implements the matching for a Program Statement. Makes use of WORDClsBase, as the required match is a string followed by a class. The class is made compulsory for the match as the PROGRAM keyword is not valid without a program name.
- Parameters:
string (str) – Fortran code to check for a match
- Returns:
None if there is no match or, if there is a match, a tuple of size 2 with the first entry being the string ‘PROGRAM’ and the second entry being a Name class containing the name of the program.
- Return type:
NoneType or ( str,
fparser.two.Fortran2003.Name
)
- class fparser.two.Fortran2003.End_Program_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.EndStmtBase
<end-program-stmt> = END [ PROGRAM [ <program-name> ] ]
- static match(string)[source]
Attempts to match the supplied string as a form of ‘END xxx’ statement.
- Parameters:
stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.
stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).
string (str) – the string to attempt to match.
require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.
- Returns:
2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.
- Return type:
Optional[ Tuple[Optional[str],
Optional[
fparser.two.Fortran2003.Name
]]]
- class fparser.two.Fortran2003.Module(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<module> = <module-stmt> [ <specification-part> ] [ <module-subprogram-part> ] <end-module-stmt>
- use_names = ['Module_Stmt', 'Specification_Part', 'Module_Subprogram_Part', 'End_Module_Stmt'][source]
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Module_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
,fparser.two.utils.ScopingRegionMixin
<module-stmt> = MODULE <module-name>
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.End_Module_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.EndStmtBase
<end-module-stmt> = END [ MODULE [ <module-name> ] ]
- static match(string)[source]
Attempts to match the supplied string as a form of ‘END xxx’ statement.
- Parameters:
stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.
stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).
string (str) – the string to attempt to match.
require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.
- Returns:
2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.
- Return type:
Optional[ Tuple[Optional[str],
Optional[
fparser.two.Fortran2003.Name
]]]
- class fparser.two.Fortran2003.Module_Subprogram_Part(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<module-subprogram-part> = <contains-stmt> <module-subprogram> [ <module-subprogram> ]...
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Module_Subprogram(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<module-subprogram> = <function-subprogram> | <subroutine-subprogram>
- class fparser.two.Fortran2003.Use_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
Fortran 2003 rule R1109:
use-stmt is USE [ [ , module-nature ] :: ] module-name [ , rename-list ] or USE [ [ , module-nature ] :: ] module-name , ONLY : [ only-list ]
- static match(string)[source]
Wrapper for the match method that captures any successfully-matched use statements in the symbol table associated with the current scope (if there is one).
- TODO #379 - currently operator imports/renaming are not captured in
the symbol table.
- Parameters:
string (str) – Fortran code to check for a match.
- Returns:
5-tuple containing strings and instances of the classes describing a module (optional module nature, optional double colon delimiter, mandatory module name, optional “ONLY” specification and optional “Rename” or “Only” list) or None if the match fails.
- Return type:
5-tuple of objects (module name and 4 optional) or NoneType
- Raises:
InternalError – if an Only_List is found to contain anything other than Name or Rename objects.
- static _match(string)[source]
- Parameters:
string (str) – Fortran code to check for a match.
- Returns:
5-tuple containing strings and instances of the classes describing a module (optional module nature, optional double colon delimiter, mandatory module name, optional “ONLY” specification and optional “Rename” or “Only” list).
- Return type:
5-tuple of objects (module name and 4 optional)
- tostr()[source]
- Returns:
parsed representation of “USE” statement
- Return type:
string
- Raises:
InternalError – if items array is not the expected size
InternalError – if items array[2] is not a string or is an empty string
InternalError – if items array[3] is ‘None’ as it should be a string
- class fparser.two.Fortran2003.Module_Nature(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
R1110:
<module-nature> = INTRINSIC | NON_INTRINSIC
- class fparser.two.Fortran2003.Rename(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
Class defining Rule #R1111:
rename is local-name => use-name or OPERATOR(local-defined-operator) => OPERATOR(use-defined-operator)
where:
local-defined-operator is defined-uary-op or defined-binary-op defined-binary-op is .letter [letter] ... .
- static match(string)[source]
- Parameters:
string (str) – the string to attempt to match.
- Returns:
three tuple containing description, local name, remote name.
- Return type:
Optional[ Tuple[Optional[str],
fparser.two.Fortran2003.Local_Name
|fparser.two.Fortran2003.Local_Defined_Operator
,fparser.two.Fortran2003.Use_Name
|fparser.two.Fortran2003.Use_Defined_Operator
]]
- class fparser.two.Fortran2003.Only(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<only> = <generic-spec> | <only-use-name> | <rename>
- class fparser.two.Fortran2003.Only_Use_Name(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<only-use-name> = <name>
- class fparser.two.Fortran2003.Local_Defined_Operator(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<local-defined-operator> = <defined-unary-op> | <defined-binary-op>
- class fparser.two.Fortran2003.Use_Defined_Operator(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<use-defined-operator> = <defined-unary-op> | <defined-binary-op>
- class fparser.two.Fortran2003.Block_Data(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
- ::
- <block-data> = <block-data-stmt>
[ <specification-part> ] <end-block-data-stmt>
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Block_Data_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<block-data-stmt> = BLOCK DATA [ <block-data-name> ]
- class fparser.two.Fortran2003.End_Block_Data_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.EndStmtBase
<end-block-data-stmt> = END [ BLOCK DATA [ <block-data-name> ] ]
- static match(string)[source]
Attempts to match the supplied string as a form of ‘END xxx’ statement.
- Parameters:
stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.
stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).
string (str) – the string to attempt to match.
require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.
- Returns:
2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.
- Return type:
Optional[ Tuple[Optional[str],
Optional[
fparser.two.Fortran2003.Name
]]]
- class fparser.two.Fortran2003.Interface_Block(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<interface-block> = <interface-stmt> [ <interface-specification> ]... <end-interface-stmt>
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Interface_Specification(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<interface-specification> = <interface-body> | <procedure-stmt>
- class fparser.two.Fortran2003.Interface_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<interface-stmt> = INTERFACE [ <generic-spec> ] | ABSTRACT INTERFACE
Attributes:
items : ({Generic_Spec, 'ABSTRACT'},)
- class fparser.two.Fortran2003.End_Interface_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.EndStmtBase
<end-interface-stmt> = END INTERFACE [ <generic-spec> ]
Attributes:
items : (Generic_Spec, )
- static match(string)[source]
Attempts to match the supplied string as a form of ‘END xxx’ statement.
- Parameters:
stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.
stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).
string (str) – the string to attempt to match.
require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.
- Returns:
2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.
- Return type:
Optional[ Tuple[Optional[str],
Optional[
fparser.two.Fortran2003.Name
]]]
- class fparser.two.Fortran2003.Function_Body(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<function-body> = <function-stmt> [ <specification-part> ] <end-function-stmt>
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Subroutine_Body(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<subroutine-body> = <subroutine-stmt> [ <specification-part> ] <end-subroutine-stmt>
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Interface_Body(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<interface-body> = <function-body> | <subroutine-body>
See also
fparser.two.Fortran2003.Function_Body
andfparser.two.Fortran2003.Subroutine_Body
- class fparser.two.Fortran2003.Procedure_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<procedure-stmt> = [ MODULE ] PROCEDURE <procedure-name-list>
Attributes:
items : (Procedure_Name_List, )
- class fparser.two.Fortran2003.Generic_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<generic-spec> = <generic-name> | OPERATOR ( <defined-operator> ) | ASSIGNMENT ( = ) | <dtio-generic-spec>
Attributes:
items : ({'OPERATOR', 'ASSIGNMENT'}, {Defined_Operator, '='})
- class fparser.two.Fortran2003.Dtio_Generic_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<dtio-generic-spec> = READ ( FORMATTED ) | READ ( UNFORMATTED ) | WRITE ( FORMATTED ) | WRITE ( UNFORMATTED )
Attributes:
items : (str, )
- class fparser.two.Fortran2003.Import_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
Fortran 2003 rule R1209:
import-stmt is IMPORT [[ :: ] import-name-list ]
C1210 (R1209) The IMPORT statement is allowed only in an interface-body. Note, this constraint is not currently enforced.
C1211 (R1209) Each import-name shall be the name of an entity in the host scoping unit. This constraint is not currently enforced and can not be generally enforced as the name may come from a use statement without an only clause.
- static match(string)[source]
Implements the matching for the import-stmt rule.
Makes use of the WORDClsBase base class.
- Parameters:
string (str) – the string to match.
- Returns:
None if there is no match, otherwise a tuple of size 2 containing the string IMPORT as the first entry and an object of type Import_Name_List if names are specified in the string or None if not.
- Return type:
None, or (str,
fparser.two.Fortran2003.Import_Name_List
) or (str, None)
- class fparser.two.Fortran2003.External_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
<external-stmt> = EXTERNAL [ :: ] <external-name-list>
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Procedure_Declaration_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<procedure-declaration-stmt> = PROCEDURE ( [ <proc-interface> ] ) [ [ , <proc-attr-spec> ]... :: ] <proc-decl-list>
Attributes:
items : (Proc_Interface, Proc_Attr_Spec_List, Proc_Decl_List)
- class fparser.two.Fortran2003.Proc_Interface(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<proc-interface> = <interface-name> | <declaration-type-spec>
- class fparser.two.Fortran2003.Proc_Attr_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<proc-attr-spec> = <access-spec> | <proc-language-binding-spec> | INTENT ( <intent-spec> ) | OPTIONAL | POINTER | PROTECTED | SAVE
Attributes:
items : ({'INTENT', 'OPTIONAL', 'POINTER', 'PROTECTED', 'SAVE'}, Intent_Spec)
- class fparser.two.Fortran2003.Proc_Decl(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BinaryOpBase
<proc-decl> = <procedure-entity-name> [ => <null-init> ]
Attributes:
items : (Procedure_Entity_Name, Null_Init)
- static match(string)[source]
Matches the binary-op-base rule.
If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.
If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.
if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.
- Parameters:
lhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the lhs text.op_pattern (str or
fparser.two.pattern_tools.Pattern
) – the pattern to match.rhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the rhs text.string (str) – the string to match with the pattern and lhs and rhs rules.
right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).
exclude_op_pattern (
fparser.two.pattern_tools.Pattern
) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.
- Returns:
a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.
- Return type:
(
fparser.two.utils.Base
, str,fparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.Interface_Name(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<interface-name> = <name>
- class fparser.two.Fortran2003.Intrinsic_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.WORDClsBase
<intrinsic-stmt> = INTRINSIC [ :: ] <intrinsic-procedure-name-list>
- static match(string)[source]
Checks whether the content in string matches the expected WORDClsBase format with ‘keyword’ providing the keyword, ‘cls’ providing the following text, ‘colons’ specifying whether an optional double colon is allowed as a separator between the keyword and cls and ‘require_cls’ specifying whether cls must have content or not.
Note, if the optional double colon is allowed and exists in the string then 1) cls must also have content i.e. it implies require_cls=True and 2) white space is not required between the keyword and the double colon and the double colon and cls.
The simplest form of keyword pattern is a string. However this method can also match more complex patterns as specified by the Pattern class in pattern_tools.py. As patterns can be built from combinations of other patterns (again see pattern_tool.py) this method also supports a hierarchy of lists and/or tuples of patterns.
- Parameters:
keyword (
fparser.two.pattern_tools.Pattern
, str, tuple of str/Pattern/tuple/list or list of str/Pattern/tuple/list) – the pattern of the WORD to match. This can be a Pattern, string, list or tuple, with a list or tuple containing one or more Pattern, string, list or tuple.cls (a subclass of
fparser.two.utils.Base
) – the class to match.string (str) – Text that we are trying to match.
colons (bool) – whether a double colon is allowed as an optional separator between between WORD and cls.
require_cls (bool) – whether content for cls is required or not.
- Returns:
None if there is no match or, if there is a match, a 2-tuple containing a string matching the ‘WORD’ and an instance of ‘cls’ (or None if an instance of cls is not required and not provided).
- Return type:
- class fparser.two.Fortran2003.Function_Reference(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CallBase
- <function-reference> = <procedure-designator>
( [ <actual-arg-spec-list> ] )
- static match(string)[source]
- Parameters:
lhs_cls (str | class) – the class to match with the lhs.
rhs_cls (str | class) – the class to match with the rhs.
string (str) – the string to attempt to match.
upper_lhs (bool) – whether or not to convert the lhs to uppercase before attempting the match.
require_rhs (bool) – whether the rhs (the part within parentheses) must be present.
- Returns:
a tuple containing the lhs and rhs matches or None if there is no match.
- Return type:
Optional[Tuple[
fparser.two.utils.Base
, Optional[fparser.two.utils.Base
]]]
- class fparser.two.Fortran2003.Intrinsic_Name(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
Represents the name of a Fortran intrinsic function.
All generic intrinsic names are specified as keys in the generic_function_names dictionary, with their values indicating the minimum and maximum number of arguments allowed for this intrinsic function. A -1 indicates an unlimited number of arguments. The names are split into the categories specified in the Fortran2003 specification document.
All specific intrinsic names (which have a different name to their generic counterpart) are specified as keys in the specific_function_names dictionary, with their values indicating which generic function they are associated with.
- class fparser.two.Fortran2003.Intrinsic_Function_Reference(string, parent_cls=None)[source]
Bases:
fparser.two.utils.CallBase
Represents Fortran intrinsics:
function-reference is intrinsic-name ( [ actual-arg-spec-list ] )
- static match(string)[source]
Match the string as an intrinsic function. Also check that the number of arguments provided matches the number expected by the intrinsic.
- Parameters:
string (str) – the string to match with the pattern rule.
- Returns:
a tuple of size 2 containing the name of the intrinsic and its arguments if there is a match, or None if there is not.
- Return type:
Tuple[
fparser.two.Fortran2003.Intrinsic_Name
,fparser.two.Fortran2003.Actual_Arg_Spec_List
] | NoneType- Raises:
InternalSyntaxError – If the number of arguments provided does not match the number of arguments expected by the intrinsic and there are no wildcard imports that could be bringing a routine (that overrides it) into scope.
- class fparser.two.Fortran2003.Call_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<call-stmt> = CALL <procedure-designator> [ ( [ <actual-arg-spec-list> ] ) ]
Attributes:
items : (Procedure_Designator, Actual_Arg_Spec_List)
- class fparser.two.Fortran2003.Procedure_Designator(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BinaryOpBase
<procedure-designator> = <procedure-name> | <proc-component-ref> | <data-ref> % <binding-name>
- static match(string)[source]
Matches the binary-op-base rule.
If the operator defined by argument ‘op_pattern’ is found in the string provided in argument ‘string’ then the text to the left-hand-side of the operator is matched with the class rule provided in the ‘lhs_cls’ argument and the text to the right-hand-side of the operator is matched with the class rule provided in the ‘rhs_cls’ argument.
If the optional ‘right’ argument is set to true (the default) then, in the case where the pattern matches multiple times in the input string, the right-most match will be chosen. If the ‘right’ argument is set to false then the left-most match will be chosen.
if a pattern is provided to the optional ‘exclude_op_pattern’ argument then there will be no match if the pattern matched by the ‘op_pattern’ argument also matches this pattern. The default (None) does nothing.
- Parameters:
lhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the lhs text.op_pattern (str or
fparser.two.pattern_tools.Pattern
) – the pattern to match.rhs_cls (subclass of
fparser.two.utils.Base
) – an fparser2 object representing the rule that should be matched to the rhs text.string (str) – the string to match with the pattern and lhs and rhs rules.
right (bool) – in the case where there are multiple matches to the pattern in the string this optional argument specifies whether the righmost pattern match should be chosen (True, the default) or whether the leftmost pattern should be chosen (False).
exclude_op_pattern (
fparser.two.pattern_tools.Pattern
) – optional argument which specifies a particular subpattern to exclude from the match. Defaults to None which means there is no subpattern.
- Returns:
a tuple containing the matched lhs, the operator and the matched rhs of the input string or None if there is no match.
- Return type:
(
fparser.two.utils.Base
, str,fparser.two.utils.Base
) or NoneType
- class fparser.two.Fortran2003.Actual_Arg_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.KeywordValueBase
<actual-arg-spec> = [ <keyword> = ] <actual-arg>
- static match(string)[source]
Attempts to match the supplied string with lhs_cls = rhs_cls. If lhs_cls is a str then it is compared with the content to the left of the first ‘=’ character in string. If that content is a valid Fortran name but does not match lhs_cls then the match fails, irrespective of the setting of require_lhs.
- Parameters:
lhs_cls (names of classes deriving from :py:class:Base or str) – list, tuple or single value of classes to attempt to match LHS against (in order), or string containing keyword to match.
rhs_cls (name of a class deriving from :py:class:Base) – name of class to match RHS against.
string (str) – text to be matched.
require_lhs (bool) – whether the expression to be matched must contain a LHS that is assigned to.
upper_lhs (bool) – whether or not to convert the LHS of the matched expression to upper case.
- Returns:
instances of the classes representing quantities on the LHS and RHS (LHS is optional) or None if no match is found.
- Return type:
2-tuple of objects or NoneType
- class fparser.two.Fortran2003.Actual_Arg(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<actual-arg> = <expr> | <variable> | <procedure-name> | <proc-component-ref> | <alt-return-spec>
- class fparser.two.Fortran2003.Alt_Return_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<alt-return-spec> = * <label>
- class fparser.two.Fortran2003.Function_Subprogram(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<function-subprogram> = <function-stmt> [ <specification-part> ] [ <execution-part> ] [ <internal-subprogram-part> ] <end-function-stmt>
- use_names = ['Function_Stmt', 'Specification_Part', 'Execution_Part', 'Internal_Subprogram_Part',...[source]
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- class fparser.two.Fortran2003.Function_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.ScopingRegionMixin
<function-stmt> = [ <prefix> ] FUNCTION <function-name> ( [ <dummy-arg-name-list> ] ) [ <suffix> ]
C1242 (R1227) A prefix shall not specify ELEMENTAL if proc-language-binding-spec appears in the function-stmt or subroutine-stmt. The spec associates this constraint with R1227 but it needs to be checked here.
- class fparser.two.Fortran2003.Proc_Language_Binding_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<proc-language-binding-spec> = <language-binding-spec>
- class fparser.two.Fortran2003.Dummy_Arg_Name(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<dummy-arg-name> = <name>
- class fparser.two.Fortran2003.Prefix(string, parent_cls=None)[source]
Bases:
fparser.two.utils.SequenceBase
Fortran2003 rule R1227:
prefix is prefix-spec [ prefix-spec ] ...
C1240 (R1227) A prefix shall contain at most one of each prefix-spec. Checked below.
C1241 (R1227) A prefix shall not specify both ELEMENTAL and RECURSIVE. Checked below.
C1242 (R1227) A prefix shall not specify ELEMENTAL if proc-language-binding-spec appears in the function-stmt or subroutine-stmt. This constraint can not be checked here, it is checked in R1224 and R1232.
- static match(string)[source]
Match a space separated list of Prefix_Spec objects. Objects may be separated by 1 or more spaces.
- Returns:
A tuple of size 2 containing the separator and a tuple containing one or more Prefix_Spec objects if there is a match and None if not.
- Return type:
Optional[Tuple[Str, Tuple[
fparser.two.Fortran2003.Prefix_Spec
, …]]]
- class fparser.two.Fortran2003.Prefix_Spec(string, parent_cls=None)[source]
Bases:
fparser.two.utils.STRINGBase
<prefix-spec> = <declaration-type-spec> | ELEMENTAL | IMPURE | MODULE | PURE | RECURSIVE
- class fparser.two.Fortran2003.Suffix(string, parent_cls=None)[source]
Bases:
fparser.two.utils.Base
<suffix> = <proc-language-binding-spec> [ RESULT ( <result-name> ) ] | RESULT ( <result-name> ) [ <proc-language-binding-spec> ]
- class fparser.two.Fortran2003.End_Function_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.EndStmtBase
<end-function-stmt> = END [ FUNCTION [ <function-name> ] ]
- static match(string)[source]
Attempts to match the supplied string as a form of ‘END xxx’ statement.
- Parameters:
stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.
stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).
string (str) – the string to attempt to match.
require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.
- Returns:
2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.
- Return type:
Optional[ Tuple[Optional[str],
Optional[
fparser.two.Fortran2003.Name
]]]
- class fparser.two.Fortran2003.Subroutine_Subprogram(string, parent_cls=None)[source]
Bases:
fparser.two.utils.BlockBase
<subroutine-subprogram> = <subroutine-stmt> [ <specification-part> ] [ <execution-part> ] [ <internal-subprogram-part> ] <end-subroutine-stmt>
- use_names = ['Subroutine_Stmt', 'Specification_Part', 'Execution_Part', 'Internal_Subprogram_Part',...[source]
- static match(reader)[source]
Checks whether the content in reader matches the given type of block statement (e.g. DO..END DO, IF…END IF etc.)
- Parameters:
startcls (type) – the class marking the beginning of the block
subclasses (list) – list of classes that can be children of the block.
endcls (type) – the class marking the end of the block.
reader (str or instance of
FortranReaderBase
) – content to check for match.match_labels (bool) – whether or not the statement terminating the block must have a label that matches the opening statement. Default is False.
match_names (bool) – TBD
match_name_classes (tuple) – TBD
enable_do_label_construct_hook (bool) – TBD
enable_if_construct_hook (bool) – TBD
enable_where_construct_hook (bool) – TBD
strict_order (bool) – whether to enforce the order of the given subclasses.
strict_match_names (bool) – if start name present, end name must exist and match.
- Returns:
instance of startcls or None if no match is found
- Return type:
startcls
- fparser.two.Fortran2003.c1242_valid(prefix, binding_spec)[source]
If prefix and binding-spec exist then check whether they conform to constraint C1242 - “A prefix shall not specify ELEMENTAL if proc-language-binding-spec appears in the function-stmt or subroutine-stmt.”
- Parameters:
prefix – matching prefix instance if one exists.
binding_spec (
fparser.two.Fortran2003.Language_Binding_Spec
or NoneType) – matching binding specification instance if one exists.
- Type:
fparser.two.Fortran2003.Prefix
or NoneType- Returns:
False if prefix and binding-spec break constraint C1242, otherwise True.
- Return type:
- class fparser.two.Fortran2003.Subroutine_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.ScopingRegionMixin
Fortran2003 rule R1232:
subroutine-stmt is [ prefix ] SUBROUTINE subroutine-name [ ( [ dummy-arg-list ] ) [ proc-language-binding-spec ] ]
C1242 (R1227) A prefix shall not specify ELEMENTAL if proc-language-binding-spec appears in the function-stmt or subroutine-stmt. The spec associates this constraint with R1227 but it needs to be checked here.
- class fparser.two.Fortran2003.Dummy_Arg(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StringBase
<dummy-arg> = <dummy-arg-name> | *
- class fparser.two.Fortran2003.End_Subroutine_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.EndStmtBase
<end-subroutine-stmt> = END [ SUBROUTINE [ <subroutine-name> ] ]
- static match(string)[source]
Attempts to match the supplied string as a form of ‘END xxx’ statement.
- Parameters:
stmt_type (str) – the type of end statement (e.g. “do”) that we attempt to match.
stmt_name (type) – a class which should be used to match against the name should this statement be named (e.g. end subroutine sub).
string (str) – the string to attempt to match.
require_stmt_type (bool) – whether or not the string must contain the type of the block that is ending.
- Returns:
2-tuple containing the matched end-statement type (if any) and, optionally, an associated name or None if there is no match.
- Return type:
Optional[ Tuple[Optional[str],
Optional[
fparser.two.Fortran2003.Name
]]]
- class fparser.two.Fortran2003.Entry_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<entry-stmt> = ENTRY <entry-name> [ ( [ <dummy-arg-list> ] ) [ <suffix> ] ]
Attributes:
items : (Entry_Name, Dummy_Arg_List, Suffix)
- class fparser.two.Fortran2003.Return_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<return-stmt> = RETURN [ <scalar-int-expr> ]
- class fparser.two.Fortran2003.Contains_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
,fparser.two.utils.STRINGBase
<contains-stmt> = CONTAINS
- static match(string)[source]
Matches an input string with a specified pattern. Casts the string to upper case before performing a match and, if there is a match, returns the string in upper case.
The pattern can be a regular expression, a string, a list or a tuple. If the input pattern is a regular expression or a string, a direct equivalence is performed. If the input pattern is a list or a tuple, then all of the contents of the list or tuple are searched for a match (by recursing). The list or tuple may contain regular expressions, strings, lists or tuples. This functionality can be used to recurse down a tree of lists and or tuples until regular expressions or strings are found (at the leaves of the tree) on which to match. The patterns used to match in fparser can be found in patterns_tools.py. These make use of the pattern class, whose match method behaves like a regular expression. For example:
from fparser.two import pattern_tools pattern = pattern_tools.intrinsic_type_name result = STRINGBase.match(pattern, “logical”)
- Parameters:
pattern (list, tuple, str or an re expression) – the pattern to match
string (str) – the string to match with the pattern
- Returns:
None if there is no match, or a tuple containing the matched string in upper case.
- Return type:
NoneType or ( str )
- class fparser.two.Fortran2003.Stmt_Function_Stmt(string, parent_cls=None)[source]
Bases:
fparser.two.utils.StmtBase
<stmt-function-stmt> = <function-name> ( [ <dummy-arg-name-list> ] ) = Scalar_Expr