Draft generation of valid AI movements

This commit is contained in:
2023-02-26 14:05:17 +01:00
parent 1c37b72b55
commit 1472e9f6d8
7 changed files with 113 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
use crate::lexer::Token;
use crate::tile::Operator;
use std::fmt;
use std::iter::Peekable;
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -9,6 +10,18 @@ pub enum Expression {
Binary(Operator, Box<Expression>, Box<Expression>),
}
impl fmt::Display for Expression {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expression::Digit(value) => write!(f, "{}", value),
Expression::Parentheses(expr) => write!(f, "({})", expr),
Expression::Binary(operator, left, right) => {
write!(f, "{} {} {}", left, operator, right)
}
}
}
}
pub type Expressions = Vec<Expression>;
pub fn parse(tokens: &[Token]) -> Result<Expressions, ()> {