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