diff options
author | JJ | 2023-04-13 08:23:19 +0000 |
---|---|---|
committer | JJ | 2023-04-13 08:23:19 +0000 |
commit | f1286b162b9223f039ac561dcd4fea5bbfa831d3 (patch) | |
tree | e17767adc05c1fffaaaf004b6aff40dd9bf7a5b9 /src | |
parent | 5ae010fef48cc2bf83a0d366d2a1cfa74ecce278 (diff) |
unbreak tests
Diffstat (limited to 'src')
-rw-r--r-- | src/parser.rs | 14 | ||||
-rw-r--r-- | src/util.rs | 12 |
2 files changed, 22 insertions, 4 deletions
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<Expression, peg::error::ParseError<pe // this is kinda awful, i miss my simple nim pegs peg::parser! { grammar lambda() for str { - rule ident() -> String - = i:['a'..='z' | 'A'..='Z' | '0'..='9']+ { + rule ident() -> String = i:['a'..='z' | 'A'..='Z' | '0'..='9']+ { i.iter().collect::<String>() } - 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::<String>().parse::<usize>().unwrap(); Expression::Constant { term: if let Some(_) = p { @@ -44,6 +49,7 @@ pub fn parse_lambda(input: &str) -> Result<Expression, peg::error::ParseError<pe } } } + rule cons() -> 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<usize>) -> Term { + return Term::String { len, cap, data } +} + +pub fn Enum(val: usize, data: Vec<Type>) -> Term { + return Term::Enum { val, data } +} |