MCPcopy Create free account
hub / github.com/agenticsorg/lean-agentic / parse_inductive

Method parse_inductive

leanr-syntax/src/parser.rs:150–186  ·  view source on GitHub ↗

Parse inductive declaration

(&mut self)

Source from the content-addressed store, hash-verified

148
149 /// Parse inductive declaration
150 fn parse_inductive(&mut self) -> crate::Result<InductiveDecl> {
151 let start = self.expect(TokenKind::Inductive)?.span;
152
153 let name = self.parse_ident()?;
154 let universe_params = self.parse_universe_params()?;
155 let params = self.parse_params()?;
156
157 let type_ = if self.check(&TokenKind::Colon) {
158 self.advance();
159 Some(Box::new(self.parse_expr()?))
160 } else {
161 None
162 };
163
164 self.expect(TokenKind::Where)?;
165
166 let mut constructors = Vec::new();
167 while self.check(&TokenKind::Pipe) {
168 self.advance();
169 constructors.push(self.parse_constructor()?);
170 }
171
172 let end = if let Some(last) = constructors.last() {
173 last.span
174 } else {
175 name.span
176 };
177
178 Ok(InductiveDecl {
179 span: start.to(end),
180 name,
181 universe_params,
182 params,
183 type_,
184 constructors,
185 })
186 }
187
188 /// Parse a constructor
189 fn parse_constructor(&mut self) -> crate::Result<Constructor> {

Callers 1

parse_declMethod · 0.80

Calls 10

expectMethod · 0.80
parse_identMethod · 0.80
parse_universe_paramsMethod · 0.80
parse_paramsMethod · 0.80
parse_exprMethod · 0.80
parse_constructorMethod · 0.80
toMethod · 0.80
checkMethod · 0.45
advanceMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected