chore: run clippy and fmt
This commit is contained in:
parent
a43cd9f3d5
commit
8606c55a92
|
@ -1,4 +1,3 @@
|
|||
use crate::parse::Span;
|
||||
use std::path::PathBuf;
|
||||
use thiserror::Error;
|
||||
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
use std::path::Path;
|
||||
use nom::{ExtendInto, Offset};
|
||||
|
||||
use nom_locate::LocatedSpan;
|
||||
use std::str;
|
||||
|
||||
mod preset;
|
||||
mod token;
|
||||
mod value;
|
||||
mod preset;
|
||||
|
||||
pub(crate) type Span<'a> = LocatedSpan<&'a str>;
|
||||
pub(crate) use token::Token;
|
||||
pub(crate) use value::Value;
|
||||
|
||||
use crate::error::ParsePresetError;
|
||||
use crate::parse::preset::resolve_values;
|
||||
|
@ -17,9 +16,7 @@ use crate::parse::value::parse_preset;
|
|||
use crate::Preset;
|
||||
|
||||
pub(crate) fn remove_if<T>(values: &mut Vec<T>, f: impl FnMut(&T) -> bool) -> Option<T> {
|
||||
values.iter()
|
||||
.position(f)
|
||||
.map(|idx| values.remove(idx))
|
||||
values.iter().position(f).map(|idx| values.remove(idx))
|
||||
}
|
||||
|
||||
impl Preset {
|
||||
|
@ -31,8 +28,8 @@ impl Preset {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::path::PathBuf;
|
||||
use crate::Preset;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[test]
|
||||
pub fn parse_preset() {
|
||||
|
|
|
@ -1,62 +1,84 @@
|
|||
use crate::parse::value::Value;
|
||||
use crate::{WrapMode, FilterMode, Parameter, Preset, Scale2D, Scaling, ShaderConfig, TextureConfig};
|
||||
use crate::parse::remove_if;
|
||||
use crate::parse::value::Value;
|
||||
use crate::{Parameter, Preset, Scale2D, Scaling, ShaderConfig, TextureConfig};
|
||||
|
||||
pub fn resolve_values(mut values: Vec<Value>) -> Preset {
|
||||
let textures: Vec<TextureConfig> = values.drain_filter(|f| matches!(*f, Value::Texture { .. }))
|
||||
let textures: Vec<TextureConfig> = values
|
||||
.drain_filter(|f| matches!(*f, Value::Texture { .. }))
|
||||
.map(|value| {
|
||||
if let Value::Texture { name, filter_mode, wrap_mode, mipmap, path } = value {
|
||||
if let Value::Texture {
|
||||
name,
|
||||
filter_mode,
|
||||
wrap_mode,
|
||||
mipmap,
|
||||
path,
|
||||
} = value
|
||||
{
|
||||
TextureConfig {
|
||||
name,
|
||||
path,
|
||||
wrap_mode,
|
||||
filter_mode,
|
||||
mipmap
|
||||
mipmap,
|
||||
}
|
||||
} else {
|
||||
unreachable!("values should all be of type Texture")
|
||||
}
|
||||
}).collect();
|
||||
let parameters: Vec<Parameter> = values.drain_filter(|f| matches!(*f, Value::Parameter { .. })).map(|value| {
|
||||
if let Value::Parameter(name, value) = value {
|
||||
Parameter {
|
||||
name,
|
||||
value
|
||||
})
|
||||
.collect();
|
||||
let parameters: Vec<Parameter> = values
|
||||
.drain_filter(|f| matches!(*f, Value::Parameter { .. }))
|
||||
.map(|value| {
|
||||
if let Value::Parameter(name, value) = value {
|
||||
Parameter { name, value }
|
||||
} else {
|
||||
unreachable!("values should be all of type parameters")
|
||||
}
|
||||
} else {
|
||||
unreachable!("values should be all of type parameters")
|
||||
}
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
|
||||
let mut shaders = Vec::new();
|
||||
let shader_count = remove_if(&mut values, |v| {
|
||||
matches!(*v, Value::ShaderCount(_))
|
||||
let shader_count = remove_if(&mut values, |v| matches!(*v, Value::ShaderCount(_)))
|
||||
.map(|value| {
|
||||
if let Value::ShaderCount(count) = value {
|
||||
count
|
||||
} else {
|
||||
unreachable!("value should be of type shader_count")
|
||||
}
|
||||
})
|
||||
.map(|value| if let Value::ShaderCount(count) = value { count } else { unreachable!("value should be of type shader_count") })
|
||||
.unwrap_or(0);
|
||||
|
||||
let feedback_pass = remove_if(&mut values, |v| {
|
||||
matches!(*v, Value::FeedbackPass(_))
|
||||
let feedback_pass = remove_if(&mut values, |v| matches!(*v, Value::FeedbackPass(_)))
|
||||
.map(|value| {
|
||||
if let Value::FeedbackPass(pass) = value {
|
||||
pass
|
||||
} else {
|
||||
unreachable!("value should be of type feedback_pass")
|
||||
}
|
||||
})
|
||||
.map(|value| if let Value::FeedbackPass(pass) = value { pass } else { unreachable!("value should be of type feedback_pass") })
|
||||
.unwrap_or(0);
|
||||
|
||||
for shader in 0..shader_count {
|
||||
if let Some(Value::Shader(id, name)) = remove_if(&mut values, |v| matches!(*v, Value::Shader(shader_index, _) if shader_index == shader)) {
|
||||
let shader_values: Vec<Value> = values.drain_filter(|v| v.shader_index() == Some(shader)).collect();
|
||||
if let Some(Value::Shader(id, name)) = remove_if(
|
||||
&mut values,
|
||||
|v| matches!(*v, Value::Shader(shader_index, _) if shader_index == shader),
|
||||
) {
|
||||
let shader_values: Vec<Value> = values
|
||||
.drain_filter(|v| v.shader_index() == Some(shader))
|
||||
.collect();
|
||||
let scale_type = shader_values.iter().find_map(|f| match f {
|
||||
Value::ScaleType(_, value) => Some(*value),
|
||||
_ => None
|
||||
_ => None,
|
||||
});
|
||||
|
||||
let mut scale_type_x = shader_values.iter().find_map(|f| match f {
|
||||
Value::ScaleType(_, value) => Some(*value),
|
||||
_ => None
|
||||
_ => None,
|
||||
});
|
||||
|
||||
let mut scale_type_y = shader_values.iter().find_map(|f| match f {
|
||||
Value::ScaleType(_, value) => Some(*value),
|
||||
_ => None
|
||||
_ => None,
|
||||
});
|
||||
|
||||
if scale_type.is_some() {
|
||||
|
@ -70,17 +92,17 @@ pub fn resolve_values(mut values: Vec<Value>) -> Preset {
|
|||
|
||||
let scale = shader_values.iter().find_map(|f| match f {
|
||||
Value::Scale(_, value) => Some(*value),
|
||||
_ => None
|
||||
_ => None,
|
||||
});
|
||||
|
||||
let mut scale_x = shader_values.iter().find_map(|f| match f {
|
||||
Value::ScaleX(_, value) => Some(*value),
|
||||
_ => None
|
||||
_ => None,
|
||||
});
|
||||
|
||||
let mut scale_y = shader_values.iter().find_map(|f| match f {
|
||||
Value::ScaleY(_, value) => Some(*value),
|
||||
_ => None
|
||||
_ => None,
|
||||
});
|
||||
|
||||
if scale.is_some() {
|
||||
|
@ -95,37 +117,61 @@ pub fn resolve_values(mut values: Vec<Value>) -> Preset {
|
|||
name,
|
||||
alias: shader_values.iter().find_map(|f| match f {
|
||||
Value::Alias(_, value) => Some(value.to_string()),
|
||||
_ => None
|
||||
_ => None,
|
||||
}),
|
||||
filter: shader_values.iter().find_map(|f| match f {
|
||||
Value::FilterMode(_, value) => Some(*value),
|
||||
_ => None
|
||||
}).unwrap_or_default(),
|
||||
wrap_mode: shader_values.iter().find_map(|f| match f {
|
||||
Value::WrapMode(_, value) => Some(*value),
|
||||
_ => None
|
||||
}).unwrap_or_default(),
|
||||
frame_count_mod: shader_values.iter().find_map(|f| match f {
|
||||
Value::FrameCountMod(_, value) => Some(*value),
|
||||
_ => None
|
||||
}).unwrap_or(0),
|
||||
srgb_framebuffer: shader_values.iter().find_map(|f| match f {
|
||||
Value::SrgbFramebuffer(_, value) => Some(*value),
|
||||
_ => None
|
||||
}).unwrap_or(false),
|
||||
float_framebuffer: shader_values.iter().find_map(|f| match f {
|
||||
Value::FloatFramebuffer(_, value) => Some(*value),
|
||||
_ => None
|
||||
}).unwrap_or(false),
|
||||
mipmap_input: shader_values.iter().find_map(|f| match f {
|
||||
Value::MipmapInput(_, value) => Some(*value),
|
||||
_ => None
|
||||
}).unwrap_or(false),
|
||||
filter: shader_values
|
||||
.iter()
|
||||
.find_map(|f| match f {
|
||||
Value::FilterMode(_, value) => Some(*value),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
wrap_mode: shader_values
|
||||
.iter()
|
||||
.find_map(|f| match f {
|
||||
Value::WrapMode(_, value) => Some(*value),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
frame_count_mod: shader_values
|
||||
.iter()
|
||||
.find_map(|f| match f {
|
||||
Value::FrameCountMod(_, value) => Some(*value),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or(0),
|
||||
srgb_framebuffer: shader_values
|
||||
.iter()
|
||||
.find_map(|f| match f {
|
||||
Value::SrgbFramebuffer(_, value) => Some(*value),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or(false),
|
||||
float_framebuffer: shader_values
|
||||
.iter()
|
||||
.find_map(|f| match f {
|
||||
Value::FloatFramebuffer(_, value) => Some(*value),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or(false),
|
||||
mipmap_input: shader_values
|
||||
.iter()
|
||||
.find_map(|f| match f {
|
||||
Value::MipmapInput(_, value) => Some(*value),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or(false),
|
||||
scaling: Scale2D {
|
||||
valid: scale_valid,
|
||||
x: Scaling { scale_type: scale_type_x.unwrap_or_default(), factor: scale_x.unwrap_or_default() },
|
||||
y: Scaling { scale_type: scale_type_y.unwrap_or_default(), factor: scale_y.unwrap_or_default() }
|
||||
}
|
||||
x: Scaling {
|
||||
scale_type: scale_type_x.unwrap_or_default(),
|
||||
factor: scale_x.unwrap_or_default(),
|
||||
},
|
||||
y: Scaling {
|
||||
scale_type: scale_type_y.unwrap_or_default(),
|
||||
factor: scale_y.unwrap_or_default(),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
shaders.push(shader)
|
||||
|
@ -137,6 +183,6 @@ pub fn resolve_values(mut values: Vec<Value>) -> Preset {
|
|||
feedback_pass,
|
||||
shaders,
|
||||
textures,
|
||||
parameters
|
||||
parameters,
|
||||
}
|
||||
}
|
|
@ -1,20 +1,17 @@
|
|||
use crate::error::ParsePresetError;
|
||||
use crate::parse::Span;
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::{is_not, take_till, take_until, take_while};
|
||||
use nom::character::complete::{char, digit1, line_ending, multispace1, not_line_ending};
|
||||
use nom::character::is_space;
|
||||
use nom::bytes::complete::is_not;
|
||||
use nom::character::complete::{char, line_ending, multispace1, not_line_ending};
|
||||
|
||||
use nom::combinator::{eof, map_res, value};
|
||||
use nom::error::{ErrorKind, ParseError};
|
||||
use nom::multi::many_till;
|
||||
use nom::sequence::{delimited, pair, preceded, separated_pair};
|
||||
|
||||
use nom::sequence::{delimited, preceded};
|
||||
use nom::{
|
||||
bytes::complete::tag, character::complete::multispace0, IResult, InputIter, InputLength,
|
||||
InputTake,
|
||||
};
|
||||
use nom_locate::LocatedSpan;
|
||||
use std::num::ParseIntError;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Token<'a> {
|
||||
|
@ -146,7 +143,7 @@ pub fn do_lex(input: &str) -> Result<Vec<Token>, ParsePresetError> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::parse::token::{do_lex, parse_key_value, parse_tokens, single_comment, Span};
|
||||
use crate::parse::token::{do_lex, single_comment};
|
||||
|
||||
#[test]
|
||||
fn parses_single_line_comment() {
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
use crate::error::{ParseErrorKind, ParsePresetError};
|
||||
use crate::parse::{remove_if, Span, Token};
|
||||
use crate::{FilterMode, ScaleFactor, ScaleType, Scaling, WrapMode};
|
||||
use crate::{FilterMode, ScaleFactor, ScaleType, WrapMode};
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::digit1;
|
||||
use nom::combinator::{eof, map_res};
|
||||
use nom::error::Error;
|
||||
|
||||
use nom::IResult;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::parse::token::do_lex;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
use crate::parse::token::do_lex;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Value {
|
||||
|
@ -52,13 +52,13 @@ impl Value {
|
|||
Value::ScaleTypeX(i, _) => Some(*i),
|
||||
Value::ScaleTypeY(i, _) => Some(*i),
|
||||
Value::FilterMode(i, _) => Some(*i),
|
||||
Value::WrapMode(i, _) => Some(*i),
|
||||
Value::FrameCountMod(i, _) => Some(*i),
|
||||
Value::WrapMode(i, _) => Some(*i),
|
||||
Value::FrameCountMod(i, _) => Some(*i),
|
||||
Value::FloatFramebuffer(i, _) => Some(*i),
|
||||
Value::SrgbFramebuffer(i, _) => Some(*i),
|
||||
Value::MipmapInput(i, _) => Some(*i),
|
||||
Value::Alias(i, _) => Some(*i),
|
||||
_ => None
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,11 +67,12 @@ fn from_int(input: Span) -> Result<i32, ParsePresetError> {
|
|||
i32::from_str(input.trim()).map_err(|_| {
|
||||
eprintln!("{input}");
|
||||
ParsePresetError::ParserError {
|
||||
offset: input.location_offset(),
|
||||
row: input.location_line(),
|
||||
col: input.get_column(),
|
||||
kind: ParseErrorKind::Int,
|
||||
}})
|
||||
offset: input.location_offset(),
|
||||
row: input.location_line(),
|
||||
col: input.get_column(),
|
||||
kind: ParseErrorKind::Int,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn from_ul(input: Span) -> Result<u32, ParsePresetError> {
|
||||
|
@ -123,18 +124,6 @@ fn parse_indexed_key<'a>(key: &'static str, input: Span<'a>) -> IResult<Span<'a>
|
|||
Ok((input, idx))
|
||||
}
|
||||
|
||||
fn parse_texture_key<'a, 'b>(
|
||||
key: &'static str,
|
||||
texture_name: &'b str,
|
||||
input: Span<'a>,
|
||||
) -> IResult<Span<'a>, ()> {
|
||||
let (input, _) = tag(texture_name)(input)?;
|
||||
let (input, _) = tag("_")(input)?;
|
||||
let (input, _) = tag(key)(input)?;
|
||||
let (input, _) = eof(input)?;
|
||||
Ok((input, ()))
|
||||
}
|
||||
|
||||
pub const SHADER_MAX_REFERENCE_DEPTH: usize = 16;
|
||||
|
||||
fn load_child_reference_strings(
|
||||
|
@ -302,25 +291,23 @@ pub fn parse_values(
|
|||
t.key.starts_with(*texture)
|
||||
&& t.key.ends_with("_mipmap")
|
||||
&& t.key.len() == texture.len() + "_mipmap".len()
|
||||
}).map_or_else(|| Ok(false), |v| from_bool(v.value))?;
|
||||
})
|
||||
.map_or_else(|| Ok(false), |v| from_bool(v.value))?;
|
||||
|
||||
let linear = remove_if(&mut tokens, |t| {
|
||||
t.key.starts_with(*texture)
|
||||
&& t.key.ends_with("_linear")
|
||||
&& t.key.len() == texture.len() + "_linear".len()
|
||||
})
|
||||
.map_or_else(|| Ok(false), |v| from_bool(v.value))?;
|
||||
t.key.starts_with(*texture)
|
||||
&& t.key.ends_with("_linear")
|
||||
&& t.key.len() == texture.len() + "_linear".len()
|
||||
})
|
||||
.map_or_else(|| Ok(false), |v| from_bool(v.value))?;
|
||||
|
||||
let wrap_mode = remove_if(&mut tokens, |t| {
|
||||
t.key.starts_with(*texture)
|
||||
&& t.key.ends_with("_wrap_mode")
|
||||
&& t.key.len() == texture.len() + "_wrap_mode".len()
|
||||
})
|
||||
// NOPANIC: infallible
|
||||
.map_or_else(
|
||||
WrapMode::default,
|
||||
|v| WrapMode::from_str(&v.value).unwrap(),
|
||||
);
|
||||
t.key.starts_with(*texture)
|
||||
&& t.key.ends_with("_wrap_mode")
|
||||
&& t.key.len() == texture.len() + "_wrap_mode".len()
|
||||
})
|
||||
// NOPANIC: infallible
|
||||
.map_or_else(WrapMode::default, |v| WrapMode::from_str(&v.value).unwrap());
|
||||
|
||||
values.push(Value::Texture {
|
||||
name: texture.to_string(),
|
||||
|
@ -358,7 +345,14 @@ pub fn parse_values(
|
|||
}
|
||||
if let Ok((_, idx)) = parse_indexed_key("filter_linear", token.key) {
|
||||
let linear = from_bool(token.value)?;
|
||||
values.push(Value::FilterMode(idx, if linear { FilterMode::Linear } else { FilterMode::Nearest }));
|
||||
values.push(Value::FilterMode(
|
||||
idx,
|
||||
if linear {
|
||||
FilterMode::Linear
|
||||
} else {
|
||||
FilterMode::Nearest
|
||||
},
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"rustc_fingerprint":1842804115855352081,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.65.0-nightly (750bd1a7f 2022-09-14)\nbinary: rustc\ncommit-hash: 750bd1a7ff3e010611b97ee75d30b7cbf5f3a03c\ncommit-date: 2022-09-14\nhost: x86_64-pc-windows-msvc\nrelease: 1.65.0-nightly\nLLVM version: 15.0.0\n","stderr":""},"15697416045686424142":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\n","stderr":""},"10376369925670944939":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\ronny\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"llvm14-builtins-abi\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"pc\"\nwindows\n","stderr":""}},"successes":{}}
|
||||
{"rustc_fingerprint":13884731479247197160,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.65.0-nightly (750bd1a7f 2022-09-14)\nbinary: rustc\ncommit-hash: 750bd1a7ff3e010611b97ee75d30b7cbf5f3a03c\ncommit-date: 2022-09-14\nhost: x86_64-pc-windows-msvc\nrelease: 1.65.0-nightly\nLLVM version: 15.0.0\n","stderr":""},"16074388977461238104":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\n","stderr":""},"4658116585089295848":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\ronny\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\ndebug_assertions\nfeature=\"cargo-clippy\"\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"llvm14-builtins-abi\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"pc\"\nwindows\n","stderr":""}},"successes":{}}
|
Loading…
Reference in a new issue