fparser.two.Fortran2008

Fortran 2008 module. Contains classes which extend the Fortran 2003 standard to implement the Fortran 2008 standard.

Submodules

Package Contents

Classes

Base

Base class for Fortran 2003 syntax rules.

SequenceBase

Match one or more fparser2 rules separated by a defined separator:

Program_Unit

Fortran 2008 rule R202.

Executable_Construct

Fortran 2008 rule R213.

Executable_Construct_C201

executable-construct-c201 is executable construct.

Action_Stmt

Fortran 2008 rule R214.

Action_Stmt_C201

action-stmt-c201 is action-stmt

Action_Stmt_C816

action-stmt-c816 is action-stmt

Action_Stmt_C828

action-stmt-c828 is action-stmt

Data_Component_Def_Stmt

Fortran 2008 rule 436.

Component_Attr_Spec

Fortran 2008 rule R437.

Type_Declaration_Stmt

Fortran 2008 rule 501.

Codimension_Attr_Spec

codimension-attr-spec is CODIMENSION lbracket coarray-spec rbracket

Coarray_Bracket_Spec

coarray-bracket-spec is lbracket coarray-spec rbracket

Attr_Spec

Fortran 2008 rule R502.

Coarray_Spec

Fortran 2008 rule R509.

Deferred_Coshape_Spec

Fortran 2008 rule R510

Explicit_Coshape_Spec

Fortran 2008 rule R511

Coshape_Spec

coshape-spec is [ lower-cobound : ] upper-cobound

Lower_Cobound

Fortran 2008 rule R512

Upper_Cobound

Fortran 2008 rule R513

Do_Term_Action_Stmt

Fortran 2008 rule R826.

Alloc_Opt

Fortran2008 rule R627.

Allocate_Stmt

Fortran 2008 rule R626.

Loop_Control

Fortran 2008 rule R818

If_Stmt

Fortran 2008 rule R837

Error_Stop_Stmt

Fortran 2008 rule R856

Specification_Part_C1112

Fortran 2008 constraint C1112

Implicit_Part_C1112

Fortran 2008 constraint C1112

Implicit_Part_Stmt_C1112

Fortran 2008 constraint C1112

Declaration_Construct_C1112

Fortran 2008 constraint C1112

Submodule

Fortran 2008 rule R1116.

Submodule_Stmt

Fortran 2008 rule R1117:

End_Submodule_Stmt

Fortran 2008 rule R1119

Parent_Identifier

Fortran 2008 rule R1118

Open_Stmt

Fortran2008 Rule R904.

Connect_Spec

Fortran2008 rule R905. Extends the Fortran2003 definition with support for

Block_Construct

Fortran 2008 Rule 807.

Block_Stmt

Fortran 2008 Rule 808.

End_Block_Stmt

Fortran 2008 Rule 809.

Critical_Construct

Fortran 2008 Rule 810.

Critical_Stmt

Fortran 2008 Rule R811.

End_Critical_Stmt

Fortran 2008 Rule 812.

Procedure_Stmt

Fortran 2008 Rule 1206.

Action_Term_Do_Construct

Subclass the 2003 version so that this class will import the

Block_Label_Do_Construct

Subclass the 2003 version so that this class will import the

Block_Nonlabel_Do_Construct

Subclass the 2003 version so that this class will import the

Label_Do_Stmt

Subclass the 2003 version so that this class will import the

Attributes

ClassType

_names

NEW_CLS

NEW_CLS

classes

__all__

class fparser.two.Fortran2008.Base(string, parent_cls=None)[source]

Bases: ComparableMixin

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:
property children

Return an iterable containing the immediate children of this node in the parse tree.

If this node represents an expression then its children are contained in a tuple which is immutable. Therefore, the manipulation of the children of such a node must be done by replacing the items property of the node directly rather than via the objects returned by this method.

Returns:

the immediate children of this node.

Return type:

list or tuple containing zero or more of fparser.two.utils.Base or NoneType or str

subclasses
get_root()[source]

Gets the node at the root of the parse tree to which this node belongs.

Returns:

the node at the root of the parse tree.

Return type:

fparser.two.utils.Base

init(*items)[source]

Store the supplied list of nodes in the items list of this node.

Parameters:

items (tuple of fparser.two.utils.Base) – the children of this node.

torepr()[source]
__str__()[source]

Return str(self).

__repr__()[source]

Return repr(self).

_cmpkey()[source]

Provides a key of objects to be used for comparing.

tofortran(tab='', isfix=None)[source]

Produce the Fortran representation of this Comment.

Parameters:
  • tab (str) – characters to pre-pend to output.

  • isfix (bool) – whether or not this is fixed-format code.

Returns:

Fortran representation of this comment.

Return type:

str

restore_reader(reader)[source]
class fparser.two.Fortran2008.SequenceBase(string, parent_cls=None)[source]

Bases: Base

Match one or more fparser2 rules separated by a defined separator:

sequence-base is obj [sep obj ] ...
static match(separator, subcls, string)[source]

Match one or more ‘subcls’ fparser2 rules in the string ‘string’ separated by ‘separator’.

Parameters:
  • separator (str) – the separator used to split the supplied string.

  • subcls (subclass of fparser.two.utils.Base) – an fparser2 object representing the rule that should be matched.

  • string (str) – the input string to match.

Returns:

a tuple containing 1) the separator and 2) the matched objects in a tuple, or None if there is no match.

Return type:

Optional[(Str, fparser.two.utils.Base)]

Raises:
  • InternalError – if the separator or string arguments are not the expected type.

  • InternalError – if the separator is white space.

init(separator, items)[source]

Store the result of the match method if the match is successful.

Parameters:
  • separator (str) – the separator used to split the supplied string.

  • items (tuple(Subclass of fparser.two.utils.Base)) – a tuple containing the matched objects.

tostr()[source]
Returns:

The Fortran representation of this object as a string.

Return type:

str

torepr()[source]
Returns:

The Python representation of this object as a string.

Return type:

str

class fparser.two.Fortran2008.Program_Unit(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Program_Unit

Fortran 2008 rule R202.

program-unit is main-program
                or external-subprogram
                or module
                or submodule
                or block-data
subclass_names
class fparser.two.Fortran2008.Executable_Construct(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Executable_Construct

Fortran 2008 rule R213.

executable-construct is action-stmt
                     or associate-construct
                     or block-construct
                     or case-construct
                     or critical-construct
                     or do-construct
                     or forall-construct
                     or if-construct
                     or select-type-construct
                     or where-construct

Associated constraints are:

“C201 (R208) An execution-part shall not contain an end-function-stmt,

end-mp-subprogram-stmt, end-program-stmt, or end-subroutine-stmt.”

subclass_names = ['Action_Stmt', 'Associate_Construct', 'Block_Construct', 'Case_Construct',...
class fparser.two.Fortran2008.Executable_Construct_C201(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Executable_Construct_C201

executable-construct-c201 is executable construct. This applies C201.

subclass_names
class fparser.two.Fortran2008.Action_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Action_Stmt

Fortran 2008 rule R214.

action-stmt is allocate-stmt
                or assignment-stmt
                or backspace-stmt
                or call-stmt
                or close-stmt
                or continue-stmt
                or cycle-stmt
                or deallocate-stmt
                or end-function-stmt
                or end-mp-subprogram-stmt
                or end-program-stmt
                or end-subroutine-stmt
                or endfile-stmt
                or error-stop-stmt
                or exit-stmt
                or flush-stmt
                or forall-stmt
                or goto-stmt
                or if-stmt
                or inquire-stmt
                or lock-stmt
                or nullify-stmt
                or open-stmt
                or pointer-assignment-stmt
                or print-stmt
                or read-stmt
                or return-stmt
                or rewind-stmt
                or stop-stmt
                or sync-all-stmt
                or sync-images-stmt
                or sync-memory-stmt
                or unlock-stmt
                or wait-stmt
                or where-stmt
                or write-stmt
                or arithmetic-if-stmt
                or computed-goto-stmt

The implementation of this rule adds the relevant subclass names for new statements added in Fortran 2008.

Associated constraints are:

“C201 (R208) An execution-part shall not contain an end-function-stmt,

end-mp-subprogram-stmt, end-program-stmt, or end-subroutine-stmt.”

NB: The following statements are not yet implemented: end-mp-subprogram-stmt, endfile-stmt, lock-stmt, sync-all-stmt, sync-images-stmt, sync-memory-stmt, unlock-stmt.

subclass_names
class fparser.two.Fortran2008.Action_Stmt_C201(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Action_Stmt_C201

action-stmt-c201 is action-stmt C201 is applied.

subclass_names
class fparser.two.Fortran2008.Action_Stmt_C816(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Action_Stmt_C824

action-stmt-c816 is action-stmt C816 is applied.

subclass_names
class fparser.two.Fortran2008.Action_Stmt_C828(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Action_Stmt_C802

action-stmt-c828 is action-stmt C828 is applied.

subclass_names
class fparser.two.Fortran2008.Data_Component_Def_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Data_Component_Def_Stmt

Fortran 2008 rule 436.

data-component-def-stmt is declaration-type-spec [
         [ , component-attr-spec-list ] :: ] component-decl-list

The implementation of this rule does not add anything to the Fortran 2003 variant but reimplements the match method identical to Fortran 2003 as otherwise the generated Fortran 2008 variant of Component_Attr_Spec_List would not be used. Unfortunately, the required attr_spec_list_cls can not simply be provided as a class property since the relevant class is only generated at the end of this file using the use_names class property of this class.

Associated constraints are:

“C439 (R436) No component-attr-spec shall appear more than once in a given

component-def-stmt.”

“C440 (R436) If neither the POINTER nor the ALLOCATABLE attribute is

specified, the declaration-type-spec in the component-def-stmt shall specify an intrinsic type or a previously defined derived type.”

“C441 (R436) If the POINTER or ALLOCATABLE attribute is specified, each

component-array-spec shall be a deferred-shape-spec-list.”

“C442 (R436) If a coarray-spec appears, it shall be a

deferred-coshape-spec-list and the component shall have the ALLOCATABLE attribute.”

“C443 (R436) If a coarray-spec appears, the component shall not be of type

C_PTR or C_FUNPTR.”

“C445 (R436) If neither the POINTER nor the ALLOCATABLE attribute is

specified, each component-array-spec shall be an explicit-shape-spec-list.”

“C447 (R436) A component shall not have both the ALLOCATABLE and POINTER

attributes.”

“C448 (R436) If the CONTIGUOUS attribute is specified, the component shall

be an array with the POINTER attribute.”

“C457 (R436) If component-initialization appears, a double-colon separator

shall appear before the component-decl-list.”

“C458 (R436) If component-initialization appears, every type parameter and

array bound of the component shall be a colon or constant expression.

“C459 (R436) If => appears in component-initialization, POINTER shall

appear in the component-attr-spec-list. If = appears in component-initialization, neither POINTER nor ALLOCATABLE shall appear in the component-attr-spec-list.”

C439-C443, C445, C447-C448, C457-C459 are currently not checked - issue #258.

static match(string)[source]

Implements the matching of a data component definition statement.

Parameters:

string (str) – the reader or string to match as a data component definition statement.

Returns:

a 3-tuple containing declaration type specification, component attribute specification and component declaration list if there is a match or None if there is no match.

Return type:

NoneType or (fparser.two.Fortran2003.Declaration_Type_Spec, fparser.two.Fortran2008.Component_Attr_Spec_List, fparser.two.Fortran2003.Component_Decl_List)

class fparser.two.Fortran2008.Component_Attr_Spec(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Component_Attr_Spec

Fortran 2008 rule R437.

component-attr-spec is access-spec
                       or ALLOCATABLE
                       or CODIMENSION lbracket coarray-spec rbracket
                       or CONTIGUOUS
                       or DIMENSION ( component-array-spec )
                       or POINTER

In the spec above, lbracket and rbracket are left and right square brackets [] but not printed explicitly to avoid misinterpretation as optional parts.

This rule adds CODIMENSION and CONTIGUOUS attributes to Fortran2003’s R441.

subclass_names
attributes
class fparser.two.Fortran2008.Type_Declaration_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Type_Declaration_Stmt

Fortran 2008 rule 501.

type-declaration-stmt is declaration-type-spec [ [ , attr-spec ] ... :: ]
                         entity-decl-list

The implementation of this rule does not add anything to the Fortran 2003 variant but overwrites get_attr_spec_list_cls() to use the Fortran 2008 variant of Attr_Spec_List.

Associated constraints are:

“C501 (R501) The same attr-spec shall not appear more than once in a given

type-declaration-stmt.”

“C502 (R501) If a language-binding-spec with a NAME= specifier appears,

the entity-decl-list shall consist of a single entity-decl.”

“C503 (R501) If a language-binding-spec is specified, the entity-decl-list

shall not contain any procedure names.”

“C505 (R501) If initialization appears, a double-colon separator shall

appear before the entity-decl-list.”

C501-C503, C505 are currently not checked - issue #259.

static get_attr_spec_list_cls()[source]

Return the type used to match the attr-spec-list

This overwrites the Fortran 2003 type with the Fortran 2008 variant.

class fparser.two.Fortran2008.Codimension_Attr_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.WORDClsBase

codimension-attr-spec is CODIMENSION lbracket coarray-spec rbracket

In the spec above, lbracket and rbracket are left and right square brackets [] but not printed explicitly to avoid misinterpretation as optional parts.

subclass_names = []
use_names = ['Coarray_Bracket_Spec']
static match(string)[source]

Implements the matching for the CODIMENSION attribute.

Parameters:

string (str) – the string to match as the attribute.

Returns:

None if there is no match, otherwise a 2-tuple containing CODIMENSION as a string and the matched coarray-spec..

Return type:

NoneType or (str, fparser.two.Fortran2008.Coarray_Bracket_Spec,)

class fparser.two.Fortran2008.Coarray_Bracket_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.BracketBase

coarray-bracket-spec is lbracket coarray-spec rbracket

In the spec above, lbracket and rbracket are left and right square brackets [] but not printed explicitly to avoid misinterpretation as optional parts.

subclass_names = []
use_names = ['Coarray_Spec']
static match(string)[source]

Implements the matching for the coarray specification including the square brackets.

Parameters:

string (str) – the string to match as the specification.

Returns:

None if there is no match, otherwise a 3-tuple containing the left bracket, the matched coarray-spec, and the right bracket.

Return type:

NoneType or (str, fparser.two.Fortran2008.Coarray_Spec, str)

class fparser.two.Fortran2008.Attr_Spec(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Attr_Spec

Fortran 2008 rule R502.

attr-spec is access-spec
             or ALLOCATABLE
             or ASYNCHRONOUS
             or CODIMENSION lbracket coarray-spec rbracket
             or CONTIGUOUS
             or DIMENSION ( array-spec )
             or EXTERNAL
             or INTENT ( intent-spec )
             or INTRINSIC
             or language-binding-spec
             or OPTIONAL
             or PARAMETER
             or POINTER
             or PROTECTED
             or SAVE
             or TARGET
             or VALUE
             or VOLATILE

In the spec above, lbracket and rbracket are left and right square brackets [] but not printed explicitly to avoid misinterpretation as optional parts.

This rule adds CODIMENSION and CONTIGUOUS attributes to Fortran2003’s R503.

subclass_names
use_names = []
static match(string)[source]

Implements the matching for attributes of types.

Parameters:

string (str) – the string to match as attribute.

Returns:

None if there is no match, otherwise a 1-tuple containing the matched string.

Return type:

NoneType or (str,)

class fparser.two.Fortran2008.Coarray_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2008 rule R509.

coarray-spec is deferred-coshape-spec-list
                or explicit-coshape-spec-list
subclass_names = ['Explicit_Coshape_Spec', 'Deferred_Coshape_Spec_List']
class fparser.two.Fortran2008.Deferred_Coshape_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.SeparatorBase

Fortran 2008 rule R510 deferred-coshape-spec is :

subclass_names = []
static match(string)[source]

Implements the matching for deferred coarray shape specification.

Parameters:

string (str) – the string to match as deferred shape.

Returns:

None if there is no match, otherwise a 2-tuple containing None.

Return type:

NoneType or (None, None)

class fparser.two.Fortran2008.Explicit_Coshape_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.SeparatorBase

Fortran 2008 rule R511 explicit-coshape-spec is [ coshape-spec-list , ] [ lower-cobound : ] *

Associated constraint is:

“C529 (R511) A lower-cobound or upper-cobound that is not a constant

expression shall appear only in a subprogram, BLOCK construct, or interface body.”

C529 is currently not checked - issue #259.

subclass_names = []
use_names = ['Coshape_Spec_List', 'Lower_Cobound']
static match(string)[source]

Implements the matching for explicit coarray shape specification.

Parameters:

string (str) – the string to match as deferred shape.

Returns:

None if there is no match, otherwise a 2-tuple containing matched coshape-spec-list or None and matched lower-cobound or None.

Return type:

NoneType or (fparser.two.Fortran2008.Coshape_Spec_List or None, fparser.two:Fortran2008.Lower_Cobound or None)

tostr()[source]

Converts the explicit coarray shape specification to string.

Returns:

the shape specification as string.

Return type:

str

class fparser.two.Fortran2008.Coshape_Spec(string, parent_cls=None)[source]

Bases: fparser.two.utils.SeparatorBase

coshape-spec is [ lower-cobound : ] upper-cobound

subclass_names = []
use_names = ['Lower_Cobound', 'Upper_Cobound']
static match(string)[source]

Implements the matching for a coarray shape.

Parameters:

string (str) – the string to match as shape.

Returns:

None if there is no match, otherwise a 2-tuple with lower bound if given or None, and upper bound.

Return type:

NoneType or (None, fparser.two.Fortran2008.Upper_Cobound) or (fparser.two.Fortran2008.Lower_Cobound, fparser.two.Fortran2008.Upper_Cobound)

tostr()[source]

Converts the Shape specification to string.

Returns:

the shape specification as string.

Return type:

str

class fparser.two.Fortran2008.Lower_Cobound(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2008 rule R512 lower-cobound is specification-expr

subclass_names = ['Specification_Expr']
class fparser.two.Fortran2008.Upper_Cobound(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2008 rule R513 upper-cobound is specification-expr

subclass_names = ['Specification_Expr']
class fparser.two.Fortran2008.Do_Term_Action_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Do_Term_Action_Stmt

Fortran 2008 rule R826.

do-term-action-stmt is action-stmt

Associated constraints are:

“C816 (R826) A do-term-action-stmt shall not be an arithmetic-if-stmt,

continue-stmt, cycle-stmt, end-function-stmt, end-mp-subprogram-stmt, end-program-stmt, end-subroutine-stmt, error-stop-stmt, exit-stmt, goto-stmt, return-stmt, or stop-stmt.”

subclass_names = ['Action_Stmt_C816']
class fparser.two.Fortran2008.Alloc_Opt(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Alloc_Opt

Fortran2008 rule R627.

alloc-opt is ERRMSG = errmsg-variable
          or MOLD = source-expr
          or SOURCE = source-expr
          or STAT = stat-variable

Extends the Fortran2003 version of this class by updating the keyword pairs (used in match) with support for MOLD.

_keyword_pairs = [('STAT',), ('ERRMSG',), ('SOURCE',), ('MOLD',)]
class fparser.two.Fortran2008.Allocate_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Allocate_Stmt

Fortran 2008 rule R626.

allocate-stmt is ALLOCATE ( [ type-spec :: ] allocation-list
                            [, alloc-opt-list ] )

The implementation of this rule simply ensures that the Fortran2008 version of Alloc_Opt is used.

subclass_names = []
use_names = ['Type_Spec', 'Allocation_List', 'Alloc_Opt_List']
classmethod alloc_opt_list()[source]
Returns:

the Fortran2008 flavour of Alloc_Opt_List.

Return type:

type

class fparser.two.Fortran2008.Loop_Control(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Loop_Control

Fortran 2008 rule R818

loop-control is [ , ] do-variable = scalar-int-expr , scalar-int-expr

[ , scalar-int-expr ]

or [ , ] WHILE ( scalar-logical-expr ) or [ , ] CONCURRENT forall-header

Extends the Fortran2003 rule R830 with the additional CONCURRENT clause.

The F2003 Loop_Control class would be better and more extensible if it called 2 classes, one for each of the above expressions. This would then affect the implementation of this class. 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

subclass_names = []
use_names
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 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, the third entry indicating whether there is an optional preceding ‘,’ and the fourth entry providing the result of matching the ‘CONCURRENT’ part of the rule if there is a match.

Return type:

Optional[Tuple[ Optional[ fparser.two.Fortran2003.Scalar_Logical_Expr], Optional[Tuple[ fparser.two.Fortran2003.Do_Variable, List[str]]], Optional[str], Optional[fparser.two.Fortran2003.Forall_Header]]]

tostr()[source]
Returns:

the Fortran representation of this object.

Return type:

str

class fparser.two.Fortran2008.If_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.If_Stmt

Fortran 2008 rule R837 if-stmt is IF ( scalar-logical-expr ) action-stmt

The implementation of this rule only replaces the use_names and action_stmt_class attributes to use the Fortran 2008 variant Action_Stmt_C828 instead of fparser.two.Fortran2003.Action_Stmt_C802.

Associated constraints are:

C828 (R837) The action-stmt in the if-stmt shall not be an end-function-stmt,

end-mp-subprogram-stmt, end-program-stmt, end-subroutine-stmt, or if-stmt.

use_names = ['Scalar_Logical_Expr', 'Action_Stmt_C828']
action_stmt_cls
class fparser.two.Fortran2008.Error_Stop_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

Fortran 2008 rule R856 error-stop-stmt is ERROR STOP [ stop-code ]

subclass_names = []
use_names = ['Stop_Code']
static match(string)[source]

Check whether the input matches the rule

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 a string matching ‘ERROR STOP’ and an instance of fparser.two.Fortran2003.Stop_Code (or None if an instance of ‘Stop_Code’ is not required and not provided).

Return type:

(str, fparser.two.Fortran2003.Stop_Code or None) or NoneType

class fparser.two.Fortran2008.Specification_Part_C1112(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Specification_Part

Fortran 2008 constraint C1112 C1112 A submodule specification-part shall not contain a format-stmt, entry-stmt, or stmt-function-stmt.

These statements are found in the following rule hierarchy

format-stmt Specification_Part/implicit_part/implicit_part_stmt/format_stmt

Specification_Part/declaration_construct/format_stmt

entry-stmt Specification_Part/implicit_part/implicit_part_stmt/entry_stmt

Specification_Part/declaration_construct/entry_stmt

stmt-function-stmt Specification_Part/declaration_construct/

stmt-function-stmt

Therefore we need to specialise implicit_part, implicit_part_stmt and declaration_construct

use_names = ['Use_Stmt', 'Import_Stmt', 'Implicit_Part_C1112', 'Declaration_Construct_C1112']
static match(reader)[source]

Check whether the input matches the rule

param reader: 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

Return type:

Optional[Tuple[List[fparser.two.utils.Base]]]

class fparser.two.Fortran2008.Implicit_Part_C1112(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Implicit_Part

Fortran 2008 constraint C1112 C1112 A submodule specification-part shall not contain a format-stmt, entry-stmt, or stmt-function-stmt.

This class specialises ‘Implicit_Part’ so that the specialised ‘Implicit_Part_Stmt_C1112’ is called rather than the original ‘Implicit_Part_Stmt’

use_names = ['Implicit_Part_Stmt_C1112', 'Implicit_Stmt']
static match(reader)[source]

Check whether the input matches the rule

param reader: 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.Fortran2008.Implicit_Part_Stmt_C1112(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Implicit_Part_Stmt

Fortran 2008 constraint C1112 C1112 A submodule specification-part shall not contain a format-stmt, entry-stmt, or stmt-function-stmt.

This class specialises ‘Implicit_Part_Stmt’ to remove ‘Format_Stmt’ and ‘Entry_Stmt’

subclass_names
class fparser.two.Fortran2008.Declaration_Construct_C1112(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Declaration_Construct

Fortran 2008 constraint C1112 C1112 A submodule specification-part shall not contain a format-stmt, entry-stmt, or stmt-function-stmt.

This class specialises ‘Declaration_Construct’ to remove ‘Format_Stmt’, ‘Entry_Stmt’ and ‘Stmt_Function_Stmt’

subclass_names
class fparser.two.Fortran2008.Submodule(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

Fortran 2008 rule R1116.

submodule is submodule-stmt
             [ specification-part ]
             [ module-subprogram-part ]
             end-submodule-stmt

C1112 A submodule specification-part shall not contain a format-stmt, entry-stmt, or stmt-function-stmt. This constraint is handled by specialising the Specification_Part class.

C1114 If a submodule-name appears in the end-submodule-stmt, it shall be identical to the one in the submodule-stmt. This constraint is handled by the Base class with the names being provided by the ‘Submodule_Stmt and ‘End_Submodule_Stmt’ classes via a get_name method.

subclass_names = []
use_names = ['Submodule_Stmt', 'Specification_Part_C1112', 'Module_Subprogram_Part', 'End_Submodule_Stmt']
static match(reader)[source]

Check whether the input matches the rule

param reader: 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.Fortran2008.Submodule_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base, fparser.two.utils.ScopingRegionMixin

Fortran 2008 rule R1117:

submodule-stmt is SUBMODULE ( parent-identifier ) submodule-name
subclass_names = []
use_names = ['Submodule_Name', 'Parent_Identifier']
static match(fstring)[source]

Check whether the input matches the rule

Parameters:

fstring (st) – contains the Fortran that we are trying to match.

Returns:

instances of the Classes that have matched if there is a match or None if there is no match.

Return type:

Optional[Tuple[fparser.two.Fortran2008.Parent_Identifier, fparser.two.Fortran2008.Submodule_Name]]

tostr()[source]

return the fortran representation of this object

get_name()[source]

Fortran 2008 constraint C1114 return the submodule name. This is used by the base class to check whether the submodule name matches the name used for the end submodule statement if one is provided.

Returns:

the name of the submodule stored in a Name class

Return type:

fparser.two.Fortran2003.Name

class fparser.two.Fortran2008.End_Submodule_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

Fortran 2008 rule R1119 end-submodule-stmt is END [ SUBMODULE [ submodule-name ] ]

subclass_names = []
use_names = ['Submodule_Name']
static match(fstring)[source]

Check whether the input matches the rule

param string fstring : contains the Fortran that we are trying to match

Returns:

instances of the Classes that have matched if there

is a match or None if there is no match

get_name()[source]

Fortran 2008 constraint C1114 return the submodule name as specified by the end submodule statement or None if one is not specified. This is used by the base class to check whether this name matches the submodule name.

Returns:

the name of the submodule stored in a Name class

Return type:

fparser.two.Fortran2003.Name or None

class fparser.two.Fortran2008.Parent_Identifier(string, parent_cls=None)[source]

Bases: fparser.two.utils.Base

Fortran 2008 rule R1118 parent-identifier is ancestor-module-name [ : parent-submodule-name ]

C1113 The ancestor-module-name shall be the name of a nonintrinsic module; the parent-submodule name shall be the name of a descendant of that module. This constraint can not be tested by fparser in general as the module or submodule may be in a different file. We therefore do not check this constraint in fparser.

use_names = ['Ancestor_Module_Name', 'Parent_SubModule_Name']
static match(fstring)[source]

Check whether the input matches the rule

param string fstring : contains the Fortran that we are trying to match

Returns:

instances of the Classes that have matched if there

is a match or None if there is no match

tostr()[source]

return the fortran representation of this object

class fparser.two.Fortran2008.Open_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Open_Stmt

Fortran2008 Rule R904.

open-stmt is OPEN ( connect-spec-list )

subclass_names = []
use_names = ['Connect_Spec_List']
static match(string)[source]

Attempts to match the supplied string as an Open_Stmt.

Parameters:

string (str) – the string to attempt to match.

Returns:

a new Open_Stmt object if the match is successful, None otherwise.

Return type:

Optional[:py:class:`fparser.two.Fortran2008.Open_Stmt]

class fparser.two.Fortran2008.Connect_Spec(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Connect_Spec

Fortran2008 rule R905. Extends the Fortran2003 definition with support for the NEWUNIT specifier.

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 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 NEWUNIT = 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

R906 file-name-expr is scalar-default-char-expr R907 iomsg-variable is scalar-default-char-variable C903 No specifier shall appear more than once in a given connect-spec-list.

C904 (R904) If the NEWUNIT= specifier does not appear, a file-unit-number

shall be specified; if the optional characters UNIT= are omitted, the file-unit-number shall be the first item in the connect-spec-list.

C905 (R904) The label used in the ERR= specifier shall be the statement label

of a branch target statement that appears in the same inclusive scope as the OPEN statement.

C906 (R904) If a NEWUNIT= specifier appears, a file-unit-number shall not

appear.

The constraints listed above are checked for in the Open_Stmt.match() method as we don’t have access to the full list of Connect_Spec elements here. The exceptions are the second part of C904 (un-named file-unit-number must be first in the list) and C905: these are not currently checked.

subclass_names = []
use_names = ['File_Unit_Number', 'Scalar_Default_Char_Expr', 'Label', 'File_Name_Expr', 'Iomsg_Variable',...
classmethod _keyword_value_list()[source]

Extends the list of keywords supported in Fortran2003 with NEWUNIT.

Returns:

list of keyword, class pairs to match against.

Return type:

list[tuple[str, type]]

class fparser.two.Fortran2008.Block_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

Fortran 2008 Rule 807.

block-construct is block-stmt

[ specification-part ] block end-block-stmt

TODO #394: Should disallow COMMON, EQUIVALENCE, IMPLICIT, INTENT, NAMELIST, OPTIONAL, VALUE, and statement functions (C806) (which are all valid members of Specification_Part).

subclass_names = []
use_names = ['Block_Stmt', 'Specification_Part', 'Execution_Part_Construct', 'End_Block_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.Fortran2008.Block_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase, fparser.two.utils.ScopingRegionMixin

Fortran 2008 Rule 808.

block-stmt is [ block-construct-name : ] BLOCK

subclass_names = []
use_names = ['Block_Construct_Name']
counter = 0
static match(string)[source]

Attempts to match the supplied text with this rule.

Parameters:

string (str) – the text to match.

Returns:

a tuple of the matched node and instance of Counter or None if there is no match.

Return type:

Tuple[“BLOCK”, fparser.two.Fortran2008.Block_Stmt.Counter] | NoneType

get_scope_name()[source]
Returns:

the name of this scoping region.

Return type:

str

get_start_name()[source]
Returns:

the name associated with this Block construct or None.

Return type:

str | NoneType

tostr()[source]
Returns:

the string representation of this node.

Return type:

str

class fparser.two.Fortran2008.End_Block_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

Fortran 2008 Rule 809.

end-block-stmt is END BLOCK [ block-construct-name ]

subclass_names = []
use_names = ['Block_Construct_Name']
static match(string)[source]
Parameters:

string (str) – Fortran code to check for a match

Returns:

2-tuple containing “BLOCK” and, optionally, an associated Name or None if no match.

Return type:

Optional[Tuple[ str, Optional[fparser.two.Fortran2003.Block_Construct_Name]]]

class fparser.two.Fortran2008.Critical_Construct(string, parent_cls=None)[source]

Bases: fparser.two.utils.BlockBase

Fortran 2008 Rule 810.

critical-construct is critical-stmt

block end-critical-stmt

TODO: Should disallow RETURN (C809) and CYCLE or EXIT to outside block (C811)

subclass_names = []
use_names = ['Critical_Stmt', 'Execution_Part_Construct', 'End_Critical_Stmt']
static match(reader)[source]

Attempt to match the supplied content with this Rule.

Parameters:

reader (fparser.common.readfortran.FortranFileReader | fparser.common.readfortran.FortranStringReader) – the fortran file reader containing the line(s) of code that we are trying to match

Returns:

instance of class that has matched or None if no match.

Return type:

fparser.two.utils.BlockBase | NoneType

class fparser.two.Fortran2008.Critical_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.StmtBase, fparser.two.utils.WORDClsBase

Fortran 2008 Rule R811.

critical-stmt is [ critical-construct-name : ] CRITICAL

subclass_names = []
use_names = ['Critical_Construct_Name']
static match(string)[source]

Attempts to match the supplied string as a CRITICAL statement.

Parameters:

string (str) – the string to attempt to match.

Returns:

2-tuple containing the matched word “CRITICAL” and None or None if no match.

Return type:

Tuple[str, NoneType] or NoneType

get_start_name()[source]
Returns:

the name associated with the start of this CRITICAL region (if any)

Return type:

str | NoneType

tostr()[source]
Returns:

the string representation of this node.

Return type:

str

class fparser.two.Fortran2008.End_Critical_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.utils.EndStmtBase

Fortran 2008 Rule 812.

end-critical-stmt is END CRITICAL [ critical-construct-name ]

subclass_names = []
use_names = ['Critical_Construct_Name']
static match(string)[source]
Parameters:

string (str) – Fortran code to check for a match

Returns:

2-tuple containing “CRITICAL” and, optionally, an associated Name or None if there is no match.

Return type:

Optional[Tuple[ str, Optional[fparser.two.Fortran2003.Critical_Construct_Name]]]

class fparser.two.Fortran2008.Procedure_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Procedure_Stmt

Fortran 2008 Rule 1206.

procedure-stmt is [ MODULE ] PROCEDURE [ :: ] procedure-name-list

static match(string)[source]
Parameters:

string (str) – Fortran code to check for a match

Returns:

3-tuple containing a boolean indicating whether the optional MODULE keyword is included, a boolean indicating whether the optional ‘::’ is included and a Procedure_Name_List instance, or None if there is no match.

Return type:

Optional[Tuple[ bool, bool, fparser.two.Fortran2003.Procedure_Name_List]]]

tostr()[source]
Returns:

the string representation of this node.

Return type:

str

class fparser.two.Fortran2008.Action_Term_Do_Construct(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Action_Term_Do_Construct

Subclass the 2003 version so that this class will import the Fortran2008 Label_Do_Stmt class.

static label_do_stmt_cls()[source]
Returns:

Fortran2008 Label_Do_Stmt class.

Return type:

fparser.two.Fortran2008.Label_Do_Stmt

class fparser.two.Fortran2008.Block_Label_Do_Construct(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Block_Label_Do_Construct

Subclass the 2003 version so that this class will import the Fortran2008 Label_Do_Stmt class

static label_do_stmt_cls()[source]
Returns:

Fortran2008 Label_Do_Stmt class.

Return type:

fparser.two.Fortran2008.Label_Do_Stmt

class fparser.two.Fortran2008.Block_Nonlabel_Do_Construct(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Block_Nonlabel_Do_Construct

Subclass the 2003 version so that this class will import the Fortran2008 Nonlabel_Do_Stmt class

static nonlabel_do_stmt_cls()[source]
Returns:

Fortran2008 Nonlabel_Do_Stmt class.

Return type:

fparser.two.Fortran2008.Nonlabel_Do_Stmt

class fparser.two.Fortran2008.Label_Do_Stmt(string, parent_cls=None)[source]

Bases: fparser.two.Fortran2003.Label_Do_Stmt

Subclass the 2003 version so that this class will import the Fortran2008 Label_Do_Stmt class.

static loop_control_cls()[source]
Returns:

Fortran2008 Loop_Control class.

Return type:

fparser.two.Fortran2008.Loop_Control

fparser.two.Fortran2008.ClassType[source]
fparser.two.Fortran2008._names[source]
fparser.two.Fortran2008.NEW_CLS[source]
fparser.two.Fortran2008.NEW_CLS[source]
fparser.two.Fortran2008.classes[source]
fparser.two.Fortran2008.__all__[source]