From a265db27843674c80d5b869c500837e87e862d03 Mon Sep 17 00:00:00 2001 From: Ryan Pitasky <111201305+rpitasky@users.noreply.github.com> Date: Thu, 28 Nov 2024 03:35:16 -0500 Subject: [PATCH] parse: half-baked attempt at Ans( parsing --- .../src/parse/components/mod.rs | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/ti-basic-optimizer/src/parse/components/mod.rs b/ti-basic-optimizer/src/parse/components/mod.rs index 2715cad..7098d72 100644 --- a/ti-basic-optimizer/src/parse/components/mod.rs +++ b/ti-basic-optimizer/src/parse/components/mod.rs @@ -1,4 +1,4 @@ -use crate::error_reporting::TokenReport; +use crate::error_reporting::{expect_some, next_or_err, TokenReport}; pub use crate::parse::components::{ binary_operator::BinOp, data_access::{EquationIndex, ListIndex, ListIndexable, MatrixIndex, MatrixIndexable}, @@ -102,6 +102,33 @@ impl Parse for Operand { Ok(NumericVarName::parse(token, more)?.map(Self::NumericVarName)) } Token::OneByte(0x72) => Ok(Some(Self::Ans)), + Token::OneByte(0x72) => { + if more.peek() == Some(Token::OneByte(0x10)) { // ( + more.next(); + // conservatively guess that this is a list or matrix access- we can maybe demote it to a muliplication later + let index = expect_some!(Expression::parse(next_or_err!(more)?, more)?, more, "an expression")?; + + match more.peek() { + Some(Token ::OneByte(0x2B)) => { + // , -> matrix access + todo!() + }, + Some(Token::OneByte(0x11)) => { + // ) + more.next(); + }, + + _ => {} + }; + + Ok(Some(Self::ListAccess(ListIndex { + subject: ListIndexable::Ans, + index: Box::new(index), + }))) + } else { + Ok(Some(Self::Ans)) + } + }, Token::OneByte(0x2C) => Ok(Some(Self::I)), Token::OneByte(0xAD) => Ok(Some(Self::GetKey)), Token::TwoByte(0xEF, 0x09) => Ok(Some(Self::GetDate)),