LibreOffice Module starmath (master) 1
parsebase.hxx
Go to the documentation of this file.
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
24#pragma once
25
26#include <unotools/resmgr.hxx>
27
28#include "node.hxx"
29
30#include <set>
31#include <utility>
32
33#define DEPTH_LIMIT 1024
34
35// Those are the errors that the parser may encounter.
36enum class SmParseError : uint_fast8_t
37{
38 None = 0,
41 PoundExpected = 3,
42 ColorExpected = 4,
48 RightExpected = 10,
49 FontExpected = 11,
50 SizeExpected = 12,
51 DoubleAlign = 13,
54};
55
57{
60 OUString m_aText;
61
62 SmErrorDesc(SmParseError eType, SmNode* pNode, OUString aText)
63 : m_eType(eType)
64 , m_pNode(pNode)
65 , m_aText(std::move(aText))
66 {
67 }
68};
69
71{
72private:
73 sal_Int32& m_rParseDepth;
74
75public:
76 DepthProtect(sal_Int32& rParseDepth)
77 : m_rParseDepth(rParseDepth)
78 {
81 throw std::range_error("parser depth limit");
82 }
84};
85
86namespace starmathdatabase
87{
88// Must be in sync with SmParseError list
89extern const TranslateId SmParseErrorDesc[16];
90
92}
93
95{
96public:
97 virtual ~AbstractSmParser() {}
98
100 virtual std::unique_ptr<SmTableNode> Parse(const OUString& rBuffer) = 0;
102 virtual std::unique_ptr<SmNode> ParseExpression(const OUString& rBuffer) = 0;
103
104 virtual const OUString& GetText() const = 0;
105
106 virtual bool IsImportSymbolNames() const = 0;
107 virtual void SetImportSymbolNames(bool bVal) = 0;
108 virtual bool IsExportSymbolNames() const = 0;
109 virtual void SetExportSymbolNames(bool bVal) = 0;
110
111 virtual const SmErrorDesc* NextError() = 0;
112 virtual const SmErrorDesc* PrevError() = 0;
113 virtual const SmErrorDesc* GetError() const = 0;
114 virtual const std::set<OUString>& GetUsedSymbols() const = 0;
115};
116
117/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual const SmErrorDesc * NextError()=0
virtual bool IsImportSymbolNames() const =0
virtual const std::set< OUString > & GetUsedSymbols() const =0
virtual ~AbstractSmParser()
Definition: parsebase.hxx:97
virtual void SetExportSymbolNames(bool bVal)=0
virtual const SmErrorDesc * GetError() const =0
virtual void SetImportSymbolNames(bool bVal)=0
virtual std::unique_ptr< SmTableNode > Parse(const OUString &rBuffer)=0
Parse rBuffer to formula tree.
virtual bool IsExportSymbolNames() const =0
virtual const SmErrorDesc * PrevError()=0
virtual std::unique_ptr< SmNode > ParseExpression(const OUString &rBuffer)=0
Parse rBuffer to formula subtree that constitutes an expression.
virtual const OUString & GetText() const =0
DepthProtect(sal_Int32 &rParseDepth)
Definition: parsebase.hxx:76
sal_Int32 & m_rParseDepth
Definition: parsebase.hxx:73
Definition: node.hxx:125
DocumentType eType
None
Parses the starmath code and creates the nodes.
Definition: attribute.hxx:191
const TranslateId SmParseErrorDesc[16]
Definition: parsebase.cxx:24
OUString getParseErrorDesc(SmParseError err)
Definition: parsebase.cxx:45
SmParseError
Definition: parsebase.hxx:37
#define DEPTH_LIMIT
Parses the starmath code and creates the nodes.
Definition: parsebase.hxx:33
SmParseError m_eType
Definition: parsebase.hxx:58
SmErrorDesc(SmParseError eType, SmNode *pNode, OUString aText)
Definition: parsebase.hxx:62
OUString m_aText
Definition: parsebase.hxx:60
SmNode * m_pNode
Definition: parsebase.hxx:59