12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667(*
* This file is part of the Watson Conversation Service OCaml API project.
*
* Copyright 2016-2017 IBM Corporation
*
* Licensed 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.
*)(** JSON with embedded expressions. *)typejson_spel=[`Assocof(string*json_spel)list|`Boolofbool|`Floatoffloat|`Intofint|`Listofjson_spellist|`Null|`ExprofSpel_t.expression](** {6 Serialization/deserialization functions for atdgen} *)letrecyojson_of_json_spel(j:json_spel):Yojson.Basic.json=beginmatchjwith|`Assocl->`Assoc(List.map(funx->(fstx,yojson_of_json_spel(sndx)))l)|`Boolb->`Boolb|`Floatf->`Floatf|`Inti->`Inti|`Listl->`List(List.mapyojson_of_json_spell)|`Null->`Null|`Expre->`String(Spel_print.to_texte)endletrecjson_spel_of_yojson(j:Yojson.Basic.json):json_spel=beginmatchjwith|`Assocl->`Assoc(List.map(funx->(fstx,json_spel_of_yojson(sndx)))l)|`Boolb->`Boolb|`Floatf->`Floatf|`Inti->`Inti|`Listl->`List(List.mapjson_spel_of_yojsonl)|`Null->`Null|`Strings->`Expr(Spel_parse.quoted_expr_from_strings)(* This catches parse errors at the expression level *)endletwrite_json_spelbuffx=Yojson.Basic.write_jsonbuff(yojson_of_json_spelx)letread_json_spelstatelexbuf=json_spel_of_yojson(Yojson.Basic.read_jsonstatelexbuf)letto_stringx=Yojson.Basic.to_string(yojson_of_json_spelx)