diff options
author | stuebinm | 2025-01-06 02:48:29 +0100 |
---|---|---|
committer | stuebinm | 2025-01-06 02:52:11 +0100 |
commit | c363db95be7e2520e5c69c49733544fe98dff838 (patch) | |
tree | 445f9b41f34a05e9d48506cd666bde376d289090 /src/parser.rs | |
parent | 6befe9f334a3384e6a6bf494211edb4e549efa2f (diff) |
new parser, support exporttree, generally nicer code
Diffstat (limited to 'src/parser.rs')
-rw-r--r-- | src/parser.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/parser.rs b/src/parser.rs new file mode 100644 index 0000000..13cd22b --- /dev/null +++ b/src/parser.rs @@ -0,0 +1,38 @@ + +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!() + } + } +} |