fparser Reference Guide  0.0.14
fparser.two.Fortran2003.Io_Control_Spec_List Class Reference
Inheritance diagram for fparser.two.Fortran2003.Io_Control_Spec_List:
Collaboration diagram for fparser.two.Fortran2003.Io_Control_Spec_List:

Static Public Member Functions

def match (string)
 

Static Public Attributes

 subclass_names
 
 use_names
 

Detailed Description

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.

Definition at line 8117 of file Fortran2003.py.

Member Function Documentation

◆ match()

def fparser.two.Fortran2003.Io_Control_Spec_List.match (   string)
static
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.

:param str string: the string that is checked for a match.

:returns: a tuple of Io_Control_Spec objects if the match is \
  successful, None otherwise.
:rtype: tuple of :py:class:`fparser.two.Fortran2003.Io_Control_Spec` \
objects or NoneType

Definition at line 8179 of file Fortran2003.py.

8179  def match(string):
8180  """
8181  Attempts to match the supplied string with a list of Io_Control_Spec
8182  items. We have to override the base implementation because the first
8183  two items in the list have specific meanings if they are not explictly
8184  named: the first must be the unit number and the second may be either
8185  a format specifier *or* a namelist-group-name.
8186 
8187  :param str string: the string that is checked for a match.
8188 
8189  :returns: a tuple of Io_Control_Spec objects if the match is \
8190  successful, None otherwise.
8191  :rtype: tuple of :py:class:`fparser.two.Fortran2003.Io_Control_Spec` \
8192  objects or NoneType
8193 
8194  """
8195  line, repmap = string_replace_map(string)
8196  splitted = line.split(",")
8197  lst = []
8198 
8199  # Examine the first entry in the list. If it is not named then it must
8200  # be a unit number (C910).
8201  have_unit = False
8202  have_unnamed_nml_or_fmt = False
8203  spec = splitted.pop(0).strip()
8204  spec = repmap(spec)
8205 
8206  try:
8207 
8208  try:
8209  Io_Unit(spec)
8210  # We matched an unamed unit number. We now need to construct an
8211  # Io_Control_Spec for it. In order to do so we have to
8212  # temporarily name it so that Io_Control_Spec matches it.
8213  io_spec = Io_Control_Spec("unit=" + spec)
8214  # Remove the name from the new object
8215  io_spec.items = (None, io_spec.items[1])
8216  lst.append(io_spec)
8217  # Record that we have found a unit number for the purpose of
8218  # performing validation checks.
8219  have_unit = True
8220 
8221  if not splitted:
8222  # The list only has one entry and it is an IO unit
8223  return ",", tuple(lst)
8224 
8225  # Since the unit-number was not named, the following item may
8226  # also not be named if it is a format specifier or namelist
8227  # group name.
8228  spec = splitted.pop(0).strip()
8229  spec = repmap(spec)
8230  for cls, name in [(Namelist_Group_Name, "nml"), (Format, "fmt")]:
8231  try:
8232  if cls(spec):
8233  # We have a match on an un-named entry. We
8234  # temporarily add the name so that Io_Control_Spec
8235  # matches the correct one.
8236  io_spec = Io_Control_Spec(name + "=" + spec)
8237  # Remove the name from the new object
8238  io_spec.items = (None, io_spec.items[1])
8239  lst.append(io_spec)
8240  have_unnamed_nml_or_fmt = True
8241  break
8242  except NoMatchError:
8243  pass
8244  else:
8245  raise NoMatchError("Not an un-named nml-group-name or fmt")
8246 
8247  except NoMatchError:
8248  # If we get here we failed to match an un-named spec so from
8249  # here on, they must all be named.
8250  lst.append(Io_Control_Spec(spec))
8251 
8252  # Deal with the remainder of the list entries. These must all be
8253  # named.
8254  for spec in splitted:
8255  mapped_spec = repmap(spec.strip())
8256  lst.append(Io_Control_Spec(mapped_spec))
8257 
8258  except NoMatchError:
8259  return None
8260 
8261  # At this point we need to check the list and apply constraints.
8262  # TODO #267 enforce remaining constraints.
8263  have_nml = False
8264  have_fmt = False
8265  for spec in lst:
8266  if spec.children[0] == "UNIT":
8267  have_unit = True
8268  elif spec.children[0] == "NML":
8269  have_nml = True
8270  elif spec.children[0] == "FMT":
8271  have_fmt = True
8272  # C910: An io-unit shall be specified
8273  if not have_unit:
8274  return None
8275  # C916: an io-control-spec-list shall not contain both a format
8276  # and a namelist-group-name
8277  if have_nml and have_fmt:
8278  return None
8279  if have_unnamed_nml_or_fmt and (have_nml or have_fmt):
8280  return None
8281 
8282  return ",", tuple(lst)
8283 
8284 
Here is the caller graph for this function:

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