From 8e0e1dcca503a8595e715a478b0a2e1fc3ff46fb Mon Sep 17 00:00:00 2001 From: mos Date: Sat, 27 Jul 2024 16:45:32 +0200 Subject: [PATCH] improve ParseResult usage --- bip/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bip/src/lib.rs b/bip/src/lib.rs index 67e567c..c597544 100644 --- a/bip/src/lib.rs +++ b/bip/src/lib.rs @@ -5,7 +5,7 @@ pub mod bp; pub mod de; pub mod error; -type ParseResult = Result; +type ParseResult = Result; #[derive(Debug)] pub enum ParseError { @@ -163,11 +163,11 @@ impl<'a> Parser<'a> { } } - fn peek(&self) -> Result<&Symbol, ParseError> { + fn peek(&self) -> ParseResult<&Symbol> { self.read().ok_or(ParseError::Eof) } - fn expect(&self, sym: Symbol, err: ParseError) -> Result<(), ParseError> { + fn expect(&self, sym: Symbol, err: ParseError) -> ParseResult<()> { if *self.peek()? != sym { Err(err) } else { @@ -179,7 +179,7 @@ impl<'a> Parser<'a> { self.pos += 1; } - fn parse_term(&mut self) -> Result { + fn parse_term(&mut self) -> ParseResult { match self.peek()? { Symbol::Int(n) => Ok(Node::new_op(NodeOp::Const(*n, false))), Symbol::SInt(n) => Ok(Node::new_op(NodeOp::Const(*n, true))), @@ -212,7 +212,7 @@ impl<'a> Parser<'a> { } } - fn parse_expr(&mut self) -> ParseResult { + fn parse_expr(&mut self) -> ParseResult { let mut lhs = self.parse_term()?; if lhs.op == NodeOp::Data || lhs.op == NodeOp::List { @@ -248,7 +248,7 @@ impl<'a> Parser<'a> { Err(ParseError::Eof) } - pub fn parse(&mut self) -> Result, ParseError> { + pub fn parse(&mut self) -> ParseResult> { let mut node_tree = vec![]; loop {