Skip to content

Commit

Permalink
Addressed comments in matrial parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
gadunga committed Jul 30, 2022
1 parent acfcef4 commit c6ed504
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/test/mtl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,22 @@ parse_material_test!(
..Default::default()
}
);

parse_material_test!(
neon_green_with_comments,
"newmtl neon_green
#
# some comment
#
Kd 0.0000 1.0000 0.0000
#
# Some other comment
#
illum 0",
Material {
name: "neon_green".to_string(),
diffuse: Some(ColorType::Rgb(0.0, 1.0, 0.0)),
illumination_mode: Some(0),
..Default::default()
}
);
7 changes: 5 additions & 2 deletions src/tokenizer/mtl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::result::Result;

use nom::{
branch::alt,
bytes::complete::{is_not, tag, tag_no_case},
bytes::complete::{is_not, tag, tag_no_case, take_till},
character::complete::{line_ending, multispace0, multispace1},
combinator::map,
multi::fold_many0,
Expand Down Expand Up @@ -65,7 +65,10 @@ pub fn parse_mtl(input: &str) -> Result<Vec<Token>, TokenizeError> {
),
super::parse_float,
super::parse_digit,
map(preceded(tag("#"), is_not("\r\n")), |_| Token::Ignore),
map(
preceded(tag("#"), take_till(|c| c == '\n' || c == '\r')),
|_| Token::Ignore,
),
map(alt((line_ending, multispace1)), |_| Token::Ignore),
map(is_not(" \r\n"), |s: &str| Token::String(s.to_string())),
)),
Expand Down

0 comments on commit c6ed504

Please sign in to comment.