Skip to content

syntax: Tweak path parsing logic - #37290

Merged
bors merged 2 commits into
rust-lang:masterfrom
petrochenkov:pnp
Oct 21, 2016
Merged

syntax: Tweak path parsing logic#37290
bors merged 2 commits into
rust-lang:masterfrom
petrochenkov:pnp

Conversation

@petrochenkov

@petrochenkovpetrochenkov commented Oct 19, 2016

Copy link
Copy Markdown
Contributor

Associated paths starting with << are parsed in patterns.

Paths like self::foo::bar are interpreted as paths and not as self arguments in methods (cc @matklad).
Now, I believe, all paths are consistently parsed greedily in case of ambiguity.
Detection of &'a mut self:: requires pretty large (but still fixed) lookahead, so I had to increase the size of parser's lookahead buffer.
Curiously, if lookahead_distance >= lookahead_buffer_size was used previously, the parser hung forever, I fixed this as well, now it ICEs.

r? @jseyfried

@jseyfriedjseyfried left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice! r=me modulo union!();

Comment threadsrc/libsyntax/parse/parser.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I believe this can be slightly simplified to

(LOOKAHEAD_BUFFER_CAPACITY + self.end - self.start) % LOOKAHEAD_BUFFER_CAPACITY

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yep, looks simpler.

Comment threadsrc/libsyntax/parse/parser.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a reason this is 8? I think 6 would suffice.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

x % LOOKAHEAD_BUFFER_CAPACITY is faster.
Not much difference either way, though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good point -- I forgot about peephole optimizations.

Comment threadsrc/libsyntax/parse/parser.rs Outdated

@jseyfriedjseyfriedOct 20, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this would break the macro invocation union!(); in an item position.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Hmm, right, will fix.

@petrochenkov

Copy link
Copy Markdown
ContributorAuthor

@bors r=jseyfried

@bors

bors commented Oct 20, 2016

Copy link
Copy Markdown
Collaborator

📌 Commit fea630e has been approved by jseyfried

@bors

bors commented Oct 21, 2016

Copy link
Copy Markdown
Collaborator

⌛ Testing commit fea630e with merge 5509ae3...

bors added a commit that referenced this pull request Oct 21, 2016
syntax: Tweak path parsing logic
Associated paths starting with `<<` are parsed in patterns.
Paths like `self::foo::bar` are interpreted as paths and not as `self` arguments in methods (cc @matklad).
Now, I believe, *all* paths are consistently parsed greedily in case of ambiguity.
Detection of `&'a mut self::` requires pretty large (but still fixed) lookahead, so I had to increase the size of parser's lookahead buffer.
Curiously, if `lookahead_distance >= lookahead_buffer_size` was used previously, the parser hung forever, I fixed this as well, now it ICEs.
r? @jseyfried
@bors
bors merged commit fea630e into rust-lang:masterOct 21, 2016
@durkadurka mentioned this pull request Nov 14, 2016
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Nov 17, 2016
add test for rust-lang#37765
Adds a test for rust-lang#37765, a path parsing fix which removes the need for a parenthesis workaround.
Closesrust-lang#37765.
cc rust-lang#37290@withoutboats
r? @petrochenkov
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Nov 17, 2016
add test for rust-lang#37765
Adds a test for rust-lang#37765, a path parsing fix which removes the need for a parenthesis workaround.
Closesrust-lang#37765.
cc rust-lang#37290@withoutboats
r? @petrochenkov
nikomatsakis added a commit to nikomatsakis/rust that referenced this pull request Dec 1, 2016
nikomatsakis added a commit to nikomatsakis/rust that referenced this pull request Dec 3, 2016
@petrochenkov
petrochenkov deleted the pnp branch March 16, 2017 19:40
@ehussehuss mentioned this pull request Feb 9, 2026
35 tasks
Sign up for freeto 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.

3 participants

@petrochenkov@bors@jseyfried