Skip to content

Commit

Permalink
Add toplevel let to parser
Browse files Browse the repository at this point in the history
  • Loading branch information
BinderDavid committed Mar 21, 2024
1 parent db40458 commit 570150f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lang/parser/src/cst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub enum Decl {
Codata(Codata),
Def(Def),
Codef(Codef),
Let(Let),
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -99,6 +100,17 @@ pub struct Codef {
pub body: Match,
}

#[derive(Debug, Clone)]
pub struct Let {
pub span: Span,
pub doc: Option<DocComment>,
pub name: Ident,
pub attr: Attribute,
pub params: Telescope,
pub typ: Rc<Exp>,
pub body: Rc<Exp>,
}

#[derive(Debug, Clone)]
pub struct Match {
pub span: Span,
Expand Down
4 changes: 3 additions & 1 deletion lang/parser/src/grammar/cst.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ match {
r"0|[1-9][0-9]*",
// Keywords
"data", "codata",
"def", "codef",
"def", "codef", "let",
"match", "as", "comatch",
"absurd", "..absurd",
"Type",
Expand Down Expand Up @@ -95,6 +95,8 @@ pub Decl: Decl = {
<l: @L> <doc: DocComment?> <attr: OptAttribute> "codata" <name: UpperIdent> <params: OptTelescope> "{" <dtors: Comma<Dtor>> "}" <r: @R> => Decl::Codata(Codata { span: span(l, r), doc, name, attr, params, dtors }),
<l: @L> <doc: DocComment?> <attr: OptAttribute> "def" <scrutinee: Scrutinee> "." <name: LowerIdent> <params: OptTelescope> ":" <ret_typ: Exp> "{" <body: Match> "}" <r: @R> => Decl::Def(Def { span: span(l, r), doc, name, attr, params, scrutinee, ret_typ, body }),
<l: @L> <doc: DocComment?> <attr: OptAttribute> "codef" <name: UpperIdent> <params: OptTelescope> ":" <typ: TypApp> "{" <body: Match> "}" <r: @R> => Decl::Codef(Codef { span: span(l, r), doc, name, attr, params, typ, body }),
<l: @L> <doc: DocComment?> <attr: OptAttribute> "let" <name: LowerIdent><params: OptTelescope> ":" <typ: Exp> "{" <body: Exp> "}" <r: @R> =>
Decl::Let(Let { span: span(l,r), doc, name, attr, params, typ, body }),
}

Ctor: Ctor = {
Expand Down

0 comments on commit 570150f

Please sign in to comment.