Skip to content

Commit

Permalink
02/12/2023
Browse files Browse the repository at this point in the history
  • Loading branch information
doonv committed Dec 1, 2023
1 parent a22e8b6 commit b9c5127
Show file tree
Hide file tree
Showing 14 changed files with 608 additions and 474 deletions.
479 changes: 285 additions & 194 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"

[dependencies]
ahash = "0.8.6"
bevy = "0.12.0"
bevy = "0.12.1"
bevy_egui = "0.23.0"
chrono = "0.4.31"
logos = "0.13.0"
Expand All @@ -22,3 +22,6 @@ opt-level = 1
# Enable high optimizations for dependencies (incl. Bevy), but not for our code:
[profile.dev.package."*"]
opt-level = 3

[lints]
clippy.useless_format = "allow"
7 changes: 6 additions & 1 deletion examples/resource.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use bevy::{log::LogPlugin, prelude::*};
use bevy::{
log::{Level, LogPlugin},
prelude::*,
};
use bevy_dev_console::prelude::*;

#[derive(Resource, Reflect, Default, Debug)]
Expand All @@ -17,6 +20,7 @@ enum MyEnum {
struct MyStruct {
number1: f64,
number2: f64,
number3: f32,
string: String,
}

Expand All @@ -28,6 +32,7 @@ fn main() {
.insert_resource(MyStruct {
number1: 52138.0,
number2: -123.8,
number3: 0.0,
string: "hi there :)".to_string(),
})
.add_plugins((
Expand Down
14 changes: 0 additions & 14 deletions src/parser.rs → src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,5 @@ impl Command for ExecuteConsoleCommand {
}
Err(err) => error!("{err:#?}"),
}

// let mut engine = rhai::Engine::new();

// engine.on_print(|str| info!("{str}"));

// let res = engine.eval_with_scope::<rhai::Dynamic>(&mut scope.0, command);

// match res {
// Ok(val) => match val.0 {
// Dynamci
// _ => info!("{val}")
// },
// Err(err) => error!("{err}"),
// }
}
}
File renamed without changes.
25 changes: 17 additions & 8 deletions src/parser/parser.rs → src/command/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::{
Environment, Spanned,
};

pub type AST = Vec<Spanned<Expression>>;
pub type Ast = Vec<Spanned<Expression>>;

macro_rules! expect {
($tokens:ident, $token:pat, $tokenexpr:expr) => {
Expand Down Expand Up @@ -46,9 +46,9 @@ pub enum Expression {
ForLoop {
index_name: String,
loop_count: u64,
block: AST,
block: Ast,
},
MemberExpression {
Member {
left: Box<Spanned<Expression>>,
right: String,
},
Expand Down Expand Up @@ -86,13 +86,22 @@ pub enum ParseError {
got: Token,
span: Span,
},
ExpectedEndline(Spanned<Token>),
UnexpectedToken(Spanned<Token>),
}

pub fn parse(tokens: &mut TokenStream, environment: &Environment) -> Result<AST, ParseError> {
pub fn parse(tokens: &mut TokenStream, environment: &Environment) -> Result<Ast, ParseError> {
let mut ast = Vec::new();
while let Some(_) = tokens.peek() {
while tokens.peek().is_some() {
ast.push(parse_expression(tokens, environment)?);
match tokens.next() {
Some(Ok(Token::SemiColon)) => continue,
Some(Ok(token)) => return Err(ParseError::ExpectedEndline(tokens.wrap_span(token))),
Some(Err(FailedToLexCharacter)) => {
return Err(ParseError::FailedToLexCharacter(tokens.span()))
}
None => break,
}
}
Ok(ast)
}
Expand Down Expand Up @@ -146,7 +155,7 @@ fn parse_expression(
None => return Err(ParseError::ExpectedMoreTokens(tokens.peek_span())),
})
}
fn parse_block(tokens: &mut TokenStream, environment: &Environment) -> Result<AST, ParseError> {
fn parse_block(tokens: &mut TokenStream, environment: &Environment) -> Result<Ast, ParseError> {
expect!(tokens, Token::LeftBracket, Token::LeftBracket);
let ast = parse(tokens, environment)?;
expect!(tokens, Token::RightBracket, Token::RightBracket);
Expand Down Expand Up @@ -297,7 +306,7 @@ fn parse_primary(
let right = tokens.slice().to_string();
expr = Spanned {
span: expr.span.start..tokens.span().end,
value: Expression::MemberExpression {
value: Expression::Member {
left: Box::new(expr),
right,
},
Expand Down Expand Up @@ -354,7 +363,7 @@ fn parse_object(

#[cfg(test)]
mod tests {
use crate::parser::Environment;
use crate::command::Environment;

use super::{super::lexer::TokenStream, parse};

Expand Down
Loading

0 comments on commit b9c5127

Please sign in to comment.