Skip to content

Commit

Permalink
chore: update winnow to 0.6+ and vecmap-rs to 0.2+ (#324)
Browse files Browse the repository at this point in the history
* update winnow to 0.6+ and vecmap-rs to 0.2+

* fix clippy warnings
  • Loading branch information
gruebel committed Apr 8, 2024
1 parent 9dedb62 commit 9b5a4a3
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 47 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions crates/hcl-edit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ default = []
perf = ["hcl-primitives/perf"]

[dependencies]
fnv = "1.0.7"
fnv = "1.0"
hcl-primitives = { version = "0.1.2", path = "../hcl-primitives" }
vecmap-rs = "0.1.12"
winnow = "0.5.15"
vecmap-rs = "0.2"
winnow = "0.6"

[dev-dependencies]
indoc = "2.0"
pretty_assertions = "1.4.0"
pretty_assertions = "1.4"
testdata = { path = "../testdata" }

[[example]]
Expand Down
37 changes: 19 additions & 18 deletions crates/hcl-edit/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use crate::{Decorate, Decorated, Formatted, Ident, RawString, SetSpan, Spanned};
use std::cell::RefCell;
use winnow::ascii::{crlf, dec_uint, line_ending, newline, space0};
use winnow::combinator::{
alt, cut_err, delimited, fail, not, opt, peek, preceded, repeat, separated0, separated1,
separated_pair, success, terminated,
alt, cut_err, delimited, empty, fail, not, opt, peek, preceded, repeat, separated,
separated_pair, terminated,
};
use winnow::token::{any, none_of, one_of, take};

Expand Down Expand Up @@ -56,7 +56,7 @@ fn expr_inner<'i, 's>(
// `//` and `/*` are comment starts. Do not mistakenly parse a `/` as binary
// division operator.
Ok(b"//" | b"/*" | b"..") => {
input.reset(checkpoint);
input.reset(&checkpoint);
return Ok(());
}
// Traversal operator.
Expand Down Expand Up @@ -86,7 +86,7 @@ fn expr_inner<'i, 's>(
}
// None of the above matched or we hit the end of input.
_ => {
input.reset(checkpoint);
input.reset(&checkpoint);
return Ok(());
}
}
Expand Down Expand Up @@ -236,8 +236,8 @@ fn unary_op<'i, 's>(

fn unary_operator(input: &mut Input) -> PResult<UnaryOperator> {
dispatch! {any;
b'-' => success(UnaryOperator::Neg),
b'!' => success(UnaryOperator::Not),
b'-' => empty.value(UnaryOperator::Neg),
b'!' => empty.value(UnaryOperator::Not),
_ => fail,
}
.parse_next(input)
Expand All @@ -262,17 +262,17 @@ fn binary_operator(input: &mut Input) -> PResult<BinaryOperator> {
b'!' => b'='.value(BinaryOperator::NotEq),
b'<' => alt((
b'='.value(BinaryOperator::LessEq),
success(BinaryOperator::Less),
empty.value(BinaryOperator::Less),
)),
b'>' => alt((
b'='.value(BinaryOperator::GreaterEq),
success(BinaryOperator::Greater),
empty.value(BinaryOperator::Greater),
)),
b'+' => success(BinaryOperator::Plus),
b'-' => success(BinaryOperator::Minus),
b'*' => success(BinaryOperator::Mul),
b'/' => success(BinaryOperator::Div),
b'%' => success(BinaryOperator::Mod),
b'+' => empty.value(BinaryOperator::Plus),
b'-' => empty.value(BinaryOperator::Minus),
b'*' => empty.value(BinaryOperator::Mul),
b'/' => empty.value(BinaryOperator::Div),
b'%' => empty.value(BinaryOperator::Mod),
b'&' => b'&'.value(BinaryOperator::And),
b'|' => b'|'.value(BinaryOperator::Or),
_ => fail,
Expand Down Expand Up @@ -327,7 +327,7 @@ fn array_items<'i, 's>(
state: &'s RefCell<ExprParseState>,
) -> impl Parser<Input<'i>, (), ContextError> + 's {
move |input: &mut Input<'i>| {
let values = separated0(decorated(ws, preceded(not(b']'), expr), ws), b',');
let values = separated(0.., decorated(ws, preceded(not(b']'), expr), ws), b',');

(values, opt(b','), raw_string(ws))
.map(|(values, comma, trailing)| {
Expand Down Expand Up @@ -489,8 +489,8 @@ fn object_value(input: &mut Input) -> PResult<ObjectValue> {

fn object_value_assignment(input: &mut Input) -> PResult<ObjectValueAssignment> {
dispatch! {any;
b'=' => success(ObjectValueAssignment::Equals),
b':' => success(ObjectValueAssignment::Colon),
b'=' => empty.value(ObjectValueAssignment::Equals),
b':' => empty.value(ObjectValueAssignment::Colon),
_ => cut_err(fail)
.context(StrContext::Label("object value assignment"))
.context(StrContext::Expected(StrContextValue::CharLiteral('=')))
Expand Down Expand Up @@ -644,13 +644,14 @@ fn func_args(input: &mut Input) -> PResult<FuncArgs> {
Ellipsis,
}

let args = separated1(
let args = separated(
1..,
decorated(ws, preceded(peek(none_of(b",.)")), expr), ws),
b',',
);

let trailer = dispatch! {any;
b',' => success(Trailer::Comma),
b',' => empty.value(Trailer::Comma),
b'.' => cut_tag("..").value(Trailer::Ellipsis),
_ => fail,
};
Expand Down
24 changes: 12 additions & 12 deletions crates/hcl-edit/src/parser/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::trivia::void;
use crate::{Decorated, Ident, RawString};

use std::borrow::Cow;
use winnow::combinator::{alt, cut_err, delimited, fail, not, opt, preceded, repeat, success};
use winnow::combinator::{alt, cut_err, delimited, empty, fail, not, opt, preceded, repeat};
use winnow::stream::AsChar;
use winnow::token::{any, one_of, take, take_while};

Expand Down Expand Up @@ -102,7 +102,7 @@ where
/// interpolation/directive start markers.
fn string_literal<'a>(input: &mut Input<'a>) -> PResult<&'a str> {
let literal_end = dispatch! {any;
b'\"' | b'\\' => success(true),
b'\"' | b'\\' => empty.value(true),
b'$' | b'%' => b'{'.value(true),
_ => fail,
};
Expand All @@ -124,8 +124,8 @@ where
/// Parse an escaped start marker for a template interpolation or directive.
fn escaped_marker(input: &mut Input) -> PResult<EscapedMarker> {
dispatch! {take::<_, Input, _>(3usize);
b"$${" => success(EscapedMarker::Interpolation),
b"%%{" => success(EscapedMarker::Directive),
b"$${" => empty.value(EscapedMarker::Interpolation),
b"%%{" => empty.value(EscapedMarker::Directive),
_ => fail,
}
.parse_next(input)
Expand All @@ -136,14 +136,14 @@ fn escaped_char(input: &mut Input) -> PResult<char> {
b'\\'.parse_next(input)?;

dispatch! {any;
b'n' => success('\n'),
b'r' => success('\r'),
b't' => success('\t'),
b'\\' => success('\\'),
b'"' => success('"'),
b'/' => success('/'),
b'b' => success('\u{08}'),
b'f' => success('\u{0C}'),
b'n' => empty.value('\n'),
b'r' => empty.value('\r'),
b't' => empty.value('\t'),
b'\\' => empty.value('\\'),
b'"' => empty.value('"'),
b'/' => empty.value('/'),
b'b' => empty.value('\u{08}'),
b'f' => empty.value('\u{0C}'),
b'u' => cut_err(hexescape::<4>)
.context(StrContext::Label("unicode 4-digit hex code")),
b'U' => cut_err(hexescape::<8>)
Expand Down
2 changes: 1 addition & 1 deletion crates/hcl-edit/src/parser/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn structure<'i, 's>(
let mut structure = match peek(any).parse_next(input)? {
b'=' => {
if state.borrow_mut().is_redefined(ident) {
input.reset(checkpoint);
input.reset(&checkpoint);
return cut_err(fail)
.context(StrContext::Label("attribute"))
.context(StrContext::Expected(StrContextValue::Description(
Expand Down
10 changes: 5 additions & 5 deletions crates/hcl-edit/src/parser/trivia.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::prelude::*;

use winnow::ascii::{multispace0, not_line_ending, space0};
use winnow::ascii::{multispace0, space0, till_line_ending};
use winnow::combinator::{alt, delimited, fail, peek, preceded, repeat};
use winnow::token::{any, take_until0};
use winnow::token::{any, take_until};

pub(super) fn ws(input: &mut Input) -> PResult<()> {
(
Expand Down Expand Up @@ -41,15 +41,15 @@ pub(super) fn line_comment(input: &mut Input) -> PResult<()> {
}

fn hash_line_comment(input: &mut Input) -> PResult<()> {
preceded(b'#', not_line_ending).void().parse_next(input)
preceded(b'#', till_line_ending).void().parse_next(input)
}

fn double_slash_line_comment(input: &mut Input) -> PResult<()> {
preceded(b"//", not_line_ending).void().parse_next(input)
preceded(b"//", till_line_ending).void().parse_next(input)
}

fn inline_comment(input: &mut Input) -> PResult<()> {
delimited(b"/*", take_until0("*/"), b"*/")
delimited(b"/*", take_until(0.., "*/"), b"*/")
.void()
.parse_next(input)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hcl-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ itoa = "1.0.9"
hcl-edit = { version = "0.7.5", path = "../hcl-edit" }
hcl-primitives = { version = "0.1.2", path = "../hcl-primitives", features = ["serde"] }
serde = { version = "1.0.188", features = ["derive"] }
vecmap-rs = { version = "0.1.12", features = ["serde"] }
vecmap-rs = { version = "0.2", features = ["serde"] }

[dev-dependencies]
indoc = "2.0"
Expand Down
1 change: 1 addition & 0 deletions crates/hcl-rs/src/eval/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ pub(super) struct Collection<'a> {
key_var: Option<&'a Identifier>,
value_var: &'a Identifier,
cond_expr: Option<&'a Expression>,
#[allow(clippy::struct_field_names)]
collection: Vec<(Value, Value)>,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/hcl-rs/src/eval/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl Evaluate for TemplateExpr {
// spec:
//
// https://github.com/hashicorp/hcl/blob/main/hclsyntax/spec.md#template-interpolation-unwrapping
match elements.get(0) {
match elements.first() {
Some(Element::Interpolation(interp)) if elements.len() == 1 => {
interp.expr.evaluate(ctx)
}
Expand Down
1 change: 1 addition & 0 deletions crates/hcl-rs/src/expr/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ impl<'de> de::MapAccess<'de> for FuncCallAccess {
}
}

#[allow(clippy::struct_field_names)]
pub struct ConditionalAccess {
cond_expr: Option<Expression>,
true_expr: Option<Expression>,
Expand Down
2 changes: 1 addition & 1 deletion crates/hcl-rs/src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
pub use crate::expr::to_expression;

thread_local! {
static INTERNAL_SERIALIZATION: AtomicBool = AtomicBool::new(false);
static INTERNAL_SERIALIZATION: AtomicBool = const { AtomicBool::new(false) };
}

pub(crate) fn in_internal_serialization() -> bool {
Expand Down

0 comments on commit 9b5a4a3

Please sign in to comment.