pub struct Buffer { /* private fields */ }Expand description
A growable source file that can be parsed incrementally.
let mut buffer = welly_parser::Buffer::default();
buffer.push_str("hw = \"Hello, world!\\n\";\n");
buffer.push_str("for _ in 10 { print(hw); }");
while let Some(token) = buffer.try_parse() {
println!("{:#?}", token);
}Implementations§
source§impl Buffer
impl Buffer
sourcepub fn remainder(&self) -> &str
pub fn remainder(&self) -> &str
Returns the suffix of the source code that has not yet been parsed.
sourcepub fn complete(&mut self)
pub fn complete(&mut self)
Inform self that it has all the source code.
This can be important, as in the following example:
let mut buffer = welly_parser::Buffer::default();
buffer.push_str("if c {}"); // Could be followed by `else`.
assert!(buffer.try_parse().is_none());
buffer.complete(); // Exclude `else`.
assert!(buffer.try_parse().is_some());sourcepub fn try_parse(&mut self) -> Option<(Rc<str>, Token)>
pub fn try_parse(&mut self) -> Option<(Rc<str>, Token)>
Attempt to parse [self.remainder()]. Hopefully the returned Token
is a Stmt. Other possibilities can be found in welly.
Some((source, token)) indicates that there was enough source code to
parse a Token (which might be an error message). Locations are
relative to the returned source, which is removed from self.
None indicates that there was not enough source code, either because
we need to wait for more, or because there is no more. In this case
self is not modified.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Buffer
impl !RefUnwindSafe for Buffer
impl !Send for Buffer
impl !Sync for Buffer
impl Unpin for Buffer
impl !UnwindSafe for Buffer
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more