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