diff --git a/assets/scenes/00.scene b/assets/scenes/00.scene index 95eb7ce..37e8e3d 100644 --- a/assets/scenes/00.scene +++ b/assets/scenes/00.scene @@ -1,2 +1 @@ 00/a.entity -00/a.entity diff --git a/assets/scenes/00/a.entity b/assets/scenes/00/a.entity index 20cc19d..05e88ff 100644 --- a/assets/scenes/00/a.entity +++ b/assets/scenes/00/a.entity @@ -1 +1,3 @@ name "Hello world" +# camera3d +# transform ... diff --git a/shell.nix b/shell.nix index 35cf8b6..19c81c7 100644 --- a/shell.nix +++ b/shell.nix @@ -22,6 +22,7 @@ mkShell rec { vulkan-loader # Rendering xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr # To use the x11 feature tmux # Sharing environemnt between editor and terminal + git-bug ]; LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs; diff --git a/src/parser.rs b/src/parser.rs index aa8908e..f5d8cbe 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -21,6 +21,8 @@ pub(crate) enum Token { Tag(String), Str(String), Num(f32), + Comment(String), + Etc, } /// @@ -30,32 +32,46 @@ pub(crate) fn tokenize(line: &str) -> Vec { let mut l = line; let mut tokens = Vec::new(); - while l.len() > 0 { - debug!("Line: {:?}", l); - if let Ok((rem, (_, s, _))) = tuple(( - char::<&str, ()>('"'), - take_until("\""), - char::<&str, ()>('"'), - ))(l) - { - debug!("Parsed string {:?}", s); - tokens.push(Token::Str(s.into())); - l = rem; - } else if let Ok((rem, num)) = float::<&str, ()>(l) { - debug!("Parsed float {:?}", num); - tokens.push(Token::Num(num.into())); - l = rem; - } else if let Ok((rem, (_, tag, _))) = tuple((space0, alphanumeric1::<&str, ()>, space0))(l) - { - debug!("Parsed tag {:?}", tag); - tokens.push(Token::Tag(tag.into())); - l = rem; - } else { - debug!("Breaking loop"); - break; + // Check for comment + if let Ok((_, (_start, content))) = tuple((char::<&str, ()>('#'), not_line_ending))(line) { + tokens.push(Token::Comment(content.strip_prefix(" ").unwrap().into())); + } else { + // Check for all other token types in a loop + while l.len() > 0 { + if let Ok((rem, (_, s, _))) = tuple(( + char::<&str, ()>('"'), + take_until("\""), + char::<&str, ()>('"'), + ))(l) + { + debug!("Parsed string {:?}", s); + tokens.push(Token::Str(s.into())); + l = rem; + } else if let Ok((rem, num)) = float::<&str, ()>(l) { + debug!("Parsed float {:?}", num); + tokens.push(Token::Num(num.into())); + l = rem; + } else if let Ok((rem, (_, etc, _))) = + tuple((space0, tag::<&str, &str, ()>("..."), space0))(l) + { + debug!("Parsed etc. {:?}", etc); + tokens.push(Token::Etc); + l = rem; + } else if let Ok((rem, (_, tag, _))) = + tuple((space0, alphanumeric1::<&str, ()>, space0))(l) + { + debug!("Parsed tag {:?}", tag); + tokens.push(Token::Tag(tag.into())); + l = rem; + } else { + debug!("Breaking loop"); + break; + } } } + debug!("Parsed tokens: {:?}", tokens); + tokens } diff --git a/src/prelude.rs b/src/prelude.rs index cf2aeb0..1640a67 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -10,8 +10,8 @@ pub(crate) use bevy::{ window::{PrimaryWindow, WindowCloseRequested, WindowRef}, }; pub(crate) use nom::{ - bytes::complete::take_until, - character::complete::{char, space0, alphanumeric1}, + bytes::complete::{tag, take_until}, + character::complete::{alphanumeric1, char, not_line_ending, space0}, number::complete::float, sequence::tuple, }; diff --git a/src/save.rs b/src/save.rs index 423e7c2..79cc67a 100644 --- a/src/save.rs +++ b/src/save.rs @@ -79,25 +79,29 @@ impl SaveEntity { // Tokenize the line let tokens = tokenize(line); - // Run line against all parsers - for f in fns { - if let Ok(c) = f(&tokens) { - // Bundle the Type ID with this entry for auditing purposes - let t = c.get_represented_type_info().unwrap().type_id(); - entity.components.push(SaveEntityComponent { - type_id: t, - data: c, - }); - good = true; + if matches!(tokens[0], Token::Comment(..)) { + debug!("Skipping parsing comment line {:?}", tokens); + } else { + // Run line against all parsers + for f in fns { + if let Ok(c) = f(&tokens) { + // Bundle the Type ID with this entry for auditing purposes + let t = c.get_represented_type_info().unwrap().type_id(); + entity.components.push(SaveEntityComponent { + type_id: t, + data: c, + }); + good = true; + } } - } - if !good { - error!( - file = load_context.path().to_str().unwrap(), - line = line, - "failed to parse component", - ); + if !good { + error!( + file = load_context.path().to_str().unwrap(), + line = line, + "failed to parse component", + ); + } } }); // Check for duplicate component types and emit an error