diff --git a/src/root/nom_parser/parse_blocks.rs b/src/root/nom_parser/parse_blocks.rs index d3394b7..8f6bcdf 100644 --- a/src/root/nom_parser/parse_blocks.rs +++ b/src/root/nom_parser/parse_blocks.rs @@ -4,6 +4,8 @@ use nom::character::complete::char; use nom::sequence::Tuple; use nom_supreme::tag::complete::tag; +// ! BROKEN + pub fn braced_section(s: Span) -> ParseResult { (char('{'), take_until("}"), char('}')) .parse(s) diff --git a/src/root/nom_parser/parse_function/parse_assigner.rs b/src/root/nom_parser/parse_function/parse_assigner.rs index 3b7e13c..726497a 100644 --- a/src/root/nom_parser/parse_function/parse_assigner.rs +++ b/src/root/nom_parser/parse_function/parse_assigner.rs @@ -28,8 +28,6 @@ const ASSIGNERS: [(&str, AssignmentOperatorTokens); 2] = [ ]; pub fn parse_assigner(s: Span) -> ParseResult { - let (s, _) = multispace0(s)?; - let (ns, a) = alt_many(ASSIGNERS.map(|(t, o)| move |x| tag(t)(x).map(|(s, _)| (s, o.clone())))) .parse(s)?; diff --git a/src/root/nom_parser/parse_function/parse_assignment.rs b/src/root/nom_parser/parse_function/parse_assignment.rs index e7c55eb..3089c0b 100644 --- a/src/root/nom_parser/parse_function/parse_assignment.rs +++ b/src/root/nom_parser/parse_function/parse_assignment.rs @@ -1,11 +1,38 @@ -use crate::root::nom_parser::parse::Location; -use crate::root::nom_parser::parse_function::parse_assigner::AssignmentOperatorToken; -use crate::root::nom_parser::parse_function::parse_evaluable::EvaluableToken; +use nom::character::complete::{multispace0, multispace1}; +use nom::sequence::Tuple; +use nom_supreme::tag::complete::tag; +use crate::root::nom_parser::parse::{Location, ParseResult, Span}; +use crate::root::nom_parser::parse_function::parse_assigner::{AssignmentOperatorToken, parse_assigner}; +use crate::root::nom_parser::parse_function::parse_evaluable::{EvaluableToken, parse_evaluable}; +use crate::root::nom_parser::parse_function::parse_initialisation::parse_initialisation; +use crate::root::nom_parser::parse_function::parse_line::{LineTestFn, LineTokens}; +use crate::root::nom_parser::parse_name::{NameToken, parse_full_name}; #[derive(Debug)] pub struct AssignmentToken { location: Location, - name: String, + name: NameToken, assignment_operator: AssignmentOperatorToken, value: EvaluableToken, } + +// TODO: Find good way to implement? +pub fn test_parse_assignment<'a>(s: Span<'a>) -> ParseResult> { + Ok((s, |x| parse_assignment(x).map(|(s, x)| (s, LineTokens::Assignment(x))))) +} + +pub fn parse_assignment(s: Span) -> ParseResult { + let (s, _) = multispace0(s)?; + let location = Location::from_span(s); + let (s, n) = parse_full_name(s)?; + let (s, _) = multispace0(s)?; + let (s, a) = parse_assigner(s)?; + let (s, _) = multispace0(s)?; + let (s, e) = parse_evaluable(s, true)?; + Ok((s, AssignmentToken { + location, + name: n, + assignment_operator: a, + value: e, + })) +} \ No newline at end of file diff --git a/src/root/nom_parser/parse_function/parse_line.rs b/src/root/nom_parser/parse_function/parse_line.rs index 823de4c..57d9c7c 100644 --- a/src/root/nom_parser/parse_function/parse_line.rs +++ b/src/root/nom_parser/parse_function/parse_line.rs @@ -1,5 +1,5 @@ use crate::root::nom_parser::parse::{ErrorTree, ParseResult, Span}; -use crate::root::nom_parser::parse_function::parse_assignment::AssignmentToken; +use crate::root::nom_parser::parse_function::parse_assignment::{AssignmentToken, test_parse_assignment}; use crate::root::nom_parser::parse_function::parse_break::{test_parse_break, BreakToken}; use crate::root::nom_parser::parse_function::parse_evaluable::{parse_evaluable, EvaluableToken}; use crate::root::nom_parser::parse_function::parse_if::{test_parse_if, IfToken}; @@ -50,6 +50,7 @@ pub fn parse_line(s: Span) -> ParseResult { test_parse_initialisation, test_parse_while, test_parse_if, + test_parse_assignment, )) .parse(s) { diff --git a/src/root/nom_parser/parse_name.rs b/src/root/nom_parser/parse_name.rs index a432dba..9b36de1 100644 --- a/src/root/nom_parser/parse_name.rs +++ b/src/root/nom_parser/parse_name.rs @@ -1,6 +1,7 @@ use crate::root::nom_parser::parse::{ErrorTree, Location, ParseResult, Span}; use crate::root::nom_parser::parse_function::parse_evaluable::EvaluableToken; use nom::bytes::complete::take_till; +use nom::character::complete::multispace0; use nom::Err::Error; use nom::InputTake; use nom_supreme::error::{BaseErrorKind, Expectation}; @@ -22,6 +23,8 @@ pub struct NameToken { pub fn parse_full_name(s: Span) -> ParseResult { // TODO: Handle function calls + let (s, _) = multispace0(s)?; + let location = Location::from_span(s); let (mut s, base_name) = parse_simple_name(s)?;