2010-10-14 01:30:41 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2000-09-18 11:07:07 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 06:36:38 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 11:07:07 -05:00
|
|
|
*
|
2010-02-12 08:01:35 -06:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 11:07:07 -05:00
|
|
|
*
|
2008-04-10 06:36:38 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 11:07:07 -05:00
|
|
|
*
|
2008-04-10 06:36:38 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 11:07:07 -05:00
|
|
|
*
|
2008-04-10 06:36:38 -05:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 11:07:07 -05:00
|
|
|
*
|
2008-04-10 06:36:38 -05:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 11:07:07 -05:00
|
|
|
*
|
2008-04-10 06:36:38 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 11:07:07 -05:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
#ifndef PARSE_HXX
|
|
|
|
#define PARSE_HXX
|
|
|
|
|
|
|
|
|
2001-04-18 02:54:29 -05:00
|
|
|
#include <vcl/svapp.hxx>
|
2000-09-18 11:07:07 -05:00
|
|
|
#include <tools/stack.hxx>
|
|
|
|
#include <tools/string.hxx>
|
|
|
|
|
2010-10-13 04:39:15 -05:00
|
|
|
#include <set>
|
|
|
|
#include <stack>
|
|
|
|
#include <list>
|
|
|
|
|
2000-09-18 11:07:07 -05:00
|
|
|
#include "types.hxx"
|
|
|
|
|
2010-12-12 08:59:49 -06:00
|
|
|
#include <vector>
|
|
|
|
|
2000-09-18 11:07:07 -05:00
|
|
|
class SmNode;
|
2001-08-28 01:47:20 -05:00
|
|
|
class SmDocShell;
|
2000-09-18 11:07:07 -05:00
|
|
|
|
2010-10-13 04:39:15 -05:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
2000-09-18 11:07:07 -05:00
|
|
|
|
|
|
|
// TokenGroups
|
|
|
|
#define TGOPER 0x00000001
|
|
|
|
#define TGRELATION 0x00000002
|
|
|
|
#define TGSUM 0x00000004
|
|
|
|
#define TGPRODUCT 0x00000008
|
|
|
|
#define TGUNOPER 0x00000010
|
|
|
|
#define TGPOWER 0x00000020
|
|
|
|
#define TGATTRIBUT 0x00000040
|
|
|
|
#define TGALIGN 0x00000080
|
|
|
|
#define TGFUNCTION 0x00000100
|
|
|
|
#define TGBLANK 0x00000200
|
|
|
|
#define TGLBRACES 0x00000400
|
|
|
|
#define TGRBRACES 0x00000800
|
|
|
|
#define TGCOLOR 0x00001000
|
|
|
|
#define TGFONT 0x00002000
|
|
|
|
#define TGSTANDALONE 0x00004000
|
|
|
|
#define TGDISCARDED 0x00008000
|
|
|
|
#define TGLIMIT 0x00010000
|
|
|
|
#define TGFONTATTR 0x00020000
|
|
|
|
|
|
|
|
|
|
|
|
enum SmTokenType
|
|
|
|
{
|
2011-08-30 09:43:09 -05:00
|
|
|
/* 0*/ TEND, TLGROUP, TRGROUP, TLPARENT, TRPARENT,
|
|
|
|
/* 5*/ TLBRACKET, TRBRACKET, TPLUS, TMINUS, TMULTIPLY,
|
|
|
|
/* 10*/ TDIVIDEBY, TASSIGN, TPOUND, TSPECIAL, TSLASH,
|
|
|
|
/* 15*/ TBACKSLASH, TBLANK, TSBLANK, TRSUB, TRSUP,
|
|
|
|
/* 20*/ TCSUB, TCSUP, TLSUB, TLSUP, TGT,
|
|
|
|
/* 25*/ TLT, TAND, TOR, TINTERSECT, TUNION,
|
|
|
|
/* 30*/ TNEWLINE, TBINOM, TFROM, TTO, TINT,
|
|
|
|
/* 35*/ TSUM, TOPER, TABS, TSQRT, TFACT,
|
|
|
|
/* 40*/ TNROOT, TOVER, TTIMES, TGE, TLE,
|
|
|
|
/* 45*/ TGG, TLL, TDOTSAXIS, TDOTSLOW, TDOTSVERT,
|
|
|
|
/* 50*/ TDOTSDIAG, TDOTSUP, TDOTSDOWN, TACUTE, TBAR,
|
|
|
|
/* 55*/ TBREVE, TCHECK, TCIRCLE, TDOT, TDDOT,
|
|
|
|
/* 60*/ TDDDOT, TGRAVE, THAT, TTILDE, TVEC,
|
|
|
|
/* 65*/ TUNDERLINE, TOVERLINE, TOVERSTRIKE, TITALIC, TNITALIC,
|
|
|
|
/* 70*/ TBOLD, TNBOLD, TPHANTOM, TFONT, TSIZE,
|
|
|
|
/* 75*/ TCOLOR, TALIGNL, TALIGNC, TALIGNR, TLEFT,
|
|
|
|
/* 80*/ TRIGHT, TLANGLE, TLBRACE, TLLINE, TLDLINE,
|
|
|
|
/* 85*/ TLCEIL, TLFLOOR, TNONE, TMLINE, TRANGLE,
|
|
|
|
/* 90*/ TRBRACE, TRLINE, TRDLINE, TRCEIL, TRFLOOR,
|
|
|
|
/* 95*/ TSIN, TCOS, TTAN, TCOT, TFUNC,
|
|
|
|
/*100*/ TSTACK, TMATRIX, TMATFORM, TDPOUND, TPLACE,
|
|
|
|
/*105*/ TTEXT, TNUMBER, TCHARACTER, TIDENT, TNEQ,
|
|
|
|
/*110*/ TEQUIV, TDEF, TPROP, TSIM, TSIMEQ,
|
|
|
|
/*115*/ TAPPROX, TPARALLEL, TORTHO, TIN, TNOTIN,
|
|
|
|
/*120*/ TSUBSET, TSUBSETEQ, TSUPSET, TSUPSETEQ, TPLUSMINUS,
|
|
|
|
/*125*/ TMINUSPLUS, TOPLUS, TOMINUS, TDIV, TOTIMES,
|
|
|
|
/*130*/ TODIVIDE, TTRANSL, TTRANSR, TIINT, TIIINT,
|
|
|
|
/*135*/ TLINT, TLLINT, TLLLINT, TPROD, TCOPROD,
|
2011-09-17 15:43:49 -05:00
|
|
|
/*140*/ TFORALL, TEXISTS, TNOTEXISTS, TLIM, TNABLA,
|
|
|
|
/*145*/ TTOWARD, TSINH, TCOSH, TTANH, TCOTH,
|
|
|
|
/*150*/ TASIN, TACOS, TATAN, TLN, TLOG,
|
|
|
|
/*155*/ TUOPER, TBOPER, TBLACK, TWHITE, TRED,
|
|
|
|
/*160*/ TGREEN, TBLUE, TCYAN, TMAGENTA, TYELLOW,
|
|
|
|
/*165*/ TFIXED, TSANS, TSERIF, TPOINT, TASINH,
|
|
|
|
/*170*/ TACOSH, TATANH, TACOTH, TACOT, TEXP,
|
|
|
|
/*175*/ TCDOT, TODOT, TLESLANT, TGESLANT, TNSUBSET,
|
|
|
|
/*180*/ TNSUPSET, TNSUBSETEQ, TNSUPSETEQ, TPARTIAL, TNEG,
|
|
|
|
/*185*/ TNI, TBACKEPSILON, TALEPH, TIM, TRE,
|
|
|
|
/*190*/ TWP, TEMPTYSET, TINFINITY, TESCAPE, TLIMSUP,
|
|
|
|
/*195*/ TLIMINF, TNDIVIDES, TDRARROW, TDLARROW, TDLRARROW,
|
|
|
|
/*200*/ TUNDERBRACE, TOVERBRACE, TCIRC, TTOP, THBAR,
|
|
|
|
/*205*/ TLAMBDABAR, TLEFTARROW, TRIGHTARROW, TUPARROW, TDOWNARROW,
|
|
|
|
/*210*/ TDIVIDES, TNDIBVIDES, TSETN, TSETZ, TSETQ,
|
|
|
|
/*215*/ TSETR, TSETC, TWIDEVEC, TWIDETILDE, TWIDEHAT,
|
|
|
|
/*220*/ TWIDESLASH, TWIDEBACKSLASH, TLDBRACKET, TRDBRACKET, TNOSPACE,
|
2011-11-15 07:34:43 -06:00
|
|
|
/*225*/ TUNKNOWN, TDEBUG, TPRECEDES, TSUCCEEDS, TPRECEDESEQUAL,
|
|
|
|
/*230*/ TSUCCEEDSEQUAL, TPRECEDESEQUIV, TSUCCEEDSEQUIV, TNOTPRECEDES, TNOTSUCCEEDS
|
2000-09-18 11:07:07 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct SmToken
|
|
|
|
{
|
2010-10-13 04:39:15 -05:00
|
|
|
|
|
|
|
String aText; // token text
|
|
|
|
SmTokenType eType; // token info
|
2010-10-01 15:04:50 -05:00
|
|
|
sal_Unicode cMathChar;
|
2010-10-13 04:39:15 -05:00
|
|
|
|
2000-09-18 11:07:07 -05:00
|
|
|
// parse-help info
|
2011-01-14 10:19:25 -06:00
|
|
|
sal_uLong nGroup;
|
|
|
|
sal_uInt16 nLevel;
|
2010-10-13 04:39:15 -05:00
|
|
|
|
2000-09-18 11:07:07 -05:00
|
|
|
// token position
|
2011-01-14 10:19:25 -06:00
|
|
|
sal_uInt16 nRow;
|
2010-10-13 04:39:15 -05:00
|
|
|
xub_StrLen nCol;
|
2000-09-18 11:07:07 -05:00
|
|
|
|
|
|
|
SmToken();
|
2010-10-01 15:04:50 -05:00
|
|
|
SmToken(SmTokenType eTokenType,
|
|
|
|
sal_Unicode cMath,
|
|
|
|
const sal_Char* pText,
|
2011-03-14 11:51:14 -05:00
|
|
|
sal_uLong nTokenGroup = 0,
|
|
|
|
sal_uInt16 nTokenLevel = 0);
|
2000-09-18 11:07:07 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum SmParseError
|
|
|
|
{
|
|
|
|
PE_NONE, PE_UNEXPECTED_END_OF_INPUT,
|
|
|
|
PE_UNEXPECTED_CHAR, PE_UNEXPECTED_TOKEN,
|
|
|
|
PE_FUNC_EXPECTED, PE_UNOPER_EXPECTED,
|
|
|
|
PE_BINOPER_EXPECTED, PE_SYMBOL_EXPECTED,
|
|
|
|
PE_IDENTIFIER_EXPECTED, PE_POUND_EXPECTED,
|
|
|
|
PE_COLOR_EXPECTED, PE_LGROUP_EXPECTED,
|
|
|
|
PE_RGROUP_EXPECTED, PE_LBRACE_EXPECTED,
|
|
|
|
PE_RBRACE_EXPECTED, PE_PARENT_MISMATCH,
|
|
|
|
PE_RIGHT_EXPECTED, PE_FONT_EXPECTED,
|
|
|
|
PE_SIZE_EXPECTED, PE_DOUBLE_ALIGN,
|
|
|
|
PE_DOUBLE_SUBSUPSCRIPT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct SmErrorDesc
|
|
|
|
{
|
|
|
|
SmParseError Type;
|
|
|
|
SmNode *pNode;
|
2001-04-18 02:54:29 -05:00
|
|
|
String Text;
|
2000-09-18 11:07:07 -05:00
|
|
|
};
|
|
|
|
|
2010-10-13 04:39:15 -05:00
|
|
|
|
2007-05-25 06:09:50 -05:00
|
|
|
DECLARE_STACK(SmNodeStack, SmNode *)
|
2010-12-12 08:59:49 -06:00
|
|
|
typedef ::std::vector< SmErrorDesc* > SmErrDescList;
|
2000-09-18 11:07:07 -05:00
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2001-12-14 02:07:32 -06:00
|
|
|
// defines possible conversions of the formula text from the format of
|
|
|
|
// one release to the one of another.
|
|
|
|
enum SmConvert
|
|
|
|
{
|
|
|
|
CONVERT_NONE,
|
|
|
|
CONVERT_40_TO_50,
|
|
|
|
CONVERT_50_TO_60,
|
|
|
|
CONVERT_60_TO_50
|
|
|
|
};
|
|
|
|
|
2010-10-01 15:04:50 -05:00
|
|
|
struct SmTokenTableEntry
|
|
|
|
{
|
|
|
|
const sal_Char* pIdent;
|
|
|
|
SmTokenType eType;
|
|
|
|
sal_Unicode cMathChar;
|
2011-03-14 11:51:14 -05:00
|
|
|
sal_uLong nGroup;
|
|
|
|
sal_uInt16 nLevel;
|
2010-10-01 15:04:50 -05:00
|
|
|
};
|
2001-12-14 02:07:32 -06:00
|
|
|
|
2000-09-18 11:07:07 -05:00
|
|
|
class SmParser
|
|
|
|
{
|
2010-10-13 04:39:15 -05:00
|
|
|
String m_aBufferString;
|
|
|
|
SmToken m_aCurToken;
|
|
|
|
SmNodeStack m_aNodeStack;
|
|
|
|
SmErrDescList m_aErrDescList;
|
|
|
|
int m_nCurError;
|
|
|
|
LanguageType m_nLang;
|
|
|
|
xub_StrLen m_nBufferIndex,
|
|
|
|
m_nTokenIndex;
|
2011-02-07 11:01:48 -06:00
|
|
|
sal_uInt16 m_Row,
|
2010-10-13 04:39:15 -05:00
|
|
|
m_nColOff;
|
|
|
|
SmConvert m_eConversion;
|
2010-11-05 19:33:05 -05:00
|
|
|
bool bImportSymNames,
|
2010-10-13 04:39:15 -05:00
|
|
|
m_bExportSymNames;
|
|
|
|
|
|
|
|
// map of used symbols (used to reduce file size by exporting only actually used symbols)
|
|
|
|
std::set< rtl::OUString > m_aUsedSymbols;
|
2000-09-18 11:07:07 -05:00
|
|
|
|
2011-05-31 15:50:51 -05:00
|
|
|
//! locale where '.' is decimal seperator!
|
|
|
|
::com::sun::star::lang::Locale m_aDotLoc;
|
|
|
|
|
2000-09-18 11:07:07 -05:00
|
|
|
// declare copy-constructor and assignment-operator private
|
|
|
|
SmParser(const SmParser &);
|
|
|
|
SmParser & operator = (const SmParser &);
|
|
|
|
|
|
|
|
protected:
|
2011-08-04 15:18:00 -05:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
2010-11-05 19:33:05 -05:00
|
|
|
bool IsDelimiter( const String &rTxt, xub_StrLen nPos );
|
2004-08-11 09:06:33 -05:00
|
|
|
#endif
|
2000-09-18 11:07:07 -05:00
|
|
|
void NextToken();
|
2010-10-13 04:39:15 -05:00
|
|
|
xub_StrLen GetTokenIndex() const { return m_nTokenIndex; }
|
2011-01-14 10:19:25 -06:00
|
|
|
void Insert(const String &rText, sal_uInt16 nPos);
|
2011-02-07 11:01:48 -06:00
|
|
|
void Replace( sal_uInt16 nPos, sal_uInt16 nLen, const String &rText );
|
2000-09-18 11:07:07 -05:00
|
|
|
|
2011-03-14 11:51:14 -05:00
|
|
|
inline bool TokenInGroup( sal_uLong nGroup );
|
2000-09-18 11:07:07 -05:00
|
|
|
|
|
|
|
// grammar
|
|
|
|
void Table();
|
|
|
|
void Line();
|
|
|
|
void Expression();
|
|
|
|
void Relation();
|
|
|
|
void Sum();
|
|
|
|
void Product();
|
2011-01-14 10:19:25 -06:00
|
|
|
void SubSup(sal_uLong nActiveGroup);
|
2000-09-18 11:07:07 -05:00
|
|
|
void OpSubSup();
|
|
|
|
void Power();
|
|
|
|
void Blank();
|
|
|
|
void Term();
|
|
|
|
void Escape();
|
|
|
|
void Operator();
|
|
|
|
void Oper();
|
|
|
|
void UnOper();
|
|
|
|
void Align();
|
|
|
|
void FontAttribut();
|
|
|
|
void Attribut();
|
|
|
|
void Font();
|
|
|
|
void FontSize();
|
|
|
|
void Color();
|
|
|
|
void Brace();
|
2010-11-05 19:33:05 -05:00
|
|
|
void Bracebody(bool bIsLeftRight);
|
2000-09-18 11:07:07 -05:00
|
|
|
void Function();
|
|
|
|
void Binom();
|
|
|
|
void Stack();
|
|
|
|
void Matrix();
|
|
|
|
void Special();
|
|
|
|
void GlyphSpecial();
|
|
|
|
// end of grammar
|
|
|
|
|
2010-10-13 04:39:15 -05:00
|
|
|
LanguageType GetLanguage() const { return m_nLang; }
|
|
|
|
void SetLanguage( LanguageType nNewLang ) { m_nLang = nNewLang; }
|
2001-12-14 02:07:32 -06:00
|
|
|
|
2000-09-18 11:07:07 -05:00
|
|
|
void Error(SmParseError Error);
|
|
|
|
|
2010-10-13 04:39:15 -05:00
|
|
|
void ClearUsedSymbols() { m_aUsedSymbols.clear(); }
|
|
|
|
void AddToUsedSymbols( const String &rSymbolName ) { m_aUsedSymbols.insert( rSymbolName ); }
|
|
|
|
|
2000-09-18 11:07:07 -05:00
|
|
|
public:
|
|
|
|
SmParser();
|
|
|
|
|
2010-10-01 15:04:50 -05:00
|
|
|
/** Parse rBuffer to formula tree */
|
2001-04-18 02:54:29 -05:00
|
|
|
SmNode *Parse(const String &rBuffer);
|
2010-10-01 15:04:50 -05:00
|
|
|
/** Parse rBuffer to formula subtree that constitutes an expression */
|
|
|
|
SmNode *ParseExpression(const String &rBuffer);
|
2000-09-18 11:07:07 -05:00
|
|
|
|
2010-10-13 04:39:15 -05:00
|
|
|
const String & GetText() const { return m_aBufferString; };
|
2000-09-18 11:07:07 -05:00
|
|
|
|
2011-03-14 11:51:14 -05:00
|
|
|
SmConvert GetConversion() const { return m_eConversion; }
|
|
|
|
void SetConversion(SmConvert eConv) { m_eConversion = eConv; }
|
2001-08-28 01:47:20 -05:00
|
|
|
|
2010-12-12 08:59:49 -06:00
|
|
|
bool IsImportSymbolNames() const { return bImportSymNames; }
|
|
|
|
void SetImportSymbolNames(bool bVal) { bImportSymNames = bVal; }
|
2011-03-14 11:51:14 -05:00
|
|
|
bool IsExportSymbolNames() const { return m_bExportSymNames; }
|
|
|
|
void SetExportSymbolNames(bool bVal) { m_bExportSymNames = bVal; }
|
2000-09-18 11:07:07 -05:00
|
|
|
|
2010-12-12 08:59:49 -06:00
|
|
|
size_t AddError(SmParseError Type, SmNode *pNode);
|
|
|
|
const SmErrorDesc* NextError();
|
|
|
|
const SmErrorDesc* PrevError();
|
|
|
|
const SmErrorDesc* GetError(size_t i = size_t(-1) );
|
2010-10-01 15:04:50 -05:00
|
|
|
static const SmTokenTableEntry* GetTokenTableEntry( const String &rName );
|
2010-12-10 02:13:28 -06:00
|
|
|
bool IsUsedSymbol( const String &rSymbolName ) const { return m_aUsedSymbols.find( rSymbolName ) != m_aUsedSymbols.end(); }
|
2010-10-13 04:39:15 -05:00
|
|
|
std::set< rtl::OUString > GetUsedSymbols() const { return m_aUsedSymbols; }
|
2000-09-18 11:07:07 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-03-14 11:51:14 -05:00
|
|
|
inline bool SmParser::TokenInGroup( sal_uLong nGroup)
|
2000-09-18 11:07:07 -05:00
|
|
|
{
|
2011-03-14 11:51:14 -05:00
|
|
|
return (m_aCurToken.nGroup & nGroup) ? true : false;
|
2000-09-18 11:07:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-10-14 01:30:41 -05:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|