From f1286b162b9223f039ac561dcd4fea5bbfa831d3 Mon Sep 17 00:00:00 2001 From: JJ Date: Thu, 13 Apr 2023 01:23:19 -0700 Subject: unbreak tests --- src/parser.rs | 14 ++++++++++---- src/util.rs | 12 ++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/parser.rs b/src/parser.rs index 8eac52d..d6eb69d 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -29,12 +29,17 @@ pub fn parse_lambda(input: &str) -> Result String - = i:['a'..='z' | 'A'..='Z' | '0'..='9']+ { + rule ident() -> String = i:['a'..='z' | 'A'..='Z' | '0'..='9']+ { i.iter().collect::() } - rule cons() -> Expression - = p:"-"? c:['0'..='9']+ { + rule bool() -> Expression = b:$("true" / "false") { + match b { + "true" => Expression::Constant { term: Term::Boolean(true) }, + "false" => Expression::Constant { term: Term::Boolean(false) }, + _ => Expression::Constant { term: Term::Unit() } + } + } + rule num() -> Expression = p:"-"? c:['0'..='9']+ { let value = c.iter().collect::().parse::().unwrap(); Expression::Constant { term: if let Some(_) = p { @@ -44,6 +49,7 @@ pub fn parse_lambda(input: &str) -> Result Expression = c:(bool() / num()) rule primitive() -> Type = k:$("empty" / "unit" / "bool" / "nat" / "int") { match k { diff --git a/src/util.rs b/src/util.rs index 70bd8e4..4b47afc 100644 --- a/src/util.rs +++ b/src/util.rs @@ -65,3 +65,15 @@ pub const Unit: Type = Type::Unit; pub const Bool: Type = Type::Boolean; pub const Nat: Type = Type::Natural; pub const Int: Type = Type::Integer; + +pub fn Float(term: f32) -> Term { + return Term::Float(term) +} + +pub fn Str(len: usize, cap: usize, data: Vec) -> Term { + return Term::String { len, cap, data } +} + +pub fn Enum(val: usize, data: Vec) -> Term { + return Term::Enum { val, data } +} -- cgit v1.2.3-70-g09d2