Home | History | Annotate | Download | only in fm2js
      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_FM_LEXER_H
      8 #define _XFA_FM_LEXER_H
      9 enum XFA_FM_TOKEN {
     10   TOKand,
     11   TOKlparen,
     12   TOKrparen,
     13   TOKmul,
     14   TOKplus,
     15   TOKcomma,
     16   TOKminus,
     17   TOKdot,
     18   TOKdiv,
     19   TOKlt,
     20   TOKassign,
     21   TOKgt,
     22   TOKlbracket,
     23   TOKrbracket,
     24   TOKor,
     25   TOKdotscream,
     26   TOKdotstar,
     27   TOKdotdot,
     28   TOKle,
     29   TOKne,
     30   TOKeq,
     31   TOKge,
     32   TOKdo,
     33   TOKkseq,
     34   TOKksge,
     35   TOKksgt,
     36   TOKif,
     37   TOKin,
     38   TOKksle,
     39   TOKkslt,
     40   TOKksne,
     41   TOKksor,
     42   TOKnull,
     43   TOKbreak,
     44   TOKksand,
     45   TOKend,
     46   TOKeof,
     47   TOKfor,
     48   TOKnan,
     49   TOKksnot,
     50   TOKvar,
     51   TOKthen,
     52   TOKelse,
     53   TOKexit,
     54   TOKdownto,
     55   TOKreturn,
     56   TOKinfinity,
     57   TOKendwhile,
     58   TOKforeach,
     59   TOKendfunc,
     60   TOKelseif,
     61   TOKwhile,
     62   TOKendfor,
     63   TOKthrow,
     64   TOKstep,
     65   TOKupto,
     66   TOKcontinue,
     67   TOKfunc,
     68   TOKendif,
     69   TOKstar,
     70   TOKidentifier,
     71   TOKunderscore,
     72   TOKdollar,
     73   TOKexclamation,
     74   TOKcall,
     75   TOKstring,
     76   TOKnumber,
     77   TOKreserver
     78 };
     79 struct XFA_FMKeyword {
     80   XFA_FM_TOKEN m_type;
     81   uint32_t m_uHash;
     82   const FX_WCHAR* m_keword;
     83 };
     84 const FX_WCHAR* XFA_FM_KeywordToString(XFA_FM_TOKEN op);
     85 class CXFA_FMToken {
     86  public:
     87   CXFA_FMToken();
     88   CXFA_FMToken(FX_DWORD uLineNum);
     89   ~CXFA_FMToken();
     90   CFX_WideStringC m_wstring;
     91   XFA_FM_TOKEN m_type;
     92   FX_DWORD m_uLinenum;
     93   CXFA_FMToken* m_pNext;
     94 };
     95 class CXFA_FMLexer {
     96  public:
     97   CXFA_FMLexer(const CFX_WideStringC& wsFormcalc, CXFA_FMErrorInfo* pErrorInfo);
     98   ~CXFA_FMLexer();
     99   CXFA_FMToken* NextToken();
    100   FX_DWORD Number(CXFA_FMToken* t, const FX_WCHAR* p, const FX_WCHAR*& pEnd);
    101   FX_DWORD String(CXFA_FMToken* t, const FX_WCHAR* p, const FX_WCHAR*& pEnd);
    102   FX_DWORD Identifiers(CXFA_FMToken* t,
    103                        const FX_WCHAR* p,
    104                        const FX_WCHAR*& pEnd);
    105   void Comment(const FX_WCHAR* p, const FX_WCHAR*& pEnd);
    106   XFA_FM_TOKEN IsKeyword(const CFX_WideStringC& p);
    107   void SetCurrentLine(FX_DWORD line) { m_uCurrentLine = line; }
    108   void SetToken(CXFA_FMToken* pToken) {
    109     if (m_pToken) {
    110       delete m_pToken;
    111     }
    112     m_pToken = pToken;
    113   }
    114   const FX_WCHAR* SavePos() { return m_ptr; }
    115   void RestorePos(const FX_WCHAR* pPos) { m_ptr = pPos; }
    116   void Error(XFA_FM_ERRMSG msg, ...);
    117   FX_BOOL HasError() const;
    118 
    119  protected:
    120   CXFA_FMToken* Scan();
    121   const FX_WCHAR* m_pScript;
    122   const FX_WCHAR* m_ptr;
    123   FX_STRSIZE m_uLength;
    124   FX_DWORD m_uCurrentLine;
    125   CXFA_FMToken* m_pToken;
    126   CXFA_FMErrorInfo* m_pErrorInfo;
    127 };
    128 #endif
    129