From dcbdb382e1f87979756d632e80ee5a226c15df7c Mon Sep 17 00:00:00 2001 From: chyyran Date: Sun, 13 Nov 2022 01:57:22 -0500 Subject: [PATCH] presets: allow comments on the same line as a declaration --- librashader-presets/src/parse/token.rs | 19 +++++++--- librashader-presets/src/parse/value.rs | 8 +++++ librashader-reflect/src/back/targets.rs | 46 ------------------------- librashader-reflect/src/reflect/mod.rs | 4 +-- 4 files changed, 24 insertions(+), 53 deletions(-) diff --git a/librashader-presets/src/parse/token.rs b/librashader-presets/src/parse/token.rs index 8b12b35..a4854ac 100644 --- a/librashader-presets/src/parse/token.rs +++ b/librashader-presets/src/parse/token.rs @@ -1,10 +1,10 @@ use crate::error::ParsePresetError; use crate::parse::Span; use nom::branch::alt; -use nom::bytes::complete::is_not; +use nom::bytes::complete::{is_not, take_until}; use nom::character::complete::{char, line_ending, multispace1, not_line_ending}; -use nom::combinator::{eof, map_res, value}; +use nom::combinator::{eof, map_res, opt, value}; use nom::error::{ErrorKind, ParseError}; use nom::sequence::{delimited, preceded}; @@ -12,6 +12,7 @@ use nom::{ bytes::complete::tag, character::complete::multispace0, IResult, InputIter, InputLength, InputTake, }; +use nom::multi::many0; #[derive(Debug)] pub struct Token<'a> { @@ -53,7 +54,9 @@ fn parse_assignment(input: Span) -> IResult { } fn extract_from_quotes(input: Span) -> IResult { - let (input, between) = delimited(char('"'), is_not("\""), preceded(char('"'), eof))(input)?; + let (input, between) = delimited(char('"'), is_not("\""), char('"'))(input)?; + let (input, _) = whitespace(input)?; + let (input, _) = eof(input)?; Ok((input, between)) } @@ -90,6 +93,12 @@ fn parse_reference(input: Span) -> IResult { fn parse_key_value(input: Span) -> IResult { let (input, (key, _)) = take_up_to(parse_assignment)(input)?; let (input, (_, value)) = map_res(not_line_ending, optional_quotes)(input)?; + let (_, value) = take_until::<_, _, nom::error::Error>("//")(value) + .unwrap_or((input, value)); + let (_, value) = take_until::<_, _, nom::error::Error>("#")(value) + .unwrap_or((input, value)); + let (_, (_, value)) = map_res(not_line_ending, optional_quotes)(value)?; + Ok((input, Token { key, value })) } @@ -155,7 +164,7 @@ mod test { #[test] fn parses_key_value_line() { let parsed = do_lex(TEST); - eprintln!("{:?}", parsed) + eprintln!("{:#?}", parsed) } // todo: fix @@ -169,7 +178,7 @@ shader9 = ../../shaders/dogway/hsm-grade.slang shaders = 54 shader0 = ../../shaders/base/add-params-all.slang -alias0 = "CorePass" +alias0 = "CorePass" # hello shader1 = ../../shaders/hyllian/cubic/hsm-drez-b-spline-x.slang filter_linear1 = false diff --git a/librashader-presets/src/parse/value.rs b/librashader-presets/src/parse/value.rs index 9c5ecd8..08d2095 100644 --- a/librashader-presets/src/parse/value.rs +++ b/librashader-presets/src/parse/value.rs @@ -362,6 +362,14 @@ pub fn parse_values( continue; } + // crt-royale uses 'texture_wrap_mode' instead of 'wrap_mode', I have no idea + // how this possibly could work in RA, but here it is.. + if let Ok((_, idx)) = parse_indexed_key("texture_wrap_mode", token.key) { + let wrap_mode = WrapMode::from_str(&token.value).unwrap(); + values.push(Value::WrapMode(idx, wrap_mode)); + continue; + } + if let Ok((_, idx)) = parse_indexed_key("frame_count_mod", token.key) { let frame_count_mod = from_ul(token.value)?; values.push(Value::FrameCountMod(idx, frame_count_mod)); diff --git a/librashader-reflect/src/back/targets.rs b/librashader-reflect/src/back/targets.rs index 19eae2d..3c0c726 100644 --- a/librashader-reflect/src/back/targets.rs +++ b/librashader-reflect/src/back/targets.rs @@ -81,49 +81,3 @@ mod test { let _x = GLSL::from_compilation(value).unwrap(); } } - -// -// impl ReflectShader for GLSL { -// fn reflect(&mut self, pass_number: u32, semantics: &ReflectSemantics) -> Result { -// self.0.reflect(pass_number, semantics) -// } -// } -// -// impl ShaderCompiler for GLSL { -// type Output = String; -// type Context = Vec; -// fn compile(&mut self, options: Self::Options) -> Result, ShaderCompileError> { -// self.0.compile(options) -// } -// } -// -// impl TryFrom for GLSL { -// type Error = ShaderReflectError; -// -// fn try_from(value: GlslangCompilation) -> Result { -// let value = GlslReflect::try_from(value)?; -// Ok(Self(value)) -// } -// } -// -// impl ReflectShader for HLSL { -// fn reflect(&mut self, pass_number: u32, semantics: &ReflectSemantics) -> Result { -// self.0.reflect(pass_number, semantics) -// } -// } -// -// impl ShaderCompiler for HLSL { -// type Output = String; -// fn compile(&mut self, options: Self::Options) -> Result, ShaderCompileError> { -// self.0.compile(options) -// } -// } -// -// impl TryFrom for HLSL { -// type Error = ShaderReflectError; -// -// fn try_from(value: GlslangCompilation) -> Result { -// let value = HlslReflect::try_from(value)?; -// Ok(Self(value)) -// } -// } diff --git a/librashader-reflect/src/reflect/mod.rs b/librashader-reflect/src/reflect/mod.rs index b2ec5e5..75ba5e6 100644 --- a/librashader-reflect/src/reflect/mod.rs +++ b/librashader-reflect/src/reflect/mod.rs @@ -120,13 +120,13 @@ impl TextureSemanticMap for FxHashMap), Texture(SemanticMap), } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct ReflectSemantics { pub uniform_semantics: FxHashMap, pub non_uniform_semantics: FxHashMap>,