plum

#treesitter#compiler#wasm

git clone https://git.pyrossh.dev/plum

A statically typed, imperative programming language inspired by rust, python


82f60a0 — Peter John 2026-11-10T11:39:06+05:30
parser: one path for a type that may be a fn type
Files changed (1) hide show
  1. compiler/core/src/parser.rs +4 -16
compiler/core/src/parser.rs CHANGED
@@ -454,13 +454,7 @@ impl<'a> AstParser<'a> {
454
454
  .unwrap_or_default();
455
455
  let ty = n
456
456
  .child_by_field_name("type")
457
- .map(|c| match c.kind() {
458
- "fn_value_type" => match self.parseFnValueType(c) {
459
- ParamType::Fn(ps, ret) => Type::fnType(ps, ret.map(|r| *r)),
460
- _ => unreachable!(),
461
- },
462
- _ => self.parseType(c),
457
+ .map(|c| self.parseTypeOrFn(c))
463
- })
464
458
  .unwrap_or(Type {
465
459
  name: String::new(),
466
460
  generics: vec![],
@@ -712,8 +706,8 @@ impl<'a> AstParser<'a> {
712
706
  let generics: Vec<Type> = node
713
707
  .named_children(&mut cursor)
714
708
  .skip(1)
715
- .filter(|n| n.kind() == "type")
709
+ .filter(|n| n.kind() == "type" || n.kind() == "fn_value_type")
716
- .map(|n| self.parseType(n))
710
+ .map(|n| self.parseTypeOrFn(n))
717
711
  .collect();
718
712
  Type { name, generics }
719
713
  }
@@ -864,13 +858,7 @@ impl<'a> AstParser<'a> {
864
858
  // The annotated form `name: Type := value` has a `type` field child
865
859
  // between the one target and the values.
866
860
  let ty_node = node.child_by_field_name("type");
867
- let ty = ty_node.map(|n| match n.kind() {
861
+ let ty = ty_node.map(|n| self.parseTypeOrFn(n));
868
- "fn_value_type" => match self.parseFnValueType(n) {
869
- ParamType::Fn(ps, ret) => Type::fnType(ps, ret.map(|r| *r)),
870
- _ => unreachable!(),
871
- },
872
- _ => self.parseType(n),
873
- });
874
862
  let named: Vec<Node> = self
875
863
  .namedChildren(node)
876
864
  .into_iter()