Draft generation of valid AI movements
This commit is contained in:
@@ -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, ()> {
|
||||
|
Reference in New Issue
Block a user