add order of operations to the parser ( . | + - | * / % | == != < <= > >= | = )

This commit is contained in:
mark 2023-05-23 12:20:36 +02:00
parent 7af9902b6a
commit 14d1995d8b

View File

@ -840,8 +840,16 @@ pub mod implementation {
// special characters that can follow a statement (loop because these can be chained) // special characters that can follow a statement (loop because these can be chained)
loop { loop {
file.skip_whitespaces(); file.skip_whitespaces();
// most local (a.b)
// 010 .
// 020 + -
// 025 * / %
// 050 == != > < >= <=
// 200 =
// least local (a == b) | -> a.b == c + 2 works as expected
out = match (chain_level, file.peek()) { out = match (chain_level, file.peek()) {
(0..=200, Some('.')) // 010 .
(0..=10, Some('.'))
if !matches!( if !matches!(
file.get_char(file.get_pos().current_char_index + 1), file.get_char(file.get_pos().current_char_index + 1),
Some('.') Some('.')
@ -849,7 +857,7 @@ pub mod implementation {
{ {
file.next(); file.next();
let err_start_of_wrapper = *file.get_pos(); let err_start_of_wrapper = *file.get_pos();
let wrapper = parse_statement_adv(file, true, 250)?; let wrapper = parse_statement_adv(file, true, 11)?;
let err_end_of_wrapper = *file.get_pos(); let err_end_of_wrapper = *file.get_pos();
match *wrapper.statement { match *wrapper.statement {
SStatementEnum::FunctionCall(func, args) => { SStatementEnum::FunctionCall(func, args) => {
@ -891,49 +899,52 @@ pub mod implementation {
} }
} }
} }
(0..=100, Some('+')) => { // 20 + -
(0..=20, Some('+')) => {
file.next(); file.next();
SStatementEnum::FunctionCall( SStatementEnum::FunctionCall(
"add".to_owned(), "add".to_owned(),
// AMONG // AMONG
vec![out, parse_statement_adv(file, true, 100)?], vec![out, parse_statement_adv(file, false, 21)?],
) )
.to() .to()
} }
(0..=100, Some('-')) => { (0..=20, Some('-')) => {
file.next(); file.next();
SStatementEnum::FunctionCall( SStatementEnum::FunctionCall(
"sub".to_owned(), "sub".to_owned(),
// US // US
vec![out, parse_statement_adv(file, true, 100)?], vec![out, parse_statement_adv(file, false, 21)?],
) )
.to() .to()
} }
(0..=100, Some('*')) => { // 025 * / %
(0..=25, Some('*')) => {
file.next(); file.next();
SStatementEnum::FunctionCall( SStatementEnum::FunctionCall(
"mul".to_owned(), "mul".to_owned(),
vec![out, parse_statement_adv(file, true, 100)?], vec![out, parse_statement_adv(file, false, 26)?],
) )
.to() .to()
} }
(0..=100, Some('/')) => { (0..=25, Some('/')) => {
file.next(); file.next();
SStatementEnum::FunctionCall( SStatementEnum::FunctionCall(
"div".to_owned(), "div".to_owned(),
// RED SUSSY MOGUS MAN // RED SUSSY MOGUS MAN
vec![out, parse_statement_adv(file, true, 100)?], vec![out, parse_statement_adv(file, false, 26)?],
) )
.to() .to()
} }
(0..=100, Some('%')) => { (0..=25, Some('%')) => {
file.next(); file.next();
SStatementEnum::FunctionCall( SStatementEnum::FunctionCall(
"mod".to_owned(), "mod".to_owned(),
vec![out, parse_statement_adv(file, true, 100)?], vec![out, parse_statement_adv(file, false, 26)?],
) )
.to() .to()
} }
// 050 == != > >= < <=
(0..=50, Some('>')) => { (0..=50, Some('>')) => {
file.next(); file.next();
SStatementEnum::FunctionCall( SStatementEnum::FunctionCall(
@ -943,7 +954,7 @@ pub mod implementation {
} else { } else {
"gt".to_owned() "gt".to_owned()
}, },
vec![out, parse_statement_adv(file, true, 50)?], vec![out, parse_statement_adv(file, false, 51)?],
) )
.to() .to()
} }
@ -956,7 +967,7 @@ pub mod implementation {
} else { } else {
"lt".to_owned() "lt".to_owned()
}, },
vec![out, parse_statement_adv(file, true, 50)?], vec![out, parse_statement_adv(file, false, 51)?],
) )
.to() .to()
} }
@ -970,7 +981,7 @@ pub mod implementation {
file.next(); file.next();
SStatementEnum::FunctionCall( SStatementEnum::FunctionCall(
"eq".to_owned(), "eq".to_owned(),
vec![out, parse_statement_adv(file, true, 50)?], vec![out, parse_statement_adv(file, false, 51)?],
) )
.to() .to()
} }
@ -984,11 +995,12 @@ pub mod implementation {
file.next(); file.next();
SStatementEnum::FunctionCall( SStatementEnum::FunctionCall(
"ne".to_owned(), "ne".to_owned(),
vec![out, parse_statement_adv(file, true, 50)?], vec![out, parse_statement_adv(file, false, 51)?],
) )
.to() .to()
} }
(0..=10, Some('=')) => { // 200 =
(0..=200, Some('=')) => {
file.next(); file.next();
match out.statement.as_mut() { match out.statement.as_mut() {
SStatementEnum::Variable(name, r) => { SStatementEnum::Variable(name, r) => {
@ -1000,6 +1012,7 @@ pub mod implementation {
} }
_ => {} _ => {}
} }
// NOTE: Set this 0 to 201 to prevent a = b = c from being valid
parse_statement(file)?.output_to(out, 0) parse_statement(file)?.output_to(out, 0)
} }
_ => break, _ => break,