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_FMLEXER_H_ 8 #define XFA_FXFA_FM2JS_CXFA_FMLEXER_H_ 9 10 #include "core/fxcrt/fx_string.h" 11 12 enum XFA_FM_TOKEN { 13 TOKand, 14 TOKlparen, 15 TOKrparen, 16 TOKmul, 17 TOKplus, 18 TOKcomma, 19 TOKminus, 20 TOKdot, 21 TOKdiv, 22 TOKlt, 23 TOKassign, 24 TOKgt, 25 TOKlbracket, 26 TOKrbracket, 27 TOKor, 28 TOKdotscream, 29 TOKdotstar, 30 TOKdotdot, 31 TOKle, 32 TOKne, 33 TOKeq, 34 TOKge, 35 TOKdo, 36 TOKkseq, 37 TOKksge, 38 TOKksgt, 39 TOKif, 40 TOKin, 41 TOKksle, 42 TOKkslt, 43 TOKksne, 44 TOKksor, 45 TOKnull, 46 TOKbreak, 47 TOKksand, 48 TOKend, 49 TOKeof, 50 TOKfor, 51 TOKnan, 52 TOKksnot, 53 TOKvar, 54 TOKthen, 55 TOKelse, 56 TOKexit, 57 TOKdownto, 58 TOKreturn, 59 TOKinfinity, 60 TOKendwhile, 61 TOKforeach, 62 TOKendfunc, 63 TOKelseif, 64 TOKwhile, 65 TOKendfor, 66 TOKthrow, 67 TOKstep, 68 TOKupto, 69 TOKcontinue, 70 TOKfunc, 71 TOKendif, 72 TOKstar, 73 TOKidentifier, 74 TOKunderscore, 75 TOKdollar, 76 TOKexclamation, 77 TOKcall, 78 TOKstring, 79 TOKnumber, 80 TOKreserver 81 }; 82 83 struct XFA_FMKeyword { 84 XFA_FM_TOKEN m_type; 85 const char* m_keyword; // Raw, POD struct. 86 }; 87 88 class CXFA_FMToken { 89 public: 90 CXFA_FMToken(); 91 explicit CXFA_FMToken(XFA_FM_TOKEN token); 92 CXFA_FMToken(const CXFA_FMToken&); 93 ~CXFA_FMToken(); 94 95 #ifndef NDEBUG 96 WideString ToDebugString() const; 97 #endif // NDEBUG 98 99 WideStringView m_string; 100 XFA_FM_TOKEN m_type; 101 }; 102 103 class CXFA_FMLexer { 104 public: 105 explicit CXFA_FMLexer(WideStringView wsFormcalc); 106 ~CXFA_FMLexer(); 107 108 CXFA_FMToken NextToken(); IsComplete()109 bool IsComplete() const { return m_nCursor >= m_spInput.size(); } 110 111 private: 112 CXFA_FMToken AdvanceForNumber(); 113 CXFA_FMToken AdvanceForString(); 114 CXFA_FMToken AdvanceForIdentifier(); 115 void AdvanceForComment(); 116 RaiseError()117 void RaiseError() { m_bLexerError = true; } 118 119 pdfium::span<const wchar_t> m_spInput; 120 size_t m_nCursor = 0; 121 bool m_bLexerError = false; 122 }; 123 124 #endif // XFA_FXFA_FM2JS_CXFA_FMLEXER_H_ 125