binary-op-base is lhs op rhs
Splits the input text into text to the left of the matched
operator and text to the right of the matched operator and tries
to match the lhs text with the supplied lhs class rule and the rhs
text with the supplied rhs class rule.
Definition at line 965 of file utils.py.
def fparser.two.utils.BinaryOpBase.match |
( |
|
lhs_cls, |
|
|
|
op_pattern, |
|
|
|
rhs_cls, |
|
|
|
string, |
|
|
|
right = True , |
|
|
|
exclude_op_pattern = None |
|
) |
| |
|
static |
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.
:param lhs_cls: an fparser2 object representing the rule that \
should be matched to the lhs text.
:type lhs_cls: subclass of :py:class:`fparser.two.utils.Base`
:param op_pattern: the pattern to match.
:type op_pattern: `str` or \
:py:class:`fparser.two.pattern_tools.Pattern`
:param rhs_cls: an fparser2 object representing the rule that \
should be matched to the rhs text.
:type rhs_cls: subclass of :py:class:`fparser.two.utils.Base`
:param str string: the string to match with the pattern and \
lhs and rhs rules.
:param bool right: 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).
:param exclude_op_pattern: optional argument which specifies a \
particular subpattern to exclude from the match. Defaults \
to None which means there is no subpattern.
:type exclude_op_pattern: :py:class:`fparser.two.pattern_tools.Pattern`
:returns: a tuple containing the matched lhs, the operator and \
the matched rhs of the input string or None if there is \
no match.
:rtype: (:py:class:`fparser.two.utils.Base`, str, \
:py:class:`fparser.two.utils.Base`) or NoneType
Definition at line 978 of file utils.py.
979 """Matches the binary-op-base rule. 981 If the operator defined by argument 'op_pattern' is found in 982 the string provided in argument 'string' then the text to the 983 left-hand-side of the operator is matched with the class rule 984 provided in the 'lhs_cls' argument and the text to the 985 right-hand-side of the operator is matched with the class rule 986 provided in the 'rhs_cls' argument. 988 If the optional 'right' argument is set to true (the default) 989 then, in the case where the pattern matches multiple times in 990 the input string, the right-most match will be chosen. If the 991 'right' argument is set to false then the left-most match will 994 if a pattern is provided to the optional 'exclude_op_pattern' 995 argument then there will be no match if the pattern matched by 996 the 'op_pattern' argument also matches this pattern. The 997 default (None) does nothing. 999 :param lhs_cls: an fparser2 object representing the rule that \ 1000 should be matched to the lhs text. 1001 :type lhs_cls: subclass of :py:class:`fparser.two.utils.Base` 1002 :param op_pattern: the pattern to match. 1003 :type op_pattern: `str` or \ 1004 :py:class:`fparser.two.pattern_tools.Pattern` 1005 :param rhs_cls: an fparser2 object representing the rule that \ 1006 should be matched to the rhs text. 1007 :type rhs_cls: subclass of :py:class:`fparser.two.utils.Base` 1008 :param str string: the string to match with the pattern and \ 1010 :param bool right: in the case where there are multiple \ 1011 matches to the pattern in the string this optional \ 1012 argument specifies whether the righmost pattern match \ 1013 should be chosen (True, the default) or whether the \ 1014 leftmost pattern should be chosen (False). 1015 :param exclude_op_pattern: optional argument which specifies a \ 1016 particular subpattern to exclude from the match. Defaults \ 1017 to None which means there is no subpattern. 1018 :type exclude_op_pattern: :py:class:`fparser.two.pattern_tools.Pattern` 1020 :returns: a tuple containing the matched lhs, the operator and \ 1021 the matched rhs of the input string or None if there is \ 1023 :rtype: (:py:class:`fparser.two.utils.Base`, str, \ 1024 :py:class:`fparser.two.utils.Base`) or NoneType 1027 line, repmap = string_replace_map(string)
1029 if isinstance(op_pattern, str):
1031 text_split = line.rsplit(op_pattern, 1)
1033 text_split = line.split(op_pattern, 1)
1034 if len(text_split) != 2:
1036 lhs, rhs = text_split[0].rstrip(), text_split[1].lstrip()
1040 text_split = op_pattern.rsplit(line)
1042 text_split = op_pattern.lsplit(line)
1043 if not text_split
or len(text_split) != 3:
1045 lhs, oper, rhs = text_split
1049 if not lhs
or not rhs:
1051 if exclude_op_pattern
and exclude_op_pattern.match(oper):
1059 rhs_obj = rhs_cls(repmap(rhs))
1060 lhs_obj = lhs_cls(repmap(lhs))
1064 lhs_obj = lhs_cls(repmap(lhs))
1065 rhs_obj = rhs_cls(repmap(rhs))
1067 return (lhs_obj, oper.replace(
" ",
""), rhs_obj)
def fparser.two.utils.BinaryOpBase.tostr |
( |
|
self | ) |
|
Return the string representation of this object. Uses join() which
is efficient and can make a big performance difference for
complex expressions.
:returns: the string representation of this object.
:rtype: str
Definition at line 1069 of file utils.py.
References 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, and fparser.one.statements.Depend.items.
1070 """Return the string representation of this object. Uses join() which 1071 is efficient and can make a big performance difference for 1072 complex expressions. 1074 :returns: the string representation of this object. 1078 return " ".join([str(self.items[0]), str(self.items[1]), str(self.items[2])])