fn parse_prototype(&mut self) -> Result<Prototype, &'static str> {
        let (id, is_operator, precedence) = match self.curr() {
            Ident(id) => {
                self.advance()?;

                (id, false, 0)
            }

            Binary => {
                self.advance()?;

                let op = match self.curr() {
                    Op(ch) => ch,
                    _ => return Err("Expected operator in custom operator declaration."),
                };

                self.advance()?;

                let mut name = String::from("binary");

                name.push(op);

                let prec = if let Number(prec) = self.curr() {
                    self.advance()?;

                    prec as usize
                } else {
                    0
                };

                self.prec.insert(op, prec as i32);

                (name, true, prec)
            }

            Unary => {
                self.advance()?;

                let op = match self.curr() {
                    Op(ch) => ch,
                    _ => return Err("Expected operator in custom operator declaration."),
                };

                let mut name = String::from("unary");

                name.push(op);

                self.advance()?;

                (name, true, 0)
            }

            _ => return Err("Expected identifier in prototype declaration."),
        };

        match self.curr() {
            LParen => (),
            _ => return Err("Expected '(' character in prototype declaration."),
        }

        self.advance()?;

        if let RParen = self.curr() {
            self.advance();

            return Ok(Prototype {
                name: id,
                args: vec![],
                is_op: is_operator,
                prec: precedence,
            });
        }

        let mut args = vec![];

        loop {
            match self.curr() {
                Ident(name) => args.push(name),
                _ => return Err("Expected identifier in parameter declaration."),
            }

            self.advance()?;

            match self.curr() {
                RParen => {
                    self.advance();
                    break;
                }
                Comma => {
                    self.advance();
                }
                _ => return Err("Expected ',' or ')' character in prototype declaration."),
            }
        }

        Ok(Prototype {
            name: id,
            args: args,
            is_op: is_operator,
            prec: precedence,
        })
    }
/// Parses the prototype of a function, whether external or user-defined.
Parses the prototype of a function, whether external or user-defined.
Parses the prototype of a function whether external or user - defined .
fn parse_prototype(&mut self) -> Result<Prototype, &'static str> {
        let (id, is_operator, precedence) = match self.curr() {
            Ident(id) => {
                self.advance()?;
                (id, false, 0)
            }
            Binary => {
                self.advance()?;
                let op = match self.curr() {
                    Op(ch) => ch,
                    _ => return Err("Expected operator in custom operator declaration."),
                };
                self.advance()?;
                let mut name = String::from("binary");
                name.push(op);
                let prec = if let Number(prec) = self.curr() {
                    self.advance()?;
                    prec as usize
                } else {
                    0
                };
                self.prec.insert(op, prec as i32);
                (name, true, prec)
            }
            Unary => {
                self.advance()?;
                let op = match self.curr() {
                    Op(ch) => ch,
                    _ => return Err("Expected operator in custom operator declaration."),
                };
                let mut name = String::from("unary");
                name.push(op);
                self.advance()?;
                (name, true, 0)
            }
            _ => return Err("Expected identifier in prototype declaration."),
        };
        match self.curr() {
            LParen => (),
            _ => return Err("Expected '(' character in prototype declaration."),
        }
        self.advance()?;
        if let RParen = self.curr() {
            self.advance();
            return Ok(Prototype {
                name: id,
                args: vec![],
                is_op: is_operator,
                prec: precedence,
            });
        }
        let mut args = vec![];
        loop {
            match self.curr() {
                Ident(name) => args.push(name),
                _ => return Err("Expected identifier in parameter declaration."),
            }
            self.advance()?;
            match self.curr() {
                RParen => {
                    self.advance();
                    break;
                }
                Comma => {
                    self.advance();
                }
                _ => return Err("Expected ',' or ')' character in prototype declaration."),
            }
        }
        Ok(Prototype {
            name: id,
            args: args,
            is_op: is_operator,
            prec: precedence,
        })
    }
fn parse_prototype ( & mut self ) -> Result < Prototype , & ' static str > { let ( id , is_operator , precedence ) = match self . curr ( ) { Ident ( id ) => { self . advance ( ) ? ; ( id , false , 0 ) } Binary => { self . advance ( ) ? ; let op = match self . curr ( ) { Op ( ch ) => ch , _ => return Err ( " " ) , } ; self . advance ( ) ? ; let mut name = String :: from ( " " ) ; name . push ( op ) ; let prec = if let Number ( prec ) = self . curr ( ) { self . advance ( ) ? ; prec as usize } else { 0 } ; self . prec . insert ( op , prec as i32 ) ; ( name , true , prec ) } Unary => { self . advance ( ) ? ; let op = match self . curr ( ) { Op ( ch ) => ch , _ => return Err ( " " ) , } ; let mut name = String :: from ( " " ) ; name . push ( op ) ; self . advance ( ) ? ; ( name , true , 0 ) } _ => return Err ( " " ) , } ; match self . curr ( ) { LParen => ( ) , _ => return Err ( " " ) , } self . advance ( ) ? ; if let RParen = self . curr ( ) { self . advance ( ) ; return Ok ( Prototype { name : id , args : vec ! [ ] , is_op : is_operator , prec : precedence , } ) ; } let mut args = vec ! [ ] ; loop { match self . curr ( ) { Ident ( name ) => args . push ( name ) , _ => return Err ( " " ) , } self . advance ( ) ? ; match self . curr ( ) { RParen => { self . advance ( ) ; break ; } Comma => { self . advance ( ) ; } _ => return Err ( " " ) , } } Ok ( Prototype { name : id , args : args , is_op : is_operator , prec : precedence , } ) }
Parses the prototype of a function, whether external or user-defined.
Parses the prototype of a function whether external or user - defined .
&mut self
&mut self