presets: allow comments on the same line as a declaration

This commit is contained in:
chyyran 2022-11-13 01:57:22 -05:00
parent 66d1c872ee
commit dcbdb382e1
4 changed files with 24 additions and 53 deletions

View file

@ -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<Span, ()> {
}
fn extract_from_quotes(input: Span) -> IResult<Span, Span> {
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<Span, Token> {
fn parse_key_value(input: Span) -> IResult<Span, Token> {
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<Span>>("//")(value)
.unwrap_or((input, value));
let (_, value) = take_until::<_, _, nom::error::Error<Span>>("#")(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

View file

@ -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));

View file

@ -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<ShaderReflection, ShaderReflectError> {
// self.0.reflect(pass_number, semantics)
// }
// }
//
// impl ShaderCompiler<GLSL> for GLSL {
// type Output = String;
// type Context = Vec<u32>;
// fn compile(&mut self, options: Self::Options) -> Result<CompiledShader<Self::Output, Self::Context>, ShaderCompileError> {
// self.0.compile(options)
// }
// }
//
// impl TryFrom<GlslangCompilation> for GLSL {
// type Error = ShaderReflectError;
//
// fn try_from(value: GlslangCompilation) -> Result<Self, Self::Error> {
// let value = GlslReflect::try_from(value)?;
// Ok(Self(value))
// }
// }
//
// impl ReflectShader for HLSL {
// fn reflect(&mut self, pass_number: u32, semantics: &ReflectSemantics) -> Result<ShaderReflection, ShaderReflectError> {
// self.0.reflect(pass_number, semantics)
// }
// }
//
// impl ShaderCompiler<HLSL> for HLSL {
// type Output = String;
// fn compile(&mut self, options: Self::Options) -> Result<CompiledShader<Self::Output, Self::Context>, ShaderCompileError> {
// self.0.compile(options)
// }
// }
//
// impl TryFrom<GlslangCompilation> for HLSL {
// type Error = ShaderReflectError;
//
// fn try_from(value: GlslangCompilation) -> Result<Self, Self::Error> {
// let value = HlslReflect::try_from(value)?;
// Ok(Self(value))
// }
// }

View file

@ -120,13 +120,13 @@ impl TextureSemanticMap<UniformSemantic> for FxHashMap<String, SemanticMap<Textu
}
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum UniformSemantic {
Variable(SemanticMap<VariableSemantics>),
Texture(SemanticMap<TextureSemantics>),
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct ReflectSemantics {
pub uniform_semantics: FxHashMap<String, UniformSemantic>,
pub non_uniform_semantics: FxHashMap<String, SemanticMap<TextureSemantics>>,