LCOV - code coverage report
Current view: top level - starmath/inc - parse.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 14 15 93.3 %
Date: 2014-11-03 Functions: 16 18 88.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #ifndef INCLUDED_STARMATH_INC_PARSE_HXX
      20             : #define INCLUDED_STARMATH_INC_PARSE_HXX
      21             : 
      22             : #include <vcl/svapp.hxx>
      23             : 
      24             : #include <set>
      25             : #include <stack>
      26             : #include <list>
      27             : 
      28             : #include "types.hxx"
      29             : 
      30             : #include <vector>
      31             : 
      32             : class SmNode;
      33             : 
      34             : 
      35             : 
      36             : // TokenGroups
      37             : #define TGOPER          0x00000001
      38             : #define TGRELATION      0x00000002
      39             : #define TGSUM           0x00000004
      40             : #define TGPRODUCT       0x00000008
      41             : #define TGUNOPER        0x00000010
      42             : #define TGPOWER         0x00000020
      43             : #define TGATTRIBUT      0x00000040
      44             : #define TGALIGN         0x00000080
      45             : #define TGFUNCTION      0x00000100
      46             : #define TGBLANK         0x00000200
      47             : #define TGLBRACES       0x00000400
      48             : #define TGRBRACES       0x00000800
      49             : #define TGCOLOR         0x00001000
      50             : #define TGFONT          0x00002000
      51             : #define TGSTANDALONE    0x00004000
      52             : #define TGDISCARDED     0x00008000
      53             : #define TGLIMIT         0x00010000
      54             : #define TGFONTATTR      0x00020000
      55             : 
      56             : 
      57             : enum SmTokenType
      58             : {
      59             : /*  0*/ TEND,           TLGROUP,        TRGROUP,        TLPARENT,       TRPARENT,
      60             : /*  5*/ TLBRACKET,      TRBRACKET,      TPLUS,          TMINUS,         TMULTIPLY,
      61             : /* 10*/ TDIVIDEBY,      TASSIGN,        TPOUND,         TSPECIAL,       TSLASH,
      62             : /* 15*/ TBACKSLASH,     TBLANK,         TSBLANK,        TRSUB,          TRSUP,
      63             : /* 20*/ TCSUB,          TCSUP,          TLSUB,          TLSUP,          TGT,
      64             : /* 25*/ TLT,            TAND,           TOR,            TINTERSECT,     TUNION,
      65             : /* 30*/ TNEWLINE,       TBINOM,         TFROM,          TTO,            TINT,
      66             : /* 35*/ TSUM,           TOPER,          TABS,           TSQRT,          TFACT,
      67             : /* 40*/ TNROOT,         TOVER,          TTIMES,         TGE,            TLE,
      68             : /* 45*/ TGG,            TLL,            TDOTSAXIS,      TDOTSLOW,       TDOTSVERT,
      69             : /* 50*/ TDOTSDIAG,      TDOTSUP,        TDOTSDOWN,      TACUTE,         TBAR,
      70             : /* 55*/ TBREVE,         TCHECK,         TCIRCLE,        TDOT,           TDDOT,
      71             : /* 60*/ TDDDOT,         TGRAVE,         THAT,           TTILDE,         TVEC,
      72             : /* 65*/ TUNDERLINE,     TOVERLINE,      TOVERSTRIKE,    TITALIC,        TNITALIC,
      73             : /* 70*/ TBOLD,          TNBOLD,         TPHANTOM,       TFONT,          TSIZE,
      74             : /* 75*/ TCOLOR,         TALIGNL,        TALIGNC,        TALIGNR,        TLEFT,
      75             : /* 80*/ TRIGHT,         TLANGLE,        TLBRACE,        TLLINE,         TLDLINE,
      76             : /* 85*/ TLCEIL,         TLFLOOR,        TNONE,          TMLINE,         TRANGLE,
      77             : /* 90*/ TRBRACE,        TRLINE,         TRDLINE,        TRCEIL,         TRFLOOR,
      78             : /* 95*/ TSIN,           TCOS,           TTAN,           TCOT,           TFUNC,
      79             : /*100*/ TSTACK,         TMATRIX,        TMATFORM,       TDPOUND,        TPLACE,
      80             : /*105*/ TTEXT,          TNUMBER,        TCHARACTER,     TIDENT,         TNEQ,
      81             : /*110*/ TEQUIV,         TDEF,           TPROP,          TSIM,           TSIMEQ,
      82             : /*115*/ TAPPROX,        TPARALLEL,      TORTHO,         TIN,            TNOTIN,
      83             : /*120*/ TSUBSET,        TSUBSETEQ,      TSUPSET,        TSUPSETEQ,      TPLUSMINUS,
      84             : /*125*/ TMINUSPLUS,     TOPLUS,         TOMINUS,        TDIV,           TOTIMES,
      85             : /*130*/ TODIVIDE,       TTRANSL,        TTRANSR,        TIINT,          TIIINT,
      86             : /*135*/ TLINT,          TLLINT,         TLLLINT,        TPROD,          TCOPROD,
      87             : /*140*/ TFORALL,        TEXISTS,        TNOTEXISTS,     TLIM,           TNABLA,
      88             : /*145*/ TTOWARD,        TSINH,          TCOSH,          TTANH,          TCOTH,
      89             : /*150*/ TASIN,          TACOS,          TATAN,          TLN,            TLOG,
      90             : /*155*/ TUOPER,         TBOPER,         TBLACK,         TWHITE,         TRED,
      91             : /*160*/ TGREEN,         TBLUE,          TCYAN,          TMAGENTA,       TYELLOW,
      92             : /*165*/ TFIXED,         TSANS,          TSERIF,         TPOINT,         TASINH,
      93             : /*170*/ TACOSH,         TATANH,         TACOTH,         TACOT,          TEXP,
      94             : /*175*/ TCDOT,          TODOT,          TLESLANT,       TGESLANT,       TNSUBSET,
      95             : /*180*/ TNSUPSET,       TNSUBSETEQ,     TNSUPSETEQ,     TPARTIAL,       TNEG,
      96             : /*185*/ TNI,            TBACKEPSILON,   TALEPH,         TIM,            TRE,
      97             : /*190*/ TWP,            TEMPTYSET,      TINFINITY,      TESCAPE,        TLIMSUP,
      98             : /*195*/ TLIMINF,        TNDIVIDES,      TDRARROW,       TDLARROW,       TDLRARROW,
      99             : /*200*/ TUNDERBRACE,    TOVERBRACE,     TCIRC,          TTOP,           THBAR,
     100             : /*205*/ TLAMBDABAR,     TLEFTARROW,     TRIGHTARROW,    TUPARROW,       TDOWNARROW,
     101             : /*210*/ TDIVIDES,       TNDIBVIDES,     TSETN,          TSETZ,          TSETQ,
     102             : /*215*/ TSETR,          TSETC,          TWIDEVEC,       TWIDETILDE,     TWIDEHAT,
     103             : /*220*/ TWIDESLASH,     TWIDEBACKSLASH, TLDBRACKET,     TRDBRACKET,     TNOSPACE,
     104             : /*225*/ TUNKNOWN,       TDEBUG,         TPRECEDES,      TSUCCEEDS,      TPRECEDESEQUAL,
     105             : /*230*/ TSUCCEEDSEQUAL, TPRECEDESEQUIV, TSUCCEEDSEQUIV, TNOTPRECEDES,   TNOTSUCCEEDS,
     106             : /*235*/ TSILVER,        TGRAY,          TMAROON,        TPURPLE,        TLIME,
     107             : /*240*/ TOLIVE,         TNAVY,          TTEAL,          TAQUA,          TFUCHSIA,
     108             : /*245*/ TINTD
     109             : };
     110             : 
     111       65816 : struct SmToken
     112             : {
     113             : 
     114             :     OUString        aText;      // token text
     115             :     SmTokenType     eType;      // token info
     116             :     sal_Unicode cMathChar;
     117             : 
     118             :     // parse-help info
     119             :     sal_uLong       nGroup;
     120             :     sal_uInt16      nLevel;
     121             : 
     122             :     // token position
     123             :     sal_Int32      nRow;
     124             :     sal_Int32      nCol;
     125             : 
     126             :     SmToken();
     127             :     SmToken(SmTokenType eTokenType,
     128             :             sal_Unicode cMath,
     129             :             const sal_Char* pText,
     130             :             sal_uLong nTokenGroup = 0,
     131             :             sal_uInt16 nTokenLevel = 0);
     132             : };
     133             : 
     134             : 
     135             : enum SmParseError
     136             : {
     137             :     PE_NONE,                    PE_UNEXPECTED_END_OF_INPUT,
     138             :     PE_UNEXPECTED_CHAR,         PE_UNEXPECTED_TOKEN,
     139             :     PE_FUNC_EXPECTED,           PE_UNOPER_EXPECTED,
     140             :     PE_BINOPER_EXPECTED,        PE_SYMBOL_EXPECTED,
     141             :     PE_IDENTIFIER_EXPECTED,     PE_POUND_EXPECTED,
     142             :     PE_COLOR_EXPECTED,          PE_LGROUP_EXPECTED,
     143             :     PE_RGROUP_EXPECTED,         PE_LBRACE_EXPECTED,
     144             :     PE_RBRACE_EXPECTED,         PE_PARENT_MISMATCH,
     145             :     PE_RIGHT_EXPECTED,          PE_FONT_EXPECTED,
     146             :     PE_SIZE_EXPECTED,           PE_DOUBLE_ALIGN,
     147             :     PE_DOUBLE_SUBSUPSCRIPT
     148             : };
     149             : 
     150             : 
     151          86 : struct SmErrorDesc
     152             : {
     153             :     SmParseError  Type;
     154             :     SmNode       *pNode;
     155             :     OUString      Text;
     156             : };
     157             : 
     158             : 
     159             : typedef ::std::stack< SmNode* > SmNodeStack;
     160             : typedef ::std::vector< SmErrorDesc* > SmErrDescList;
     161             : 
     162             : /**************************************************************************/
     163             : 
     164             : struct SmTokenTableEntry
     165             : {
     166             :     const sal_Char* pIdent;
     167             :     SmTokenType     eType;
     168             :     sal_Unicode     cMathChar;
     169             :     sal_uLong       nGroup;
     170             :     sal_uInt16      nLevel;
     171             : };
     172             : 
     173        2334 : class SmParser
     174             : {
     175             :     OUString        m_aBufferString;
     176             :     SmToken         m_aCurToken;
     177             :     SmNodeStack     m_aNodeStack;
     178             :     SmErrDescList   m_aErrDescList;
     179             :     int             m_nCurError;
     180             :     LanguageType    m_nLang;
     181             :     sal_Int32       m_nBufferIndex,
     182             :                     m_nTokenIndex;
     183             :     sal_Int32       m_Row,
     184             :                     m_nColOff;
     185             :     bool            bImportSymNames,
     186             :                     m_bExportSymNames;
     187             : 
     188             :     // map of used symbols (used to reduce file size by exporting only actually used symbols)
     189             :     std::set< OUString >   m_aUsedSymbols;
     190             : 
     191             :     //! locale where '.' is decimal separator!
     192             :     ::com::sun::star::lang::Locale m_aDotLoc;
     193             : 
     194             :     // declare copy-constructor and assignment-operator private
     195             :     SmParser(const SmParser &);
     196             :     SmParser & operator = (const SmParser &);
     197             : 
     198             : protected:
     199             : #if OSL_DEBUG_LEVEL > 1
     200             :     bool            IsDelimiter( const OUString &rTxt, sal_Int32 nPos );
     201             : #endif
     202             :     void            NextToken();
     203           0 :     sal_Int32       GetTokenIndex() const   { return m_nTokenIndex; }
     204             :     void            Replace( sal_Int32 nPos, sal_Int32 nLen, const OUString &rText );
     205             : 
     206             :     inline bool     TokenInGroup( sal_uLong nGroup );
     207             : 
     208             :     // grammar
     209             :     void    Table();
     210             :     void    Line();
     211             :     void    Expression();
     212             :     void    Relation();
     213             :     void    Sum();
     214             :     void    Product();
     215             :     void    SubSup(sal_uLong nActiveGroup);
     216             :     void    OpSubSup();
     217             :     void    Power();
     218             :     void    Blank();
     219             :     void    Term(bool bGroupNumberIdent);
     220             :     void    Escape();
     221             :     void    Operator();
     222             :     void    Oper();
     223             :     void    UnOper();
     224             :     void    Align();
     225             :     void    FontAttribut();
     226             :     void    Attribut();
     227             :     void    Font();
     228             :     void    FontSize();
     229             :     void    Color();
     230             :     void    Brace();
     231             :     void    Bracebody(bool bIsLeftRight);
     232             :     void    Function();
     233             :     void    Binom();
     234             :     void    Stack();
     235             :     void    Matrix();
     236             :     void    Special();
     237             :     void    GlyphSpecial();
     238             :     // end of grammar
     239             : 
     240             :     LanguageType    GetLanguage() const { return m_nLang; }
     241        3470 :     void            SetLanguage( LanguageType nNewLang ) { m_nLang = nNewLang; }
     242             : 
     243             :     void    Error(SmParseError Error);
     244             : 
     245        1778 :     void    ClearUsedSymbols()                              { m_aUsedSymbols.clear(); }
     246         262 :     void    AddToUsedSymbols( const OUString &rSymbolName ) { m_aUsedSymbols.insert( rSymbolName ); }
     247             : 
     248             : public:
     249             :                  SmParser();
     250             : 
     251             :     /** Parse rBuffer to formula tree */
     252             :     SmNode      *Parse(const OUString &rBuffer);
     253             :     /** Parse rBuffer to formula subtree that constitutes an expression */
     254             :     SmNode      *ParseExpression(const OUString &rBuffer);
     255             : 
     256        1122 :     const OUString & GetText() const { return m_aBufferString; };
     257             : 
     258         266 :     bool        IsImportSymbolNames() const        { return bImportSymNames; }
     259           8 :     void        SetImportSymbolNames(bool bVal)    { bImportSymNames = bVal; }
     260        1380 :     bool        IsExportSymbolNames() const        { return m_bExportSymNames; }
     261        2236 :     void        SetExportSymbolNames(bool bVal)    { m_bExportSymNames = bVal; }
     262             : 
     263             :     size_t      AddError(SmParseError Type, SmNode *pNode);
     264             :     const SmErrorDesc*  NextError();
     265             :     const SmErrorDesc*  PrevError();
     266             :     const SmErrorDesc*  GetError(size_t i = size_t(-1) );
     267             :     static const SmTokenTableEntry* GetTokenTableEntry( const OUString &rName );
     268             :     bool    IsUsedSymbol( const OUString &rSymbolName ) const { return m_aUsedSymbols.find( rSymbolName ) != m_aUsedSymbols.end(); }
     269         648 :     std::set< OUString >   GetUsedSymbols() const      { return m_aUsedSymbols; }
     270             : };
     271             : 
     272             : 
     273       96360 : inline bool SmParser::TokenInGroup( sal_uLong nGroup)
     274             : {
     275       96360 :     return (m_aCurToken.nGroup & nGroup) ? true : false;
     276             : }
     277             : 
     278             : 
     279             : #endif
     280             : 
     281             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10