Skip to content

Commit

Permalink
(ast/syntax) fix nested simpleblock parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus committed Nov 10, 2024
1 parent 2fec6b5 commit e95f977
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions crates/hdx_ast/src/css/stylerule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ mod tests {
assert_parse!(StyleRule, ".foo *{}", ".foo * {\n}");
assert_parse!(StyleRule, ":nth-child(1) {\n\topacity: 0;\n}");
assert_parse!(StyleRule, ".foo {\n\t--bar: (baz);\n}");
assert_parse!(StyleRule, ".foo {\n\twidth: calc(1px + (var(--foo)) + 1px);\n}");
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions crates/hdx_ast/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,21 @@ pub struct SimpleBlock<'a> {
// https://drafts.csswg.org/css-syntax-3/#consume-a-simple-block
impl<'a> Parse<'a> for SimpleBlock<'a> {
fn parse(parser: &mut Parser<'a>) -> ParserResult<Self> {
let pair = parser.parse::<Token![PairWise]>()?;
let pair = parser.parse::<Token![PairWise]>()?.to_pairwise().unwrap();
let mut values = parser.new_vec();
loop {
if parser.at_end() {
break;
}
if let Some(token) = parser.peek::<Token![PairWise]>() {
if token.to_pairwise() == pair.to_pairwise() {
if token.to_pairwise() == Some(pair) && token.kind() == pair.end() {
parser.hop(token);
break;
}
}
values.push(parser.parse_spanned::<ComponentValue>()?);
}
Ok(Self { values, pairwise: pair.to_pairwise().unwrap() })
Ok(Self { values, pairwise: pair })
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/hdx_lexer/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ impl serde::ser::Serialize for Token {
}
}

#[derive(Debug, Eq, PartialEq, Clone, Hash)]
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub enum PairWise {
Paren,
Expand Down

0 comments on commit e95f977

Please sign in to comment.