diff --git a/src/parser/expression/expression.rs b/src/parser/expression/expression.rs index 564a162..f366e63 100644 --- a/src/parser/expression/expression.rs +++ b/src/parser/expression/expression.rs @@ -11,6 +11,23 @@ use super::super::LineLocation; #[derive(Debug)] #[derive(Clone)] pub enum Expression { + // Meaning of `LineLocation`: + // + // For Variables, Constants, Quantities, Tuples: + // If this expression was parsed, LineLocation is what part of the prompt was parsed to get this expression + // If this expression is the result of a calculation, LineLocaion is the sum of the LineLocations of + // all expressions used to make it. In other words, it points to the part of the prompt that was evaluated + // to get this new expression. + // + // For Operators: + // Linelocation points to the operator's position in the prompt. + // If this is a function, it points to the function name. + // If this is `+`, `!`, or etc, it points to that character. + // Operator arguments are NOT included in this linelocation. + // + // + // All the above rules are implemented when parsing and evaluating expressions. + Variable(LineLocation, String), Quantity(LineLocation, Quantity), Constant(LineLocation, Constant), diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 56f4eef..fe3a0d5 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -35,6 +35,12 @@ pub fn parse_no_context(s: &String) -> Result String { if !context.config.enable_substituion { return s.clone(); } let (_, s) = substitute_cursor(context, s, s.chars().count()); diff --git a/src/parser/stage/find_subs.rs b/src/parser/stage/find_subs.rs index 865f407..a7b09d4 100644 --- a/src/parser/stage/find_subs.rs +++ b/src/parser/stage/find_subs.rs @@ -62,13 +62,13 @@ fn sub_string(s: &str) -> Option<&'static str> { } - - +// Finds substitutions in an array of tokens. +// Returns new token array and substitution list. pub fn find_subs( mut g: VecDeque, ) -> ( - VecDeque<(LineLocation, String)>, - VecDeque + VecDeque<(LineLocation, String)>, // List of substrings to replace (in order) + VecDeque // New token array, with updated strings and linelocations ) { // Array of replacements @@ -103,7 +103,7 @@ pub fn find_subs( }; if target.is_none() { - // Even if nothing changed, we need to update token location + // Even if nothing changed, we need to update the new token's linelocation let l = t.get_mut_linelocation(); *l = LineLocation{pos: l.pos - offset, len: l.len}; } else {