get_precedence_rhs

sherpa.models.op.get_precedence_rhs(rstr: str, opstr: str, rp: int, p: int) str[source] [edit on github]

Return the string to use for the right side of a binary operator.

This is only needed when the operator (represented by the p value) is written in infix form - such as ‘a + b’- rather than prefix form like ‘np.add(a, b)’.

Parameters:
  • rstr (str) – The term to the right of the operator.

  • opstr (str) – The string representing the operator.

  • rp (int) – Precedences of any operator in rstr.

  • p (int) – Precedences of the current operator.

Returns:

term – Either rstr or (rstr).

Return type:

str

Examples

>>> get_precedence_rhs("a", "/", NO_PRECEDENCE, lprec[np.divide])
'a'
>>> get_precedence_rhs("a + b", "/", lprec[np.add], lprec[np.divide])
'(a + b)'