Skip to content

Commit

Permalink
Updated yaml-rust to use yaml-rust2 due to deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
tkmcmaster committed Jun 3, 2024
1 parent 3cf8241 commit b9c4991
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 26 deletions.
54 changes: 41 additions & 13 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion lib/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ regex = "1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
unicode-segmentation = "1"
yaml-rust = "0.4"
yaml-rust2 = "0.8"
zip_all = { path = "../zip_all" }
js-sys = "0.3"
log = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion lib/config/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{error::Error as StdError, fmt};

use serde_json as json;
use yaml_rust::scanner::{Marker, ScanError};
use yaml_rust2::scanner::{Marker, ScanError};

type PestError = pest::error::Error<crate::select_parser::Rule>;

Expand Down
2 changes: 1 addition & 1 deletion lib/config/src/expression_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rand::distributions::{Distribution, Uniform};
use regex::Regex;
use serde_json as json;
use unicode_segmentation::UnicodeSegmentation;
use yaml_rust::scanner::Marker;
use yaml_rust2::scanner::Marker;
use zip_all::zip_all;

use std::{
Expand Down
21 changes: 14 additions & 7 deletions lib/config/src/from_yaml.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::error::Error;

use serde_json as json;
use yaml_rust::{
use yaml_rust2::{
parser::Parser as YamlParser,
scanner::{Marker, TScalarStyle, TokenType},
parser::Tag as YamlTag,
scanner::{Marker, TScalarStyle},
Event as YamlParseEvent,
};

Expand Down Expand Up @@ -265,7 +266,7 @@ impl<I: Iterator<Item = char>> YamlDecoder<I> {
}
continue;
}
let (event, marker) = self.parser.next()?;
let (event, marker) = self.parser.next_token()?;
let in_reference = !self.reference_stack.is_empty();
let (alias_id, event) = match event {
Nothing | StreamStart | DocumentStart => continue,
Expand All @@ -280,16 +281,21 @@ impl<I: Iterator<Item = char>> YamlDecoder<I> {
continue;
}
Scalar(s, style, alias_id, tag) => {
let tag = if let Some(TokenType::Tag(a, b)) = tag {
// Switching from the unmaintained yaml-rust to yaml-rust2 converts the TokenType::Tag Tuple to a Tag struct
let tag = if let Some(YamlTag {
handle: a,
suffix: b,
}) = tag
{
Some((a, b))
} else {
None
};
(alias_id, YamlEvent::Scalar(s, style, tag))
}
MappingStart(alias_id) => (alias_id, YamlEvent::MappingStart),
MappingStart(alias_id, _) => (alias_id, YamlEvent::MappingStart),
MappingEnd => (0, YamlEvent::MappingEnd),
SequenceStart(alias_id) => (alias_id, YamlEvent::SequenceStart),
SequenceStart(alias_id, _) => (alias_id, YamlEvent::SequenceStart),
SequenceEnd => (0, YamlEvent::SequenceEnd),
};
if in_reference || alias_id > 0 {
Expand Down Expand Up @@ -483,7 +489,8 @@ impl<T: FromYaml> FromYaml for Nullable<T> {
let marker = *marker;
let is_null = match event {
YamlEvent::Scalar(_, _, Some((bang_bang, null)))
if bang_bang == "!!" && null == "null" =>
// Switching from the unmaintained yaml-rust to yaml-rust2 converts the '!!' to 'tag:yaml.org,2002:'
if (bang_bang == "!!" || bang_bang == "tag:yaml.org,2002:") && null == "null" =>
{
true
}
Expand Down
2 changes: 1 addition & 1 deletion lib/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub use select_parser::{
};
use serde::Serialize;
use serde_json as json;
use yaml_rust::scanner::{Marker, Scanner};
use yaml_rust2::scanner::{Marker, Scanner};

use log::{debug, error, LevelFilter};
use std::{
Expand Down
4 changes: 2 additions & 2 deletions lib/config/src/select_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use pest::{
};
use pest_derive::Parser;
use serde_json as json;
use yaml_rust::scanner::Marker;
use yaml_rust2::scanner::Marker;
use zip_all::zip_all;

use std::{
Expand Down Expand Up @@ -1237,7 +1237,7 @@ impl Template {

// #[cfg(test)]
pub fn simple(t: &str) -> Template {
let s = yaml_rust::scanner::Scanner::new("".chars());
let s = yaml_rust2::scanner::Scanner::new("".chars());
let marker = s.mark();
Template::new(
t,
Expand Down

0 comments on commit b9c4991

Please sign in to comment.