MCPcopy Create free account
hub / github.com/IBAMR/IBAMR / IsOprt

Method IsOprt

ibtk/contrib/muparser/src/muParserTokenReader.cpp:649–705  ·  view source on GitHub ↗

\brief Check if a string position contains a binary operator. \param a_Tok [out] Operator token if one is found. This can either be a binary operator or an infix operator token. \return true if an operator token has been found. */

Source from the content-addressed store, hash-verified

647 \return true if an operator token has been found.
648 */
649 bool ParserTokenReader::IsOprt(token_type& a_Tok)
650 {
651 const char_type* const szExpr = m_strFormula.c_str();
652 string_type strTok;
653
654 auto iEnd = ExtractOperatorToken(strTok, (std::size_t)m_iPos);
655 if (iEnd == m_iPos)
656 return false;
657
658 // Check if the operator is a built in operator, if so ignore it here
659 const char_type** const pOprtDef = m_pParser->GetOprtDef();
660 for (int i = 0; m_pParser->HasBuiltInOprt() && pOprtDef[i]; ++i)
661 {
662 if (string_type(pOprtDef[i]) == strTok)
663 return false;
664 }
665
666 // Note:
667 // All tokens in oprt_bin_maptype are have been sorted by their length
668 // Long operators must come first! Otherwise short names (like: "add") that
669 // are part of long token names (like: "add123") will be found instead
670 // of the long ones.
671 // Length sorting is done with ascending length so we use a reverse iterator here.
672 funmap_type::const_reverse_iterator it = m_pOprtDef->rbegin();
673 for (; it != m_pOprtDef->rend(); ++it)
674 {
675 const string_type& sID = it->first;
676 if (sID == string_type(szExpr + m_iPos, szExpr + m_iPos + sID.length()))
677 {
678 a_Tok.Set(it->second, strTok);
679
680 // operator was found
681 if (m_iSynFlags & noOPT)
682 {
683 // An operator was found but is not expected to occur at
684 // this position of the formula, maybe it is an infix
685 // operator, not a binary operator. Both operator types
686 // can share characters in their identifiers.
687 if (IsInfixOpTok(a_Tok))
688 return true;
689 else
690 {
691 // nope, no infix operator
692 return false;
693 //Error(ecUNEXPECTED_OPERATOR, m_iPos, a_Tok.GetAsString());
694 }
695
696 }
697
698 m_iPos += (int)sID.length();
699 m_iSynFlags = noBC | noOPT | noARG_SEP | noPOSTOP | noEND | noASSIGN;
700 return true;
701 }
702 }
703
704 return false;
705 }
706

Callers

nothing calls this directly

Calls 5

GetOprtDefMethod · 0.80
HasBuiltInOprtMethod · 0.80
lengthMethod · 0.80
rbeginMethod · 0.45
rendMethod · 0.45

Tested by

no test coverage detected