/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #ifndef INCLUDED_STARMATH_INC_PARSE_HXX #define INCLUDED_STARMATH_INC_PARSE_HXX #include #include #include #include #include "token.hxx" #include "error.hxx" class SmBlankNode; class SmBracebodyNode; class SmExpressionNode; class SmGlyphSpecialNode; class SmNode; class SmOperNode; class SmSpecialNode; class SmStructureNode; class SmTableNode; class SmTextNode; #define DEPTH_LIMIT 1024 class SmParser { OUString m_aBufferString; SmToken m_aCurToken; std::vector> m_aErrDescList; int m_nCurError; sal_Int32 m_nBufferIndex, m_nTokenIndex; sal_Int32 m_nRow, // 1-based m_nColOff; // 0-based bool m_bImportSymNames, m_bExportSymNames; sal_Int32 m_nParseDepth; class DepthProtect { private: sal_Int32& m_rParseDepth; public: DepthProtect(sal_Int32& rParseDepth) : m_rParseDepth(rParseDepth) { ++m_rParseDepth; } bool TooDeep() const { return m_rParseDepth > DEPTH_LIMIT; } ~DepthProtect() { --m_rParseDepth; } }; // map of used symbols (used to reduce file size by exporting only actually used symbols) std::set< OUString > m_aUsedSymbols; // CharClass representing a locale for parsing numbers CharClass m_aNumCC; // pointer to System locale's CharClass, which is alive inside SM_MOD() const CharClass* m_pSysCC; SmParser(const SmParser&) = delete; SmParser& operator=(const SmParser&) = delete; void NextToken(); sal_Int32 GetTokenIndex() const { return m_nTokenIndex; } void Replace( sal_Int32 nPos, sal_Int32 nLen, const OUString &rText ); inline bool TokenInGroup( TG nGroup ); // grammar std::unique_ptr DoTable(); std::unique_ptr DoLine(); std::unique_ptr DoExpression(bool bUseExtraSpaces = true); std::unique_ptr DoRelation(); std::unique_ptr DoSum(); std::unique_ptr DoProduct(); std::unique_ptr DoSubSup(TG nActiveGroup, SmNode *pGivenNode); std::unique_ptr DoOpSubSup(); std::unique_ptr DoPower(); std::unique_ptr DoBlank(); std::unique_ptr DoTerm(bool bGroupNumberIdent); std::unique_ptr DoEscape(); std::unique_ptr DoOperator(); std::unique_ptr DoOper(); std::unique_ptr DoUnOper(); std::unique_ptr DoAlign(bool bUseExtraSpaces = true); std::unique_ptr DoFontAttribut(); std::unique_ptr DoAttribut(); std::unique_ptr DoFont(); std::unique_ptr DoFontSize(); std::unique_ptr DoColor(); std::unique_ptr DoBrace(); std::unique_ptr DoBracebody(bool bIsLeftRight); std::unique_ptr DoFunction(); std::unique_ptr DoBinom(); std::unique_ptr DoStack(); std::unique_ptr DoMatrix(); std::unique_ptr DoSpecial(); std::unique_ptr DoGlyphSpecial(); std::unique_ptr DoError(SmParseError Error); // end of grammar public: SmParser(); /** Parse rBuffer to formula tree */ std::unique_ptr Parse(const OUString &rBuffer); /** Parse rBuffer to formula subtree that constitutes an expression */ std::unique_ptr ParseExpression(const OUString &rBuffer); const OUString & GetText() const { return m_aBufferString; }; bool IsImportSymbolNames() const { return m_bImportSymNames; } void SetImportSymbolNames(bool bVal) { m_bImportSymNames = bVal; } bool IsExportSymbolNames() const { return m_bExportSymNames; } void SetExportSymbolNames(bool bVal) { m_bExportSymNames = bVal; } void AddError(SmParseError Type, SmNode *pNode); const SmErrorDesc* NextError(); const SmErrorDesc* PrevError(); const SmErrorDesc* GetError(); static const SmTokenTableEntry* GetTokenTableEntry( const OUString &rName ); const std::set< OUString >& GetUsedSymbols() const { return m_aUsedSymbols; } }; inline bool SmParser::TokenInGroup( TG nGroup) { return bool(m_aCurToken.nGroup & nGroup); } #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */