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

Evaluate yaml-rust2 #2001

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
43 changes: 43 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ toml = "0.8"
typed-arena = "2.0.2"
unicode-segmentation = "1.10.1"
void = "1"
yaml-rust2 = "0.8.1"

metrics = "0.21"
metrics-util = "0.15"
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ sha2.workspace = true
md-5.workspace = true
unicode-segmentation.workspace = true
indoc.workspace = true
yaml-rust2.workspace = true

termimad = { workspace = true, optional = true }
ansi_term = { workspace = true, optional = true }
Expand Down
36 changes: 2 additions & 34 deletions core/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,40 +540,8 @@ impl Cache {
.map(|t| (attach_pos(t), ParseErrors::default()))
.map_err(|err| ParseError::from_serde_json(err, file_id, &self.files)),
InputFormat::Yaml => {
// YAML files can contain multiple documents. If there is only
// one we transparently deserialize it. If there are multiple,
// we deserialize the file as an array.
let de = serde_yaml::Deserializer::from_str(self.files.source(file_id));
let mut terms = de
.map(|de| {
RichTerm::deserialize(de)
.map(attach_pos)
.map_err(|err| (ParseError::from_serde_yaml(err, file_id)))
})
.collect::<Result<Vec<_>, _>>()?;

if terms.is_empty() {
unreachable!(
"serde always produces at least one document, \
the empty string turns into `null`"
)
} else if terms.len() == 1 {
Ok((
terms.pop().expect("we just checked the length"),
ParseErrors::default(),
))
} else {
Ok((
attach_pos(
Term::Array(
Array::new(Rc::from(terms.into_boxed_slice())),
Default::default(),
)
.into(),
),
ParseErrors::default(),
))
}
let rt = crate::yaml::load(self.files.source(file_id), file_id).unwrap();
Ok((rt, ParseErrors::default()))
}
InputFormat::Toml => {
crate::serialize::toml_deser::from_str(self.files.source(file_id), file_id)
Expand Down
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub mod term;
pub mod transform;
pub mod typ;
pub mod typecheck;
pub mod yaml;

pub(crate) mod metrics;

Expand Down
Loading
Loading