difftreelog
style fix clippy warnings
in: master
8 files changed
crates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-evaluator/Cargo.toml
+++ b/crates/jrsonnet-evaluator/Cargo.toml
@@ -31,7 +31,6 @@
pathdiff = "0.2.0"
closure = "0.3.0"
-indexmap = "1.6"
md5 = "0.7.0"
base64 = "0.13.0"
crates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -585,8 +585,7 @@
name: &str,
args: &ArgsDesc,
) -> Result<Val> {
- if let Some(f) = BUILTINS.with(|builtins| builtins.get(name).copied()) {
- return Ok(f(context, loc, args)?);
- }
- throw!(IntrinsicNotFound(name.into()))
+ BUILTINS.with(|builtins| builtins.get(name).copied()).ok_or_else(||
+ IntrinsicNotFound(name.into())
+ )?(context, loc, args)
}
crates/jrsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate.rs
@@ -222,12 +222,12 @@
let future_this = FutureObjValue::new();
let context_creator = context_creator!(
closure!(clone context, clone new_bindings, |this: Option<ObjValue>, super_obj: Option<ObjValue>| {
- Ok(context.clone().extend_unbound(
+ context.clone().extend_unbound(
new_bindings.clone().unwrap(),
context.dollar().clone().or_else(||this.clone()),
Some(this.unwrap()),
super_obj
- )?)
+ )
})
);
{
@@ -327,12 +327,12 @@
let new_bindings = FutureNewBindings::new();
let context_creator = context_creator!(
closure!(clone context, clone new_bindings, |this: Option<ObjValue>, super_obj: Option<ObjValue>| {
- Ok(context.clone().extend_unbound(
+ context.clone().extend_unbound(
new_bindings.clone().unwrap(),
context.dollar().clone().or_else(||this.clone()),
None,
super_obj
- )?)
+ )
})
);
let mut bindings: HashMap<IStr, LazyBinding> = HashMap::new();
@@ -439,7 +439,7 @@
Var(name) => push(
loc.as_ref(),
|| format!("variable <{}>", name),
- || Ok(context.binding(name.clone())?.evaluate()?),
+ || context.binding(name.clone())?.evaluate(),
)?,
Index(value, index) => {
match (evaluate(context.clone(), value)?, evaluate(context, index)?) {
crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -344,11 +344,11 @@
None,
|| "during TLA call".to_owned(),
|| {
- Ok(func.evaluate_map(
+ func.evaluate_map(
self.create_default_context()?,
&self.settings().tla_vars,
true,
- )?)
+ )
},
)?,
v => v,
@@ -432,7 +432,7 @@
Ok(self.settings().import_resolver.resolve_file(from, path)?)
}
pub fn load_file_contents(&self, path: &PathBuf) -> Result<IStr> {
- Ok(self.settings().import_resolver.load_file_contents(path)?)
+ self.settings().import_resolver.load_file_contents(path)
}
pub fn import_resolver(&self) -> Ref<dyn ImportResolver> {
@@ -548,8 +548,8 @@
.to_json(0)
.unwrap()
.replace("\n", "")
- })
- }};
+ })
+ }};
}
/// Asserts given code returns `true`
crates/jrsonnet-evaluator/src/typed.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/typed.rs
+++ b/crates/jrsonnet-evaluator/src/typed.rs
@@ -16,8 +16,8 @@
match $value {
$match(v) => v,
_ => unreachable!(),
- }
- }};
+ }
+ }};
}
#[derive(Debug, Error, Clone)]
@@ -177,7 +177,7 @@
None,
|| format!("array index {}", i),
|| ValuePathItem::Index(i as u64),
- || Ok(elem_type.check(&item.clone()?)?),
+ || elem_type.check(&item.clone()?),
)?;
}
Ok(())
@@ -191,7 +191,7 @@
None,
|| format!("array index {}", i),
|| ValuePathItem::Index(i as u64),
- || Ok(elem_type.check(&item.clone()?)?),
+ || elem_type.check(&item.clone()?),
)?;
}
Ok(())
crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -343,7 +343,7 @@
match $e {
$p => $r,
_ => panic!("no match"),
- }
+ }
};
}
impl Val {
@@ -537,7 +537,7 @@
let ctx = s
.create_default_context()?
.with_var("__tmp__to_json__".into(), self.clone());
- Ok(evaluate(
+ evaluate(
ctx,
&el!(Expr::Apply(
el!(Expr::Index(
@@ -558,7 +558,7 @@
false
)),
)?
- .try_cast_str("to json")?)
+ .try_cast_str("to json")
})
}
}
crates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth1use jrsonnet_interner::IStr;2#[cfg(feature = "deserialize")]3use serde::Deserialize;4#[cfg(feature = "serialize")]5use serde::Serialize;6use std::{7 fmt::{Debug, Display},8 ops::Deref,9 path::PathBuf,10 rc::Rc,11};1213#[cfg_attr(feature = "serialize", derive(Serialize))]14#[cfg_attr(feature = "deserialize", derive(Deserialize))]15#[derive(Debug, PartialEq)]16pub enum FieldName {17 /// {fixed: 2}18 Fixed(IStr),19 /// {["dyn"+"amic"]: 3}20 Dyn(LocExpr),21}2223#[cfg_attr(feature = "serialize", derive(Serialize))]24#[cfg_attr(feature = "deserialize", derive(Deserialize))]25#[derive(Debug, Clone, Copy, PartialEq)]26pub enum Visibility {27 /// :28 Normal,29 /// ::30 Hidden,31 /// :::32 Unhide,33}3435#[cfg_attr(feature = "serialize", derive(Serialize))]36#[cfg_attr(feature = "deserialize", derive(Deserialize))]37#[derive(Debug, PartialEq)]38pub struct AssertStmt(pub LocExpr, pub Option<LocExpr>);3940#[cfg_attr(feature = "serialize", derive(Serialize))]41#[cfg_attr(feature = "deserialize", derive(Deserialize))]42#[derive(Debug, PartialEq)]43pub struct FieldMember {44 pub name: FieldName,45 pub plus: bool,46 pub params: Option<ParamsDesc>,47 pub visibility: Visibility,48 pub value: LocExpr,49}5051#[cfg_attr(feature = "serialize", derive(Serialize))]52#[cfg_attr(feature = "deserialize", derive(Deserialize))]53#[derive(Debug, PartialEq)]54pub enum Member {55 Field(FieldMember),56 BindStmt(BindSpec),57 AssertStmt(AssertStmt),58}5960#[cfg_attr(feature = "serialize", derive(Serialize))]61#[cfg_attr(feature = "deserialize", derive(Deserialize))]62#[derive(Debug, Clone, Copy, PartialEq)]63pub enum UnaryOpType {64 Plus,65 Minus,66 BitNot,67 Not,68}69impl Display for UnaryOpType {70 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {71 use UnaryOpType::*;72 write!(73 f,74 "{}",75 match self {76 Plus => "+",77 Minus => "-",78 BitNot => "~",79 Not => "!",80 }81 )82 }83}8485#[cfg_attr(feature = "serialize", derive(Serialize))]86#[cfg_attr(feature = "deserialize", derive(Deserialize))]87#[derive(Debug, Clone, Copy, PartialEq)]88pub enum BinaryOpType {89 Mul,90 Div,9192 /// Implemented as intrinsic, put here for completeness93 Mod,9495 Add,96 Sub,9798 Lhs,99 Rhs,100101 Lt,102 Gt,103 Lte,104 Gte,105106 BitAnd,107 BitOr,108 BitXor,109110 And,111 Or,112}113impl Display for BinaryOpType {114 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {115 use BinaryOpType::*;116 write!(117 f,118 "{}",119 match self {120 Mul => "*",121 Div => "/",122 Mod => "%",123 Add => "+",124 Sub => "-",125 Lhs => "<<",126 Rhs => ">>",127 Lt => "<",128 Gt => ">",129 Lte => "<=",130 Gte => ">=",131 BitAnd => "&",132 BitOr => "|",133 BitXor => "^",134 And => "&&",135 Or => "||",136 }137 )138 }139}140141/// name, default value142#[cfg_attr(feature = "serialize", derive(Serialize))]143#[cfg_attr(feature = "deserialize", derive(Deserialize))]144#[derive(Debug, PartialEq)]145pub struct Param(pub IStr, pub Option<LocExpr>);146147/// Defined function parameters148#[cfg_attr(feature = "serialize", derive(Serialize))]149#[cfg_attr(feature = "deserialize", derive(Deserialize))]150#[derive(Debug, Clone, PartialEq)]151pub struct ParamsDesc(pub Rc<Vec<Param>>);152impl Deref for ParamsDesc {153 type Target = Vec<Param>;154 fn deref(&self) -> &Self::Target {155 &self.0156 }157}158159#[cfg_attr(feature = "serialize", derive(Serialize))]160#[cfg_attr(feature = "deserialize", derive(Deserialize))]161#[derive(Debug, PartialEq)]162pub struct Arg(pub Option<String>, pub LocExpr);163164#[cfg_attr(feature = "serialize", derive(Serialize))]165#[cfg_attr(feature = "deserialize", derive(Deserialize))]166#[derive(Debug, PartialEq)]167pub struct ArgsDesc(pub Vec<Arg>);168impl Deref for ArgsDesc {169 type Target = Vec<Arg>;170 fn deref(&self) -> &Self::Target {171 &self.0172 }173}174175#[cfg_attr(feature = "serialize", derive(Serialize))]176#[cfg_attr(feature = "deserialize", derive(Deserialize))]177#[derive(Debug, Clone, PartialEq)]178pub struct BindSpec {179 pub name: IStr,180 pub params: Option<ParamsDesc>,181 pub value: LocExpr,182}183184#[cfg_attr(feature = "serialize", derive(Serialize))]185#[cfg_attr(feature = "deserialize", derive(Deserialize))]186#[derive(Debug, PartialEq)]187pub struct IfSpecData(pub LocExpr);188189#[cfg_attr(feature = "serialize", derive(Serialize))]190#[cfg_attr(feature = "deserialize", derive(Deserialize))]191#[derive(Debug, PartialEq)]192pub struct ForSpecData(pub IStr, pub LocExpr);193194#[cfg_attr(feature = "serialize", derive(Serialize))]195#[cfg_attr(feature = "deserialize", derive(Deserialize))]196#[derive(Debug, PartialEq)]197pub enum CompSpec {198 IfSpec(IfSpecData),199 ForSpec(ForSpecData),200}201202#[cfg_attr(feature = "serialize", derive(Serialize))]203#[cfg_attr(feature = "deserialize", derive(Deserialize))]204#[derive(Debug, PartialEq)]205pub struct ObjComp {206 pub pre_locals: Vec<BindSpec>,207 pub key: LocExpr,208 pub value: LocExpr,209 pub post_locals: Vec<BindSpec>,210 pub compspecs: Vec<CompSpec>,211}212213#[cfg_attr(feature = "serialize", derive(Serialize))]214#[cfg_attr(feature = "deserialize", derive(Deserialize))]215#[derive(Debug, PartialEq)]216pub enum ObjBody {217 MemberList(Vec<Member>),218 ObjComp(ObjComp),219}220221#[cfg_attr(feature = "serialize", derive(Serialize))]222#[cfg_attr(feature = "deserialize", derive(Deserialize))]223#[derive(Debug, PartialEq, Clone, Copy)]224pub enum LiteralType {225 This,226 Super,227 Dollar,228 Null,229 True,230 False,231}232233#[derive(Debug, PartialEq)]234pub struct SliceDesc {235 pub start: Option<LocExpr>,236 pub end: Option<LocExpr>,237 pub step: Option<LocExpr>,238}239240/// Syntax base241#[cfg_attr(feature = "serialize", derive(Serialize))]242#[cfg_attr(feature = "deserialize", derive(Deserialize))]243#[derive(Debug, PartialEq)]244pub enum Expr {245 Literal(LiteralType),246247 /// String value: "hello"248 Str(IStr),249 /// Number: 1, 2.0, 2e+20250 Num(f64),251 /// Variable name: test252 Var(IStr),253254 /// Array of expressions: [1, 2, "Hello"]255 Arr(Vec<LocExpr>),256 /// Array comprehension:257 /// ```jsonnet258 /// ingredients: [259 /// { kind: kind, qty: 4 / 3 }260 /// for kind in [261 /// 'Honey Syrup',262 /// 'Lemon Juice',263 /// 'Farmers Gin',264 /// ]265 /// ],266 /// ```267 ArrComp(LocExpr, Vec<CompSpec>),268269 /// Object: {a: 2}270 Obj(ObjBody),271 /// Object extension: var1 {b: 2}272 ObjExtend(LocExpr, ObjBody),273274 /// (obj)275 Parened(LocExpr),276277 /// -2278 UnaryOp(UnaryOpType, LocExpr),279 /// 2 - 2280 BinaryOp(LocExpr, BinaryOpType, LocExpr),281 /// assert 2 == 2 : "Math is broken"282 AssertExpr(AssertStmt, LocExpr),283 /// local a = 2; { b: a }284 LocalExpr(Vec<BindSpec>, LocExpr),285286 /// import "hello"287 Import(PathBuf),288 /// importStr "file.txt"289 ImportStr(PathBuf),290 /// error "I'm broken"291 ErrorStmt(LocExpr),292 /// a(b, c)293 Apply(LocExpr, ArgsDesc, bool),294 /// a[b]295 Index(LocExpr, LocExpr),296 /// function(x) x297 Function(ParamsDesc, LocExpr),298 /// std.primitiveEquals299 Intrinsic(IStr),300 /// if true == false then 1 else 2301 IfElse {302 cond: IfSpecData,303 cond_then: LocExpr,304 cond_else: Option<LocExpr>,305 },306}307308/// file, begin offset, end offset309#[cfg_attr(feature = "serialize", derive(Serialize))]310#[cfg_attr(feature = "deserialize", derive(Deserialize))]311#[derive(Clone, PartialEq)]312pub struct ExprLocation(pub Rc<PathBuf>, pub usize, pub usize);313impl Debug for ExprLocation {314 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {315 write!(f, "{:?}:{:?}-{:?}", self.0, self.1, self.2)316 }317}318319/// Holds AST expression and its location in source file320#[cfg_attr(feature = "serialize", derive(Serialize))]321#[cfg_attr(feature = "deserialize", derive(Deserialize))]322#[derive(Clone, PartialEq)]323pub struct LocExpr(pub Rc<Expr>, pub Option<ExprLocation>);324impl Debug for LocExpr {325 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {326 write!(f, "{:?} from {:?}", self.0, self.1)327 }328}329330/// Creates LocExpr from Expr and ExprLocation components331#[macro_export]332macro_rules! loc_expr {333 ($expr:expr, $need_loc:expr,($name:expr, $start:expr, $end:expr)) => {334 LocExpr(335 std::rc::Rc::new($expr),336 if $need_loc {337 Some(ExprLocation($name, $start, $end))338 } else {339 None340 },341 )342 };343}344345/// Creates LocExpr without location info346#[macro_export]347macro_rules! loc_expr_todo {348 ($expr:expr) => {349 LocExpr(Rc::new($expr), None)350 };351}1use jrsonnet_interner::IStr;2#[cfg(feature = "deserialize")]3use serde::Deserialize;4#[cfg(feature = "serialize")]5use serde::Serialize;6use std::{7 fmt::{Debug, Display},8 ops::Deref,9 path::PathBuf,10 rc::Rc,11};1213#[cfg_attr(feature = "serialize", derive(Serialize))]14#[cfg_attr(feature = "deserialize", derive(Deserialize))]15#[derive(Debug, PartialEq)]16pub enum FieldName {17 /// {fixed: 2}18 Fixed(IStr),19 /// {["dyn"+"amic"]: 3}20 Dyn(LocExpr),21}2223#[cfg_attr(feature = "serialize", derive(Serialize))]24#[cfg_attr(feature = "deserialize", derive(Deserialize))]25#[derive(Debug, Clone, Copy, PartialEq)]26pub enum Visibility {27 /// :28 Normal,29 /// ::30 Hidden,31 /// :::32 Unhide,33}3435impl Visibility {36 pub fn is_visible(&self) -> bool {37 matches!(self, Self::Normal | Self::Unhide)38 }39}4041#[cfg_attr(feature = "serialize", derive(Serialize))]42#[cfg_attr(feature = "deserialize", derive(Deserialize))]43#[derive(Debug, PartialEq)]44pub struct AssertStmt(pub LocExpr, pub Option<LocExpr>);4546#[cfg_attr(feature = "serialize", derive(Serialize))]47#[cfg_attr(feature = "deserialize", derive(Deserialize))]48#[derive(Debug, PartialEq)]49pub struct FieldMember {50 pub name: FieldName,51 pub plus: bool,52 pub params: Option<ParamsDesc>,53 pub visibility: Visibility,54 pub value: LocExpr,55}5657#[cfg_attr(feature = "serialize", derive(Serialize))]58#[cfg_attr(feature = "deserialize", derive(Deserialize))]59#[derive(Debug, PartialEq)]60pub enum Member {61 Field(FieldMember),62 BindStmt(BindSpec),63 AssertStmt(AssertStmt),64}6566#[cfg_attr(feature = "serialize", derive(Serialize))]67#[cfg_attr(feature = "deserialize", derive(Deserialize))]68#[derive(Debug, Clone, Copy, PartialEq)]69pub enum UnaryOpType {70 Plus,71 Minus,72 BitNot,73 Not,74}75impl Display for UnaryOpType {76 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {77 use UnaryOpType::*;78 write!(79 f,80 "{}",81 match self {82 Plus => "+",83 Minus => "-",84 BitNot => "~",85 Not => "!",86 }87 )88 }89}9091#[cfg_attr(feature = "serialize", derive(Serialize))]92#[cfg_attr(feature = "deserialize", derive(Deserialize))]93#[derive(Debug, Clone, Copy, PartialEq)]94pub enum BinaryOpType {95 Mul,96 Div,9798 /// Implemented as intrinsic, put here for completeness99 Mod,100101 Add,102 Sub,103104 Lhs,105 Rhs,106107 Lt,108 Gt,109 Lte,110 Gte,111112 BitAnd,113 BitOr,114 BitXor,115116 And,117 Or,118}119impl Display for BinaryOpType {120 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {121 use BinaryOpType::*;122 write!(123 f,124 "{}",125 match self {126 Mul => "*",127 Div => "/",128 Mod => "%",129 Add => "+",130 Sub => "-",131 Lhs => "<<",132 Rhs => ">>",133 Lt => "<",134 Gt => ">",135 Lte => "<=",136 Gte => ">=",137 BitAnd => "&",138 BitOr => "|",139 BitXor => "^",140 And => "&&",141 Or => "||",142 }143 )144 }145}146147/// name, default value148#[cfg_attr(feature = "serialize", derive(Serialize))]149#[cfg_attr(feature = "deserialize", derive(Deserialize))]150#[derive(Debug, PartialEq)]151pub struct Param(pub IStr, pub Option<LocExpr>);152153/// Defined function parameters154#[cfg_attr(feature = "serialize", derive(Serialize))]155#[cfg_attr(feature = "deserialize", derive(Deserialize))]156#[derive(Debug, Clone, PartialEq)]157pub struct ParamsDesc(pub Rc<Vec<Param>>);158impl Deref for ParamsDesc {159 type Target = Vec<Param>;160 fn deref(&self) -> &Self::Target {161 &self.0162 }163}164165#[cfg_attr(feature = "serialize", derive(Serialize))]166#[cfg_attr(feature = "deserialize", derive(Deserialize))]167#[derive(Debug, PartialEq)]168pub struct Arg(pub Option<String>, pub LocExpr);169170#[cfg_attr(feature = "serialize", derive(Serialize))]171#[cfg_attr(feature = "deserialize", derive(Deserialize))]172#[derive(Debug, PartialEq)]173pub struct ArgsDesc(pub Vec<Arg>);174impl Deref for ArgsDesc {175 type Target = Vec<Arg>;176 fn deref(&self) -> &Self::Target {177 &self.0178 }179}180181#[cfg_attr(feature = "serialize", derive(Serialize))]182#[cfg_attr(feature = "deserialize", derive(Deserialize))]183#[derive(Debug, Clone, PartialEq)]184pub struct BindSpec {185 pub name: IStr,186 pub params: Option<ParamsDesc>,187 pub value: LocExpr,188}189190#[cfg_attr(feature = "serialize", derive(Serialize))]191#[cfg_attr(feature = "deserialize", derive(Deserialize))]192#[derive(Debug, PartialEq)]193pub struct IfSpecData(pub LocExpr);194195#[cfg_attr(feature = "serialize", derive(Serialize))]196#[cfg_attr(feature = "deserialize", derive(Deserialize))]197#[derive(Debug, PartialEq)]198pub struct ForSpecData(pub IStr, pub LocExpr);199200#[cfg_attr(feature = "serialize", derive(Serialize))]201#[cfg_attr(feature = "deserialize", derive(Deserialize))]202#[derive(Debug, PartialEq)]203pub enum CompSpec {204 IfSpec(IfSpecData),205 ForSpec(ForSpecData),206}207208#[cfg_attr(feature = "serialize", derive(Serialize))]209#[cfg_attr(feature = "deserialize", derive(Deserialize))]210#[derive(Debug, PartialEq)]211pub struct ObjComp {212 pub pre_locals: Vec<BindSpec>,213 pub key: LocExpr,214 pub value: LocExpr,215 pub post_locals: Vec<BindSpec>,216 pub compspecs: Vec<CompSpec>,217}218219#[cfg_attr(feature = "serialize", derive(Serialize))]220#[cfg_attr(feature = "deserialize", derive(Deserialize))]221#[derive(Debug, PartialEq)]222pub enum ObjBody {223 MemberList(Vec<Member>),224 ObjComp(ObjComp),225}226227#[cfg_attr(feature = "serialize", derive(Serialize))]228#[cfg_attr(feature = "deserialize", derive(Deserialize))]229#[derive(Debug, PartialEq, Clone, Copy)]230pub enum LiteralType {231 This,232 Super,233 Dollar,234 Null,235 True,236 False,237}238239#[derive(Debug, PartialEq)]240pub struct SliceDesc {241 pub start: Option<LocExpr>,242 pub end: Option<LocExpr>,243 pub step: Option<LocExpr>,244}245246/// Syntax base247#[cfg_attr(feature = "serialize", derive(Serialize))]248#[cfg_attr(feature = "deserialize", derive(Deserialize))]249#[derive(Debug, PartialEq)]250pub enum Expr {251 Literal(LiteralType),252253 /// String value: "hello"254 Str(IStr),255 /// Number: 1, 2.0, 2e+20256 Num(f64),257 /// Variable name: test258 Var(IStr),259260 /// Array of expressions: [1, 2, "Hello"]261 Arr(Vec<LocExpr>),262 /// Array comprehension:263 /// ```jsonnet264 /// ingredients: [265 /// { kind: kind, qty: 4 / 3 }266 /// for kind in [267 /// 'Honey Syrup',268 /// 'Lemon Juice',269 /// 'Farmers Gin',270 /// ]271 /// ],272 /// ```273 ArrComp(LocExpr, Vec<CompSpec>),274275 /// Object: {a: 2}276 Obj(ObjBody),277 /// Object extension: var1 {b: 2}278 ObjExtend(LocExpr, ObjBody),279280 /// (obj)281 Parened(LocExpr),282283 /// -2284 UnaryOp(UnaryOpType, LocExpr),285 /// 2 - 2286 BinaryOp(LocExpr, BinaryOpType, LocExpr),287 /// assert 2 == 2 : "Math is broken"288 AssertExpr(AssertStmt, LocExpr),289 /// local a = 2; { b: a }290 LocalExpr(Vec<BindSpec>, LocExpr),291292 /// import "hello"293 Import(PathBuf),294 /// importStr "file.txt"295 ImportStr(PathBuf),296 /// error "I'm broken"297 ErrorStmt(LocExpr),298 /// a(b, c)299 Apply(LocExpr, ArgsDesc, bool),300 /// a[b]301 Index(LocExpr, LocExpr),302 /// function(x) x303 Function(ParamsDesc, LocExpr),304 /// std.primitiveEquals305 Intrinsic(IStr),306 /// if true == false then 1 else 2307 IfElse {308 cond: IfSpecData,309 cond_then: LocExpr,310 cond_else: Option<LocExpr>,311 },312}313314/// file, begin offset, end offset315#[cfg_attr(feature = "serialize", derive(Serialize))]316#[cfg_attr(feature = "deserialize", derive(Deserialize))]317#[derive(Clone, PartialEq)]318pub struct ExprLocation(pub Rc<PathBuf>, pub usize, pub usize);319impl Debug for ExprLocation {320 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {321 write!(f, "{:?}:{:?}-{:?}", self.0, self.1, self.2)322 }323}324325/// Holds AST expression and its location in source file326#[cfg_attr(feature = "serialize", derive(Serialize))]327#[cfg_attr(feature = "deserialize", derive(Deserialize))]328#[derive(Clone, PartialEq)]329pub struct LocExpr(pub Rc<Expr>, pub Option<ExprLocation>);330impl Debug for LocExpr {331 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {332 write!(f, "{:?} from {:?}", self.0, self.1)333 }334}335336/// Creates LocExpr from Expr and ExprLocation components337#[macro_export]338macro_rules! loc_expr {339 ($expr:expr, $need_loc:expr,($name:expr, $start:expr, $end:expr)) => {340 LocExpr(341 std::rc::Rc::new($expr),342 if $need_loc {343 Some(ExprLocation($name, $start, $end))344 } else {345 None346 },347 )348 };349}350351/// Creates LocExpr without location info352#[macro_export]353macro_rules! loc_expr_todo {354 ($expr:expr) => {355 LocExpr(Rc::new($expr), None)356 };357}crates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-parser/src/lib.rs
+++ b/crates/jrsonnet-parser/src/lib.rs
@@ -319,8 +319,8 @@
&ParserSettings {
loc_data: false,
file_name: Rc::new(PathBuf::from("/test.jsonnet")),
- },
- )
+ },
+ )
.unwrap()
};
}