summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;