LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / starmath / inc / parse5.hxx
blob69528c403c0aa09b9a02776d4207c3cef773d1c3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 /** Parses the starmath code and creates the nodes.
24 #pragma once
26 #include "parsebase.hxx"
28 class SmParser5 final : public AbstractSmParser
30 OUString m_aBufferString;
31 SmToken m_aCurToken;
32 ESelection m_aCurESelection;
33 std::vector<SmErrorDesc> m_aErrDescList;
34 int m_nCurError;
35 sal_Int32 m_nBufferIndex, m_nTokenIndex;
36 sal_Int32 m_nRow, // 1-based
37 m_nColOff; // 0-based
38 bool m_bImportSymNames, m_bExportSymNames;
39 sal_Int32 m_nParseDepth;
41 // map of used symbols (used to reduce file size by exporting only actually used symbols)
42 std::set<OUString> m_aUsedSymbols;
44 // CharClass representing a locale for parsing numbers
45 CharClass m_aNumCC;
46 // pointer to System locale's CharClass, which is alive inside SM_MOD()
47 const CharClass* m_pSysCC;
49 SmParser5(const SmParser5&) = delete;
50 SmParser5& operator=(const SmParser5&) = delete;
52 // Moves between tokens inside starmath code.
53 void NextToken();
54 void NextTokenColor(SmTokenType dvipload);
55 void NextTokenFontSize();
56 sal_Int32 GetTokenIndex() const { return m_nTokenIndex; }
57 void Replace(sal_Int32 nPos, sal_Int32 nLen, const OUString& rText);
59 inline bool TokenInGroup(TG nGroup);
61 // grammar
62 std::unique_ptr<SmTableNode> DoTable();
63 std::unique_ptr<SmNode> DoLine();
64 std::unique_ptr<SmNode> DoExpression(bool bUseExtraSpaces = true);
65 std::unique_ptr<SmNode> DoRelation();
66 std::unique_ptr<SmNode> DoSum();
67 std::unique_ptr<SmNode> DoProduct();
68 std::unique_ptr<SmNode> DoSubSup(TG nActiveGroup, std::unique_ptr<SmNode> xGivenNode);
69 std::unique_ptr<SmNode> DoSubSupEvaluate(std::unique_ptr<SmNode> xGivenNode);
70 std::unique_ptr<SmNode> DoOpSubSup();
71 std::unique_ptr<SmNode> DoPower();
72 std::unique_ptr<SmBlankNode> DoBlank();
73 std::unique_ptr<SmNode> DoTerm(bool bGroupNumberIdent);
74 std::unique_ptr<SmNode> DoEscape();
75 std::unique_ptr<SmOperNode> DoOperator();
76 std::unique_ptr<SmNode> DoOper();
77 std::unique_ptr<SmStructureNode> DoUnOper();
78 std::unique_ptr<SmNode> DoAlign(bool bUseExtraSpaces = true);
79 std::unique_ptr<SmStructureNode> DoFontAttribute();
80 std::unique_ptr<SmStructureNode> DoAttribute();
81 std::unique_ptr<SmStructureNode> DoFont();
82 std::unique_ptr<SmStructureNode> DoFontSize();
83 std::unique_ptr<SmStructureNode> DoColor();
84 std::unique_ptr<SmStructureNode> DoBrace();
85 std::unique_ptr<SmBracebodyNode> DoBracebody(bool bIsLeftRight);
86 std::unique_ptr<SmNode> DoEvaluate();
87 std::unique_ptr<SmTextNode> DoFunction();
88 std::unique_ptr<SmTableNode> DoBinom();
89 std::unique_ptr<SmBinVerNode> DoFrac();
90 std::unique_ptr<SmStructureNode> DoStack();
91 std::unique_ptr<SmStructureNode> DoMatrix();
92 std::unique_ptr<SmSpecialNode> DoSpecial();
93 std::unique_ptr<SmGlyphSpecialNode> DoGlyphSpecial();
94 std::unique_ptr<SmExpressionNode> DoError(SmParseError Error);
95 // end of grammar
97 public:
98 SmParser5();
99 virtual ~SmParser5();
101 /** Parse rBuffer to formula tree */
102 std::unique_ptr<SmTableNode> Parse(const OUString& rBuffer);
103 /** Parse rBuffer to formula subtree that constitutes an expression */
104 std::unique_ptr<SmNode> ParseExpression(const OUString& rBuffer);
106 const OUString& GetText() const { return m_aBufferString; };
108 bool IsImportSymbolNames() const { return m_bImportSymNames; }
109 void SetImportSymbolNames(bool bVal) { m_bImportSymNames = bVal; }
110 bool IsExportSymbolNames() const { return m_bExportSymNames; }
111 void SetExportSymbolNames(bool bVal) { m_bExportSymNames = bVal; }
113 const SmErrorDesc* NextError();
114 const SmErrorDesc* PrevError();
115 const SmErrorDesc* GetError() const;
116 const std::set<OUString>& GetUsedSymbols() const { return m_aUsedSymbols; }
119 inline bool SmParser5::TokenInGroup(TG nGroup) { return bool(m_aCurToken.nGroup & nGroup); }
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */