Skip to content

Commit

Permalink
(ast) rename all rule nodes to be suffixed "Rule"
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus committed Dec 11, 2024
1 parent 266ad13 commit 15b0f67
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 119 deletions.
16 changes: 8 additions & 8 deletions crates/hdx_ast/src/css/rules/charset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ use hdx_parser::{diagnostics, Parse, Parser, Result as ParserResult, ToCursors,
// https://drafts.csswg.org/css-syntax-3/#charset-rule
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
pub struct Charset {
pub struct CharsetRule {
at_keyword: T![AtKeyword],
space: T![' '],
string: T![String],
semicolon: Option<T![;]>,
}

// Charset is a special rule which means it cannot use standard AtRule parsing... comments below
// CharsetRule is a special rule which means it cannot use standard AtRule parsing... comments below
// https://drafts.csswg.org/css-syntax-3/#determine-the-fallback-encoding
impl<'a> Parse<'a> for Charset {
impl<'a> Parse<'a> for CharsetRule {
fn parse(p: &mut Parser<'a>) -> ParserResult<Self> {
let at_keyword = p.parse::<T![AtKeyword]>()?;
let c: Cursor = at_keyword.into();
// Charset MUST be all lowercase, alt cases such as CHARSET or charSet aren't
// CharsetRule MUST be all lowercase, alt cases such as CHARSET or charSet aren't
// valid here, compares to other at-rules which are case insensitive.
let atom = p.parse_atom(c);
if atom != atom!("charset") {
Expand All @@ -35,7 +35,7 @@ impl<'a> Parse<'a> for Charset {
}
}

impl<'a> ToCursors<'a> for Charset {
impl<'a> ToCursors<'a> for CharsetRule {
fn to_cursors(&self, s: &mut hdx_parser::CursorStream<'a>) {
s.append(self.at_keyword.into());
s.append(self.space.into());
Expand All @@ -53,12 +53,12 @@ mod tests {

#[test]
fn size_test() {
assert_size!(Charset, 44);
assert_size!(CharsetRule, 44);
}

#[test]
fn test_writes() {
assert_parse!(Charset, "@charset \"utf-8\";", "@charset \"utf-8\";");
assert_parse!(Charset, "@charset \"UTF-8\";", "@charset \"UTF-8\";");
assert_parse!(CharsetRule, "@charset \"utf-8\";", "@charset \"utf-8\";");
assert_parse!(CharsetRule, "@charset \"UTF-8\";", "@charset \"UTF-8\";");
}
}
6 changes: 3 additions & 3 deletions crates/hdx_ast/src/css/rules/color_profile.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::Todo;

// https://drafts.csswg.org/css-color-5/#at-profile
pub type ColorProfile = Todo;
pub type ColorProfileRule = Todo;

#[cfg(test)]
mod tests {
Expand All @@ -10,11 +10,11 @@ mod tests {

#[test]
fn size_test() {
assert_size!(ColorProfile, 0);
assert_size!(ColorProfileRule, 0);
}

#[test]
fn test_writes() {
//assert_parse!(ColorProfile, "@color-profile --swop5c {\n\tsrc: url(\"https://example.org/SWOP2006_Coated5v2.icc\");}");
//assert_parse!(ColorProfileRule, "@color-profile --swop5c {\n\tsrc: url(\"https://example.org/SWOP2006_Coated5v2.icc\");}");
}
}
6 changes: 3 additions & 3 deletions crates/hdx_ast/src/css/rules/container.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::Todo;

// https://drafts.csswg.org/css-contain-3/#container-rule
pub type Container = Todo;
pub type ContainerRule = Todo;

#[cfg(test)]
mod tests {
Expand All @@ -10,11 +10,11 @@ mod tests {

#[test]
fn size_test() {
assert_size!(Container, 0);
assert_size!(ContainerRule, 0);
}

#[test]
fn test_writes() {
//assert_parse!(Container, "@container (width > 400px) { h2 { font-size; 1.5rem } }");
//assert_parse!(ContainerRule, "@container (width > 400px) { h2 { font-size; 1.5rem } }");
}
}
6 changes: 3 additions & 3 deletions crates/hdx_ast/src/css/rules/counter_style.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::Todo;

// https://drafts.csswg.org/css-counter-styles-3/#the-counter-style-rule
pub type CounterStyle = Todo;
pub type CounterStyleRule = Todo;

#[cfg(test)]
mod tests {
Expand All @@ -10,11 +10,11 @@ mod tests {

#[test]
fn size_test() {
assert_size!(CounterStyle, 0);
assert_size!(CounterStyleRule, 0);
}

#[test]
fn test_writes() {
//assert_parse!(CounterStyle, "@counter-style thumbs {}");
//assert_parse!(CounterStyleRule, "@counter-style thumbs {}");
}
}
12 changes: 6 additions & 6 deletions crates/hdx_ast/src/css/rules/font_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ use crate::css::properties::StyleValue;
// https://drafts.csswg.org/css-fonts/#font-face-rule
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
pub struct FontFace<'a> {
pub struct FontFaceRule<'a> {
pub at_keyword: T![AtKeyword],
pub block: FontFaceDeclaration<'a>,
}

impl<'a> AtRule<'a> for FontFace<'a> {
impl<'a> AtRule<'a> for FontFaceRule<'a> {
type Prelude = NoPreludeAllowed;
type Block = FontFaceDeclaration<'a>;
}

impl<'a> Parse<'a> for FontFace<'a> {
impl<'a> Parse<'a> for FontFaceRule<'a> {
fn parse(p: &mut Parser<'a>) -> ParserResult<Self> {
let (at_keyword, _, block) = Self::parse_at_rule(p, Some(atom!("font-face")))?;
Ok(Self { at_keyword, block })
}
}

impl<'a> ToCursors<'a> for FontFace<'a> {
impl<'a> ToCursors<'a> for FontFaceRule<'a> {
fn to_cursors(&self, s: &mut CursorStream<'a>) {
s.append(self.at_keyword.into());
ToCursors::to_cursors(&self.block, s);
Expand Down Expand Up @@ -129,11 +129,11 @@ mod tests {

#[test]
fn size_test() {
assert_size!(FontFace, 72);
assert_size!(FontFaceRule, 72);
}

#[test]
fn test_writes() {
//assert_parse!(FontFace, "@font-face {}");
//assert_parse!(FontFaceRule, "@font-face {}");
}
}
6 changes: 3 additions & 3 deletions crates/hdx_ast/src/css/rules/font_feature_values.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::Todo;

// https://drafts.csswg.org/css-fonts/#at-ruledef-font-feature-values
pub type FontFeatureValues = Todo;
pub type FontFeatureValuesRule = Todo;

#[cfg(test)]
mod tests {
Expand All @@ -10,11 +10,11 @@ mod tests {

#[test]
fn size_test() {
assert_size!(FontFeatureValues, 0);
assert_size!(FontFeatureValuesRule, 0);
}

#[test]
fn test_writes() {
//assert_parse!(FontFeatureValues, "@font-feature-values Taisho Gothic {}");
//assert_parse!(FontFeatureValuesRule, "@font-feature-values Taisho Gothic {}");
}
}
6 changes: 3 additions & 3 deletions crates/hdx_ast/src/css/rules/font_palette_values.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::Todo;

// https://drafts.csswg.org/css-fonts/#at-ruledef-font-palette-values
pub type FontPaletteValues = Todo;
pub type FontPaletteValuesRule = Todo;

#[cfg(test)]
mod tests {
Expand All @@ -10,11 +10,11 @@ mod tests {

#[test]
fn size_test() {
assert_size!(FontPaletteValues, 0);
assert_size!(FontPaletteValuesRule, 0);
}

#[test]
fn test_writes() {
//assert_parse!(FontPaletteValues, "@font-palette-values --cooler {}");
//assert_parse!(FontPaletteValuesRule, "@font-palette-values --cooler {}");
}
}
6 changes: 3 additions & 3 deletions crates/hdx_ast/src/css/rules/import.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::Todo;

// https://drafts.csswg.org/css-cascade-5/#at-ruledef-import
pub type Import = Todo;
pub type ImportRule = Todo;

#[cfg(test)]
mod tests {
Expand All @@ -10,11 +10,11 @@ mod tests {

#[test]
fn size_test() {
assert_size!(Import, 0);
assert_size!(ImportRule, 0);
}

#[test]
fn test_writes() {
//assert_parse!(Import, "@import \"foo.css\"");
//assert_parse!(ImportRule, "@import \"foo.css\"");
}
}
22 changes: 11 additions & 11 deletions crates/hdx_ast/src/css/rules/keyframes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ pub mod kw {
// https://drafts.csswg.org/css-animations/#at-ruledef-keyframes
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))]
pub struct Keyframes<'a> {
pub struct KeyframesRule<'a> {
at_keyword: T![AtKeyword],
name: Option<KeyframesName>,
rules: KeyframesBlock<'a>,
}

impl<'a> AtRule<'a> for Keyframes<'a> {
impl<'a> AtRule<'a> for KeyframesRule<'a> {
type Prelude = KeyframesName;
type Block = KeyframesBlock<'a>;
}

impl<'a> Parse<'a> for Keyframes<'a> {
impl<'a> Parse<'a> for KeyframesRule<'a> {
fn parse(p: &mut Parser<'a>) -> ParserResult<Self> {
let (at_keyword, name, rules) = Self::parse_at_rule(p, Some(atom!("keyframes")))?;
Ok(Self { at_keyword, name, rules })
}
}

impl<'a> ToCursors<'a> for Keyframes<'a> {
impl<'a> ToCursors<'a> for KeyframesRule<'a> {
fn to_cursors(&self, s: &mut CursorStream<'a>) {
s.append(self.at_keyword.into());
if let Some(name) = self.name {
Expand Down Expand Up @@ -263,16 +263,16 @@ mod tests {

#[test]
fn size_test() {
assert_size!(Keyframes, 88);
assert_size!(KeyframesRule, 88);
}

#[test]
fn test_writes() {
assert_parse!(Keyframes, "@keyframes foo{}");
assert_parse!(Keyframes, "@keyframes\"include\"{}");
assert_parse!(Keyframes, "@keyframes spin{0%{rotate:0deg}100%{rotate:360deg}}");
assert_parse!(Keyframes, "@keyframes spin{from,0%{rotate:0deg}to,100%{rotate:360deg}}");
assert_parse!(Keyframes, "@keyframes spin{to{transform:rotate(360deg)}}");
assert_parse!(Keyframes, "@keyframes x{to{animation-timing-function:cubic-bezier(0,0,0.2,1)}}");
assert_parse!(KeyframesRule, "@keyframes foo{}");
assert_parse!(KeyframesRule, "@keyframes\"include\"{}");
assert_parse!(KeyframesRule, "@keyframes spin{0%{rotate:0deg}100%{rotate:360deg}}");
assert_parse!(KeyframesRule, "@keyframes spin{from,0%{rotate:0deg}to,100%{rotate:360deg}}");
assert_parse!(KeyframesRule, "@keyframes spin{to{transform:rotate(360deg)}}");
assert_parse!(KeyframesRule, "@keyframes x{to{animation-timing-function:cubic-bezier(0,0,0.2,1)}}");
}
}
20 changes: 10 additions & 10 deletions crates/hdx_ast/src/css/rules/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ use crate::css::stylesheet::Rule;
// https://drafts.csswg.org/css-cascade-5/#layering
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
pub struct Layer<'a> {
pub struct LayerRule<'a> {
pub at_keyword: T![AtKeyword],
pub names: Option<LayerNameList<'a>>,
pub block: OptionalLayerBlock<'a>,
}

// https://drafts.csswg.org/css-page-3/#syntax-page-selector
impl<'a> Parse<'a> for Layer<'a> {
impl<'a> Parse<'a> for LayerRule<'a> {
fn parse(p: &mut Parser<'a>) -> ParserResult<Self> {
let (at_keyword, names, block) = Self::parse_at_rule(p, Some(atom!("layer")))?;
if let Some(ref names) = names {
Expand All @@ -30,12 +30,12 @@ impl<'a> Parse<'a> for Layer<'a> {
}
}

impl<'a> AtRule<'a> for Layer<'a> {
impl<'a> AtRule<'a> for LayerRule<'a> {
type Prelude = LayerNameList<'a>;
type Block = OptionalLayerBlock<'a>;
}

impl<'a> ToCursors<'a> for Layer<'a> {
impl<'a> ToCursors<'a> for LayerRule<'a> {
fn to_cursors(&self, s: &mut CursorStream<'a>) {
s.append(self.at_keyword.into());
if let Some(names) = &self.names {
Expand Down Expand Up @@ -167,7 +167,7 @@ mod tests {

#[test]
fn size_test() {
assert_size!(Layer, 104);
assert_size!(LayerRule, 104);
assert_size!(LayerNameList, 32);
assert_size!(LayerName, 48);
assert_size!(OptionalLayerBlock, 56);
Expand All @@ -176,10 +176,10 @@ mod tests {

#[test]
fn test_writes() {
assert_parse!(Layer, "@layer foo{}");
assert_parse!(Layer, "@layer foo;");
assert_parse!(Layer, "@layer foo,bar;");
assert_parse!(Layer, "@layer foo.bar,baz.bing.baz;");
assert_parse!(Layer, "@layer foo.bar{body{color:black}}");
assert_parse!(LayerRule, "@layer foo{}");
assert_parse!(LayerRule, "@layer foo;");
assert_parse!(LayerRule, "@layer foo,bar;");
assert_parse!(LayerRule, "@layer foo.bar,baz.bing.baz;");
assert_parse!(LayerRule, "@layer foo.bar{body{color:black}}");
}
}
Loading

0 comments on commit 15b0f67

Please sign in to comment.