function, object, parser, and executer rewrites

This commit is contained in:
2024-10-18 02:21:31 -04:00
parent 34569248d3
commit f2cfb03fa1
6 changed files with 401 additions and 454 deletions

View File

@@ -42,7 +42,7 @@ impl Display for TokenizeError {
impl error::Error for TokenizeError {}
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum Op {
pub enum Op {
Add,
Sub,
Mul,
@@ -85,7 +85,7 @@ pub(crate) enum Op {
}
#[derive(Debug, Clone)]
pub(crate) enum Token {
pub enum Token {
Identifier(String),
Operator(Op),
Constant(Value),
@@ -408,26 +408,4 @@ impl<R: BufRead> std::iter::Iterator for Tokenizer<R> {
Err(e) => Some(Err(TokenizeError::IO(e))),
}
}
}
#[cfg(test)]
mod tests {
use std::str::FromStr;
use crate::parser::{Parser, ParseTree, ParseError};
use super::*;
#[test]
fn uwu() {
let program = ":. map ?: f Any -> Any ?. x [Any] -> [Any] ?? bool x + f head x map 'f tail x empty map ;x ** x 2 [1 2 3 4 5]";
let tokens: Vec<Token> = Tokenizer::from_str(program).unwrap().collect::<Result<_, TokenizeError>>().unwrap();
println!("{tokens:?}");
let trees: Result<Vec<ParseTree>, ParseError> = Parser::new(tokens.into_iter().map(|x| Ok(x))).collect();
println!("{trees:?}");
}
}