Repository: vxquery Updated Branches: refs/heads/master d7cb0a09f -> ef8efbc26 (forced update)
Implement SimpleObjectUnionConstructor Project: http://git-wip-us.apache.org/repos/asf/vxquery/repo Commit: http://git-wip-us.apache.org/repos/asf/vxquery/commit/85cb2811 Tree: http://git-wip-us.apache.org/repos/asf/vxquery/tree/85cb2811 Diff: http://git-wip-us.apache.org/repos/asf/vxquery/diff/85cb2811 Branch: refs/heads/master Commit: 85cb281114d085d2f955442814b7b5db3016e9c6 Parents: 4670e80 Author: riyafa <[email protected]> Authored: Sat Jul 16 00:21:31 2016 +0530 Committer: riyafa <[email protected]> Committed: Tue Jul 19 11:52:08 2016 +0530 ---------------------------------------------------------------------- .../org/apache/vxquery/xmlquery/ast/ASTTag.java | 1 + .../ast/SimpleObjectUnionConstructor.java | 40 ++++++++++++++++ .../xmlquery/translator/XMLQueryTranslator.java | 37 +++++++++------ vxquery-core/src/main/javacc/xquery-grammar.jj | 49 +++++++++++--------- 4 files changed, 91 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/vxquery/blob/85cb2811/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/ASTTag.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/ASTTag.java b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/ASTTag.java index a68dbd7..eb71923 100644 --- a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/ASTTag.java +++ b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/ASTTag.java @@ -110,5 +110,6 @@ public enum ASTTag { SINGLE_TYPE, ARRAY_CONSTRUCTOR, OBJECT_CONSTRUCTOR, + SIMPLE_OBJECT_UNION_CONSTRUCTOR, PAIR_CONSTRUCTOR } http://git-wip-us.apache.org/repos/asf/vxquery/blob/85cb2811/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/SimpleObjectUnionConstructor.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/SimpleObjectUnionConstructor.java b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/SimpleObjectUnionConstructor.java new file mode 100644 index 0000000..c5895c9 --- /dev/null +++ b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/SimpleObjectUnionConstructor.java @@ -0,0 +1,40 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You under the Apache License, Version 2.0 +* (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package org.apache.vxquery.xmlquery.ast; + +import org.apache.vxquery.util.SourceLocation; + +public class SimpleObjectUnionConstructor extends ASTNode { + private ASTNode expression; + + public SimpleObjectUnionConstructor(SourceLocation loc) { + super(loc); + } + + @Override + public ASTTag getTag() { + return ASTTag.SIMPLE_OBJECT_UNION_CONSTRUCTOR; + } + + public ASTNode getExpression() { + return expression; + } + + public void setExpression(ASTNode expression) { + this.expression = expression; + } +} http://git-wip-us.apache.org/repos/asf/vxquery/blob/85cb2811/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java index c8cfb2b..bd150e0 100644 --- a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java +++ b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java @@ -168,6 +168,7 @@ import org.apache.vxquery.xmlquery.ast.QueryBodyNode; import org.apache.vxquery.xmlquery.ast.RelativePathExprNode; import org.apache.vxquery.xmlquery.ast.SchemaImportNode; import org.apache.vxquery.xmlquery.ast.SequenceTypeNode; +import org.apache.vxquery.xmlquery.ast.SimpleObjectUnionConstructor; import org.apache.vxquery.xmlquery.ast.SingleTypeNode; import org.apache.vxquery.xmlquery.ast.TypeDeclNode; import org.apache.vxquery.xmlquery.ast.TypeExprNode; @@ -837,6 +838,11 @@ public class XMLQueryTranslator { return translateObjectConstructor(tCtx, obj); } + case SIMPLE_OBJECT_UNION_CONSTRUCTOR: { + SimpleObjectUnionConstructor aNode = (SimpleObjectUnionConstructor) value; + return translateSimpleObjectUnionConstructor(tCtx, aNode); + } + case QNAME: { QNameNode qnNode = (QNameNode) value; return translateQNameNode(tCtx, qnNode); @@ -1208,20 +1214,14 @@ public class XMLQueryTranslator { List<ILogicalExpression> content = new ArrayList<ILogicalExpression>(); PairConstructor pc; for (ASTNode aVal : obj.getContent()) { - if (aVal.getTag()==ASTTag.PAIR_CONSTRUCTOR) { - pc=(PairConstructor) aVal; - ILogicalExpression ke = string(data(vre(translateExpression(pc.getKey(), tCtx)))); - content.add(ke); - ILogicalExpression ve = vre(translateExpression(pc.getValue(), tCtx)); - content.add(ve); - ILogicalExpression qmce = ce(SequenceType.create(BuiltinTypeRegistry.XS_BOOLEAN, Quantifier.QUANT_ONE), - pc.isQuestionMarkColon()); - content.add(qmce); - } else { - ILogicalExpression aExpr = aVal == null ? sfce(BuiltinOperators.CONCATENATE) - : vre(translateExpression(aVal, tCtx)); - return createAssignment(sfce(BuiltinOperators.SIMPLE_OBJECT_UNION, aExpr), tCtx); - } + pc = (PairConstructor) aVal; + ILogicalExpression ke = string(data(vre(translateExpression(pc.getKey(), tCtx)))); + content.add(ke); + ILogicalExpression ve = vre(translateExpression(pc.getValue(), tCtx)); + content.add(ve); + ILogicalExpression qmce = ce(SequenceType.create(BuiltinTypeRegistry.XS_BOOLEAN, Quantifier.QUANT_ONE), + pc.isQuestionMarkColon()); + content.add(qmce); } return createAssignment( @@ -1229,6 +1229,15 @@ public class XMLQueryTranslator { tCtx); } + private LogicalVariable translateSimpleObjectUnionConstructor(TranslationContext tCtx, + SimpleObjectUnionConstructor aNode) throws SystemException { + ASTNode expression = aNode.getExpression(); + ILogicalExpression aExpr = expression == null ? sfce(BuiltinOperators.CONCATENATE) + : vre(translateExpression(expression, tCtx)); + LogicalVariable lVar = createAssignment(sfce(BuiltinOperators.SIMPLE_OBJECT_UNION, aExpr), tCtx); + return lVar; + } + private LogicalVariable translateDirectElementConstructorNode(TranslationContext tCtx, DirectElementConstructorNode decNode) throws SystemException { QNameNode startName = decNode.getStartTagName(); http://git-wip-us.apache.org/repos/asf/vxquery/blob/85cb2811/vxquery-core/src/main/javacc/xquery-grammar.jj ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/javacc/xquery-grammar.jj b/vxquery-core/src/main/javacc/xquery-grammar.jj index 9ea3943..bfb5d26 100644 --- a/vxquery-core/src/main/javacc/xquery-grammar.jj +++ b/vxquery-core/src/main/javacc/xquery-grammar.jj @@ -1999,8 +1999,9 @@ ASTNode JsonConstructor() : } { ( - result = ObjectConstructor() - | result = ArrayConstructor() + result = ArrayConstructor() + | result = ObjectConstructor() + | result = SimpleObjectUnionConstructor() ) { return result; } @@ -2013,27 +2014,17 @@ ASTNode ObjectConstructor() : ASTNode pc; } { + t = <LbraceExprEnclosure> ( - ( - t = <LbraceExprEnclosure> - ( - pc = PairConstructor() { - content.add(pc); - } ( - "," pc = PairConstructor() { - content.add(pc); - } - )* - )* - <Rbrace> - ) - | ( - t = "{|" pc = Expr() "|}" - { - content.add(pc); - } - ) - ) + pc = PairConstructor() { + content.add(pc); + } ( + "," pc = PairConstructor() { + content.add(pc); + } + )* + )* + <Rbrace> { ObjectConstructor obj = new ObjectConstructor(createSourceLocation(t)); obj.setContent(content); @@ -2077,6 +2068,20 @@ ASTNode ArrayConstructor() : } } +ASTNode SimpleObjectUnionConstructor() : +{ + ASTNode expr = null; + Token start; +} +{ + start = "{|" expr = Expr() "|}" + { + SimpleObjectUnionConstructor souc = new SimpleObjectUnionConstructor(createSourceLocation(start)); + souc.setExpression(expr); + return souc; + } +} + ASTNode DirectConstructor() : { ASTNode result;
