1 /* 2 * Copyright 2006-2008 The FLWOR Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 #ifndef ZORBA_COMPILER_JSON_EXPRS 18 #define ZORBA_COMPILER_JSON_EXPRS 19 20 #include <string> 21 #include <vector> 22 23 #include <zorba/store_consts.h> 24 25 #include "compiler/expression/expr_base.h" 26 27 #ifdef ZORBA_WITH_JSON 28 29 30 namespace zorba 31 { 32 33 /******************************************************************************* 34 ArrayConstructor ::= "[" Expr? "]" 35 ********************************************************************************/ 36 class json_array_expr : public expr 37 { 38 friend class ExprIterator; 39 friend class ExprManager; 40 41 protected: 42 expr * theContentExpr; 43 44 protected: 45 json_array_expr( 46 CompilerCB* ccb, 47 static_context* sctx, 48 const QueryLoc& loc, 49 expr* content); 50 51 public: get_expr()52 expr* get_expr() const { return theContentExpr; } 53 54 void compute_scripting_kind(); 55 56 expr* cloneImpl(substitution_t& s) const; 57 58 void accept(expr_visitor&); 59 60 std::ostream& put(std::ostream&) const; 61 }; 62 63 64 /******************************************************************************* 65 SimpleObjectUnion ::= "{|" Expr? "|}" 66 67 AccumulatorObjectUnion ::= "{[" Expr? "]}" 68 69 The Expr must return a sequence of zero or more objects 70 ********************************************************************************/ 71 class json_object_expr : public expr 72 { 73 friend class ExprIterator; 74 friend class ExprManager; 75 76 protected: 77 expr * theContentExpr; 78 bool theAccumulate; 79 80 protected: 81 json_object_expr( 82 CompilerCB* ccb, 83 static_context* sctx, 84 const QueryLoc& loc, 85 expr* content, 86 bool accumulate); 87 88 public: get_expr()89 expr* get_expr() const { return theContentExpr; } 90 is_accumulating()91 bool is_accumulating() const { return theAccumulate; } 92 93 void compute_scripting_kind(); 94 95 expr* cloneImpl(substitution_t& s) const; 96 97 void accept(expr_visitor&); 98 99 std::ostream& put(std::ostream&) const; 100 }; 101 102 103 /******************************************************************************* 104 DirectObjectConstructor ::= "{" PairConstructor ("," PairConstructor )* "}" 105 106 PairConstructor ::= ExprSingle ":" ExprSingle 107 108 The 1st ExprSingle must return exactly one string. 109 The 2nd ExprSingle must contain exactly one item of any kind. 110 ********************************************************************************/ 111 class json_direct_object_expr : public expr 112 { 113 friend class ExprIterator; 114 friend class ExprManager; 115 116 protected: 117 std::vector<expr*> theNames; 118 std::vector<expr*> theValues; 119 120 protected: 121 json_direct_object_expr( 122 CompilerCB* ccb, 123 static_context* sctx, 124 const QueryLoc& loc, 125 std::vector<expr*>& names, 126 std::vector<expr*>& values); 127 128 public: num_pairs()129 csize num_pairs() const { return theNames.size(); } 130 get_value_expr(csize i)131 expr* get_value_expr(csize i) const { return theValues[i]; } 132 get_name_expr(csize i)133 expr* get_name_expr(csize i) const { return theNames[i]; } 134 135 void compute_scripting_kind(); 136 137 expr* cloneImpl(substitution_t& s) const; 138 139 void accept(expr_visitor&); 140 141 std::ostream& put(std::ostream&) const; 142 }; 143 144 145 146 } 147 148 #endif // ZORBA_WITH_JSON 149 150 #endif 151 152 /* 153 * Local variables: 154 * mode: c++ 155 * End: 156 */ 157 /* vim:set et sw=2 ts=2: */ 158