fparser Reference Guide  0.0.14
fparser.two.utils.Base Class Reference
Inheritance diagram for fparser.two.utils.Base:
Collaboration diagram for fparser.two.utils.Base:

Public Member Functions

def __init__ (self, string, parent_cls=None)
 
def __new__ (cls, string, parent_cls=None)
 
def get_root (self)
 
def children (self)
 
def init (self, items)
 
def torepr (self)
 
def __str__ (self)
 
def __repr__ (self)
 
def tofortran (self, tab="", isfix=None)
 
def restore_reader (self, reader)
 
- Public Member Functions inherited from fparser.two.utils.ComparableMixin
def __lt__ (self, other)
 
def __le__ (self, other)
 
def __eq__ (self, other)
 
def __ge__ (self, other)
 
def __gt__ (self, other)
 
def __ne__ (self, other)
 

Public Attributes

 parent
 
 items
 

Static Public Attributes

 subclasses
 

Detailed Description

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.

:param type cls: the class of object to create.
:param string: (source of) Fortran string to parse.
:type string: `str` or \
              :py:class:`fparser.common.readfortran.FortranReaderBase`
:param parent_cls: the parent class of this object.
:type parent_cls: `type`

Definition at line 327 of file utils.py.

Member Function Documentation

◆ children()

def fparser.two.utils.Base.children (   self)
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.
:rtype: list or tuple containing zero or more of \
:py:class:`fparser.two.utils.Base` or NoneType or str

Definition at line 464 of file utils.py.

464  def children(self):
465  """Return an iterable containing the immediate children of this node in
466  the parse tree.
467 
468  If this node represents an expression then its children are
469  contained in a tuple which is immutable. Therefore, the
470  manipulation of the children of such a node must be done by
471  replacing the `items` property of the node directly rather than via the
472  objects returned by this method.
473 
474  :returns: the immediate children of this node.
475  :rtype: list or tuple containing zero or more of \
476  :py:class:`fparser.two.utils.Base` or NoneType or str
477 
478  """
479  child_list = getattr(self, "content", None)
480  if child_list is None:
481  child_list = getattr(self, "items", [])
482  return child_list
483 

◆ get_root()

def fparser.two.utils.Base.get_root (   self)
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.
:rtype: :py:class:`fparser.two.utils.Base`

Definition at line 450 of file utils.py.

450  def get_root(self):
451  """
452  Gets the node at the root of the parse tree to which this node belongs.
453 
454  :returns: the node at the root of the parse tree.
455  :rtype: :py:class:`fparser.two.utils.Base`
456 
457  """
458  current = self
459  while current.parent:
460  current = current.parent
461  return current
462 

◆ init()

def fparser.two.utils.Base.init (   self,
  items 
)
Store the supplied list of nodes in the `items` list of this node.

:param items: the children of this node.
:type items: tuple of :py:class:`fparser.two.utils.Base`

Definition at line 484 of file utils.py.

References fparser.one.statements.GeneralAssignment.__class__, fparser.one.statements.Read.__class__, fparser.two.Fortran2003.Comment.items, fparser.one.statements.StatementWithNamelist.items, fparser.one.statements.Assign.items, fparser.one.statements.Call.items, fparser.one.statements.ComputedGoto.items, fparser.one.statements.AssignedGoto.items, fparser.two.utils.Base.items, fparser.one.statements.Print.items, fparser.one.statements.Read0.items, fparser.one.statements.Read1.items, fparser.one.typedecl_statements.Implicit.items, fparser.one.statements.Write.items, fparser.one.statements.Allocate.items, fparser.one.statements.Deallocate.items, fparser.one.statements.ModuleProcedure.items, fparser.one.statements.Access.items, fparser.one.statements.Save.items, fparser.one.statements.Nullify.items, fparser.one.statements.Use.items, fparser.one.statements.Parameter.items, fparser.one.statements.Equivalence.items, fparser.one.statements.Dimension.items, fparser.one.statements.Target.items, fparser.one.statements.Pointer.items, fparser.one.statements.Inquire.items, fparser.one.statements.Namelist.items, fparser.one.statements.Common.items, fparser.one.statements.Intent.items, fparser.one.statements.Entry.items, fparser.one.statements.GenericBinding.items, fparser.one.statements.Allocatable.items, fparser.one.statements.Bind.items, fparser.one.statements.Case.items, fparser.one.statements.TypeIs.items, fparser.one.statements.ClassIs.items, fparser.one.statements.Enumerator.items, fparser.one.statements.Depend.items, fparser.common.base_classes.AttributeHolder.torepr(), fparser.two.utils.Base.torepr(), fparser.common.base_classes.Statement.torepr(), fparser.common.base_classes.BeginStatement.torepr(), fparser.two.C99Preprocessor.Cpp_Pp_Tokens.tostr(), fparser.two.Fortran2003.Comment.tostr(), fparser.two.C99Preprocessor.Cpp_If_Stmt.tostr(), fparser.two.C99Preprocessor.Cpp_Elif_Stmt.tostr(), fparser.two.C99Preprocessor.Cpp_Else_Stmt.tostr(), fparser.two.C99Preprocessor.Cpp_Endif_Stmt.tostr(), fparser.one.typedecl_statements.TypeDeclarationStatement.tostr(), fparser.one.block_statements.BeginSource.tostr(), fparser.two.C99Preprocessor.Cpp_Macro_Identifier_List.tostr(), fparser.two.C99Preprocessor.Cpp_Undef_Stmt.tostr(), fparser.one.block_statements.Interface.tostr(), fparser.two.C99Preprocessor.Cpp_Warning_Stmt.tostr(), fparser.one.block_statements.SubProgramStatement.tostr(), fparser.common.base_classes.BeginStatement.tostr(), fparser.two.utils.BlockBase.tostr(), fparser.two.utils.SequenceBase.tostr(), fparser.two.utils.UnaryOpBase.tostr(), fparser.one.block_statements.SelectCase.tostr(), fparser.one.block_statements.SelectType.tostr(), fparser.two.utils.BinaryOpBase.tostr(), fparser.one.block_statements.Where.tostr(), fparser.two.utils.SeparatorBase.tostr(), fparser.one.block_statements.Forall.tostr(), fparser.one.block_statements.IfThen.tostr(), fparser.two.utils.KeywordValueBase.tostr(), fparser.one.block_statements.If.tostr(), fparser.two.utils.BracketBase.tostr(), fparser.two.utils.NumberBase.tostr(), fparser.one.block_statements.Do.tostr(), fparser.two.utils.CallBase.tostr(), fparser.one.block_statements.Associate.tostr(), fparser.two.utils.StringBase.tostr(), fparser.one.block_statements.Type.tostr(), fparser.two.utils.EndStmtBase.tostr(), fparser.two.utils.WORDClsBase.tostr(), fparser.two.utils.Type_Declaration_StmtBase.tostr(), fparser.two.Fortran2003.Generic_Binding.tostr(), fparser.two.Fortran2003.Ac_Implied_Do.tostr(), fparser.two.Fortran2003.Ac_Implied_Do_Control.tostr(), and fparser.two.Fortran2003.Data_Edit_Desc_C1002.tostr().

484  def init(self, *items):
485  """
486  Store the supplied list of nodes in the `items` list of this node.
487 
488  :param items: the children of this node.
489  :type items: tuple of :py:class:`fparser.two.utils.Base`
490 
491  """
492  self.items = items
493 
Here is the call graph for this function:

◆ tofortran()

def fparser.two.utils.Base.tofortran (   self,
  tab = "",
  isfix = None 
)
Produce the Fortran representation of this Comment.

:param str tab: characters to pre-pend to output.
:param bool isfix: whether or not this is fixed-format code.

:returns: Fortran representation of this comment.
:rtype: str

Definition at line 507 of file utils.py.

References fparser.two.Fortran2003.Comment.item, and fparser.common.base_classes.Statement.item.

507  def tofortran(self, tab="", isfix=None):
508  """
509  Produce the Fortran representation of this Comment.
510 
511  :param str tab: characters to pre-pend to output.
512  :param bool isfix: whether or not this is fixed-format code.
513 
514  :returns: Fortran representation of this comment.
515  :rtype: str
516  """
517  this_str = str(self)
518  if this_str.strip():
519  return tab + this_str
520  # If this_str is empty (i.e this Comment is a blank line) then
521  # don't prepend any spaces to it
522  return this_str
523 
Here is the caller graph for this function:

The documentation for this class was generated from the following file: