fparser Reference Guide  0.0.14
fparser.two.pattern_tools.Pattern Class Reference

Public Member Functions

def __init__ (self, label, pattern, optional=0, flags=0, value=None)
 
def flags (self, flags)
 
def get_compiled (self)
 
def match (self, string)
 
def search (self, string)
 
def rsplit (self, string, is_add=False)
 
def lsplit (self, string)
 
def __abs__ (self)
 
def __repr__ (self)
 
def __or__ (self, other)
 
def __and__ (self, other)
 
def __rand__ (self, other)
 
def __invert__ (self)
 
def __add__ (self, other)
 
def __radd__ (self, other)
 
def named (self, name=None)
 
def rename (self, label)
 
def __call__ (self, string)
 

Public Attributes

 label
 
 pattern
 
 optional
 
 value
 

Detailed Description

p1 | p2    -> <p1> | <p2>
p1 + p2    -> <p1> <p2>
p1 & p2    -> <p1><p2>
~p1        -> [ <p1> ]
~~p1       -> [ <p1> ]...
~~~p1      -> <p1> [ <p1> ]...
~~~~p1     -> ~~~p1
abs(p1)    -> whole string match of <p1>
p1.named(name) -> match of <p1> has name
p1.match(string) -> return string match with <p1>
p1.flags(<re.I,..>)
p1.rsplit(..) -> split a string from the rightmost p1 occurrence
p1.lsplit(..) -> split a string from the leftmost p1 occurrence

Definition at line 82 of file pattern_tools.py.

Member Function Documentation

◆ lsplit()

def fparser.two.pattern_tools.Pattern.lsplit (   self,
  string 
)
Return (<lhs>, <pattern_match>, <rhs>) where
  string = lhs + pattern_match + rhs
and rhs does not contain pattern_match.
If no pattern_match is found in string, return None.

Definition at line 169 of file pattern_tools.py.

References fparser.one.statements.GeneralAssignment.__class__, fparser.one.statements.Read.__class__, fparser.two.pattern_tools.Pattern._flags, fparser.two.pattern_tools.Pattern._special_symbol_map, fparser.two.pattern_tools.Pattern.get_compiled(), fparser.two.pattern_tools.Pattern.label, fparser.common.readfortran.Line.label, fparser.one.statements.Goto.label, fparser.one.statements.Continue.label, fparser.two.C99Preprocessor.Cpp_Pp_Tokens.match(), fparser.two.pattern_tools.Pattern.match(), fparser.two.C99Preprocessor.Cpp_If_Stmt.match(), fparser.one.statements.GeneralAssignment.match, fparser.two.C99Preprocessor.Cpp_Elif_Stmt.match(), fparser.two.C99Preprocessor.Cpp_Else_Stmt.match(), fparser.one.statements.Assign.match, fparser.two.C99Preprocessor.Cpp_Endif_Stmt.match(), fparser.one.statements.Call.match, fparser.one.block_statements.EndSource.match, fparser.one.block_statements.BeginSource.match, fparser.one.statements.Goto.match, fparser.one.statements.ComputedGoto.match, fparser.one.block_statements.EndModule.match, fparser.one.block_statements.Module.match, fparser.one.statements.AssignedGoto.match, fparser.one.statements.Continue.match, fparser.one.typedecl_statements.Integer.match, fparser.one.statements.Return.match, fparser.one.typedecl_statements.Real.match, fparser.one.typedecl_statements.DoublePrecision.match, fparser.one.statements.Stop.match, fparser.one.typedecl_statements.Complex.match, fparser.two.C99Preprocessor.Cpp_Macro_Identifier_List.match(), fparser.one.block_statements.EndPythonModule.match, fparser.one.typedecl_statements.DoubleComplex.match, fparser.one.statements.Print.match, fparser.one.block_statements.PythonModule.match, fparser.one.typedecl_statements.Logical.match, fparser.one.typedecl_statements.Character.match, fparser.one.block_statements.EndProgram.match, fparser.one.typedecl_statements.Byte.match, fparser.one.typedecl_statements.Type.match, fparser.one.statements.Read.match, fparser.two.C99Preprocessor.Cpp_Undef_Stmt.match(), fparser.one.typedecl_statements.Class.match, fparser.one.block_statements.EndBlockData.match, fparser.one.typedecl_statements.Implicit.match, fparser.one.block_statements.BlockData.match, fparser.one.block_statements.EndInterface.match, fparser.one.statements.Write.match, fparser.one.block_statements.Interface.match, fparser.one.statements.Flush.match, fparser.one.statements.Wait.match, fparser.two.C99Preprocessor.Cpp_Warning_Stmt.match(), fparser.one.statements.Contains.match, fparser.one.statements.Allocate.match, fparser.one.statements.Deallocate.match, fparser.one.statements.ModuleProcedure.match, fparser.one.statements.Access.match, fparser.one.block_statements.EndSubroutine.match, fparser.one.block_statements.Subroutine.match, fparser.one.block_statements.EndFunction.match, fparser.one.block_statements.Function.match, fparser.one.statements.Close.match, fparser.one.statements.Cycle.match, fparser.one.statements.FilePositioningStatement.match, fparser.one.block_statements.SubprogramPrefix.match, fparser.one.block_statements.EndSelect.match, fparser.one.statements.Open.match, fparser.one.block_statements.SelectCase.match, fparser.one.block_statements.SelectType.match, fparser.one.statements.Format.match, fparser.one.block_statements.EndWhere.match, fparser.one.block_statements.Where.match, fparser.one.statements.Save.match, fparser.one.block_statements.EndForall.match, fparser.one.block_statements.Forall.match, fparser.two.Fortran2003.Digit_String.match(), fparser.one.statements.Data.match, fparser.one.block_statements.EndIfThen.match, fparser.one.block_statements.IfThen.match, fparser.one.statements.Nullify.match, fparser.one.block_statements.If.match, fparser.one.statements.Use.match, fparser.one.block_statements.EndDo.match, fparser.one.block_statements.Do.match, fparser.one.statements.Exit.match, fparser.one.block_statements.EndAssociate.match, fparser.one.block_statements.Associate.match, fparser.one.statements.Parameter.match, fparser.one.block_statements.EndType.match, fparser.one.statements.Equivalence.match, fparser.one.block_statements.Type.match, fparser.one.statements.Dimension.match, fparser.one.statements.Target.match, fparser.one.statements.Pointer.match, fparser.one.statements.Protected.match, fparser.one.statements.Volatile.match, fparser.one.block_statements.EndEnum.match, fparser.one.statements.Value.match, fparser.one.block_statements.Enum.match, fparser.one.statements.ArithmeticIf.match, fparser.one.statements.Intrinsic.match, fparser.one.statements.Inquire.match, fparser.one.statements.Sequence.match, fparser.one.statements.External.match, fparser.one.statements.Namelist.match, fparser.one.statements.Common.match, fparser.one.statements.Optional.match, fparser.one.statements.Intent.match, fparser.one.statements.Entry.match, fparser.two.Fortran2003.Dimension_Component_Attr_Spec.match(), fparser.one.statements.Import.match, fparser.one.statements.Forall.match, fparser.one.statements.SpecificBinding.match, fparser.one.statements.GenericBinding.match, fparser.one.statements.FinalBinding.match, fparser.one.statements.Allocatable.match, fparser.two.Fortran2003.Proc_Component_PASS_Arg_Name.match(), fparser.one.statements.Asynchronous.match, fparser.one.statements.Bind.match, fparser.one.statements.Else.match, fparser.one.statements.ElseIf.match, fparser.one.statements.Case.match, fparser.one.statements.TypeIs.match, fparser.one.statements.ClassIs.match, fparser.two.Fortran2003.Binding_PASS_Arg_Name.match(), fparser.two.Fortran2003.Generic_Binding.match(), fparser.one.statements.Where.match, fparser.one.statements.ElseWhere.match, fparser.one.statements.Enumerator.match, fparser.one.statements.FortranName.match, fparser.one.statements.Threadsafe.match, fparser.one.statements.Depend.match, fparser.one.statements.Check.match, fparser.one.statements.CallStatement.match, fparser.one.statements.CallProtoArgument.match, fparser.one.statements.Pause.match, fparser.one.statements.Comment.match, fparser.two.Fortran2003.Ac_Implied_Do.match(), fparser.two.Fortran2003.Ac_Implied_Do_Control.match(), fparser.two.Fortran2003.Object_Name_Deferred_Shape_Spec_List_Item.match(), fparser.two.Fortran2003.Target_Entity_Decl.match(), fparser.two.Fortran2003.Data_Ref.match(), fparser.two.Fortran2003.Parenthesis.match(), fparser.two.Fortran2003.Connect_Spec.match(), fparser.two.Fortran2003.Io_Control_Spec_List.match(), fparser.two.Fortran2003.Io_Control_Spec.match(), fparser.two.Fortran2003.Data_Edit_Desc_C1002.match(), fparser.two.Fortran2003.Main_Program0.match(), fparser.two.Fortran2003.Function_Body.match(), fparser.two.Fortran2003.Subroutine_Body.match(), fparser.two.Fortran2003.Prefix.match(), fparser.two.pattern_tools.Pattern.optional, fparser.two.pattern_tools.Pattern.pattern, fparser.one.block_statements.Interface.pattern, fparser.one.block_statements.Subroutine.pattern, fparser.one.block_statements.Function.pattern, fparser.one.block_statements.Do.pattern, fparser.one.block_statements.Type.pattern, fparser.two.pattern_tools.Pattern.value, fparser.two.C99Preprocessor.Cpp_If_Stmt.value, fparser.two.C99Preprocessor.Cpp_Elif_Stmt.value, fparser.two.C99Preprocessor.Cpp_Endif_Stmt.value, fparser.two.C99Preprocessor.Cpp_Undef_Stmt.value, fparser.two.C99Preprocessor.Cpp_Warning_Stmt.value, fparser.one.statements.FortranName.value, fparser.one.statements.Check.value, and fparser.one.statements.Pause.value.

169  def lsplit(self, string):
170  """
171  Return (<lhs>, <pattern_match>, <rhs>) where
172  string = lhs + pattern_match + rhs
173  and rhs does not contain pattern_match.
174  If no pattern_match is found in string, return None.
175  """
176  compiled = self.get_compiled()
177  t = compiled.split(string) # can be optimized
178  if len(t) < 3:
179  return
180  lhs = t[0].strip()
181  pattern_match = t[1].strip()
182  rhs = ("".join(t[2:])).strip()
183  assert abs(self).match(pattern_match), repr(pattern_match)
184  return lhs, pattern_match, rhs
185 
Here is the call graph for this function:

◆ rsplit()

def fparser.two.pattern_tools.Pattern.rsplit (   self,
  string,
  is_add = False 
)
Return (<lhs>, <pattern_match>, <rhs>) where
  string = lhs + pattern_match + rhs
and rhs does not contain pattern_match.
If no pattern_match is found in string, return None.

Definition at line 146 of file pattern_tools.py.

References fparser.two.pattern_tools.Pattern.get_compiled().

146  def rsplit(self, string, is_add=False):
147  """
148  Return (<lhs>, <pattern_match>, <rhs>) where
149  string = lhs + pattern_match + rhs
150  and rhs does not contain pattern_match.
151  If no pattern_match is found in string, return None.
152  """
153  compiled = self.get_compiled()
154  t = compiled.split(string)
155  if is_add:
156  n = "".join(t[-3:]).replace(" ", "")
157  if abs_real_literal_constant.match(n):
158  t = t[:-3] + [n]
159  if len(t) < 3:
160  return
161  if "" in t[1:-1]:
162  return
163  rhs = t[-1].strip()
164  pattern_match = t[-2].strip()
165  assert abs(self).match(pattern_match), repr((self, string, t, pattern_match))
166  lhs = ("".join(t[:-2])).strip()
167  return lhs, pattern_match, rhs
168 
Here is the call graph for this function:

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