pub struct Parser<'a> { buf: &'a str, offset: usize } impl<'a> Parser<'a> { pub fn new(buf: &'a str) -> Self { Parser{buf, offset: 0} } pub fn next_word(&mut self) -> &'a str { match self.buf[self.offset..].split_once(' ') { Some((a,_)) => { self.offset += a.len() + 1; a }, None => { let res = &self.buf[self.offset..]; self.offset += self.buf.len() - self.offset; res } } } pub fn remainder(&mut self) -> String { let res = self.buf[self.offset..].to_owned(); self.offset = self.buf.len(); res } pub fn assert_end(&self) { if self.buf.len() != self.offset { println!("ERROR: failed parsing"); panic!() } } }