starmath: Convert SmParseError to scoped enum

Change-Id: Ia2663a768c424ea6f03bd0933a3c2fd608c239d8
Reviewed-on: https://gerrit.libreoffice.org/34422
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Takeshi Abe <tabe@fixedpoint.jp>
This commit is contained in:
Takeshi Abe
2017-02-19 12:01:56 +09:00
parent 28416331ff
commit 1f02e9b5a7
3 changed files with 59 additions and 52 deletions

View File

@@ -23,18 +23,25 @@
class SmNode; class SmNode;
enum SmParseError enum class SmParseError
{ {
PE_NONE, None,
PE_UNEXPECTED_CHAR, PE_UNEXPECTED_TOKEN, UnexpectedChar,
PE_FUNC_EXPECTED, PE_UNOPER_EXPECTED, UnexpectedToken,
PE_POUND_EXPECTED, FuncExpected,
PE_COLOR_EXPECTED, PE_LGROUP_EXPECTED, UnoperExpected,
PE_RGROUP_EXPECTED, PE_LBRACE_EXPECTED, PoundExpected,
PE_RBRACE_EXPECTED, PE_PARENT_MISMATCH, ColorExpected,
PE_RIGHT_EXPECTED, PE_FONT_EXPECTED, LgroupExpected,
PE_SIZE_EXPECTED, PE_DOUBLE_ALIGN, RgroupExpected,
PE_DOUBLE_SUBSUPSCRIPT LbraceExpected,
RbraceExpected,
ParentMismatch,
RightExpected,
FontExpected,
SizeExpected,
DoubleAlign,
DoubleSubsupscript
}; };

View File

@@ -150,18 +150,18 @@ void Test::editFailure()
const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError(); const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError();
CPPUNIT_ASSERT_MESSAGE("Should be a PE_COLOR_EXPECTED", CPPUNIT_ASSERT_MESSAGE("Should be a SmParseError::ColorExpected",
pErrorDesc && pErrorDesc->m_eType == PE_COLOR_EXPECTED); pErrorDesc && pErrorDesc->m_eType == SmParseError::ColorExpected);
pErrorDesc = m_xDocShRef->GetParser().PrevError(); pErrorDesc = m_xDocShRef->GetParser().PrevError();
CPPUNIT_ASSERT_MESSAGE("Should be a PE_UNEXPECTED_CHAR", CPPUNIT_ASSERT_MESSAGE("Should be a SmParseError::UnexpectedChar",
pErrorDesc && pErrorDesc->m_eType == PE_UNEXPECTED_CHAR); pErrorDesc && pErrorDesc->m_eType == SmParseError::UnexpectedChar);
pErrorDesc = m_xDocShRef->GetParser().PrevError(); pErrorDesc = m_xDocShRef->GetParser().PrevError();
CPPUNIT_ASSERT_MESSAGE("Should be a PE_RGROUP_EXPECTED", CPPUNIT_ASSERT_MESSAGE("Should be a SmParseError::RgroupExpected",
pErrorDesc && pErrorDesc->m_eType == PE_RGROUP_EXPECTED); pErrorDesc && pErrorDesc->m_eType == SmParseError::RgroupExpected);
const SmErrorDesc *pLastErrorDesc = m_xDocShRef->GetParser().PrevError(); const SmErrorDesc *pLastErrorDesc = m_xDocShRef->GetParser().PrevError();

View File

@@ -950,7 +950,7 @@ SmTableNode *SmParser::DoTable()
} }
if (m_aCurToken.eType != TEND) if (m_aCurToken.eType != TEND)
Error(PE_UNEXPECTED_CHAR); Error(SmParseError::UnexpectedChar);
SmNodeArray LineArray(m_aNodeStack.size()); SmNodeArray LineArray(m_aNodeStack.size());
for (auto rIt = LineArray.rbegin(), rEnd = LineArray.rend(); rIt != rEnd; ++rIt) for (auto rIt = LineArray.rbegin(), rEnd = LineArray.rend(); rIt != rEnd; ++rIt)
@@ -977,7 +977,7 @@ void SmParser::DoAlign()
// allow for just one align statement in 5.0 // allow for just one align statement in 5.0
if (TokenInGroup(TG::Align)) if (TokenInGroup(TG::Align))
{ {
Error(PE_DOUBLE_ALIGN); Error(SmParseError::DoubleAlign);
return; return;
} }
} }
@@ -1230,7 +1230,7 @@ void SmParser::DoSubSup(TG nActiveGroup)
// set sub-/supscript if not already done // set sub-/supscript if not already done
if (aSubNodes[nIndex] != nullptr) if (aSubNodes[nIndex] != nullptr)
Error(PE_DOUBLE_SUBSUPSCRIPT); Error(SmParseError::DoubleSubsupscript);
aSubNodes[nIndex] = popOrZero(m_aNodeStack); aSubNodes[nIndex] = popOrZero(m_aNodeStack);
} }
@@ -1319,7 +1319,7 @@ void SmParser::DoTerm(bool bGroupNumberIdent)
{ {
DoAlign(); DoAlign();
if (m_aCurToken.eType != TRGROUP) if (m_aCurToken.eType != TRGROUP)
Error(PE_RGROUP_EXPECTED); Error(SmParseError::RgroupExpected);
else else
NextToken(); NextToken();
} }
@@ -1518,7 +1518,7 @@ void SmParser::DoTerm(bool bGroupNumberIdent)
DoFunction(); DoFunction();
} }
else else
Error(PE_UNEXPECTED_CHAR); Error(SmParseError::UnexpectedChar);
} }
} }
@@ -1550,7 +1550,7 @@ void SmParser::DoEscape()
case TRDLINE : case TRDLINE :
break; break;
default: default:
Error(PE_UNEXPECTED_TOKEN); Error(SmParseError::UnexpectedToken);
} }
m_aNodeStack.push_front(o3tl::make_unique<SmMathSymbolNode>(m_aCurToken)); m_aNodeStack.push_front(o3tl::make_unique<SmMathSymbolNode>(m_aCurToken));
@@ -1678,7 +1678,7 @@ void SmParser::DoUnOper()
break; break;
default : default :
Error(PE_UNOPER_EXPECTED); Error(SmParseError::UnoperExpected);
} }
// get argument // get argument
@@ -1804,7 +1804,7 @@ void SmParser::DoColor()
NextToken(); NextToken();
} }
else else
Error(PE_COLOR_EXPECTED); Error(SmParseError::ColorExpected);
} while (m_aCurToken.eType == TCOLOR); } while (m_aCurToken.eType == TCOLOR);
m_aNodeStack.push_front(o3tl::make_unique<SmFontNode>(aToken)); m_aNodeStack.push_front(o3tl::make_unique<SmFontNode>(aToken));
@@ -1824,7 +1824,7 @@ void SmParser::DoFont()
NextToken(); NextToken();
} }
else else
Error(PE_FONT_EXPECTED); Error(SmParseError::FontExpected);
} while (m_aCurToken.eType == TFONT); } while (m_aCurToken.eType == TFONT);
m_aNodeStack.push_front(o3tl::make_unique<SmFontNode>(aToken)); m_aNodeStack.push_front(o3tl::make_unique<SmFontNode>(aToken));
@@ -1871,7 +1871,7 @@ void SmParser::DoFontSize()
case TDIVIDEBY: Type = FontSizeType::DIVIDE; break; case TDIVIDEBY: Type = FontSizeType::DIVIDE; break;
default: default:
Error(PE_SIZE_EXPECTED); Error(SmParseError::SizeExpected);
return; return;
} }
@@ -1880,7 +1880,7 @@ void SmParser::DoFontSize()
NextToken(); NextToken();
if (m_aCurToken.eType != TNUMBER) if (m_aCurToken.eType != TNUMBER)
{ {
Error(PE_SIZE_EXPECTED); Error(SmParseError::SizeExpected);
return; return;
} }
} }
@@ -1926,7 +1926,7 @@ void SmParser::DoBrace()
std::unique_ptr<SmStructureNode> pSNode(new SmBraceNode(m_aCurToken)); std::unique_ptr<SmStructureNode> pSNode(new SmBraceNode(m_aCurToken));
std::unique_ptr<SmNode> pBody, pLeft, pRight; std::unique_ptr<SmNode> pBody, pLeft, pRight;
SmScaleMode eScaleMode = SCALE_NONE; SmScaleMode eScaleMode = SCALE_NONE;
SmParseError eError = PE_NONE; SmParseError eError = SmParseError::None;
if (m_aCurToken.eType == TLEFT) if (m_aCurToken.eType == TLEFT)
{ NextToken(); { NextToken();
@@ -1952,13 +1952,13 @@ void SmParser::DoBrace()
NextToken(); NextToken();
} }
else else
eError = PE_RBRACE_EXPECTED; eError = SmParseError::RbraceExpected;
} }
else else
eError = PE_RIGHT_EXPECTED; eError = SmParseError::RightExpected;
} }
else else
eError = PE_LBRACE_EXPECTED; eError = SmParseError::LbraceExpected;
} }
else else
{ {
@@ -1991,10 +1991,10 @@ void SmParser::DoBrace()
NextToken(); NextToken();
} }
else else
eError = PE_PARENT_MISMATCH; eError = SmParseError::ParentMismatch;
} }
if (eError == PE_NONE) if (eError == SmParseError::None)
{ {
assert(pLeft); assert(pLeft);
assert(pRight); assert(pRight);
@@ -2028,7 +2028,7 @@ void SmParser::DoBracebody(bool bIsLeftRight)
nNum++; nNum++;
if (m_aCurToken.eType != TMLINE && m_aCurToken.eType != TRIGHT) if (m_aCurToken.eType != TMLINE && m_aCurToken.eType != TRIGHT)
Error(PE_RIGHT_EXPECTED); Error(SmParseError::RightExpected);
} }
} while (m_aCurToken.eType != TEND && m_aCurToken.eType != TRIGHT); } while (m_aCurToken.eType != TEND && m_aCurToken.eType != TRIGHT);
} }
@@ -2048,7 +2048,7 @@ void SmParser::DoBracebody(bool bIsLeftRight)
nNum++; nNum++;
if (m_aCurToken.eType != TMLINE && !TokenInGroup(TG::RBrace)) if (m_aCurToken.eType != TMLINE && !TokenInGroup(TG::RBrace))
Error(PE_RBRACE_EXPECTED); Error(SmParseError::RbraceExpected);
} }
} while (m_aCurToken.eType != TEND && !TokenInGroup(TG::RBrace)); } while (m_aCurToken.eType != TEND && !TokenInGroup(TG::RBrace));
} }
@@ -2097,7 +2097,7 @@ void SmParser::DoFunction()
break; break;
default: default:
Error(PE_FUNC_EXPECTED); Error(SmParseError::FuncExpected);
} }
} }
@@ -2139,7 +2139,7 @@ void SmParser::DoStack()
} }
if (m_aCurToken.eType != TRGROUP) if (m_aCurToken.eType != TRGROUP)
Error(PE_RGROUP_EXPECTED); Error(SmParseError::RgroupExpected);
pSNode->SetSubNodes(ExpressionArray); pSNode->SetSubNodes(ExpressionArray);
m_aNodeStack.push_front(std::move(pSNode)); m_aNodeStack.push_front(std::move(pSNode));
@@ -2147,7 +2147,7 @@ void SmParser::DoStack()
NextToken(); NextToken();
} }
else else
Error(PE_LGROUP_EXPECTED); Error(SmParseError::LgroupExpected);
} }
void SmParser::DoMatrix() void SmParser::DoMatrix()
@@ -2181,7 +2181,7 @@ void SmParser::DoMatrix()
NextToken(); NextToken();
} }
else else
Error(PE_POUND_EXPECTED); Error(SmParseError::PoundExpected);
} }
} }
@@ -2197,7 +2197,7 @@ void SmParser::DoMatrix()
} }
if (m_aCurToken.eType != TRGROUP) if (m_aCurToken.eType != TRGROUP)
Error(PE_RGROUP_EXPECTED); Error(SmParseError::RgroupExpected);
pMNode->SetSubNodes(ExpressionArray); pMNode->SetSubNodes(ExpressionArray);
pMNode->SetRowCol(r, c); pMNode->SetRowCol(r, c);
@@ -2206,7 +2206,7 @@ void SmParser::DoMatrix()
NextToken(); NextToken();
} }
else else
Error(PE_LGROUP_EXPECTED); Error(SmParseError::LgroupExpected);
} }
void SmParser::DoSpecial() void SmParser::DoSpecial()
@@ -2340,16 +2340,16 @@ void SmParser::AddError(SmParseError Type, SmNode *pNode)
sal_uInt16 nRID; sal_uInt16 nRID;
switch (Type) switch (Type)
{ {
case PE_UNEXPECTED_CHAR: nRID = RID_ERR_UNEXPECTEDCHARACTER; break; case SmParseError::UnexpectedChar: nRID = RID_ERR_UNEXPECTEDCHARACTER; break;
case PE_LGROUP_EXPECTED: nRID = RID_ERR_LGROUPEXPECTED; break; case SmParseError::LgroupExpected: nRID = RID_ERR_LGROUPEXPECTED; break;
case PE_RGROUP_EXPECTED: nRID = RID_ERR_RGROUPEXPECTED; break; case SmParseError::RgroupExpected: nRID = RID_ERR_RGROUPEXPECTED; break;
case PE_LBRACE_EXPECTED: nRID = RID_ERR_LBRACEEXPECTED; break; case SmParseError::LbraceExpected: nRID = RID_ERR_LBRACEEXPECTED; break;
case PE_RBRACE_EXPECTED: nRID = RID_ERR_RBRACEEXPECTED; break; case SmParseError::RbraceExpected: nRID = RID_ERR_RBRACEEXPECTED; break;
case PE_FUNC_EXPECTED: nRID = RID_ERR_FUNCEXPECTED; break; case SmParseError::FuncExpected: nRID = RID_ERR_FUNCEXPECTED; break;
case PE_UNOPER_EXPECTED: nRID = RID_ERR_UNOPEREXPECTED; break; case SmParseError::UnoperExpected: nRID = RID_ERR_UNOPEREXPECTED; break;
case PE_POUND_EXPECTED: nRID = RID_ERR_POUNDEXPECTED; break; case SmParseError::PoundExpected: nRID = RID_ERR_POUNDEXPECTED; break;
case PE_COLOR_EXPECTED: nRID = RID_ERR_COLOREXPECTED; break; case SmParseError::ColorExpected: nRID = RID_ERR_COLOREXPECTED; break;
case PE_RIGHT_EXPECTED: nRID = RID_ERR_RIGHTEXPECTED; break; case SmParseError::RightExpected: nRID = RID_ERR_RIGHTEXPECTED; break;
default: default:
nRID = RID_ERR_UNKNOWN; nRID = RID_ERR_UNKNOWN;