Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support of buf_redux / streaming input #26

Merged
merged 4 commits into from
Mar 15, 2023
Merged

Drop support of buf_redux / streaming input #26

merged 4 commits into from
Mar 15, 2023

Conversation

gwenn
Copy link
Owner

@gwenn gwenn commented Mar 8, 2023

Should fix #21 and #23

@gwenn
Copy link
Owner Author

gwenn commented Mar 8, 2023

Some rustdoc is not up to date like here but I will fix them later...

@gwenn gwenn mentioned this pull request Mar 8, 2023
Copy link
Contributor

@MarinPostma MarinPostma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@MarinPostma
Copy link
Contributor

MarinPostma commented Mar 9, 2023

Actually, there is a drawback to this, the scanner is not allowed to own its buffer. This is an issue when you want to store the parser

@MarinPostma
Copy link
Contributor

I think we should let the scanner own the buffer and add store an offset to the current byte position, instead of re-slicing.

The buffer can be made generic over T: AsRef<[u8]>

@gwenn
Copy link
Owner Author

gwenn commented Mar 9, 2023

I think we should let the scanner own the buffer and add store an offset to the current byte position, instead of re-slicing.

This solution should also help fixing #4

@gwenn
Copy link
Owner Author

gwenn commented Mar 9, 2023

With input: AsRef<[u8]>:

error[E0502]: cannot borrow `*self` as mutable because it is also borrowed as immutable
   --> src/lexer/scan.rs:115:25
    |
98  |     pub fn scan(&mut self) -> ScanResult<'_, S::TokenType, S::Error> {
    |                 - let's call the lifetime of this reference `'1`
...
104 |                 let data = &self.input.as_ref()[self.offset..];
    |                             ------------------- immutable borrow occurs here
...
115 |                         self.consume(amt);
    |                         ^^^^^^^^^^^^^^^^^ mutable borrow occurs here
...
120 |                         return Ok(tok);
    |                                ------- returning this value requires that `self.input` is borrowed for `'1`

I should be able to fix consume but not the lifetime issue...

@gwenn
Copy link
Owner Author

gwenn commented Mar 11, 2023

I think we should let the scanner own the buffer and add store an offset to the current byte position, instead of re-slicing.

I had to do the contrary in 611b94f: the input is now passed as a parameter to the scan method and the parser now keeps a reference to the input (to make the borrow checker happy in Parser::next).

@gwenn gwenn merged commit bd27d0e into master Mar 15, 2023
@gwenn gwenn deleted the rm_buf_redux branch March 15, 2023 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

future-incompatibilities: buf_redux v0.8.4
2 participants