diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-05-16 12:59:10 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-05-16 17:10:24 +0000 |
commit | 9774984f96946eb96eed29abfcbe824cb5858bbb (patch) | |
tree | 6f96b570c81fbf771172355456e7014edcb15fd9 /xfa/fxfa/fm2js/xfa_lexer.cpp | |
parent | c0d358ad234843a524a1bcc2a439f08ad0c64aa1 (diff) | |
download | pdfium-9774984f96946eb96eed29abfcbe824cb5858bbb.tar.xz |
Add formcalc lexer tests.
This CL adds tests for CXFA_FMLexer.
Change-Id: I4cb7000212dda6d2b32211005a1c22deabb813ae
Reviewed-on: https://pdfium-review.googlesource.com/5554
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Nicolás Peña <npm@chromium.org>
Diffstat (limited to 'xfa/fxfa/fm2js/xfa_lexer.cpp')
-rw-r--r-- | xfa/fxfa/fm2js/xfa_lexer.cpp | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/xfa/fxfa/fm2js/xfa_lexer.cpp b/xfa/fxfa/fm2js/xfa_lexer.cpp index dfac51ab2c..bdffa7e998 100644 --- a/xfa/fxfa/fm2js/xfa_lexer.cpp +++ b/xfa/fxfa/fm2js/xfa_lexer.cpp @@ -124,9 +124,13 @@ std::unique_ptr<CXFA_FMToken> CXFA_FMLexer::Scan() { } while (1) { - // Make sure we don't walk off the end of the string. - if (m_ptr > m_end) + // Make sure we don't walk off the end of the string. If we don't currently + // have a token type then mark it EOF. + if (m_ptr > m_end) { + if (p->m_type == TOKreserver) + p->m_type = TOKeof; return p; + } ch = *m_ptr; if (!IsValid(m_ptr)) { @@ -172,7 +176,7 @@ std::unique_ptr<CXFA_FMToken> CXFA_FMLexer::Scan() { case '=': ++m_ptr; if (m_ptr > m_end) { - Error(kFMErrEndOfInput); + p->m_type = TOKassign; return p; } @@ -192,7 +196,7 @@ std::unique_ptr<CXFA_FMToken> CXFA_FMLexer::Scan() { case '<': ++m_ptr; if (m_ptr > m_end) { - Error(kFMErrEndOfInput); + p->m_type = TOKlt; return p; } @@ -215,7 +219,7 @@ std::unique_ptr<CXFA_FMToken> CXFA_FMLexer::Scan() { case '>': ++m_ptr; if (m_ptr > m_end) { - Error(kFMErrEndOfInput); + p->m_type = TOKgt; return p; } @@ -275,7 +279,7 @@ std::unique_ptr<CXFA_FMToken> CXFA_FMLexer::Scan() { case '/': { ++m_ptr; if (m_ptr > m_end) { - Error(kFMErrEndOfInput); + p->m_type = TOKdiv; return p; } @@ -295,7 +299,7 @@ std::unique_ptr<CXFA_FMToken> CXFA_FMLexer::Scan() { case '.': ++m_ptr; if (m_ptr > m_end) { - Error(kFMErrEndOfInput); + p->m_type = TOKdot; return p; } @@ -369,15 +373,18 @@ const wchar_t* CXFA_FMLexer::String(CXFA_FMToken* t, const wchar_t* p) { } ++p; - if (p > m_end) { - Error(kFMErrEndOfInput); - return p; - } - if (ch != '"') { + // We've hit the end of the input, return the string. + if (p > m_end) { + Error(kFMErrEndOfInput); + return p; + } ch = *p; continue; } + // We've hit the end of the input, return the string. + if (p > m_end) + break; if (!IsValid(p)) { ch = *p; @@ -405,7 +412,8 @@ const wchar_t* CXFA_FMLexer::Identifiers(CXFA_FMToken* t, const wchar_t* p) { uint16_t ch = *p; ++p; if (p > m_end) { - Error(kFMErrEndOfInput); + t->m_wstring = CFX_WideStringC(pStart, (p - pStart)); + t->m_type = IsKeyword(t->m_wstring); return p; } @@ -432,10 +440,8 @@ const wchar_t* CXFA_FMLexer::Identifiers(CXFA_FMToken* t, const wchar_t* p) { break; } ++p; - if (p > m_end) { - Error(kFMErrEndOfInput); - return p; - } + if (p > m_end) + break; } t->m_wstring = CFX_WideStringC(pStart, (p - pStart)); t->m_type = IsKeyword(t->m_wstring); @@ -445,29 +451,20 @@ const wchar_t* CXFA_FMLexer::Identifiers(CXFA_FMToken* t, const wchar_t* p) { const wchar_t* CXFA_FMLexer::Comment(const wchar_t* p) { ++p; - if (p > m_end) { - Error(kFMErrEndOfInput); + if (p > m_end) return p; - } unsigned ch = *p; while (ch) { - if (ch == L'\r') { - ++p; - if (p > m_end) - Error(kFMErrEndOfInput); - return p; - } - ++p; - if (p > m_end) { - Error(kFMErrEndOfInput); + if (ch == L'\r') return p; - } if (ch == L'\n') { ++m_uCurrentLine; return p; } + if (p > m_end) + return p; ch = *p; } return p; |