Skip to content

Commit

Permalink
Don't panic when encountering gameloop keyword (#54)
Browse files Browse the repository at this point in the history
fixes #50 

---------

Co-authored-by: Mikko <Andriamanitra@users.noreply.github.com>
  • Loading branch information
daxida and Andriamanitra authored Apr 21, 2024
1 parent 625cf7c commit 108af4d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde::Serialize;
pub use stub_config::StubConfig;

pub fn generate(config: StubConfig, generator: &str) -> Result<String> {
let stub = parser::parse_generator_stub(generator);
let stub = parser::parse_generator_stub(generator)?;

// eprint!("=======\n{:?}\n======\n", generator);
// eprint!("=======\n{:?}\n======\n", stub);
Expand Down
9 changes: 6 additions & 3 deletions src/stub/parser.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::iter;

use anyhow::{anyhow, Result};

use super::{Cmd, JoinTerm, Stub, VarType, VariableCommand};

pub fn parse_generator_stub(generator: &str) -> Stub {
pub fn parse_generator_stub(generator: &str) -> Result<Stub> {
Parser::new(generator).parse()
}

Expand All @@ -28,7 +30,7 @@ impl<'a> Parser<'a> {
}

#[rustfmt::skip]
fn parse(mut self) -> Stub {
fn parse(mut self) -> Result<Stub> {
let mut stub = Stub::default();

while let Some(token) = self.next_token() {
Expand All @@ -40,6 +42,7 @@ impl<'a> Parser<'a> {
"OUTPUT" => self.parse_output_comment(&mut stub.commands),
"INPUT" => self.parse_input_comment(&mut stub.commands),
"STATEMENT" => stub.statement = self.parse_text_block(),
"gameloop" => return Err(anyhow!("Stub generator does not currently support the 'gameloop' command")),
"\n" | "" => continue,
thing => panic!("Unknown token stub generator: '{}'", thing),
};
Expand All @@ -64,7 +67,7 @@ impl<'a> Parser<'a> {
}
}

stub
Ok(stub)
}

fn parse_read(&mut self) -> Cmd {
Expand Down

0 comments on commit 108af4d

Please sign in to comment.