Skip to content

ParserInput is an implementation detail and should not be in the public API #179

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

Closed
federicomenaquintero opened this issue Aug 17, 2017 · 3 comments

Comments

@federicomenaquintero
Copy link
Contributor

One creates a parser like this:

let mut input = ParserInput::new("foo: bar;");
let mut parser = Parser::new(&mut input);

... use parser ...
... input is never used again; has no methods but new() ...

I think we could go back to creating a parser with Parser::new(s: &'i str) based on the string's lifetime. If the parser wants to keep a cached token internally, which is the sole purpose of ParserInput, it can do that on its own.

@SimonSapin
Copy link
Member

We used to do this and it was more ergonomic, but it required a memory allocation whose cost was non-trivial for parsing short strings like in JS/CSSOM element.style.left = "10px".

@SimonSapin
Copy link
Member

Without allocation, if Parser owned ParserInput inline its sizeof would become much larger and this extra space would be wasted in the case of nested Parsers used in e.g. parse_nested_block.

Closing as I don’t think we’ll change this back unless a new idea comes up. Feel free to comment if there’s more to consider.

@federicomenaquintero
Copy link
Contributor Author

Oh, I see, the nested parser also uses the same input. I hadn't seen that function before :)

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

No branches or pull requests

2 participants