git.delta.rocks / jrsonnet / refs/commits / 0dad2a64ea4b

difftreelog

feat into_yaml conversion

Лач2020-07-16parent: #18d3b6b.patch.diff
in: master

1 file changed

modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
1use crate::{1use crate::{
2 create_error_result, evaluate,2 create_error_result, evaluate,
3 function::{parse_function_call, place_args},3 function::{parse_function_call, place_args},
4 Context, Error, ObjValue, Result,4 with_state, Context, Error, ObjValue, Result,
5};5};
6use jrsonnet_parser::{ArgsDesc, LocExpr, ParamsDesc};6use jrsonnet_parser::{el, Arg, ArgsDesc, Expr, LocExpr, ParamsDesc};
7use std::{7use std::{
8 cell::RefCell,8 cell::RefCell,
9 fmt::{Debug, Display},9 fmt::{Debug, Display},
210 .try_cast_str("to json")?)210 .try_cast_str("to json")?)
211 })211 })
212 }212 }
213 pub fn into_yaml(self, padding: usize) -> Result<Rc<str>> {
214 with_state(|s| {
215 let ctx = s
216 .create_default_context()?
217 .with_var("__tmp__to_json__".into(), self)?;
218 Ok(evaluate(
219 ctx,
220 &el!(Expr::Apply(
221 el!(Expr::Index(
222 el!(Expr::Var("std".into())),
223 el!(Expr::Str("manifestYamlDoc".into()))
224 )),
225 ArgsDesc(vec![
226 Arg(None, el!(Expr::Var("__tmp__to_json__".into()))),
227 Arg(None, el!(Expr::Str(" ".repeat(padding).into())))
228 ]),
229 false
230 )),
231 )?
232 .try_cast_str("to json")?)
233 })
234 }
213}235}
214236
215fn is_function_like(val: &Val) -> bool {237fn is_function_like(val: &Val) -> bool {