From 9d1a342cea994a9d912f348deec5cdb2032b4189 Mon Sep 17 00:00:00 2001 From: Jonas Maier Date: Mon, 1 Jun 2026 22:49:56 +0200 Subject: use consume_keyword for `fun` and `set` parsing too --- src/parse/mod.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/parse/mod.rs b/src/parse/mod.rs index b07d5f9..f61baf9 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -459,10 +459,9 @@ impl Parse for Block { impl Parse for FunDecl { fn parse(b: &mut Cursor<'_>) -> Result { - if !b.buf.starts_with(b"fun ") && !b.buf.starts_with(b"fun\t") { + if b.consume_keyword(Keyword::Fun).is_err() { return Err(ParseError::NotAFunDecl); } - b.advance(4); b.spaces(); let name = ExpString::parse(b)?; let body = Block::parse(b)?; @@ -487,10 +486,9 @@ pub struct VarAssign { impl Parse for VarAssign { fn parse(b: &mut Cursor<'_>) -> Result { - if !b.buf.starts_with(b"set ") && !b.buf.starts_with(b"set\t") { + if b.consume_keyword(Keyword::Set).is_err() { return Err(ParseError::NotAVarAssign); } - b.advance(4); b.spaces(); let var = ExpString::parse(b)?; b.spaces(); @@ -1642,7 +1640,7 @@ impl<'a> Cursor<'a> { fn expect_keyword(&mut self, kw: Keyword) -> Result<()> { if !self.is_completion() { - return self.consume_keyword(kw) + return self.consume_keyword(kw); } // very lax parsing that consumes everything in its way until the keyword arrives @@ -1712,6 +1710,8 @@ pub enum Keyword { OpenBrace, CloseBrace, Case, + Fun, + Set, } impl Keyword { @@ -1724,6 +1724,8 @@ impl Keyword { Keyword::OpenBrace => b"{", Keyword::CloseBrace => b"}", Keyword::Case => b"case", + Keyword::Fun => b"fun", + Keyword::Set => b"set", } } @@ -1736,6 +1738,8 @@ impl Keyword { Keyword::OpenBrace => false, Keyword::CloseBrace => false, Keyword::Case => true, + Keyword::Fun => true, + Keyword::Set => true, } } -- cgit v1.2.3