summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNadrieril2019-02-27 19:27:28 +0100
committerNadrieril2019-02-27 19:27:28 +0100
commit8cd386521267bf95ae00b7068cda9422305eec29 (patch)
tree1032ac5e68e14ef0833358f645670d6858468fec
parentd8b88c1a5da7218011fca2bccc525907aa439335 (diff)
Fix mixed up parsing of integers/naturals
-rw-r--r--src/lexer.rs4
-rw-r--r--src/parser.rs6
2 files changed, 5 insertions, 5 deletions
diff --git a/src/lexer.rs b/src/lexer.rs
index d396951..32e6abe 100644
--- a/src/lexer.rs
+++ b/src/lexer.rs
@@ -89,11 +89,11 @@ macro_rules! digits {
}}
}
-named!(natural<&str, usize>, preceded!(tag!("+"), digits!(usize, 10)));
+named!(natural<&str, usize>, digits!(usize, 10));
named!(integral<&str, isize>, digits!(isize, 10));
named!(integer<&str, isize>, alt!(
preceded!(tag!("-"), map!(integral, |i: isize| -i)) |
- integral
+ preceded!(tag!("+"), integral)
));
named!(boolean<&str, bool>, alt!(
value!(true, tag!("True")) |
diff --git a/src/parser.rs b/src/parser.rs
index 2e252b1..8416d9b 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -13,15 +13,15 @@ pub fn parse_expr(s: &str) -> Result<BoxExpr, ParseError> {
#[test]
fn test_parse() {
use crate::core::Expr::*;
- println!("test {:?}", parse_expr("+3 + +5 * +10"));
+ println!("test {:?}", parse_expr("3 + 5 * 10"));
assert!(parse_expr("22").is_ok());
assert!(parse_expr("(22)").is_ok());
- assert_eq!(parse_expr("+3 + +5 * +10").ok(),
+ assert_eq!(parse_expr("3 + 5 * 10").ok(),
Some(Box::new(NaturalPlus(Box::new(NaturalLit(3)),
Box::new(NaturalTimes(Box::new(NaturalLit(5)),
Box::new(NaturalLit(10))))))));
// The original parser is apparently right-associative
- assert_eq!(parse_expr("+2 * +3 * +4").ok(),
+ assert_eq!(parse_expr("2 * 3 * 4").ok(),
Some(Box::new(NaturalTimes(Box::new(NaturalLit(2)),
Box::new(NaturalTimes(Box::new(NaturalLit(3)),
Box::new(NaturalLit(4))))))));