Skip to content

Commit

Permalink
Continued nom parser implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Lucas committed Apr 10, 2024
1 parent daa0399 commit 1bbb195
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ nom = "7.1.3"
nom_locate = "4.2.0"
nom-supreme = "0.8.0"
substring = "1.4.5"
accessors-rs = "0.1.0"

[profile.release]
opt-level = 3
Expand Down
17 changes: 11 additions & 6 deletions src/root/nom_parser/parse_function/parse_evaluable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub fn parse_evaluable(s: Span, semicolon_terminated: bool) -> ParseResult<Span,

debug_assert!(after.is_empty());

let mut evaluables: Vec<_> = evaluables.into_iter().map(|e| Some(e)).collect();
let mut evaluables: Vec<_> = enumerated.into_iter().map(|(_, e)| Some(e)).collect();


fn recursively_convert_temp(base: TempOperation, evaluables: &mut Vec<Option<TempEvaluableTokens>>) -> EvaluableToken {
Expand All @@ -205,19 +205,24 @@ pub fn parse_evaluable(s: Span, semicolon_terminated: bool) -> ParseResult<Span,

match base {
TempOperation::Infix(lhs, op, rhs) => {
let lhs = recursively_convert_temp(lhs.into(), evaluables);
let lhs = recursively_convert_temp(*lhs, evaluables);
EvaluableToken {
location: lhs.location.clone(),
token: EvaluableTokens::InfixOperator(
b!(lhs),
op,
b!(recursively_convert_temp(rhs.into(), evaluables))
b!(recursively_convert_temp(*rhs, evaluables))
),
}

}
TempOperation::Prefix(_, _) => {

TempOperation::Prefix(op, operand) => {
EvaluableToken {
location: op.location().clone(),
token: EvaluableTokens::PrefixOperator(
op,
b!(recursively_convert_temp(*operand, evaluables))
),
}
}
TempOperation::Value(p) => {
not_operator(evaluables[p].take().unwrap())
Expand Down
4 changes: 3 additions & 1 deletion src/root/nom_parser/parse_function/parse_operator.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use accessors_rs::Accessors;
use nom::Err::Error;
use nom::error::{ErrorKind, ParseError};
use nom::Parser;
Expand Down Expand Up @@ -33,8 +34,9 @@ pub fn get_priority(operator: &OperatorTokens) -> usize {
panic!()
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Accessors)]
pub struct OperatorToken {
#[accessors(get)]
location: Location,
operator: OperatorTokens,
}
Expand Down

0 comments on commit 1bbb195

Please sign in to comment.