Code cleanup after monorepo-ing.
This commit is contained in:
parent
8ee4921e5e
commit
59048f68ae
6 changed files with 29 additions and 34 deletions
|
@ -1,2 +1 @@
|
|||
|
||||
|
||||
|
|
|
@ -39,6 +39,6 @@ mod input;
|
|||
mod parser;
|
||||
mod scanner;
|
||||
|
||||
pub use crate::input::BufferedInput;
|
||||
pub use crate::input::{BufferedInput, Input};
|
||||
pub use crate::parser::{Event, EventReceiver, Parser, SpannedEventReceiver, Tag};
|
||||
pub use crate::scanner::{Marker, ScanError, Span, TScalarStyle};
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::fs::{self, DirEntry};
|
|||
|
||||
use libtest_mimic::{run_tests, Arguments, Outcome, Test};
|
||||
|
||||
use saphyr::{yaml, Yaml, YamlLoader};
|
||||
use saphyr::{Hash, Yaml};
|
||||
use saphyr_parser::{Event, EventReceiver, Parser, ScanError, TScalarStyle, Tag};
|
||||
|
||||
type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>;
|
||||
|
@ -77,11 +77,11 @@ fn load_tests_from_file(entry: &DirEntry) -> Result<Vec<Test<YamlTest>>> {
|
|||
let test_name = file_name
|
||||
.strip_suffix(".yaml")
|
||||
.ok_or("unexpected filename")?;
|
||||
let tests = YamlLoader::load_from_str(&fs::read_to_string(entry.path())?)?;
|
||||
let tests = Yaml::load_from_str(&fs::read_to_string(entry.path())?)?;
|
||||
let tests = tests[0].as_vec().ok_or("no test list found in file")?;
|
||||
|
||||
let mut result = vec![];
|
||||
let mut current_test = yaml::Hash::new();
|
||||
let mut current_test = Hash::new();
|
||||
for (idx, test_data) in tests.iter().enumerate() {
|
||||
let name = if tests.len() > 1 {
|
||||
format!("{test_name}-{idx:02}")
|
||||
|
|
|
@ -3,21 +3,21 @@
|
|||
//! This is set aside so as to not clutter `annotated.rs`.
|
||||
|
||||
use hashlink::LinkedHashMap;
|
||||
use saphyr_parser::{Marker, Parser, ScanError};
|
||||
use saphyr_parser::{BufferedInput, Input, Parser, ScanError, Span};
|
||||
|
||||
use crate::{LoadableYamlNode, Yaml, YamlData, YamlLoader};
|
||||
|
||||
/// A YAML node with [`Marker`]s pointing to the start of the node.
|
||||
/// A YAML node with [`Span`]s pointing to the start of the node.
|
||||
///
|
||||
/// This structure does not implement functions to operate on the YAML object. To access those,
|
||||
/// refer to the [`Self::data`] field.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MarkedYaml {
|
||||
/// The marker pointing to the start of the node.
|
||||
/// The span indicating where in the input stream the object is.
|
||||
///
|
||||
/// The marker is relative to the start of the input stream that was given to the parser, not
|
||||
/// The markers are relative to the start of the input stream that was given to the parser, not
|
||||
/// to the start of the document within the input stream.
|
||||
pub marker: Marker,
|
||||
pub span: Span,
|
||||
/// The YAML contents of the node.
|
||||
pub data: YamlData<MarkedYaml>,
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ impl MarkedYaml {
|
|||
///
|
||||
/// [`load_from_str`]: `Yaml::load_from_str`
|
||||
pub fn load_from_iter<I: Iterator<Item = char>>(source: I) -> Result<Vec<Self>, ScanError> {
|
||||
let mut parser = Parser::new(source);
|
||||
let mut parser = Parser::new(BufferedInput::new(source));
|
||||
Self::load_from_parser(&mut parser)
|
||||
}
|
||||
|
||||
|
@ -56,9 +56,7 @@ impl MarkedYaml {
|
|||
/// Returns `ScanError` when loading fails.
|
||||
///
|
||||
/// [`load_from_str`]: `Yaml::load_from_str`
|
||||
pub fn load_from_parser<I: Iterator<Item = char>>(
|
||||
parser: &mut Parser<I>,
|
||||
) -> Result<Vec<Self>, ScanError> {
|
||||
pub fn load_from_parser<I: Input>(parser: &mut Parser<I>) -> Result<Vec<Self>, ScanError> {
|
||||
let mut loader = YamlLoader::<Self>::default();
|
||||
parser.load(&mut loader, true)?;
|
||||
Ok(loader.into_documents())
|
||||
|
@ -83,7 +81,7 @@ impl std::hash::Hash for MarkedYaml {
|
|||
impl From<YamlData<MarkedYaml>> for MarkedYaml {
|
||||
fn from(value: YamlData<MarkedYaml>) -> Self {
|
||||
Self {
|
||||
marker: Marker::default(),
|
||||
span: Span::default(),
|
||||
data: value,
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +90,7 @@ impl From<YamlData<MarkedYaml>> for MarkedYaml {
|
|||
impl LoadableYamlNode for MarkedYaml {
|
||||
fn from_bare_yaml(yaml: Yaml) -> Self {
|
||||
Self {
|
||||
marker: Marker::default(),
|
||||
span: Span::default(),
|
||||
data: match yaml {
|
||||
Yaml::Real(x) => YamlData::Real(x),
|
||||
Yaml::Integer(x) => YamlData::Integer(x),
|
||||
|
@ -138,15 +136,15 @@ impl LoadableYamlNode for MarkedYaml {
|
|||
|
||||
fn take(&mut self) -> Self {
|
||||
let mut taken_out = MarkedYaml {
|
||||
marker: Marker::default(),
|
||||
span: Span::default(),
|
||||
data: YamlData::BadValue,
|
||||
};
|
||||
std::mem::swap(&mut taken_out, self);
|
||||
taken_out
|
||||
}
|
||||
|
||||
fn with_marker(mut self, marker: Marker) -> Self {
|
||||
self.marker = marker;
|
||||
fn with_span(mut self, span: Span) -> Self {
|
||||
self.span = span;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use std::{collections::BTreeMap, sync::Arc};
|
||||
|
||||
use hashlink::LinkedHashMap;
|
||||
use saphyr_parser::{Event, MarkedEventReceiver, Marker, ScanError, TScalarStyle, Tag};
|
||||
use saphyr_parser::{Event, ScanError, Span, SpannedEventReceiver, TScalarStyle, Tag};
|
||||
|
||||
use crate::{Hash, Yaml};
|
||||
|
||||
|
@ -43,13 +43,13 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<Node> MarkedEventReceiver for YamlLoader<Node>
|
||||
impl<Node> SpannedEventReceiver for YamlLoader<Node>
|
||||
where
|
||||
Node: LoadableYamlNode,
|
||||
{
|
||||
fn on_event(&mut self, ev: Event, marker: Marker) {
|
||||
fn on_event(&mut self, ev: Event, span: Span) {
|
||||
match ev {
|
||||
Event::DocumentStart | Event::Nothing | Event::StreamStart | Event::StreamEnd => {
|
||||
Event::DocumentStart(_) | Event::Nothing | Event::StreamStart | Event::StreamEnd => {
|
||||
// do nothing
|
||||
}
|
||||
Event::DocumentEnd => {
|
||||
|
@ -57,14 +57,14 @@ where
|
|||
// empty document
|
||||
0 => self
|
||||
.docs
|
||||
.push(Node::from_bare_yaml(Yaml::BadValue).with_marker(marker)),
|
||||
.push(Node::from_bare_yaml(Yaml::BadValue).with_span(span)),
|
||||
1 => self.docs.push(self.doc_stack.pop().unwrap().0),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
Event::SequenceStart(aid, _) => {
|
||||
self.doc_stack.push((
|
||||
Node::from_bare_yaml(Yaml::Array(Vec::new())).with_marker(marker),
|
||||
Node::from_bare_yaml(Yaml::Array(Vec::new())).with_span(span),
|
||||
aid,
|
||||
));
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ where
|
|||
}
|
||||
Event::MappingStart(aid, _) => {
|
||||
self.doc_stack.push((
|
||||
Node::from_bare_yaml(Yaml::Hash(Hash::new())).with_marker(marker),
|
||||
Node::from_bare_yaml(Yaml::Hash(Hash::new())).with_span(span),
|
||||
aid,
|
||||
));
|
||||
self.key_stack.push(Node::from_bare_yaml(Yaml::BadValue));
|
||||
|
@ -122,14 +122,14 @@ where
|
|||
// Datatype is not specified, or unrecognized
|
||||
Yaml::from_str(&v)
|
||||
};
|
||||
self.insert_new_node((Node::from_bare_yaml(node).with_marker(marker), aid));
|
||||
self.insert_new_node((Node::from_bare_yaml(node).with_span(span), aid));
|
||||
}
|
||||
Event::Alias(id) => {
|
||||
let n = match self.anchor_map.get(&id) {
|
||||
Some(v) => v.clone(),
|
||||
None => Node::from_bare_yaml(Yaml::BadValue),
|
||||
};
|
||||
self.insert_new_node((n.with_marker(marker), 0));
|
||||
self.insert_new_node((n.with_span(span), 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -253,7 +253,7 @@ pub trait LoadableYamlNode: Clone + std::hash::Hash + Eq {
|
|||
/// Provide the marker for the node (builder-style).
|
||||
#[inline]
|
||||
#[must_use]
|
||||
fn with_marker(self, _: Marker) -> Self {
|
||||
fn with_span(self, _: Span) -> Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use std::{convert::TryFrom, ops::Index, ops::IndexMut};
|
||||
|
||||
use hashlink::LinkedHashMap;
|
||||
use saphyr_parser::{Parser, ScanError};
|
||||
use saphyr_parser::{BufferedInput, Input, Parser, ScanError};
|
||||
|
||||
use crate::{loader::parse_f64, YamlLoader};
|
||||
|
||||
|
@ -97,7 +97,7 @@ impl Yaml {
|
|||
/// # Errors
|
||||
/// Returns `ScanError` when loading fails.
|
||||
pub fn load_from_iter<I: Iterator<Item = char>>(source: I) -> Result<Vec<Yaml>, ScanError> {
|
||||
let mut parser = Parser::new(source);
|
||||
let mut parser = Parser::new(BufferedInput::new(source));
|
||||
Self::load_from_parser(&mut parser)
|
||||
}
|
||||
|
||||
|
@ -107,9 +107,7 @@ impl Yaml {
|
|||
///
|
||||
/// # Errors
|
||||
/// Returns `ScanError` when loading fails.
|
||||
pub fn load_from_parser<I: Iterator<Item = char>>(
|
||||
parser: &mut Parser<I>,
|
||||
) -> Result<Vec<Yaml>, ScanError> {
|
||||
pub fn load_from_parser<I: Input>(parser: &mut Parser<I>) -> Result<Vec<Yaml>, ScanError> {
|
||||
let mut loader = YamlLoader::default();
|
||||
parser.load(&mut loader, true)?;
|
||||
Ok(loader.into_documents())
|
||||
|
|
Loading…
Reference in a new issue