Adds comments to entity files

attempt/001
Elijah Voigt 1 year ago
parent 07b5fbce1a
commit f9acf9e2ff

@ -1,2 +1 @@
00/a.entity
00/a.entity

@ -1 +1,3 @@
name "Hello world"
# camera3d
# transform ...

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

@ -21,6 +21,8 @@ pub(crate) enum Token {
Tag(String),
Str(String),
Num(f32),
Comment(String),
Etc,
}
///
@ -30,8 +32,12 @@ pub(crate) fn tokenize(line: &str) -> Vec<Token> {
let mut l = line;
let mut tokens = Vec::new();
// 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 {
debug!("Line: {:?}", l);
if let Ok((rem, (_, s, _))) = tuple((
char::<&str, ()>('"'),
take_until("\""),
@ -45,7 +51,14 @@ pub(crate) fn tokenize(line: &str) -> Vec<Token> {
debug!("Parsed float {:?}", num);
tokens.push(Token::Num(num.into()));
l = rem;
} else if let Ok((rem, (_, tag, _))) = tuple((space0, alphanumeric1::<&str, ()>, space0))(l)
} 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()));
@ -55,6 +68,9 @@ pub(crate) fn tokenize(line: &str) -> Vec<Token> {
break;
}
}
}
debug!("Parsed tokens: {:?}", tokens);
tokens
}

@ -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,
};

@ -79,6 +79,9 @@ impl SaveEntity {
// Tokenize the line
let tokens = tokenize(line);
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) {
@ -99,6 +102,7 @@ impl SaveEntity {
"failed to parse component",
);
}
}
});
// Check for duplicate component types and emit an error
// TODO: It would be nice if this emitted a line refernece instead of a parsed struct!

Loading…
Cancel
Save