difftreelog
build upgrade dependencies
in: master
13 files changed
cmds/jrsonnet/Cargo.tomldiffbeforeafterboth--- a/cmds/jrsonnet/Cargo.toml
+++ b/cmds/jrsonnet/Cargo.toml
@@ -28,5 +28,5 @@
mimallocator = { version = "0.1.3", optional = true }
thiserror = "1.0"
-clap = { version = "3.2", features = ["derive"] }
-clap_complete = { version = "3.2" }
+clap = { version = "4.0", features = ["derive"] }
+clap_complete = { version = "4.0" }
cmds/jrsonnet/src/main.rsdiffbeforeafterboth--- a/cmds/jrsonnet/src/main.rs
+++ b/cmds/jrsonnet/src/main.rs
@@ -3,7 +3,7 @@
io::{Read, Write},
};
-use clap::{AppSettings, IntoApp, Parser};
+use clap::{CommandFactory, Parser};
use clap_complete::Shell;
use jrsonnet_cli::{ConfigureState, GeneralOpts, ManifestOpts, OutputOpts};
use jrsonnet_evaluator::{error::LocError, State};
@@ -42,10 +42,7 @@
}
#[derive(Parser)]
-#[clap(
- global_setting = AppSettings::DeriveDisplayOrder,
- args_conflicts_with_subcommands = true,
-)]
+#[clap(args_conflicts_with_subcommands = true, disable_version_flag = true)]
struct Opts {
#[clap(subcommand)]
sub: Option<SubOpts>,
crates/jrsonnet-cli/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-cli/Cargo.toml
+++ b/crates/jrsonnet-cli/Cargo.toml
@@ -21,4 +21,4 @@
jrsonnet-gcmodule = { version = "0.3.4" }
jrsonnet-stdlib = { path = "../../crates/jrsonnet-stdlib", version = "0.4.2" }
-clap = { version = "3.2", features = ["derive"] }
+clap = { version = "4.0", features = ["derive"] }
crates/jrsonnet-cli/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/lib.rs
+++ b/crates/jrsonnet-cli/src/lib.rs
@@ -44,7 +44,7 @@
/// Any not found `imported` file will be searched in these.
/// This can also be specified via `JSONNET_PATH` variable,
/// which should contain a colon-separated (semicolon-separated on Windows) list of directories.
- #[clap(long, short = 'J', multiple_occurrences = true)]
+ #[clap(long, short = 'J')]
jpath: Vec<PathBuf>,
}
impl ConfigureState for MiscOpts {
crates/jrsonnet-cli/src/manifest.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/manifest.rs
+++ b/crates/jrsonnet-cli/src/manifest.rs
@@ -1,10 +1,11 @@
use std::{path::PathBuf, str::FromStr};
-use clap::Parser;
+use clap::{Parser, ValueEnum};
use jrsonnet_evaluator::{error::Result, ManifestFormat, State};
use crate::ConfigureState;
+#[derive(Clone, ValueEnum)]
pub enum ManifestFormatName {
/// Expect string as output, and write them directly
String,
@@ -28,7 +29,7 @@
#[clap(next_help_heading = "MANIFESTIFICATION OUTPUT")]
pub struct ManifestOpts {
/// Output format, wraps resulting value to corresponding std.manifest call.
- #[clap(long, short = 'f', default_value = "json", possible_values = &["json", "yaml"])]
+ #[clap(long, short = 'f', default_value = "json")]
format: ManifestFormatName,
/// Expect plain string as output.
/// Mutually exclusive with `--format`
crates/jrsonnet-cli/src/stdlib.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/stdlib.rs
+++ b/crates/jrsonnet-cli/src/stdlib.rs
@@ -69,40 +69,19 @@
/// to use top level arguments whenever it's possible.
/// If [=data] is not set then it will be read from `name` env variable.
/// Can be accessed from code via `std.extVar("name")`.
- #[clap(
- long,
- short = 'V',
- name = "name[=var data]",
- number_of_values = 1,
- multiple_occurrences = true
- )]
+ #[clap(long, short = 'V', name = "name[=var data]", number_of_values = 1)]
ext_str: Vec<ExtStr>,
/// Read string external variable from file.
/// See also `--ext-str`
- #[clap(
- long,
- name = "name=var path",
- number_of_values = 1,
- multiple_occurrences = true
- )]
+ #[clap(long, name = "name=var path", number_of_values = 1)]
ext_str_file: Vec<ExtFile>,
/// Add external variable from code.
/// See also `--ext-str`
- #[clap(
- long,
- name = "name[=var source]",
- number_of_values = 1,
- multiple_occurrences = true
- )]
+ #[clap(long, name = "name[=var source]", number_of_values = 1)]
ext_code: Vec<ExtStr>,
/// Read string external variable from file.
/// See also `--ext-str`
- #[clap(
- long,
- name = "name=var code path",
- number_of_values = 1,
- multiple_occurrences = true
- )]
+ #[clap(long, name = "name=var code path", number_of_values = 1)]
ext_code_file: Vec<ExtFile>,
}
impl ConfigureState for StdOpts {
crates/jrsonnet-cli/src/tla.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/tla.rs
+++ b/crates/jrsonnet-cli/src/tla.rs
@@ -10,40 +10,19 @@
/// Top level arguments will be passed to function before manifestification stage.
/// This is preferred to ExtVars method.
/// If [=data] is not set then it will be read from `name` env variable.
- #[clap(
- long,
- short = 'A',
- name = "name[=tla data]",
- number_of_values = 1,
- multiple_occurrences = true
- )]
+ #[clap(long, short = 'A', name = "name[=tla data]", number_of_values = 1)]
tla_str: Vec<ExtStr>,
/// Read top level argument string from file.
/// See also `--tla-str`
- #[clap(
- long,
- name = "name=tla path",
- number_of_values = 1,
- multiple_occurrences = true
- )]
+ #[clap(long, name = "name=tla path", number_of_values = 1)]
tla_str_file: Vec<ExtFile>,
/// Add top level argument from code.
/// See also `--tla-str`
- #[clap(
- long,
- name = "name[=tla source]",
- number_of_values = 1,
- multiple_occurrences = true
- )]
+ #[clap(long, name = "name[=tla source]", number_of_values = 1)]
tla_code: Vec<ExtStr>,
/// Read top level argument code from file.
/// See also `--tla-str`
- #[clap(
- long,
- name = "name=tla code path",
- number_of_values = 1,
- multiple_occurrences = true
- )]
+ #[clap(long, name = "name=tla code path", number_of_values = 1)]
tla_code_file: Vec<ExtFile>,
}
impl ConfigureState for TLAOpts {
crates/jrsonnet-cli/src/trace.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/trace.rs
+++ b/crates/jrsonnet-cli/src/trace.rs
@@ -1,6 +1,4 @@
-use std::str::FromStr;
-
-use clap::Parser;
+use clap::{Parser, ValueEnum};
use jrsonnet_evaluator::{
error::Result,
trace::{CompactFormat, ExplainingFormat, PathResolver},
@@ -9,31 +7,19 @@
use crate::ConfigureState;
-#[derive(PartialEq, Eq)]
+#[derive(PartialEq, Eq, ValueEnum, Clone)]
pub enum TraceFormatName {
+ /// Only show `filename:line:column`
Compact,
+ /// Display source code with attached trace annotations
Explaining,
-}
-
-impl FromStr for TraceFormatName {
- type Err = &'static str;
- fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
- Ok(match s {
- "compact" => TraceFormatName::Compact,
- "explaining" => TraceFormatName::Explaining,
- _ => return Err("no such format"),
- })
- }
}
#[derive(Parser)]
#[clap(next_help_heading = "STACK TRACE VISUAL")]
pub struct TraceOpts {
/// Format of stack traces' display in console.
- /// `compact` format only shows `filename:line:column`s
- /// while `explaining` displays source code with attached trace annotations
- /// thus being more verbose.
- #[clap(long, possible_values = &["compact", "explaining"])]
+ #[clap(long)]
trace_format: Option<TraceFormatName>,
/// Amount of stack trace elements to be displayed.
/// If set to `0` then full stack trace will be displayed.
crates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-evaluator/Cargo.toml
+++ b/crates/jrsonnet-evaluator/Cargo.toml
@@ -31,7 +31,7 @@
jrsonnet-gcmodule = { version = "0.3.4" }
pathdiff = "0.2.1"
-hashbrown = "0.12.1"
+hashbrown = "0.12.3"
static_assertions = "1.1"
rustc-hash = "1.1"
crates/jrsonnet-interner/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-interner/Cargo.toml
+++ b/crates/jrsonnet-interner/Cargo.toml
@@ -22,4 +22,4 @@
structdump = { version = "0.2.0", optional = true }
rustc-hash = "1.1"
-hashbrown = { version = "0.12.1", features = ["inline-more"] }
+hashbrown = { version = "0.12.3", features = ["inline-more"] }
crates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth1use std::{2 fmt::{self, Debug, Display},3 ops::Deref,4 rc::Rc,5};67use jrsonnet_gcmodule::Trace;8use jrsonnet_interner::IStr;9#[cfg(feature = "serde")]10use serde::{Deserialize, Serialize};11#[cfg(feature = "structdump")]12use structdump::Codegen;1314use crate::source::Source;1516#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]17#[cfg_attr(feature = "structdump", derive(Codegen))]18#[derive(Debug, PartialEq, Trace)]19pub enum FieldName {20 /// {fixed: 2}21 Fixed(IStr),22 /// {["dyn"+"amic"]: 3}23 Dyn(LocExpr),24}2526#[cfg_attr(feature = "structdump", derive(Codegen))]27#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]28#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]29pub enum Visibility {30 /// :31 Normal,32 /// ::33 Hidden,34 /// :::35 Unhide,36}3738impl Visibility {39 pub fn is_visible(&self) -> bool {40 matches!(self, Self::Normal | Self::Unhide)41 }42}4344#[cfg_attr(feature = "structdump", derive(Codegen))]45#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]46#[derive(Clone, Debug, PartialEq, Trace)]47pub struct AssertStmt(pub LocExpr, pub Option<LocExpr>);4849#[cfg_attr(feature = "structdump", derive(Codegen))]50#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]51#[derive(Debug, PartialEq, Trace)]52pub struct FieldMember {53 pub name: FieldName,54 pub plus: bool,55 pub params: Option<ParamsDesc>,56 pub visibility: Visibility,57 pub value: LocExpr,58}5960#[cfg_attr(feature = "structdump", derive(Codegen))]61#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]62#[derive(Debug, PartialEq, Trace)]63pub enum Member {64 Field(FieldMember),65 BindStmt(BindSpec),66 AssertStmt(AssertStmt),67}6869#[cfg_attr(feature = "structdump", derive(Codegen))]70#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]71#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]72pub enum UnaryOpType {73 Plus,74 Minus,75 BitNot,76 Not,77}7879impl Display for UnaryOpType {80 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {81 use UnaryOpType::*;82 write!(83 f,84 "{}",85 match self {86 Plus => "+",87 Minus => "-",88 BitNot => "~",89 Not => "!",90 }91 )92 }93}9495#[cfg_attr(feature = "structdump", derive(Codegen))]96#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]97#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]98pub enum BinaryOpType {99 Mul,100 Div,101102 /// Implemented as intrinsic, put here for completeness103 Mod,104105 Add,106 Sub,107108 Lhs,109 Rhs,110111 Lt,112 Gt,113 Lte,114 Gte,115116 BitAnd,117 BitOr,118 BitXor,119120 Eq,121 Neq,122123 And,124 Or,125126 // Equialent to std.objectHasEx(a, b, true)127 In,128}129130impl Display for BinaryOpType {131 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {132 use BinaryOpType::*;133 write!(134 f,135 "{}",136 match self {137 Mul => "*",138 Div => "/",139 Mod => "%",140 Add => "+",141 Sub => "-",142 Lhs => "<<",143 Rhs => ">>",144 Lt => "<",145 Gt => ">",146 Lte => "<=",147 Gte => ">=",148 BitAnd => "&",149 BitOr => "|",150 BitXor => "^",151 Eq => "==",152 Neq => "!=",153 And => "&&",154 Or => "||",155 In => "in",156 }157 )158 }159}160161/// name, default value162#[cfg_attr(feature = "structdump", derive(Codegen))]163#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]164#[derive(Debug, PartialEq, Trace)]165pub struct Param(pub Destruct, pub Option<LocExpr>);166167/// Defined function parameters168#[cfg_attr(feature = "structdump", derive(Codegen))]169#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]170#[derive(Debug, Clone, PartialEq, Trace)]171pub struct ParamsDesc(pub Rc<Vec<Param>>);172173impl Deref for ParamsDesc {174 type Target = Vec<Param>;175 fn deref(&self) -> &Self::Target {176 &self.0177 }178}179180#[cfg_attr(feature = "structdump", derive(Codegen))]181#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]182#[derive(Debug, PartialEq, Trace)]183pub struct ArgsDesc {184 pub unnamed: Vec<LocExpr>,185 pub named: Vec<(IStr, LocExpr)>,186}187impl ArgsDesc {188 pub fn new(unnamed: Vec<LocExpr>, named: Vec<(IStr, LocExpr)>) -> Self {189 Self { unnamed, named }190 }191}192193#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]194#[derive(Debug, Clone, PartialEq, Eq, Trace)]195pub enum DestructRest {196 /// ...rest197 Keep(IStr),198 /// ...199 Drop,200}201202#[cfg_attr(feature = "structdump", derive(Codegen))]203#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]204#[derive(Debug, Clone, PartialEq, Trace)]205pub enum Destruct {206 Full(IStr),207 #[cfg(feature = "exp-destruct")]208 Skip,209 #[cfg(feature = "exp-destruct")]210 Array {211 start: Vec<Destruct>,212 rest: Option<DestructRest>,213 end: Vec<Destruct>,214 },215 #[cfg(feature = "exp-destruct")]216 Object {217 fields: Vec<(IStr, Option<Destruct>, Option<LocExpr>)>,218 rest: Option<DestructRest>,219 },220}221impl Destruct {222 /// Name of destructure, used for function parameter names223 pub fn name(&self) -> Option<IStr> {224 match self {225 Self::Full(name) => Some(name.clone()),226 #[cfg(feature = "exp-destruct")]227 _ => None,228 }229 }230}231232#[cfg_attr(feature = "structdump", derive(Codegen))]233#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]234#[derive(Debug, Clone, PartialEq, Trace)]235pub enum BindSpec {236 Field {237 into: Destruct,238 value: LocExpr,239 },240 Function {241 name: IStr,242 params: ParamsDesc,243 value: LocExpr,244 },245}246247#[cfg_attr(feature = "structdump", derive(Codegen))]248#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]249#[derive(Debug, PartialEq, Trace)]250pub struct IfSpecData(pub LocExpr);251252#[cfg_attr(feature = "structdump", derive(Codegen))]253#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]254#[derive(Debug, PartialEq, Trace)]255pub struct ForSpecData(pub IStr, pub LocExpr);256257#[cfg_attr(feature = "structdump", derive(Codegen))]258#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]259#[derive(Debug, PartialEq, Trace)]260pub enum CompSpec {261 IfSpec(IfSpecData),262 ForSpec(ForSpecData),263}264265#[cfg_attr(feature = "structdump", derive(Codegen))]266#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]267#[derive(Debug, PartialEq, Trace)]268pub struct ObjComp {269 pub pre_locals: Vec<BindSpec>,270 pub key: LocExpr,271 pub plus: bool,272 pub value: LocExpr,273 pub post_locals: Vec<BindSpec>,274 pub compspecs: Vec<CompSpec>,275}276277#[cfg_attr(feature = "structdump", derive(Codegen))]278#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]279#[derive(Debug, PartialEq, Trace)]280pub enum ObjBody {281 MemberList(Vec<Member>),282 ObjComp(ObjComp),283}284285#[cfg_attr(feature = "structdump", derive(Codegen))]286#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]287#[derive(Debug, PartialEq, Eq, Clone, Copy, Trace)]288pub enum LiteralType {289 This,290 Super,291 Dollar,292 Null,293 True,294 False,295}296297#[cfg_attr(feature = "structdump", derive(Codegen))]298#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]299#[derive(Debug, PartialEq, Trace)]300pub struct SliceDesc {301 pub start: Option<LocExpr>,302 pub end: Option<LocExpr>,303 pub step: Option<LocExpr>,304}305306/// Syntax base307#[cfg_attr(feature = "structdump", derive(Codegen))]308#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]309#[derive(Debug, PartialEq, Trace)]310pub enum Expr {311 Literal(LiteralType),312313 /// String value: "hello"314 Str(IStr),315 /// Number: 1, 2.0, 2e+20316 Num(f64),317 /// Variable name: test318 Var(IStr),319320 /// Array of expressions: [1, 2, "Hello"]321 Arr(Vec<LocExpr>),322 /// Array comprehension:323 /// ```jsonnet324 /// ingredients: [325 /// { kind: kind, qty: 4 / 3 }326 /// for kind in [327 /// 'Honey Syrup',328 /// 'Lemon Juice',329 /// 'Farmers Gin',330 /// ]331 /// ],332 /// ```333 ArrComp(LocExpr, Vec<CompSpec>),334335 /// Object: {a: 2}336 Obj(ObjBody),337 /// Object extension: var1 {b: 2}338 ObjExtend(LocExpr, ObjBody),339340 /// (obj)341 Parened(LocExpr),342343 /// -2344 UnaryOp(UnaryOpType, LocExpr),345 /// 2 - 2346 BinaryOp(LocExpr, BinaryOpType, LocExpr),347 /// assert 2 == 2 : "Math is broken"348 AssertExpr(AssertStmt, LocExpr),349 /// local a = 2; { b: a }350 LocalExpr(Vec<BindSpec>, LocExpr),351352 /// import "hello"353 Import(IStr),354 /// importStr "file.txt"355 ImportStr(IStr),356 /// importBin "file.txt"357 ImportBin(IStr),358 /// error "I'm broken"359 ErrorStmt(LocExpr),360 /// a(b, c)361 Apply(LocExpr, ArgsDesc, bool),362 /// a[b]363 Index(LocExpr, LocExpr),364 /// function(x) x365 Function(ParamsDesc, LocExpr),366 /// if true == false then 1 else 2367 IfElse {368 cond: IfSpecData,369 cond_then: LocExpr,370 cond_else: Option<LocExpr>,371 },372 Slice(LocExpr, SliceDesc),373}374375/// file, begin offset, end offset376#[cfg_attr(feature = "structdump", derive(Codegen))]377#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]378#[derive(Clone, PartialEq, Eq, Trace)]379#[trace(skip)]380#[repr(C)]381pub struct ExprLocation(pub Source, pub u32, pub u32);382impl ExprLocation {383 pub fn belongs_to(&self, other: &ExprLocation) -> bool {384 other.0 == self.0 && other.1 <= self.1 && other.2 >= self.2385 }386}387388#[cfg(target_pointer_width = "64")]389static_assertions::assert_eq_size!(ExprLocation, [u8; 16]);390391impl Debug for ExprLocation {392 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {393 write!(f, "{:?}:{:?}-{:?}", self.0, self.1, self.2)394 }395}396397/// Holds AST expression and its location in source file398#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]399#[cfg_attr(feature = "structdump", derive(Codegen))]400#[derive(Clone, PartialEq, Trace)]401pub struct LocExpr(pub Rc<Expr>, pub ExprLocation);402403#[cfg(target_pointer_width = "64")]404static_assertions::assert_eq_size!(LocExpr, [u8; 24]);405406impl Debug for LocExpr {407 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {408 if f.alternate() {409 write!(f, "{:#?}", self.0)?;410 } else {411 write!(f, "{:?}", self.0)?;412 }413 write!(f, " from {:?}", self.1)?;414 Ok(())415 }416}1use std::{2 fmt::{self, Debug, Display},3 ops::Deref,4 rc::Rc,5};67use jrsonnet_gcmodule::Trace;8use jrsonnet_interner::IStr;9#[cfg(feature = "serde")]10use serde::{Deserialize, Serialize};11#[cfg(feature = "structdump")]12use structdump::Codegen;1314use crate::source::Source;1516#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]17#[cfg_attr(feature = "structdump", derive(Codegen))]18#[derive(Debug, PartialEq, Trace)]19pub enum FieldName {20 /// {fixed: 2}21 Fixed(IStr),22 /// {["dyn"+"amic"]: 3}23 Dyn(LocExpr),24}2526#[cfg_attr(feature = "structdump", derive(Codegen))]27#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]28#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]29pub enum Visibility {30 /// :31 Normal,32 /// ::33 Hidden,34 /// :::35 Unhide,36}3738impl Visibility {39 pub fn is_visible(&self) -> bool {40 matches!(self, Self::Normal | Self::Unhide)41 }42}4344#[cfg_attr(feature = "structdump", derive(Codegen))]45#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]46#[derive(Clone, Debug, PartialEq, Trace)]47pub struct AssertStmt(pub LocExpr, pub Option<LocExpr>);4849#[cfg_attr(feature = "structdump", derive(Codegen))]50#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]51#[derive(Debug, PartialEq, Trace)]52pub struct FieldMember {53 pub name: FieldName,54 pub plus: bool,55 pub params: Option<ParamsDesc>,56 pub visibility: Visibility,57 pub value: LocExpr,58}5960#[cfg_attr(feature = "structdump", derive(Codegen))]61#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]62#[derive(Debug, PartialEq, Trace)]63pub enum Member {64 Field(FieldMember),65 BindStmt(BindSpec),66 AssertStmt(AssertStmt),67}6869#[cfg_attr(feature = "structdump", derive(Codegen))]70#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]71#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]72pub enum UnaryOpType {73 Plus,74 Minus,75 BitNot,76 Not,77}7879impl Display for UnaryOpType {80 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {81 use UnaryOpType::*;82 write!(83 f,84 "{}",85 match self {86 Plus => "+",87 Minus => "-",88 BitNot => "~",89 Not => "!",90 }91 )92 }93}9495#[cfg_attr(feature = "structdump", derive(Codegen))]96#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]97#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]98pub enum BinaryOpType {99 Mul,100 Div,101102 /// Implemented as intrinsic, put here for completeness103 Mod,104105 Add,106 Sub,107108 Lhs,109 Rhs,110111 Lt,112 Gt,113 Lte,114 Gte,115116 BitAnd,117 BitOr,118 BitXor,119120 Eq,121 Neq,122123 And,124 Or,125126 // Equialent to std.objectHasEx(a, b, true)127 In,128}129130impl Display for BinaryOpType {131 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {132 use BinaryOpType::*;133 write!(134 f,135 "{}",136 match self {137 Mul => "*",138 Div => "/",139 Mod => "%",140 Add => "+",141 Sub => "-",142 Lhs => "<<",143 Rhs => ">>",144 Lt => "<",145 Gt => ">",146 Lte => "<=",147 Gte => ">=",148 BitAnd => "&",149 BitOr => "|",150 BitXor => "^",151 Eq => "==",152 Neq => "!=",153 And => "&&",154 Or => "||",155 In => "in",156 }157 )158 }159}160161/// name, default value162#[cfg_attr(feature = "structdump", derive(Codegen))]163#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]164#[derive(Debug, PartialEq, Trace)]165pub struct Param(pub Destruct, pub Option<LocExpr>);166167/// Defined function parameters168#[cfg_attr(feature = "structdump", derive(Codegen))]169#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]170#[derive(Debug, Clone, PartialEq, Trace)]171pub struct ParamsDesc(pub Rc<Vec<Param>>);172173impl Deref for ParamsDesc {174 type Target = Vec<Param>;175 fn deref(&self) -> &Self::Target {176 &self.0177 }178}179180#[cfg_attr(feature = "structdump", derive(Codegen))]181#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]182#[derive(Debug, PartialEq, Trace)]183pub struct ArgsDesc {184 pub unnamed: Vec<LocExpr>,185 pub named: Vec<(IStr, LocExpr)>,186}187impl ArgsDesc {188 pub fn new(unnamed: Vec<LocExpr>, named: Vec<(IStr, LocExpr)>) -> Self {189 Self { unnamed, named }190 }191}192193#[cfg_attr(feature = "structdump", derive(Codegen))]194#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]195#[derive(Debug, Clone, PartialEq, Eq, Trace)]196pub enum DestructRest {197 /// ...rest198 Keep(IStr),199 /// ...200 Drop,201}202203#[cfg_attr(feature = "structdump", derive(Codegen))]204#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]205#[derive(Debug, Clone, PartialEq, Trace)]206pub enum Destruct {207 Full(IStr),208 #[cfg(feature = "exp-destruct")]209 Skip,210 #[cfg(feature = "exp-destruct")]211 Array {212 start: Vec<Destruct>,213 rest: Option<DestructRest>,214 end: Vec<Destruct>,215 },216 #[cfg(feature = "exp-destruct")]217 Object {218 fields: Vec<(IStr, Option<Destruct>, Option<LocExpr>)>,219 rest: Option<DestructRest>,220 },221}222impl Destruct {223 /// Name of destructure, used for function parameter names224 pub fn name(&self) -> Option<IStr> {225 match self {226 Self::Full(name) => Some(name.clone()),227 #[cfg(feature = "exp-destruct")]228 _ => None,229 }230 }231}232233#[cfg_attr(feature = "structdump", derive(Codegen))]234#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]235#[derive(Debug, Clone, PartialEq, Trace)]236pub enum BindSpec {237 Field {238 into: Destruct,239 value: LocExpr,240 },241 Function {242 name: IStr,243 params: ParamsDesc,244 value: LocExpr,245 },246}247248#[cfg_attr(feature = "structdump", derive(Codegen))]249#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]250#[derive(Debug, PartialEq, Trace)]251pub struct IfSpecData(pub LocExpr);252253#[cfg_attr(feature = "structdump", derive(Codegen))]254#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]255#[derive(Debug, PartialEq, Trace)]256pub struct ForSpecData(pub IStr, pub LocExpr);257258#[cfg_attr(feature = "structdump", derive(Codegen))]259#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]260#[derive(Debug, PartialEq, Trace)]261pub enum CompSpec {262 IfSpec(IfSpecData),263 ForSpec(ForSpecData),264}265266#[cfg_attr(feature = "structdump", derive(Codegen))]267#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]268#[derive(Debug, PartialEq, Trace)]269pub struct ObjComp {270 pub pre_locals: Vec<BindSpec>,271 pub key: LocExpr,272 pub plus: bool,273 pub value: LocExpr,274 pub post_locals: Vec<BindSpec>,275 pub compspecs: Vec<CompSpec>,276}277278#[cfg_attr(feature = "structdump", derive(Codegen))]279#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]280#[derive(Debug, PartialEq, Trace)]281pub enum ObjBody {282 MemberList(Vec<Member>),283 ObjComp(ObjComp),284}285286#[cfg_attr(feature = "structdump", derive(Codegen))]287#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]288#[derive(Debug, PartialEq, Eq, Clone, Copy, Trace)]289pub enum LiteralType {290 This,291 Super,292 Dollar,293 Null,294 True,295 False,296}297298#[cfg_attr(feature = "structdump", derive(Codegen))]299#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]300#[derive(Debug, PartialEq, Trace)]301pub struct SliceDesc {302 pub start: Option<LocExpr>,303 pub end: Option<LocExpr>,304 pub step: Option<LocExpr>,305}306307/// Syntax base308#[cfg_attr(feature = "structdump", derive(Codegen))]309#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]310#[derive(Debug, PartialEq, Trace)]311pub enum Expr {312 Literal(LiteralType),313314 /// String value: "hello"315 Str(IStr),316 /// Number: 1, 2.0, 2e+20317 Num(f64),318 /// Variable name: test319 Var(IStr),320321 /// Array of expressions: [1, 2, "Hello"]322 Arr(Vec<LocExpr>),323 /// Array comprehension:324 /// ```jsonnet325 /// ingredients: [326 /// { kind: kind, qty: 4 / 3 }327 /// for kind in [328 /// 'Honey Syrup',329 /// 'Lemon Juice',330 /// 'Farmers Gin',331 /// ]332 /// ],333 /// ```334 ArrComp(LocExpr, Vec<CompSpec>),335336 /// Object: {a: 2}337 Obj(ObjBody),338 /// Object extension: var1 {b: 2}339 ObjExtend(LocExpr, ObjBody),340341 /// (obj)342 Parened(LocExpr),343344 /// -2345 UnaryOp(UnaryOpType, LocExpr),346 /// 2 - 2347 BinaryOp(LocExpr, BinaryOpType, LocExpr),348 /// assert 2 == 2 : "Math is broken"349 AssertExpr(AssertStmt, LocExpr),350 /// local a = 2; { b: a }351 LocalExpr(Vec<BindSpec>, LocExpr),352353 /// import "hello"354 Import(IStr),355 /// importStr "file.txt"356 ImportStr(IStr),357 /// importBin "file.txt"358 ImportBin(IStr),359 /// error "I'm broken"360 ErrorStmt(LocExpr),361 /// a(b, c)362 Apply(LocExpr, ArgsDesc, bool),363 /// a[b]364 Index(LocExpr, LocExpr),365 /// function(x) x366 Function(ParamsDesc, LocExpr),367 /// if true == false then 1 else 2368 IfElse {369 cond: IfSpecData,370 cond_then: LocExpr,371 cond_else: Option<LocExpr>,372 },373 Slice(LocExpr, SliceDesc),374}375376/// file, begin offset, end offset377#[cfg_attr(feature = "structdump", derive(Codegen))]378#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]379#[derive(Clone, PartialEq, Eq, Trace)]380#[trace(skip)]381#[repr(C)]382pub struct ExprLocation(pub Source, pub u32, pub u32);383impl ExprLocation {384 pub fn belongs_to(&self, other: &ExprLocation) -> bool {385 other.0 == self.0 && other.1 <= self.1 && other.2 >= self.2386 }387}388389#[cfg(target_pointer_width = "64")]390static_assertions::assert_eq_size!(ExprLocation, [u8; 16]);391392impl Debug for ExprLocation {393 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {394 write!(f, "{:?}:{:?}-{:?}", self.0, self.1, self.2)395 }396}397398/// Holds AST expression and its location in source file399#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]400#[cfg_attr(feature = "structdump", derive(Codegen))]401#[derive(Clone, PartialEq, Trace)]402pub struct LocExpr(pub Rc<Expr>, pub ExprLocation);403404#[cfg(target_pointer_width = "64")]405static_assertions::assert_eq_size!(LocExpr, [u8; 24]);406407impl Debug for LocExpr {408 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {409 if f.alternate() {410 write!(f, "{:#?}", self.0)?;411 } else {412 write!(f, "{:?}", self.0)?;413 }414 write!(f, " from {:?}", self.1)?;415 Ok(())416 }417}crates/jrsonnet-stdlib/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-stdlib/Cargo.toml
+++ b/crates/jrsonnet-stdlib/Cargo.toml
@@ -30,7 +30,7 @@
# std.md5
md5 = "0.7.0"
# std.base64
-base64 = "0.13.0"
+base64 = "0.13.1"
# std.parseJson
serde_json = "1.0"
# std.parseYaml, custom library fork is used for C++/golang compatibility
crates/jrsonnet-types/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-types/Cargo.toml
+++ b/crates/jrsonnet-types/Cargo.toml
@@ -9,4 +9,4 @@
[dependencies]
jrsonnet-gcmodule = { version = "0.3.4" }
-peg = "0.8.0"
+peg = "0.8.1"