zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #04586
[Merge] lp:~gislenius/zorba/jsoniq-truefalsenull into lp:zorba/3.0
Ghislain Fourny has proposed merging lp:~gislenius/zorba/jsoniq-truefalsenull into lp:zorba/3.0.
Requested reviews:
Matthias Brantner (matthias-brantner)
For more details, see:
https://code.launchpad.net/~gislenius/zorba/jsoniq-truefalsenull/+merge/91844
--
https://code.launchpad.net/~gislenius/zorba/jsoniq-truefalsenull/+merge/91844
Your team Zorba Coders is subscribed to branch lp:zorba/3.0.
=== modified file 'src/compiler/parser/xquery_parser.y'
--- src/compiler/parser/xquery_parser.y 2012-02-01 11:29:03 +0000
+++ src/compiler/parser/xquery_parser.y 2012-02-07 15:07:14 +0000
@@ -3866,7 +3866,7 @@
{
RelativePathExpr* rpe;
- rpe = new RelativePathExpr(LOC(@$), ParseConstants::st_slash, NULL, $2);
+ rpe = new RelativePathExpr(LOC(@$), ParseConstants::st_slash, NULL, $2, false);
$$ = new PathExpr(LOC(@$),
ParseConstants::path_leading_slash,
@@ -3876,7 +3876,7 @@
{
RelativePathExpr* rpe;
- rpe = new RelativePathExpr(LOC(@$), ParseConstants::st_slashslash, NULL, $2);
+ rpe = new RelativePathExpr(LOC(@$), ParseConstants::st_slashslash, NULL, $2, false);
$$ = new PathExpr(LOC(@$),
ParseConstants::path_leading_slashslash,
@@ -3910,17 +3910,17 @@
$$ = (as ?
new RelativePathExpr(LOC(@$),
ParseConstants::st_slash,
- new ContextItemExpr( LOC(@$), true ), $1)
+ new ContextItemExpr( LOC(@$), true ), $1, true)
:
$1);
}
| StepExpr SLASH RelativePathExpr
{
- $$ = new RelativePathExpr(LOC(@$), ParseConstants::st_slash, $1, $3);
+ $$ = new RelativePathExpr(LOC(@$), ParseConstants::st_slash, $1, $3, false);
}
| StepExpr SLASH_SLASH RelativePathExpr
{
- $$ = new RelativePathExpr(LOC(@$), ParseConstants::st_slashslash, $1, $3);
+ $$ = new RelativePathExpr(LOC(@$), ParseConstants::st_slashslash, $1, $3, false);
}
;
=== modified file 'src/compiler/parsetree/parsenodes.cpp'
--- src/compiler/parsetree/parsenodes.cpp 2012-02-07 00:23:01 +0000
+++ src/compiler/parsetree/parsenodes.cpp 2012-02-07 15:07:14 +0000
@@ -2914,11 +2914,13 @@
const QueryLoc& loc_,
enum ParseConstants::steptype_t _step_type,
rchandle<exprnode> step,
- rchandle<exprnode> rpe)
+ rchandle<exprnode> rpe,
+ bool implicit)
:
exprnode(loc_),
step_type(_step_type),
- step_expr_h(step)
+ step_expr_h(step),
+ is_implicit_b(implicit)
{
RelativePathExpr* rpep = dynamic_cast<RelativePathExpr*>(rpe.getp());
if (rpep != NULL)
=== modified file 'src/compiler/parsetree/parsenodes.h'
--- src/compiler/parsetree/parsenodes.h 2012-02-01 11:29:03 +0000
+++ src/compiler/parsetree/parsenodes.h 2012-02-07 15:07:14 +0000
@@ -3541,19 +3541,23 @@
enum ParseConstants::steptype_t step_type;
rchandle<exprnode> step_expr_h;
rchandle<exprnode> relpath_expr_h;
+ bool is_implicit_b;
public:
RelativePathExpr(
const QueryLoc&,
ParseConstants::steptype_t,
rchandle<exprnode>,
- rchandle<exprnode>);
+ rchandle<exprnode>,
+ bool implicit);
enum ParseConstants::steptype_t get_step_type() const { return step_type; }
rchandle<exprnode> get_step_expr() const { return step_expr_h; }
rchandle<exprnode> get_relpath_expr() const { return relpath_expr_h; }
+
+ bool is_implicit() const { return is_implicit_b; }
virtual void accept(parsenode_visitor&) const;
};
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp 2012-02-07 01:23:28 +0000
+++ src/compiler/translator/translator.cpp 2012-02-07 15:07:14 +0000
@@ -8281,44 +8281,54 @@
ParseConstants::pathtype_t pe_type = pe.get_type();
- // terrible hack to allow for the value of a json pair to be
- // null, true, false
+ // terrible hack to allow for a standalone true, false or null to be
+ // interpreted as a boolean. User must use ./true, ./false or ./null for
+ // navigating XML elements named that way.
#ifdef ZORBA_WITH_JSON
- if (pe_type == ParseConstants::path_relative &&
- !theNodeStack.empty() && theNodeStack.top().dyn_cast<json_pair_expr>())
+ if (pe_type == ParseConstants::path_relative)
{
- RelativePathExpr* lRelPathExpr
+ RelativePathExpr* lRootRelPathExpr
= dynamic_cast<RelativePathExpr*>(pe.get_relpath_expr().getp());
- AxisStep* lStepExpr
- = dynamic_cast<AxisStep*>(lRelPathExpr->get_relpath_expr().getp());
- if (lStepExpr)
+ ContextItemExpr* lStepExpr
+ = dynamic_cast<ContextItemExpr*>(lRootRelPathExpr->get_step_expr().getp());
+ AxisStep* lRelPathExpr
+ = dynamic_cast<AxisStep*>(lRootRelPathExpr->get_relpath_expr().getp());
+ // Only rewrites if expression consists of a context item step on the left
+ // and of an axis step on the right,
+ // AND if this context item was set implicitly by the parser, meaning,
+ // the original expression was only an axis step.
+ if (lRelPathExpr && lStepExpr && lRootRelPathExpr->is_implicit())
{
ForwardStep* lFwdStep
- = dynamic_cast<ForwardStep*>(lStepExpr->get_forward_step().getp());
+ = dynamic_cast<ForwardStep*>(lRelPathExpr->get_forward_step().getp());
if (lFwdStep && lFwdStep->get_axis_kind() == ParseConstants::axis_child)
{
AbbrevForwardStep* lAbbrFwdStep
= dynamic_cast<AbbrevForwardStep*>(lFwdStep->get_abbrev_step().getp());
- const NameTest* lNodetest
- = dynamic_cast<const NameTest*>(lAbbrFwdStep->get_node_test());
- const rchandle<QName> lQName = lNodetest->getQName();
- if (lQName && lQName->get_namespace() == "")
- {
- const zstring& lLocal = lQName->get_localname();
- if (lLocal == "true")
- {
- push_nodestack(new const_expr(theRootSctx, loc, true));
- return (void*)1;
- } else if (lLocal == "false")
- {
- push_nodestack(new const_expr(theRootSctx, loc, false));
- return (void*)1;
- } else if (lLocal == "null")
- {
- store::Item_t lNull;
- GENV_ITEMFACTORY->createJSONNull(lNull);
- push_nodestack(new const_expr(theRootSctx, loc, lNull));
- return (void*)1;
+ if (lAbbrFwdStep) {
+ const NameTest* lNodetest
+ = dynamic_cast<const NameTest*>(lAbbrFwdStep->get_node_test());
+ if (lNodetest) {
+ const rchandle<QName> lQName = lNodetest->getQName();
+ if (lQName && lQName->get_namespace() == "")
+ {
+ const zstring& lLocal = lQName->get_localname();
+ if (lLocal == "true")
+ {
+ push_nodestack(new const_expr(theRootSctx, loc, true));
+ return (void*)1;
+ } else if (lLocal == "false")
+ {
+ push_nodestack(new const_expr(theRootSctx, loc, false));
+ return (void*)1;
+ } else if (lLocal == "null")
+ {
+ store::Item_t lNull;
+ GENV_ITEMFACTORY->createJSONNull(lNull);
+ push_nodestack(new const_expr(theRootSctx, loc, lNull));
+ return (void*)1;
+ }
+ }
}
}
}
Follow ups