summaryrefslogtreecommitdiff
path: root/src/parser.rs
diff options
context:
space:
mode:
authorJJ2023-04-13 03:06:40 +0000
committerJJ2023-04-13 03:37:06 +0000
commit188631f3bb263700c34d578af5968ab80e699485 (patch)
treefc4591684f4b9700d03516595e8b3d66d3a58579 /src/parser.rs
parent56f47bb2e5816de7630569a8825914d0620983cc (diff)
minor cleanupscpsc539
Diffstat (limited to 'src/parser.rs')
-rw-r--r--src/parser.rs22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/parser.rs b/src/parser.rs
index add31d9..6e6a262 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -47,21 +47,23 @@ pub fn parse_lambda(input: &str) -> Result<Expression, peg::error::ParseError<pe
}
}
}
- // fucking awful but i don't know another way
- // k:("empty" / "unit" / etc) returns ()
- // and i can't seem to match and raise a parse error
- // so ¯\_(ツ)_/¯
- rule empty() -> Type = k:"empty" {Type::Empty}
- rule unit() -> Type = k:"unit" {Type::Unit}
- rule boolean() -> Type = k:"bool" {Type::Boolean}
- rule natural() -> Type = k:"nat" {Type::Natural}
- rule integer() -> Type = k:"int" {Type::Integer}
+ rule primitive() -> Type
+ = k:$("empty" / "unit" / "bool" / "nat" / "int") {
+ match k {
+ "empty" => Type::Empty,
+ "unit" => Type::Unit,
+ "bool" => Type::Boolean,
+ "nat" => Type::Natural,
+ "int" => Type::Integer,
+ _ => Type::Empty
+ }
+ }
// fixme: brackets are necessary here
rule function() -> Type = "(" f:kind() " "* "->" " "* t:kind() ")" {
Type::Function { from: Box::new(f), to: Box::new(t) }
}
rule kind() -> Type
- = k:(function() / empty() / unit() / boolean() / natural() / integer()) {
+ = k:(function() / primitive()) {
k
}
rule ann() -> Expression