summaryrefslogtreecommitdiff
path: root/starmath/source/parse.cxx
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@novell.com>2010-10-23 16:20:23 +0100
committerMichael Meeks <michael.meeks@novell.com>2010-10-23 16:20:23 +0100
commit46a1843255067dfcda58d1a00913a5d26627cd04 (patch)
tree28ca6e4d88b790cd9c7fa0afad2a453a507cf6f9 /starmath/source/parse.cxx
parent88b663b7317ef1c6239c9e5ca52b1a9ec14f1993 (diff)
parentbefebfbf3690989e0eb08dab34b0e8505850760d (diff)
Merge branch 'formula' into intformulae
Conflicts: starmath/inc/node.hxx starmath/source/edit.cxx starmath/source/node.cxx starmath/source/view.cxx
Diffstat (limited to 'starmath/source/parse.cxx')
-rw-r--r--starmath/source/parse.cxx70
1 files changed, 58 insertions, 12 deletions
diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx
index 9f26ed39f626..7952fa02aeb3 100644
--- a/starmath/source/parse.cxx
+++ b/starmath/source/parse.cxx
@@ -82,16 +82,21 @@ SmToken::SmToken() :
nGroup = nCol = nRow = nLevel = 0;
}
+SmToken::SmToken(SmTokenType eTokenType,
+ sal_Unicode cMath,
+ const sal_Char* pText,
+ ULONG nTokenGroup,
+ USHORT nTokenLevel) {
+ eType = eTokenType;
+ cMathChar = cMath;
+ aText.AssignAscii(pText);
+ nGroup = nTokenGroup;
+ nLevel = nTokenLevel;
+ nCol = nRow = 0;
+}
+
///////////////////////////////////////////////////////////////////////////
-struct SmTokenTableEntry
-{
- const sal_Char* pIdent;
- SmTokenType eType;
- sal_Unicode cMathChar;
- ULONG nGroup;
- USHORT nLevel;
-};
static const SmTokenTableEntry aTokenTable[] =
{
@@ -305,8 +310,7 @@ static const SmTokenTableEntry aTokenTable[] =
{ "", TEND, '\0', 0, 0}
};
-
-static const SmTokenTableEntry * GetTokenTableEntry( const String &rName )
+const SmTokenTableEntry * SmParser::GetTokenTableEntry( const String &rName )
{
const SmTokenTableEntry * pRes = 0;
if (rName.Len())
@@ -1083,6 +1087,13 @@ void SmParser::Line()
ExpressionArray[n - 1] = NodeStack.Pop();
}
+ //If there's no expression, add an empty one.
+ //this is to avoid a formula tree without any caret
+ //positions, in visual formula editor.
+ if(ExpressionArray.size() == 0)
+ ExpressionArray.push_back(new SmExpressionNode(SmToken()));
+
+
SmStructureNode *pSNode = new SmLineNode(CurToken);
pSNode->SetSubNodes(ExpressionArray);
NodeStack.Push(pSNode);
@@ -1185,6 +1196,10 @@ void SmParser::Product()
NextToken();
+ //Let the glyph node know it's a binary operation
+ CurToken.eType = TBOPER;
+ CurToken.nGroup = TGPRODUCT;
+
GlyphSpecial();
pOper = NodeStack.Pop();
break;
@@ -1695,6 +1710,9 @@ void SmParser::UnOper()
case TUOPER :
NextToken();
+ //Let the glyph know what it is...
+ CurToken.eType = TUOPER;
+ CurToken.nGroup = TGUNOPER;
GlyphSpecial();
pOper = NodeStack.Pop();
break;
@@ -2194,7 +2212,11 @@ void SmParser::Stack()
NextToken();
- SmStructureNode *pSNode = new SmTableNode(CurToken);
+ //We need to let the table node know it context
+ //it's used in SmNodeToTextVisitor
+ SmToken aTok = CurToken;
+ aTok.eType = TSTACK;
+ SmStructureNode *pSNode = new SmTableNode(aTok);
pSNode->SetSubNodes(ExpressionArray);
NodeStack.Push(pSNode);
}
@@ -2373,7 +2395,7 @@ SmNode *SmParser::Parse(const String &rBuffer)
{
BufferString = rBuffer;
BufferString.ConvertLineEnd( LINEEND_LF );
- BufferIndex =
+ BufferIndex = 0;
nTokenIndex = 0;
Row = 1;
ColOff = 0;
@@ -2393,6 +2415,30 @@ SmNode *SmParser::Parse(const String &rBuffer)
return NodeStack.Pop();
}
+SmNode *SmParser::ParseExpression(const String &rBuffer)
+{
+ BufferString = rBuffer;
+ BufferString.ConvertLineEnd( LINEEND_LF );
+ BufferIndex = 0;
+ nTokenIndex = 0;
+ Row = 1;
+ ColOff = 0;
+ CurError = -1;
+
+ for (USHORT i = 0; i < ErrDescList.Count(); i++)
+ delete ErrDescList.Remove(i);
+
+ ErrDescList.Clear();
+
+ NodeStack.Clear();
+
+ SetLanguage( Application::GetSettings().GetUILanguage() );
+ NextToken();
+ Expression();
+
+ return NodeStack.Pop();
+}
+
USHORT SmParser::AddError(SmParseError Type, SmNode *pNode)
{