From f3638222d895857cd44010d8cbf358ca72e49ea4 Mon Sep 17 00:00:00 2001 From: ArnaudBuchholz Date: Wed, 11 Dec 2019 13:22:50 -0500 Subject: [PATCH] Increase maintainability (#326) --- src/xml/xpath/parser.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/xml/xpath/parser.js b/src/xml/xpath/parser.js index 34f3f7b1..652042d3 100644 --- a/src/xml/xpath/parser.js +++ b/src/xml/xpath/parser.js @@ -117,12 +117,12 @@ function _gpfXmlXPathParse (xpathExpression) { } function level () { - var relative = Boolean(consumeIfTokenMatch(_GPF_XML_XPATH_TOKEN.CURRENT)), + var relative, chain = new _GpfXmlXPathChain(), subOrDeep, operator; - subOrDeep = consumeIfTokenMatch(_GPF_XML_XPATH_TOKEN.SUB, _GPF_XML_XPATH_TOKEN.DEEP); - if (!subOrDeep) { + + function firstLevelNoSubOrDeep () { if (relative) { gpf.Error.invalidXPathSyntax(); } @@ -131,6 +131,16 @@ function _gpfXmlXPathParse (xpathExpression) { token: _GPF_XML_XPATH_TOKEN.SUB }; } + + function firstLevel () { + relative = Boolean(consumeIfTokenMatch(_GPF_XML_XPATH_TOKEN.CURRENT)); + subOrDeep = consumeIfTokenMatch(_GPF_XML_XPATH_TOKEN.SUB, _GPF_XML_XPATH_TOKEN.DEEP); + if (!subOrDeep) { + firstLevelNoSubOrDeep(); + } + } + + firstLevel(); while (subOrDeep) { operator = new levelClasses[subOrDeep.token](relative); operator.addChild(match());