diff options
| author | Jonas Maier <jonas@x77.dev> | 2026-06-01 22:49:56 +0200 |
|---|---|---|
| committer | Jonas Maier <jonas@x77.dev> | 2026-06-01 22:49:56 +0200 |
| commit | 9d1a342cea994a9d912f348deec5cdb2032b4189 (patch) | |
| tree | 3ca56ff18da48659014cbd4d5324825313a0a164 | |
| parent | e662dfa3a074a7603cbb9de473bf8bb45b4bb960 (diff) | |
| download | pish-9d1a342cea994a9d912f348deec5cdb2032b4189.tar.gz | |
use consume_keyword for `fun` and `set` parsing too
| -rw-r--r-- | src/parse/mod.rs | 14 |
1 files 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<PreExpansion> { fn parse(b: &mut Cursor<'_>) -> Result<Self> { - 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<S: Stage> { impl Parse for VarAssign<PreExpansion> { fn parse(b: &mut Cursor<'_>) -> Result<Self> { - 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, } } |
