Skip to content

parser: Remove ParserInput. - #446

Open
emilio wants to merge 1 commit into
mainfrom
rm-parserinput
Open

parser: Remove ParserInput.#446
emilio wants to merge 1 commit into
mainfrom
rm-parserinput

Conversation

@emilio

@emilio emilio commented Aug 27, 2026

Copy link
Copy Markdown
Member

This avoids unnecessary indirection during parsing. We only create nested parsers in two places, and it seems easy to avoid.

This avoids unnecessary indirection during parsing. We only create
nested parsers in two places, and it seems easy to avoid.
@emilio
emilio requested review from SimonSapin and tiaanl August 27, 2026 13:54
@emilio

emilio commented Aug 27, 2026

Copy link
Copy Markdown
Member Author

@SimonSapin you have more historical context than me, can you think of any reason not to do this?

@emilio

emilio commented Aug 27, 2026

Copy link
Copy Markdown
Member Author

This has been reviewed upstream in https://phabricator.services.mozilla.com/D321882 but will wait a bit before merging (at least a day or two) to get performance numbers (though I think we should do this just for simplicity), and also to wait for Simon's or other folk's feedback :)

Comment thread src/parser.rs
if let Some(block_type) = delimited_parser.at_start_of {
consume_until_end_of_block(block_type, &mut delimited_parser.input.tokenizer);
}
parser.stop_before = delimiters;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the main tricky change really.

Comment thread src/parser.rs
let result;
// Introduce a new scope to limit duration of nested_parser’s borrow
{
let mut nested_parser = Parser {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

And this one.

@nicoburns

Copy link
Copy Markdown
Contributor

IIRC there's some historical context around this in the git log (on my phone, so can't look it up right now). Would be nice if it can be removed. I think it makes the API a little less flexible around input?

Aside from this change, some docs on how to construct and use Parser (and ParserInput if it stays) would be really nice. The lib.rs docs show how to implement a Parser, but not really how to use one.

@emilio

emilio commented Aug 27, 2026

Copy link
Copy Markdown
Member Author

Err, yeah so... ParserInput was introduced in 970e1ca (by @jdm), but I think that could've probably just reused Tokenizer directly like here. If you blame that further you get to 41fa928 which is the last large rewrite, which had a very different API (Parser was returned by value from e.g. parse_nested_block), which explains this design a lot more.

So I think this is fine nowadays.

Why do you think this makes the API less flexible? I don't see how.

@SimonSapin

Copy link
Copy Markdown
Member

I feel there must have been a reason to bother with two lifetime parameters but right now I can’t remember what it is or was. Stylo is probably the biggest consumer of cssparser, so if you’ve ported it to this new API and feel it’s an improvement I trust your judgment Emilio.

@jdm

jdm commented Aug 28, 2026

Copy link
Copy Markdown
Member

I feel there must have been a reason to bother with two lifetime parameters but right now I can’t remember what it is or was. Stylo is probably the biggest consumer of cssparser, so if you’ve ported it to this new API and feel it’s an improvement I trust your judgment Emilio.

Possibly because the code was written before the stabilization of non-lexical lifetimes in the 2018 edition.

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.

4 participants