Skip to content

Conversation

Eijebong
Copy link
Contributor

No description provided.

@Eijebong
Copy link
Contributor Author

@dtolnay Mind having a quick look ? Especially the fork parts

impl Parse for Tag {
fn parse(input: ParseStream) -> Result<Self> {
input.parse::<Token![<]>()?;
let closing = input.parse::<Option<Token![/]>>()?;
Copy link

Choose a reason for hiding this comment

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

I would write this with the type on the left because ![/]>>()?; is over the threshold of reasonable adjacent punctuation.

let closing: Option<Token![/]> = input.parse()?;

fn parse(input: ParseStream) -> Result<Self> {
input.parse::<Token![<]>()?;
let closing = input.parse::<Option<Token![/]>>()?;
let name = if let Ok(i) = input.parse::<syn::Ident>() {
Copy link

Choose a reason for hiding this comment

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

I would write this as:

let name = match input.call(Ident::parse_any)? {
    ref wildcard if wildcard == "_" => None,
    other => Some(other),
};

};
input.parse::<Token![>]>()?;
Ok(Tag {
kind: if closing.is_some() { TagKind::EndTag } else { TagKind::StartTag },
Copy link

Choose a reason for hiding this comment

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

This needs to be unindented by one level.

));
impl Parse for LHS {
fn parse(input: ParseStream) -> Result<Self> {
if let Ok(p) = input.fork().parse::<syn::Pat>() {
Copy link

Choose a reason for hiding this comment

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

I would write this as:

if input.peek(Token![<]) {
    let mut tags = Vec::new();
    while !input.peek(Token![=>]) {
        tags.push(input.parse()?);
    }
    Ok(LHS::Tags(tags))
} else {
    let p: Pat = input.parse()?;
    Ok(LHS::Pattern(p))
}

};
let lhs = input.parse::<LHS>()?;
input.parse::<Token![=>]>()?;
let rhs = if let Ok(expr) = input.fork().parse() {
Copy link

Choose a reason for hiding this comment

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

This is probably not doing what you intended. This is bleeding over into the next arm and relying on the fact that { /* ... */ } < TAG > => is not a valid expression -- because => is not a valid beginning of expression. You should parse each arm without parsing the LHS of the next arm as part of the previous arm's expression.

input.parse::<Token![else]>()?;
RHS::Else
};
input.parse::<Option<Token![,]>>()?;
Copy link

Choose a reason for hiding this comment

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

This is too lenient and allows commas to be omitted where they should be required. Have the parser require a comma after else and after expressions that are not block, unless in the last arm.

}
)
));
impl Parse for MatchToken {
Copy link

Choose a reason for hiding this comment

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

Regarding fork -- I don't see anything in the input syntax that would require fork. All of this can be parsed with two tokens of lookahead. Please implement the parsing without using fork to make debugging easier and error messages better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Way better now. Thanks a lot

@SimonSapin
Copy link
Member

@bors-servo r=dtolnay+SimonSapin

@bors-servo
Copy link
Contributor

📌 Commit a3eda83 has been approved by dtolnay+SimonSapin

@bors-servo
Copy link
Contributor

⌛ Testing commit a3eda83 with merge 99ae7d3...

bors-servo pushed a commit that referenced this pull request Nov 5, 2018
@bors-servo
Copy link
Contributor

☀️ Test successful - status-travis
Approved by: dtolnay+SimonSapin
Pushing 99ae7d3 to master...

@bors-servo bors-servo merged commit a3eda83 into servo:master Nov 5, 2018
@SimonSapin
Copy link
Member

bors-servo pushed a commit to servo/servo that referenced this pull request Nov 30, 2018
Update syn

- servo/html5ever#353
- servo/rust-cssparser#229
- servo/webrender#3264
- servo/media#162
- rust-lang/rust-bindgen#1409

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22085)
<!-- Reviewable:end -->
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