1
/******************************************************************************
2
Copyright (c) 2007 netAllied GmbH, Tettnang
4
Permission is hereby granted, free of charge, to any person
5
obtaining a copy of this software and associated documentation
6
files (the "Software"), to deal in the Software without
7
restriction, including without limitation the rights to use,
8
copy, modify, merge, publish, distribute, sublicense, and/or sell
9
copies of the Software, and to permit persons to whom the
10
Software is furnished to do so, subject to the following
13
The above copyright notice and this permission notice shall be
14
included in all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
OTHER DEALINGS IN THE SOFTWARE.
24
******************************************************************************/
26
#ifndef __MATHML_PARSER_H__
27
#define __MATHML_PARSER_H__
29
#include "MathMLSolverPrerequisites.h"
30
#include <xercesc/parsers/XercesDOMParser.hpp>
31
#include "MathMLASTConstantExpression.h"
35
/** Parses a MathML file and creates an AST.
36
@todo: Convenience method returning lists, strings, etc. created within, should be created
37
in the calling method and passed as reference (-> no copying of strings, lists, etc).
39
- IS: ElementList getChildElements ( xercesc::DOMElement* element )
40
- SHOULD BE: void getChildElements ( ElementList& result, xercesc::DOMElement* element )
44
class _MATHML_SOLVER_EXPORT Parser
49
/** The file path/url. */
52
/** The xml parser. */
53
xercesc::XercesDOMParser* xmlParser;
54
/** The parser handler for notification. */
55
MathML::ParserHandler* mParserHandler;
56
/** Temporary list of variable names. */
57
ParserHandler::VariableList mVariableList;
60
/** Type definition for a list DOM nodes of type 'element'. */
61
typedef std::vector<xercesc::DOMElement*> ElementList;
62
/** Type definition for a list DOM nodes of type 'text'. */
63
typedef std::vector<xercesc::DOMText*> TextNodeList;
66
@param handler The parser handler being notifiied.
68
Parser( MathML::ParserHandler* handler = 0 );
73
/** Getter for path/url of parsing document. */
74
virtual const String& getFile();
76
/** Methode for starting a parse-process.
77
@param fileName The string of a file path or url.
79
virtual void parse( const String& fileName );
82
/** Getter for retrieving the parser handler. */
83
virtual MathML::ParserHandler* getParserHandler();
85
/** Convenience method for creating (double) constant expression
86
from a xercesc character pointer.
87
@param xmlValue The xercesc character pointer.
88
@return The AST::ConstantExpression for the given string.
90
virtual AST::ConstantExpression* createConstant( const XMLCh* xmlValue );
92
/** Convenience method for retrieving DOM child nodes of type
93
'element' for the given DOMElement.
94
@param element The element for retrieving its child elements.
96
virtual ElementList getChildElements ( xercesc::DOMElement* element );
98
/** Convenience method for checking if given child node is
100
@param node The DOMNode to be checked.
101
@param name The name to check against.
102
@return True if node is of given name, otherwise false.
104
virtual bool isElementOfName( xercesc::DOMNode* node, String name );
106
/** Convenience method for retrieving a element from a document
108
@param doc The DOMDocument to be searched.
109
@param elementId The id to search for.
110
@return The found DOMElement or 0.
112
virtual xercesc::DOMElement* getElementById( xercesc::DOMDocument* doc, const String& elementId );
114
/** Convenience method for retrieving the attribute value for
115
the given attribute name.
116
@param element The DOMElement to be search for the attribute.
117
@param attributeName The name of the attribute to search for.
118
@return The string representation of its value if found, otherwise an empty string.
120
virtual String getAttributeValue ( xercesc::DOMElement* element, String attributeName );
122
/** Convenience method for retrieving child text nodes from a given DOMElement.
123
@param element The DOMElement to be search for the text nodes.
124
@return A list of found text nodes, otherwise an empty list.
126
virtual TextNodeList getTextNodes ( xercesc::DOMElement* element );
129
/** Method for retrieving a unary operator from the given
131
@param element The element to be check for a unary operator.
132
@return The string representation for a correct unary operator,
133
otherwise the string constant 'NO_OPERATOR'.
135
virtual const String& getUnaryOperator ( xercesc::DOMElement* element );
137
/** Method for retrieving a binary operator from the given
139
@param element The element to be check for a binary operator.
140
@return The string representation for a correct binary operator,
141
otherwise the string constant 'NO_OPERATOR'.
143
virtual const String& getBinaryOperator ( xercesc::DOMElement* element );
145
/** Method for retrieving a relation operator from the given
147
@param element The element to be check for a relation operator.
148
@return The string representation for a correct relation operator,
149
otherwise the string constant 'NO_OPERATOR'.
151
virtual const String& getRelationOperator ( xercesc::DOMElement* element );
153
/** Method for retrieving a logic operator from the given
155
@param element The element to be check for a logic operator.
156
@return The string representation for a correct logic operator,
157
otherwise the string constant 'NO_OPERATOR'.
159
virtual const String& getLogicOperator ( xercesc::DOMElement* element );
161
/** Method for retrieving the name of a function from the given
163
@param element The element to be check for a function name.
164
@return The string representation for a correct function name,
165
otherwise the string constant 'NO_FUNCTION'.
167
virtual const String& getFunction ( xercesc::DOMElement* element );
169
/** Methode for handling the given DOMElement.
170
@param element The element to be further processed for its name (and attributes).
171
@return The common interface of the underlying expression.
173
virtual AST::INode* handleElement ( xercesc::DOMElement* element );
175
/** Methode for handling (MathML) <apply>-elements.
176
@param element The element to be further processed for its children and attributes.
177
@return The common interface of the underlying expression.
179
virtual AST::INode* handleElementApply( xercesc::DOMElement* element );
181
/** Methode for handling (MathML) <declare>-elements.
182
@param element The element to be further processed for its children and attributes).
183
@param siblings The list of siblings holding the parameter arguments for this declaration-construct.
184
@return The interface of an AST::FragmentExpression -node.
186
virtual AST::INode* handleElementDeclare( xercesc::DOMElement* element, const ElementList& siblings );
188
/** Methode for handling 'external' defined fragments
189
(or code) referenced by (MathML) <csymbol>-elements.
190
@param firstChild The identified<csymbol>-element of the given list.
191
@param childList The ElementList containing the <csymbol..>-element and its siblings.
192
@return The interface of an AST::FragmentExpression -node.
194
virtual AST::INode* handleExternalReferenceByCSymbol( xercesc::DOMElement* firstChild, ElementList& childList );
196
/** Methode for handling (MathML) <cn>-elements.
197
@param element The <cn> -DOMElement..
198
@return The interface of an AST::ConstantExpression -node.
200
virtual AST::INode* handleElementCN( xercesc::DOMElement* element );
202
/** Methode for handling (MathML) <ci>-elements.
203
@param element The <ci> -DOMElement..
204
@return The interface of an AST::VariableExpression -node.
206
virtual AST::INode* handleElementCI( xercesc::DOMElement* element );
208
/** Methode for handling (MathML) <logbase>-elements.
209
@param element The <logbase> -DOMElement..
210
@return The interface of an AST-node representening the base for a logarithm.
212
virtual AST::INode* handleElementLogbase( xercesc::DOMElement* element );
214
/** Methode for handling (MathML) <pi>-elements.
215
@param element The <pi> -DOMElement..
216
@return The interface of an AST::ConstantExpression -node for the constant 'PI'.
218
virtual AST::INode* handleElementPI( xercesc::DOMElement* element );
220
/** Methode for handling (MathML) <exponentiale>-elements.
221
@param element The <exponentiale> -DOMElement..
222
@return The interface of an AST::ConstantExpression -node for the constant 'e'.
224
virtual AST::INode* handleElementExponentiale( xercesc::DOMElement* element );
226
/** Methode for handling (MathML) <true>-elements.
227
@param element The <true> -DOMElement..
228
@return The interface of an AST::ConstantExpression -node for the boolean constant 'true'.
230
virtual AST::INode* handleElementTrue( xercesc::DOMElement* element );
232
/** Methode for handling (MathML) <false>-elements.
233
@param element The <false> -DOMElement..
234
@return The interface of an AST::ConstantExpression -node for the boolean constant 'false'.
236
virtual AST::INode* handleElementFalse( xercesc::DOMElement* element );
239
/** Methode for handling unary operations.
240
@param elements The list of elements containing operator and operand(s).
241
@return The interface of an AST::UnaryExpression -node.
243
virtual AST::INode* handleUnaryOperation( ElementList& elements );
245
/** Methode for handling operations with two operands.
246
@param elements The list of elements containing operator and operand(s).
247
@return The interface of an specialized AST::ExpressionNode (arithmetic, logic, ..).
249
virtual AST::INode* handleBinaryOperation( ElementList& elements );
251
/** Methode for handling operations with more than two operands.
252
@param elements The list of elements containing operator and operands.
253
@return The interface of an specialized AST::ExpressionNode (arithmetic, logic, ..)
254
but no AST::BinaryComparisionExpression (relations).
256
virtual AST::INode* handleMultiOperandOperation( ElementList& elements );
259
/** todo: description */
260
virtual String getContainer( const String& url );
261
/** todo: description */
262
virtual String getId( const String& url );
267
#endif //__MATHML_PARSER_H__