Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upstyle: Move contain outside of mako #19682
Conversation
highfive
commented
Jan 4, 2018
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @emilio (or someone else) soon. |
highfive
commented
Jan 4, 2018
|
Heads up! This PR modifies the following files:
|
highfive
commented
Jan 4, 2018
|
Looks great! Just minor nits and suggestions, other than that, r=me Thanks a lot for doing this! |
|
|
||
| impl Parse for Contain { | ||
| /// none | strict | content | [ size || layout || style || paint ] | ||
| fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) |
This comment has been minimized.
This comment has been minimized.
emilio
Jan 4, 2018
Member
nit: Indentation is off, let's do:
fn parse<'i, 't>(
_context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Contain, ParseError<'i>> {| }; | ||
| let flag = match flag { | ||
| Some(flag) if !result.contains(flag) => flag, | ||
| _ => return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(name.clone()))) |
This comment has been minimized.
This comment has been minimized.
| /// none | strict | content | [ size || layout || style || paint ] | ||
| fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) | ||
| -> Result<Contain, ParseError<'i>> { | ||
| let mut result = Contain::empty(); |
This comment has been minimized.
This comment has been minimized.
emilio
Jan 4, 2018
Member
This function is kinda dumb, and could be rewritten to be faster / clearer. Can you file a followup for it?
In particular, I'm thinking of something like:
let mut result = Contain::empty();
while let Ok(name) = input.try(|i| i.expect_ident_cloned()) {
match_ignore_ascii_case! { &name,
"layout" => Some(Contain::LAYOUT),
"style" => Some(Contain::STYLE),
"paint" => Some(Contain::PAINT),
// The following are only valid as the first value, thus the is_empty()
// checks.
"strict" => {
if result.is_empty() {
return Ok(Contain::STRICT | Contain::STRICT_BITS)
}
None
}
"none" => {
if result.is_empty() {
return Ok(result);
}
None
}
_ => None
};
// Same code as now.
}Also fine to do it in a separate commit in this same PR.
That avoids having to tokenize twice for none and strict just to tokenize an identifier again below.
This comment has been minimized.
This comment has been minimized.
stevel98
Jan 4, 2018
•
Author
Contributor
Thanks for the feedback, I will file a followup commit soon.
| } | ||
| if input.try(|input| input.expect_ident_matching("strict")).is_ok() { | ||
| result.insert(Contain::STRICT | Contain::STRICT_BITS); | ||
| return Ok(result) |
This comment has been minimized.
This comment has been minimized.
emilio
Jan 4, 2018
Member
nit: just return Ok(Contain::STRICT | Contain::STRICT_BITS) may be cleaner?
| const PAINT = 0x04; | ||
| /// `strict` variant, turns on all types of containment | ||
| const STRICT = 0x8; | ||
| /// `strict bits` variant |
This comment has been minimized.
This comment has been minimized.
|
I just pushed the changes, let me know if there need to be any more! |
| "style" => Some(Contain::STYLE), | ||
| "paint" => Some(Contain::PAINT), | ||
| "strict" if result.is_empty() => return Ok(Contain::STRICT | Contain::STRICT_BITS), | ||
| "none" if result.is_empty() => return Ok(result), |
This comment has been minimized.
This comment has been minimized.
CYBAI
Jan 4, 2018
Collaborator
I think you'll need to check if result.is_empty() inside the pattern instead of using it as a pattern matching guard. If putting if result.is_empty() as guard here, I think it will only get into the strict one?
IMO, just like @emilio commented in the comment, it might be fine to be like following
"strict" => {
if result.is_empty() {
return Ok(Contain::STRICT | Contain::STRICT_BITS)
}
None
},
"none" => {
if result.is_empty() {
return Ok(result);
}
None
}
This comment has been minimized.
This comment has been minimized.
stevel98
Jan 4, 2018
Author
Contributor
Thanks, I changed it back to the previous version. I don't really understand why it won't get into the none arm though; how would rust evaluate the guard?
This comment has been minimized.
This comment has been minimized.
emilio
Jan 4, 2018
Member
FWIW the guard should work just fine, and it's more elegant indeed.
Wanna open a PR after this one merges simplifying it? Thanks!
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
CYBAI
Jan 4, 2018
Collaborator
Ahhh... yes... sorry, I think it in a wrong way so using guard here should work fine.
Sorry for the misleading
|
Besides, I think it would be great to squash the two commits into one |
|
I'm not sure why this test failed after such a small change. Could someone please re-run it? |
|
@stevel98 I think you can try to |
|
Thanks! |
|
LGTM, thanks a lot! |
|
@bors-servo r+ |
|
|
style: Move contain outside of mako <!-- Please describe your changes on the following line: --> Sub-PR for #19015. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #19656 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because refactoring <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- 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/19682) <!-- Reviewable:end -->
|
|
|
@bors-servo retry |
style: Move contain outside of mako <!-- Please describe your changes on the following line: --> Sub-PR for #19015. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #19656 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because refactoring <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- 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/19682) <!-- Reviewable:end -->
|
|
|
@bors-servo retry
|
|
|
|
|
|
|
style: Make Contain::parse simpler <!-- Please describe your changes on the following line: --> --- Makes Contain::parse slightly simpler, as discussed in #19682 - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #19682 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because refactoring <!-- 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/19692) <!-- Reviewable:end -->
stevel98 commentedJan 4, 2018
•
edited
Sub-PR for #19015.
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is