1 // Copyright 2014 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef XFA_FXFA_FM2JS_CXFA_FMPARSER_H_ 8 #define XFA_FXFA_FM2JS_CXFA_FMPARSER_H_ 9 10 #include <memory> 11 #include <vector> 12 13 #include "xfa/fxfa/fm2js/cxfa_fmexpression.h" 14 #include "xfa/fxfa/fm2js/cxfa_fmlexer.h" 15 16 class CXFA_FMParser { 17 public: 18 explicit CXFA_FMParser(WideStringView wsFormcalc); 19 ~CXFA_FMParser(); 20 21 std::unique_ptr<CXFA_FMAST> Parse(); 22 bool HasError() const; 23 SetMaxParseDepthForTest(unsigned long max_depth)24 void SetMaxParseDepthForTest(unsigned long max_depth) { 25 m_max_parse_depth = max_depth; 26 } 27 28 private: 29 bool NextToken(); 30 bool CheckThenNext(XFA_FM_TOKEN op); 31 bool IncrementParseDepthAndCheck(); 32 33 std::vector<std::unique_ptr<CXFA_FMExpression>> ParseExpressionList(); 34 std::unique_ptr<CXFA_FMExpression> ParseFunction(); 35 std::unique_ptr<CXFA_FMExpression> ParseExpression(); 36 std::unique_ptr<CXFA_FMExpression> ParseDeclarationExpression(); 37 std::unique_ptr<CXFA_FMExpression> ParseExpExpression(); 38 std::unique_ptr<CXFA_FMExpression> ParseIfExpression(); 39 std::unique_ptr<CXFA_FMExpression> ParseWhileExpression(); 40 std::unique_ptr<CXFA_FMExpression> ParseForExpression(); 41 std::unique_ptr<CXFA_FMExpression> ParseForeachExpression(); 42 std::unique_ptr<CXFA_FMExpression> ParseDoExpression(); 43 std::unique_ptr<CXFA_FMSimpleExpression> ParseParenExpression(); 44 std::unique_ptr<CXFA_FMSimpleExpression> ParseSimpleExpression(); 45 std::unique_ptr<CXFA_FMSimpleExpression> ParseLogicalOrExpression(); 46 std::unique_ptr<CXFA_FMSimpleExpression> ParseLogicalAndExpression(); 47 std::unique_ptr<CXFA_FMSimpleExpression> ParseEqualityExpression(); 48 std::unique_ptr<CXFA_FMSimpleExpression> ParseRelationalExpression(); 49 std::unique_ptr<CXFA_FMSimpleExpression> ParseAdditiveExpression(); 50 std::unique_ptr<CXFA_FMSimpleExpression> ParseMultiplicativeExpression(); 51 std::unique_ptr<CXFA_FMSimpleExpression> ParseUnaryExpression(); 52 std::unique_ptr<CXFA_FMSimpleExpression> ParsePrimaryExpression(); 53 std::unique_ptr<CXFA_FMSimpleExpression> ParsePostExpression( 54 std::unique_ptr<CXFA_FMSimpleExpression> e); 55 std::unique_ptr<std::vector<std::unique_ptr<CXFA_FMSimpleExpression>>> 56 ParseArgumentList(); 57 std::unique_ptr<CXFA_FMSimpleExpression> ParseIndexExpression(); 58 std::unique_ptr<CXFA_FMSimpleExpression> ParseLiteral(); 59 60 std::unique_ptr<CXFA_FMLexer> m_lexer; 61 CXFA_FMToken m_token; 62 bool m_error; 63 unsigned long m_parse_depth; 64 unsigned long m_max_parse_depth; 65 }; 66 67 #endif // XFA_FXFA_FM2JS_CXFA_FMPARSER_H_ 68