Add parser (and etc.) support for print statements.

This commit is contained in:
2022-02-16 20:52:23 -08:00
parent 0293eee2d0
commit 6c5ca6b782
4 changed files with 35 additions and 27 deletions

View File

@@ -38,33 +38,35 @@ impl FromStr for Program {
#[test]
fn order_of_operations() {
let muladd1 = "1 + 2 * 3";
let muladd1 = "1 + 2 * 3;";
let testfile = 0;
assert_eq!(
Program::from_str(muladd1).unwrap(),
Program {
statements: vec![],
result: Expression::Primitive(
Location::InFile(testfile, 2),
"+".to_string(),
vec![
Expression::Value(Location::InFile(testfile, 0), Value::Number(None, 1)),
Expression::Primitive(
Location::InFile(testfile, 6),
"*".to_string(),
vec![
Expression::Value(
Location::InFile(testfile, 4),
Value::Number(None, 2),
),
Expression::Value(
Location::InFile(testfile, 8),
Value::Number(None, 3),
),
]
)
]
)
statements: vec![Statement::Expr(
Location::InFile(testfile, 0),
Expression::Primitive(
Location::InFile(testfile, 2),
"+".to_string(),
vec![
Expression::Value(Location::InFile(testfile, 0), Value::Number(None, 1)),
Expression::Primitive(
Location::InFile(testfile, 6),
"*".to_string(),
vec![
Expression::Value(
Location::InFile(testfile, 4),
Value::Number(None, 2),
),
Expression::Value(
Location::InFile(testfile, 8),
Value::Number(None, 3),
),
]
)
]
)
),],
}
);
}