summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-02-20 21:52:39 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-02-20 21:52:39 +0000
commit4102f7b86e415b2a254521a1fc52e11bdc932864 (patch)
tree47536abfbe68ea7a8a77240bede1e95e8d97ff86
parenta03eb1d3ae475e7208df80a8bed910ec4922b396 (diff)
downloadpdfium-4102f7b86e415b2a254521a1fc52e11bdc932864.tar.xz
[formcalc] Split literal parsing to its own method
This Cl moves the code to create literals in the AST from ParsePrimaryExpression to ParseLiteral. Change-Id: I41ba20f28f1cb1d76d753c5baec790872acdf1da Reviewed-on: https://pdfium-review.googlesource.com/27411 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmparser.cpp39
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmparser.h1
2 files changed, 22 insertions, 18 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmparser.cpp b/xfa/fxfa/fm2js/cxfa_fmparser.cpp
index 93fa44fedd..1805c119b6 100644
--- a/xfa/fxfa/fm2js/cxfa_fmparser.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmparser.cpp
@@ -592,21 +592,12 @@ CXFA_FMParser::ParsePrimaryExpression() {
if (HasError() || !IncrementParseDepthAndCheck())
return nullptr;
- std::unique_ptr<CXFA_FMSimpleExpression> expr;
+ std::unique_ptr<CXFA_FMSimpleExpression> expr = ParseLiteral();
+ if (expr)
+ return NextToken() ? std::move(expr) : nullptr;
+
uint32_t line = m_lexer->GetCurrentLine();
switch (m_token.m_type) {
- case TOKnumber:
- expr =
- pdfium::MakeUnique<CXFA_FMNumberExpression>(line, m_token.m_string);
- if (!NextToken())
- return nullptr;
- break;
- case TOKstring:
- expr =
- pdfium::MakeUnique<CXFA_FMStringExpression>(line, m_token.m_string);
- if (!NextToken())
- return nullptr;
- break;
case TOKidentifier: {
WideStringView wsIdentifier(m_token.m_string);
if (!NextToken())
@@ -628,11 +619,6 @@ CXFA_FMParser::ParsePrimaryExpression() {
}
break;
}
- case TOKnull:
- expr = pdfium::MakeUnique<CXFA_FMNullExpression>(line);
- if (!expr || !NextToken())
- return nullptr;
- break;
case TOKlparen:
expr = ParseParenExpression();
if (!expr)
@@ -648,6 +634,23 @@ CXFA_FMParser::ParsePrimaryExpression() {
return expr;
}
+// Literal := String | Number | Null
+std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParser::ParseLiteral() {
+ uint32_t line = m_lexer->GetCurrentLine();
+ switch (m_token.m_type) {
+ case TOKnumber:
+ return pdfium::MakeUnique<CXFA_FMNumberExpression>(line,
+ m_token.m_string);
+ case TOKstring:
+ return pdfium::MakeUnique<CXFA_FMStringExpression>(line,
+ m_token.m_string);
+ case TOKnull:
+ return pdfium::MakeUnique<CXFA_FMNullExpression>(line);
+ default:
+ return nullptr;
+ }
+}
+
std::unique_ptr<CXFA_FMSimpleExpression> CXFA_FMParser::ParsePostExpression(
std::unique_ptr<CXFA_FMSimpleExpression> expr) {
AutoRestorer<unsigned long> restorer(&m_parse_depth);
diff --git a/xfa/fxfa/fm2js/cxfa_fmparser.h b/xfa/fxfa/fm2js/cxfa_fmparser.h
index c2da48496f..e78495309e 100644
--- a/xfa/fxfa/fm2js/cxfa_fmparser.h
+++ b/xfa/fxfa/fm2js/cxfa_fmparser.h
@@ -55,6 +55,7 @@ class CXFA_FMParser {
std::unique_ptr<CXFA_FMSimpleExpression> ParsePostExpression(
std::unique_ptr<CXFA_FMSimpleExpression> e);
std::unique_ptr<CXFA_FMSimpleExpression> ParseIndexExpression();
+ std::unique_ptr<CXFA_FMSimpleExpression> ParseLiteral();
std::unique_ptr<CXFA_FMLexer> m_lexer;
CXFA_FMToken m_token;