diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index f18aa56..5ad7f0c 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -8,10 +8,24 @@
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -144,7 +158,7 @@
-
+
@@ -218,7 +232,15 @@
1717473365560
-
+
+
+ 1717562697947
+
+
+
+ 1717562697947
+
+
diff --git a/main.why b/main.why
index 573de27..3102473 100644
--- a/main.why
+++ b/main.why
@@ -3,6 +3,6 @@ struct A {
b: int
}
-fn main() -> intt {
+fn main() !-> int {
return 12;
}
diff --git a/src/root.rs b/src/root.rs
index 5e6451d..02f8cf4 100644
--- a/src/root.rs
+++ b/src/root.rs
@@ -70,7 +70,7 @@ pub fn main_args(args: Args) -> Result<(), WError> {
print!("Parsing... ");
time!(
- let parsed = parse(PathBuf::from(&args.input)).unwrap();
+ let parsed = parse(PathBuf::from(&args.input))?;
);
print!("Resolving Names... ");
diff --git a/src/root/name_resolver/name_resolvers.rs b/src/root/name_resolver/name_resolvers.rs
index 6c9578f..3926323 100644
--- a/src/root/name_resolver/name_resolvers.rs
+++ b/src/root/name_resolver/name_resolvers.rs
@@ -10,7 +10,6 @@ use crate::root::name_resolver::resolve_function_signatures::FunctionSignature;
use crate::root::parser::parse::Location;
use crate::root::shared::types::Type;
use crate::root::parser::parse_function::FunctionToken;
-use crate::root::parser::parse_name::UnresolvedNameToken;
use crate::root::parser::parse_struct::StructToken;
use crate::root::shared::common::{AddressedTypeRef, FunctionID, TypeID, TypeRef};
@@ -168,31 +167,14 @@ impl GlobalDefinitionTable {
}
pub fn add_type(&mut self, given_id: TypeID, definition: Box) {
- // TODO: handle collisions
self.type_definitions.insert(given_id, definition);
}
- pub fn resolve_local_name(&self, name: &UnresolvedNameToken, local_variable_table: &LocalVariableTable) -> NameResult {
- let temp_name = &name.names()[0].1;
-
- if let Some((a, t)) =
- local_variable_table.get_ref_and_type(
- temp_name, &self.type_definitions
- ) {
- return NameResult::Variable(a, t);
- }
+ pub fn resolve_name(&self, name: &UnresolvedNameToken, local_variable_table: &LocalVariableTable) -> NameResult {
todo!()
}
- pub fn resolve_local_name_allow_function_calls(&self, name: &UnresolvedNameToken, local_variable_table: &mut LocalVariableTable) -> NameResult {
- let temp_name = &name.names()[0].1;
-
- if let Some((a, t)) =
- local_variable_table.get_ref_and_type(
- temp_name, &self.type_definitions
- ) {
- return NameResult::Variable(a, t);
- }
+ pub fn resolve_global_name(&self, name: &UnresolvedNameToken) -> NameResult {
todo!()
}
@@ -225,16 +207,6 @@ impl GlobalDefinitionTable {
return Err(WError::n(NRErrors::FunctionSubname(next.clone(), method_name.clone()), location.clone()));
}
- // match connector {
- // NameConnectors::NonStatic => {
- // if !*function_signatures.get(function).unwrap().has_self() {
- //
- // return Err(());
- // }
- // }
- // NameConnectors::Static => {}
- // }
-
NameResultId::Function(*function)
}
else {
diff --git a/src/root/name_resolver/resolve_names.rs b/src/root/name_resolver/resolve_names.rs
index 4620f94..63dde37 100644
--- a/src/root/name_resolver/resolve_names.rs
+++ b/src/root/name_resolver/resolve_names.rs
@@ -11,7 +11,6 @@ use crate::root::name_resolver::resolve_type_sizes::{resolve_type_sizes, Unsized
use crate::root::parser::parse::Location;
use crate::root::parser::parse_function::FunctionToken;
use crate::root::parser::parse_function::parse_literal::LiteralToken;
-use crate::root::parser::parse_name::UnresolvedNameToken;
use crate::root::parser::parse_toplevel::TopLevelTokens;
use crate::root::shared::common::{LocalAddress, TypeRef};
use crate::root::shared::common::{ByteSize, FunctionID, TypeID};
diff --git a/src/root/parser/mod.rs b/src/root/parser/mod.rs
index 8a279ae..741a2e0 100644
--- a/src/root/parser/mod.rs
+++ b/src/root/parser/mod.rs
@@ -4,9 +4,10 @@ pub mod parse_blocks;
pub mod parse_comments;
pub mod parse_function;
pub mod parse_impl;
-pub mod parse_name;
+pub mod parse_name_old;
pub mod parse_parameters;
pub mod parse_struct;
pub mod parse_toplevel;
pub mod parse_util;
pub mod soft_alt;
+mod parse_name;
diff --git a/src/root/parser/parse.rs b/src/root/parser/parse.rs
index 9f6c422..56f88ed 100644
--- a/src/root/parser/parse.rs
+++ b/src/root/parser/parse.rs
@@ -9,6 +9,7 @@ use std::path::PathBuf;
use std::rc::Rc;
use color_print::cformat;
use derive_getters::Getters;
+use crate::root::errors::WError;
use crate::root::parser::parse_toplevel::TopLevelTokens;
pub type Span<'a> = LocatedSpan<&'a str, &'a Rc>;
@@ -121,12 +122,15 @@ impl Display for Location {
}
}
-pub fn parse(path: PathBuf) -> Result, ()> {
+pub fn parse(path: PathBuf) -> Result, WError> {
let text = fs::read_to_string(&path).unwrap();
let path = Rc::new(path);
let base = Span::new_extra(&text, &path);
- let (remaining, output) = parse_toplevel::parse_toplevel(base).map_err(|_| ())?;
+ let (remaining, output) = match parse_toplevel::parse_toplevel(base) {
+ Ok(v) => v,
+ Err(_) => todo!()
+ };
debug_assert!(remaining.is_empty());
Ok(output)
diff --git a/src/root/parser/parse_arguments.rs b/src/root/parser/parse_arguments.rs
index 50c1a5a..a2699c9 100644
--- a/src/root/parser/parse_arguments.rs
+++ b/src/root/parser/parse_arguments.rs
@@ -2,8 +2,9 @@ use nom::bytes::complete::{take_until, take_until1};
use nom::InputTake;
use crate::root::parser::parse::{ErrorTree, ParseResult, Span};
use crate::root::parser::parse_function::parse_evaluable::{EvaluableToken, parse_evaluable};
+use crate::root::parser::parse_name::SimpleNameToken;
-pub fn parse_arguments<'a, 'b>(s: Span<'a>, containing_class: Option<&'b str>) -> ParseResult<'a, Span<'a>, Vec> {
+pub fn parse_arguments<'a, 'b>(s: Span<'a>, containing_class: Option<&SimpleNameToken>) -> ParseResult<'a, (), Vec> {
let mut s = s;
let mut args = Vec::new();
let mut last = false;
@@ -25,5 +26,5 @@ pub fn parse_arguments<'a, 'b>(s: Span<'a>, containing_class: Option<&'b str>) -
}
}
- Ok((s, args))
+ Ok(((), args))
}
\ No newline at end of file
diff --git a/src/root/parser/parse_function.rs b/src/root/parser/parse_function.rs
index fe885fe..33cb8ac 100644
--- a/src/root/parser/parse_function.rs
+++ b/src/root/parser/parse_function.rs
@@ -5,8 +5,9 @@ use nom_supreme::tag::complete::tag;
use substring::Substring;
use crate::root::parser::parse::{ErrorTree, Location, ParseResult, Span};
use crate::root::parser::parse_blocks::default_section;
+use crate::root::parser::parse_function::parse_evaluable::{FullNameWithIndirectionToken, parse_full_name};
use crate::root::parser::parse_function::parse_line::{LineTokens, parse_lines};
-use crate::root::parser::parse_name::{parse_full_name, parse_simple_name, UnresolvedNameToken};
+use crate::root::parser::parse_name::{parse_simple_name, SimpleNameToken};
use crate::root::parser::parse_parameters::{Parameters, parse_parameters};
use crate::root::parser::parse_toplevel::{ToplevelTestFn, TopLevelTokens};
use crate::root::parser::parse_util::{discard_ignored, require_ignored};
@@ -26,8 +27,8 @@ pub mod parse_while;
#[derive(Debug, Getters, Dissolve)]
pub struct FunctionToken {
location: Location,
- name: String,
- return_type: Option<(UnresolvedNameToken, Location)>,
+ name: SimpleNameToken,
+ return_type: Option,
parameters: Parameters,
lines: Vec,
}
@@ -41,16 +42,16 @@ pub fn test_parse_function<'a>(s: Span<'a>) -> ParseResult) -> ParseResult {
+pub fn parse_function<'a, 'b>(s: Span<'a>, allow_self: Option<&'b SimpleNameToken>) -> ParseResult<'a, Span<'a>, FunctionToken> {
let location = Location::from_span(&s);
let (s, _) = tag("fn").parse(s)?;
let (s, _) = require_ignored(s)?;
let (s, name) = parse_simple_name(s)?;
let (s, _) = discard_ignored(s)?;
- let c_owned = allow_self.as_ref().and_then(|s| Some(s.base().to_string()));
- let containing_class = if let Some(s) = &c_owned {
- Some(s.as_str())
- } else { None };
+ // let c_owned = allow_self.as_ref().and_then(|s| Some(s.base().to_string()));
+ // let containing_class = if let Some(s) = &c_owned {
+ // Some(s.as_str())
+ // } else { None };
let (s, contents) = default_section(s, '(')?;
let (_, parameters) = parse_parameters(contents, allow_self)?;
@@ -60,21 +61,21 @@ pub fn parse_function(s: Span, allow_self: Option) -> Parse
let (s, return_type) = if let Ok((s, _)) = tag::<_, _, ErrorTree>("->")(s) {
let (s, _) = discard_ignored(s)?;
let location = Location::from_span(&s);
- let (s, return_type) = parse_full_name(s, containing_class.and_then(|s| Some(s.to_string())))?;
- (discard_ignored(s)?.0, Some((return_type, location)))
+ let (s, return_type) = parse_full_name(s, allow_self)?;
+ (discard_ignored(s)?.0, Some(return_type))
} else {
(s, None)
};
let (s, contents) = default_section(s, '{')?;
- let (_, lines) = parse_lines(contents, containing_class)?;
+ let (_, lines) = parse_lines(contents, allow_self)?;
Ok((
s,
FunctionToken {
location,
- name: name.to_string(),
+ name,
return_type,
parameters,
lines,
diff --git a/src/root/parser/parse_function/parse_assignment.rs b/src/root/parser/parse_function/parse_assignment.rs
index ec1ef7c..36ac626 100644
--- a/src/root/parser/parse_function/parse_assignment.rs
+++ b/src/root/parser/parse_function/parse_assignment.rs
@@ -3,16 +3,16 @@ use nom::sequence::Tuple;
use nom_supreme::tag::complete::tag;
use crate::root::parser::parse::{Location, ParseResult, Span};
use crate::root::parser::parse_function::parse_assigner::{AssignmentOperatorToken, parse_assigner};
-use crate::root::parser::parse_function::parse_evaluable::{EvaluableToken, parse_evaluable};
+use crate::root::parser::parse_function::parse_evaluable::{EvaluableToken, FullNameWithIndirectionToken, parse_evaluable, parse_full_name};
use crate::root::parser::parse_function::parse_initialisation::parse_initialisation;
use crate::root::parser::parse_function::parse_line::{LineTestFn, LineTokens};
-use crate::root::parser::parse_name::{UnresolvedNameToken, parse_full_name};
+use crate::root::parser::parse_name::SimpleNameToken;
use crate::root::parser::parse_util::discard_ignored;
#[derive(Debug)]
pub struct AssignmentToken {
location: Location,
- name: UnresolvedNameToken,
+ name: FullNameWithIndirectionToken,
assignment_operator: AssignmentOperatorToken,
value: EvaluableToken,
}
@@ -27,10 +27,10 @@ pub fn test_parse_assignment<'a, 'b>(s: Span<'a>) -> ParseResult<'a, Span<'a>, L
Ok((s, |x, c| parse_assignment(x, c).map(|(s, x)| (s, LineTokens::Assignment(x)))))
}
-pub fn parse_assignment<'a, 'b>(s: Span<'a>, containing_class: Option<&'b str>) -> ParseResult<'a, Span<'a>, AssignmentToken> {
+pub fn parse_assignment<'a, 'b>(s: Span<'a>, containing_class: Option<&SimpleNameToken>) -> ParseResult<'a, Span<'a>, AssignmentToken> {
let (s, _) = discard_ignored(s)?;
let location = Location::from_span(&s);
- let (s, n) = parse_full_name(s, containing_class.and_then(|s| Some(s.to_string())))?;
+ let (s, n) = parse_full_name(s, containing_class)?;
let (s, _) = discard_ignored(s)?;
let (s, a) = parse_assigner(s)?;
let (s, _) = discard_ignored(s)?;
diff --git a/src/root/parser/parse_function/parse_evaluable.rs b/src/root/parser/parse_function/parse_evaluable.rs
index 104e663..3b6ecc0 100644
--- a/src/root/parser/parse_function/parse_evaluable.rs
+++ b/src/root/parser/parse_function/parse_evaluable.rs
@@ -1,15 +1,19 @@
+use nom::Err;
use crate::root::parser::parse::{ErrorTree, Location, ParseResult, Span};
use crate::root::parser::parse_function::parse_literal::{
- parse_literal, LiteralToken, LiteralTokens,
+ LiteralToken, parse_literal,
};
-use crate::root::parser::parse_function::parse_operator::{parse_operator, OperatorToken};
-use crate::root::parser::parse_name::{parse_full_name, UnresolvedNameToken};
+use crate::root::parser::parse_function::parse_operator::{OperatorToken, parse_operator};
use b_box::b;
use derive_getters::Getters;
use nom::branch::alt;
-use nom::character::complete::{char};
+use nom::bytes::complete::tag;
+use nom::character::complete::char;
+use crate::root::parser::parse_arguments::parse_arguments;
+use crate::root::parser::parse_name::{SimpleNameToken, parse_simple_name};
use crate::root::parser::parse_blocks::default_section;
use crate::root::parser::parse_util::discard_ignored;
+use crate::root::shared::common::Indirection;
#[derive(Debug, Getters)]
pub struct EvaluableToken {
@@ -17,8 +21,8 @@ pub struct EvaluableToken {
token: EvaluableTokens,
}
-pub fn temp_from_token(s: Span, token: EvaluableTokens) -> TempEvaluableTokens {
- TempEvaluableTokens::EvaluableToken(EvaluableToken {
+pub fn temp_from_token(s: Span, token: EvaluableTokens) -> TempEvaluableTokensOne {
+ TempEvaluableTokensOne::EvaluableToken(EvaluableToken {
location: Location::from_span(&s),
token,
})
@@ -26,27 +30,149 @@ pub fn temp_from_token(s: Span, token: EvaluableTokens) -> TempEvaluableTokens {
#[derive(Debug)]
pub enum EvaluableTokens {
- Name(UnresolvedNameToken),
+ Name(SimpleNameToken, Option),
+ StaticAccess(Box, SimpleNameToken),
+ DynamicAccess(Box, SimpleNameToken),
+ FunctionCall(Box, SimpleNameToken, Vec),
Literal(LiteralToken),
InfixOperator(Box, OperatorToken, Box),
PrefixOperator(OperatorToken, Box),
}
+#[derive(Debug, Getters)]
+pub struct FullNameWithIndirectionToken {
+ indirection: Indirection,
+ inner: FullNameToken
+}
+
+impl FullNameWithIndirectionToken {
+ pub fn from_simple(simple: SimpleNameToken, containing_class: Option, location: Location) -> FullNameWithIndirectionToken {
+ FullNameWithIndirectionToken {
+ indirection: Indirection(0),
+ inner: FullNameToken {
+ location,
+ token: FullNameTokens::Name(simple, containing_class)
+ }
+ }
+ }
+}
+
+#[derive(Debug, Getters)]
+pub struct FullNameToken {
+ location: Location,
+ token: FullNameTokens
+}
+
+impl FullNameToken {
+ pub fn new(s: &Span, token: FullNameTokens) -> FullNameToken {
+ FullNameToken {
+ location: Location::from_span(s),
+ token,
+ }
+ }
+
+ fn to_evaluable(self) -> EvaluableToken {
+ let (location, token) = (self.location, self.token);
+ let token = token.to_evaluable_token();
+ EvaluableToken {
+ location,
+ token,
+ }
+ }
+}
+
#[derive(Debug)]
-enum TempEvaluableTokens {
+pub enum FullNameTokens {
+ Name(SimpleNameToken, Option),
+ StaticAccess(Box, SimpleNameToken),
+ DynamicAccess(Box, SimpleNameToken)
+}
+
+impl FullNameTokens {
+ pub fn to_evaluable_token(self) -> EvaluableTokens {
+ match self {
+ FullNameTokens::Name(n, c) => EvaluableTokens::Name(n, c),
+ FullNameTokens::StaticAccess(e, n) => EvaluableTokens::StaticAccess(b!(e.to_evaluable()), n),
+ FullNameTokens::DynamicAccess(e, n) => EvaluableTokens::DynamicAccess(b!(e.to_evaluable()), n),
+ }
+ }
+}
+
+#[derive(Debug)]
+enum TempEvaluableTokensOne {
+ EvaluableToken(EvaluableToken),
+ Operator(OperatorToken),
+ StaticAccess(SimpleNameToken),
+ DynamicAccess(SimpleNameToken),
+ FunctionCall(SimpleNameToken, Vec),
+}
+
+#[derive(Debug)]
+enum TempEvaluableTokensTwo {
EvaluableToken(EvaluableToken),
Operator(OperatorToken),
}
-pub fn parse_evaluable<'a, 'b>(s: Span<'a>, containing_class: Option<&'b str>, semicolon_terminated: bool) -> ParseResult<'a, Span<'a>, EvaluableToken> {
+pub fn parse_full_name<'a, 'b>(s: Span<'a>, containing_class: Option<&SimpleNameToken>) -> ParseResult<'a, Span<'a>, FullNameWithIndirectionToken> {
+ let mut indirection: usize = 0;
+ let mut s = s;
+ loop {
+ let (ns, _) = discard_ignored(s)?;
+
+ if let Ok((ns, _)) = char::('&')(ns) {
+ indirection += 1;
+ s = ns;
+ }
+ else {
+ s = ns;
+ break;
+ }
+ }
+
+ let (s, _) = discard_ignored(s)?;
+ let (s, section) = parse_simple_name(s)?;
+
+ let mut current = FullNameToken {
+ location: section.location().clone(),
+ token: FullNameTokens::Name(section, containing_class.and_then(|x| Some(x.clone())))
+ };
+
+ let mut s = s;
+
+ loop {
+ let (ns, _) = discard_ignored(s)?;
+
+ if let Ok((ns, _)) = tag::<&str, Span, ErrorTree>("::")(ns) {
+ let (ns, section) = parse_simple_name(ns)?;
+ current = FullNameToken {
+ location: section.location().clone(),
+ token: FullNameTokens::StaticAccess(b!(current), section),
+ };
+ s = ns;
+ }
+ if let Ok((ns, _)) = char::('.')(ns) {
+ let (ns, section) = parse_simple_name(ns)?;
+ current = FullNameToken {
+ location: section.location().clone(),
+ token: FullNameTokens::DynamicAccess(b!(current), section),
+ };
+ s = ns;
+ }
+ return Ok((s, FullNameWithIndirectionToken { indirection: Indirection(indirection), inner: current }))
+ }
+}
+
+pub fn parse_evaluable<'a, 'b>(s: Span<'a>, containing_class: Option<&SimpleNameToken>, semicolon_terminated: bool) -> ParseResult<'a, Span<'a>, EvaluableToken> {
assert!(!s.is_empty());
let mut s = s;
let mut evaluables = Vec::new();
+ // Collect evaluable sections into initial vec
loop {
let (ns, _) = discard_ignored(s)?;
+ // Terminate on semicolon if semicolon terminated
if semicolon_terminated {
if let Ok((ns, _)) = char::<_, ErrorTree>(';')(ns) {
s = ns;
@@ -54,8 +180,8 @@ pub fn parse_evaluable<'a, 'b>(s: Span<'a>, containing_class: Option<&'b str>, s
}
}
+ // Fail if semicolon terminated but reach end of span
if ns.is_empty() {
- // Fail if semicolon required but ns is empty
if semicolon_terminated {
// ! Intentional failure
char(';')(ns)?;
@@ -66,20 +192,49 @@ pub fn parse_evaluable<'a, 'b>(s: Span<'a>, containing_class: Option<&'b str>, s
break;
}
+ // Recursively parse bracketed sections
let ns = if let Ok((ns, _)) = default_section(s, '(') {
let (ns, evaluable) = parse_evaluable(ns, containing_class.clone(), false)?;
- evaluables.push(TempEvaluableTokens::EvaluableToken(evaluable));
+ evaluables.push(TempEvaluableTokensOne::EvaluableToken(evaluable));
ns
- } else {
+ }
+ // Parse evaluable
+ else {
let (ns, token) = alt((
|x| {
parse_literal(x)
.map(|(s, t)| (s, temp_from_token(s, EvaluableTokens::Literal(t))))
},
- |x| parse_operator(x).map(|(s, t)| (s, TempEvaluableTokens::Operator(t))),
+ |x| parse_operator(x).map(|(s, t)| (s, TempEvaluableTokensOne::Operator(t))),
|x| {
- parse_full_name(x, containing_class.and_then(|s| Some(s.to_string())))
- .map(|(s, t)| (s, temp_from_token(s, EvaluableTokens::Name(t))))
+ enum Kind {
+ Static,
+ Dynamic,
+ None
+ }
+
+ let (x, kind) = tag::<&str, Span, ErrorTree>("::")(x).map(|(a, _)| (a, Kind::Static))
+ .map_err(|_|
+ char::('.')(x).map(|a| (a, Kind::Dynamic)))
+ .unwrap_or((x, Kind::None));
+
+ let (x, section) = parse_simple_name(x)?;
+
+ Ok(if char::('(')(x).is_ok() {
+ let (x, arguments) = default_section(x, '(')?;
+ let (_, arguments) = parse_arguments(arguments, containing_class)?;
+ (x, TempEvaluableTokensOne::FunctionCall(section, arguments))
+ }
+ else {
+ match kind {
+ Kind::Static => (x, TempEvaluableTokensOne::StaticAccess(section)),
+ Kind::Dynamic => (x, TempEvaluableTokensOne::DynamicAccess(section)),
+ Kind::None => (x, TempEvaluableTokensOne::EvaluableToken(EvaluableToken {
+ location: section.location().clone(),
+ token: EvaluableTokens::Name(section, containing_class.and_then(|x| Some(x.clone()))),
+ })),
+ }
+ })
},
))(ns)?;
evaluables.push(token);
@@ -89,6 +244,53 @@ pub fn parse_evaluable<'a, 'b>(s: Span<'a>, containing_class: Option<&'b str>, s
s = ns;
}
+ let mut new_evaluables: Vec = Vec::new();
+
+ for eval in evaluables {
+ match eval {
+ TempEvaluableTokensOne::StaticAccess(n) => {
+ match new_evaluables.pop() {
+ Some(TempEvaluableTokensTwo::Operator(_)) => todo!(), // Can't be operator
+ Some(TempEvaluableTokensTwo::EvaluableToken(e)) => {
+ new_evaluables.push(TempEvaluableTokensTwo::EvaluableToken(EvaluableToken {
+ location: e.location.clone(),
+ token: EvaluableTokens::StaticAccess(b!(e), n),
+ }))
+ },
+ None => todo!(), // Must have previous
+ }
+ }
+ TempEvaluableTokensOne::DynamicAccess(n) => {
+ match new_evaluables.pop() {
+ Some(TempEvaluableTokensTwo::Operator(_)) => todo!(), // Can't be operator
+ Some(TempEvaluableTokensTwo::EvaluableToken(e)) => {
+ new_evaluables.push(TempEvaluableTokensTwo::EvaluableToken(EvaluableToken {
+ location: e.location.clone(),
+ token: EvaluableTokens::DynamicAccess(b!(e), n),
+ }))
+ },
+ None => todo!(), // Must have previous
+ }
+ }
+ TempEvaluableTokensOne::FunctionCall(n, a) => {
+ match new_evaluables.pop() {
+ Some(TempEvaluableTokensTwo::Operator(_)) => todo!(), // Can't be operator
+ Some(TempEvaluableTokensTwo::EvaluableToken(e)) => {
+ new_evaluables.push(TempEvaluableTokensTwo::EvaluableToken(EvaluableToken {
+ location: e.location.clone(),
+ token: EvaluableTokens::FunctionCall(b!(e), n, a),
+ }))
+ },
+ None => todo!(), // Must have previous
+ }
+ }
+ TempEvaluableTokensOne::EvaluableToken(e) => new_evaluables.push(TempEvaluableTokensTwo::EvaluableToken(e)),
+ TempEvaluableTokensOne::Operator(o) => new_evaluables.push(TempEvaluableTokensTwo::Operator(o)),
+ };
+ }
+
+ let evaluables = new_evaluables;
+
#[derive(Debug)]
enum TempOperation {
Infix(Box, OperatorToken, Box),
@@ -97,9 +299,9 @@ pub fn parse_evaluable<'a, 'b>(s: Span<'a>, containing_class: Option<&'b str>, s
}
fn parse_prefix(
- section: &[(usize, TempEvaluableTokens)],
- ) -> ParseResult<&[(usize, TempEvaluableTokens)], TempOperation> {
- let TempEvaluableTokens::Operator(operator) = §ion[0].1 else {
+ section: &[(usize, TempEvaluableTokensTwo)],
+ ) -> ParseResult<&[(usize, TempEvaluableTokensTwo)], TempOperation> {
+ let TempEvaluableTokensTwo::Operator(operator) = §ion[0].1 else {
panic!()
};
@@ -108,10 +310,10 @@ pub fn parse_evaluable<'a, 'b>(s: Span<'a>, containing_class: Option<&'b str>, s
}
let (remaining, operand) = match §ion[1] {
- (p, TempEvaluableTokens::EvaluableToken(_)) => {
+ (p, TempEvaluableTokensTwo::EvaluableToken(_)) => {
(§ion[2..], TempOperation::Value(*p))
}
- (_, TempEvaluableTokens::Operator(_)) => parse_prefix(§ion[1..])?,
+ (_, TempEvaluableTokensTwo::Operator(_)) => parse_prefix(§ion[1..])?,
};
Ok((
@@ -120,25 +322,25 @@ pub fn parse_evaluable<'a, 'b>(s: Span<'a>, containing_class: Option<&'b str>, s
))
}
- let enumerated: Vec<(usize, TempEvaluableTokens)> =
+ let enumerated: Vec<(usize, TempEvaluableTokensTwo)> =
evaluables.into_iter().enumerate().collect();
let mut base = None;
let mut after = Vec::new();
- let mut enumerated_slice: &[(usize, TempEvaluableTokens)] = &enumerated;
+ let mut enumerated_slice: &[(usize, TempEvaluableTokensTwo)] = &enumerated;
let mut operator_priority = Vec::new();
while enumerated_slice.len() > 0 {
let operator = if base.is_some() {
match &enumerated_slice[0] {
- (_, TempEvaluableTokens::Operator(op)) => {
+ (_, TempEvaluableTokensTwo::Operator(op)) => {
operator_priority.push(op.get_priority_t());
enumerated_slice = &enumerated_slice[1..];
Some(op.clone())
}
- (_, TempEvaluableTokens::EvaluableToken(_)) => {
+ (_, TempEvaluableTokensTwo::EvaluableToken(_)) => {
// ? Expected infix connecting operator
todo!()
}
@@ -148,11 +350,11 @@ pub fn parse_evaluable<'a, 'b>(s: Span<'a>, containing_class: Option<&'b str>, s
};
let value = match &enumerated_slice[0] {
- (p, TempEvaluableTokens::EvaluableToken(_)) => {
+ (p, TempEvaluableTokensTwo::EvaluableToken(_)) => {
enumerated_slice = &enumerated_slice[1..];
TempOperation::Value(*p)
}
- (_, TempEvaluableTokens::Operator(_)) => {
+ (_, TempEvaluableTokensTwo::Operator(_)) => {
let (new_slice, value) = match parse_prefix(enumerated_slice) {
Ok(r) => r,
Err(_) => {
@@ -198,12 +400,12 @@ pub fn parse_evaluable<'a, 'b>(s: Span<'a>, containing_class: Option<&'b str>, s
fn recursively_convert_temp(
base: TempOperation,
- evaluables: &mut Vec