Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: *stripChars builtins #162

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[tests/golden/*.jsonnet.golden]
generated_code = true
indent_style = space
indent_size = 4
insert_final_newline = false
79 changes: 49 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 15 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ serde_json = "1.0.114"
serde_yaml_with_quirks = "0.8.24"

# Error handling
anyhow = "1.0.80"
thiserror = "1.0"
anyhow = "1.0.83"
thiserror = "1.0.60"

# Code formatting
dprint-core = "0.65.0"
Expand All @@ -63,37 +63,39 @@ bincode = "1.3"
# Source code parsing.
# Jrsonnet has two parsers for jsonnet - one is for execution, and another is for better parsing diagnostics/lints/LSP.
# First (and fast one) is based on peg, second is based on rowan.
peg = "0.8.2"
peg = "0.8.3"
logos = "0.14.0"
ungrammar = "1.16.1"
rowan = "0.15"
rowan = "0.15.15"

mimallocator = "0.1.3"
indoc = "2.0"
insta = "1.35"
insta = "1.39"
tempfile = "3.10"
pathdiff = "0.2.1"
hashbrown = "0.14.3"
hashbrown = "0.14.5"
static_assertions = "1.1"
rustc-hash = "1.1"
num-bigint = "0.4.4"
num-bigint = "0.4.5"
derivative = "2.2.0"
strsim = "0.11.0"
structdump = "0.2.0"
proc-macro2 = "1.0"
quote = "1.0"
syn = "2.0"
drop_bomb = "0.1.5"
base64 = "0.21.7"
base64 = "0.22.1"
indexmap = "2.2.3"
itertools = "0.12.1"
xshell = "0.2.5"
itertools = "0.13.0"
xshell = "0.2.6"

lsp-server = "0.7.6"
lsp-types = "0.95.0"
lsp-types = "0.96.0"

regex = "1.10.3"
lru = "0.12.2"
regex = "1.10"
lru = "0.12.3"

json-structural-diff = "0.1.0"

[workspace.lints.rust]
unsafe_op_in_unsafe_fn = "deny"
Expand Down
2 changes: 1 addition & 1 deletion crates/jrsonnet-evaluator/src/arr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub use spec::{ArrayLike, *};

/// Represents a Jsonnet array value.
#[derive(Debug, Clone, Trace)]
// may contrain other ArrValue
// may contain other ArrValue
#[trace(tracking(force))]
pub struct ArrValue(Cc<TraceBox<dyn ArrayLike>>);

Expand Down
7 changes: 7 additions & 0 deletions crates/jrsonnet-evaluator/src/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ pub enum IndexableVal {
Arr(ArrValue),
}
impl IndexableVal {
pub fn is_empty(&self) -> bool {
match self {
Self::Str(s) => s.is_empty(),
Self::Arr(s) => s.is_empty(),
}
}

pub fn to_array(self) -> ArrValue {
match self {
Self::Str(s) => ArrValue::chars(s.chars()),
Expand Down
3 changes: 3 additions & 0 deletions crates/jrsonnet-stdlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ pub fn stdlib_uncached(settings: Rc<RefCell<Settings>>) -> ObjValue {
("parseOctal", builtin_parse_octal::INST),
("parseHex", builtin_parse_hex::INST),
("stringChars", builtin_string_chars::INST),
("lstripChars", builtin_lstrip_chars::INST),
("rstripChars", builtin_rstrip_chars::INST),
("stripChars", builtin_strip_chars::INST),
// Misc
("length", builtin_length::INST),
("get", builtin_get::INST),
Expand Down
16 changes: 0 additions & 16 deletions crates/jrsonnet-stdlib/src/std.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,6 @@

thisFile:: error 'std.thisFile is deprecated, to enable its support in jrsonnet - recompile it with "legacy-this-file" support.\nThis will slow down stdlib caching a bit, though',

lstripChars(str, chars)::
if std.length(str) > 0 && std.member(chars, str[0]) then
std.lstripChars(str[1:], chars)
else
str,

rstripChars(str, chars)::
local len = std.length(str);
if len > 0 && std.member(chars, str[len - 1]) then
std.rstripChars(str[:len - 1], chars)
else
str,

stripChars(str, chars)::
std.lstripChars(std.rstripChars(str, chars), chars),

mapWithIndex(func, arr)::
if !std.isFunction(func) then
error ('std.mapWithIndex first param must be function, got ' + std.type(func))
Expand Down
Loading