fn parse_function(&mut self, func_token: Token, anonymous: bool) -> Result<NodeId, Error> {
      let name = if !anonymous {
         let name = self.lexer.next_token()?;
         self.parse_identifier(name)?
      } else {
         NodeId::EMPTY
      };

      let left_paren = self.expect(TokenKind::LeftParen, |_| ErrorKind::LeftParenExpected)?;
      let mut parameters = Vec::new();
      self.parse_comma_separated(&mut parameters, TokenKind::RightParen, |p| {
         let name = p.lexer.next_token()?;
         p.parse_identifier(name)
      })?;

      // We allow either `constructor` or `static`, but not both.
      let kind = if let Some(token) = self.try_next(TokenKind::Constructor)? {
         self.ast.build_node(NodeKind::Constructor, ()).with_location(token.location).done()
      } else if let Some(token) = self.try_next(TokenKind::Static)? {
         self.ast.build_node(NodeKind::Static, ()).with_location(token.location).done()
      } else {
         NodeId::EMPTY
      };

      let parameters = self
         .ast
         .build_node(NodeKind::Parameters, kind)
         .with_location(left_paren.location)
         .with_children(parameters)
         .done();

      let mut body = Vec::new();
      self.parse_terminated_block(&func_token, &mut body, |k| *k == TokenKind::End)?;
      let _end = self.lexer.next_token();

      Ok(self
         .ast
         .build_node(NodeKind::Func, (name, parameters))
         .with_location(func_token.location)
         .with_children(body)
         .done())
   }
/// Parses a function. `anonymous` decides if the function has a name or not.
Parses a function. `anonymous` decides if the function has a name or not.
Parses a function . ` anonymous ` decides if the function has a name or not .
fn parse_function(&mut self, func_token: Token, anonymous: bool) -> Result<NodeId, Error> {
      let name = if !anonymous {
         let name = self.lexer.next_token()?;
         self.parse_identifier(name)?
      } else {
         NodeId::EMPTY
      };
      let left_paren = self.expect(TokenKind::LeftParen, |_| ErrorKind::LeftParenExpected)?;
      let mut parameters = Vec::new();
      self.parse_comma_separated(&mut parameters, TokenKind::RightParen, |p| {
         let name = p.lexer.next_token()?;
         p.parse_identifier(name)
      })?;
      // We allow either `constructor` or `static`, but not both.
      let kind = if let Some(token) = self.try_next(TokenKind::Constructor)? {
         self.ast.build_node(NodeKind::Constructor, ()).with_location(token.location).done()
      } else if let Some(token) = self.try_next(TokenKind::Static)? {
         self.ast.build_node(NodeKind::Static, ()).with_location(token.location).done()
      } else {
         NodeId::EMPTY
      };
      let parameters = self
         .ast
         .build_node(NodeKind::Parameters, kind)
         .with_location(left_paren.location)
         .with_children(parameters)
         .done();
      let mut body = Vec::new();
      self.parse_terminated_block(&func_token, &mut body, |k| *k == TokenKind::End)?;
      let _end = self.lexer.next_token();
      Ok(self
         .ast
         .build_node(NodeKind::Func, (name, parameters))
         .with_location(func_token.location)
         .with_children(body)
         .done())
   }
fn parse_function ( & mut self , func_token : Token , anonymous : bool ) -> Result < NodeId , Error > { let name = if ! anonymous { let name = self . lexer . next_token ( ) ? ; self . parse_identifier ( name ) ? } else { NodeId :: EMPTY } ; let left_paren = self . expect ( TokenKind :: LeftParen , | _ | ErrorKind :: LeftParenExpected ) ? ; let mut parameters = Vec :: new ( ) ; self . parse_comma_separated ( & mut parameters , TokenKind :: RightParen , | p | { let name = p . lexer . next_token ( ) ? ; p . parse_identifier ( name ) } ) ? ; // We allow either `constructor` or `static`, but not both. let kind = if let Some ( token ) = self . try_next ( TokenKind :: Constructor ) ? { self . ast . build_node ( NodeKind :: Constructor , ( ) ) . with_location ( token . location ) . done ( ) } else if let Some ( token ) = self . try_next ( TokenKind :: Static ) ? { self . ast . build_node ( NodeKind :: Static , ( ) ) . with_location ( token . location ) . done ( ) } else { NodeId :: EMPTY } ; let parameters = self . ast . build_node ( NodeKind :: Parameters , kind ) . with_location ( left_paren . location ) . with_children ( parameters ) . done ( ) ; let mut body = Vec :: new ( ) ; self . parse_terminated_block ( & func_token , & mut body , | k | * k == TokenKind :: End ) ? ; let _end = self . lexer . next_token ( ) ; Ok ( self . ast . build_node ( NodeKind :: Func , ( name , parameters ) ) . with_location ( func_token . location ) . with_children ( body ) . done ( ) ) }
Parses a function.
Parses a function .
&mut self
func_token
Token
anonymous
bool