refactor atrule kind to separate file
This commit is contained in:
parent
05fde03697
commit
b0c89ff8b9
167
src/atrule/kind.rs
Normal file
167
src/atrule/kind.rs
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
use std::fmt::{self, Display};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
|
pub enum AtRuleKind {
|
||||||
|
// SASS specific @rules
|
||||||
|
/// Loads mixins, functions, and variables from other Sass
|
||||||
|
/// stylesheets, and combines CSS from multiple stylesheets together
|
||||||
|
Use,
|
||||||
|
/// Loads a Sass stylesheet and makes its mixins, functions,
|
||||||
|
/// and variables available when your stylesheet is loaded
|
||||||
|
/// with the `@use` rule
|
||||||
|
Forward,
|
||||||
|
/// Extends the CSS at-rule to load styles, mixins, functions,
|
||||||
|
/// and variables from other stylesheets
|
||||||
|
Import,
|
||||||
|
Mixin,
|
||||||
|
Content,
|
||||||
|
Include,
|
||||||
|
/// Defines custom functions that can be used in SassScript
|
||||||
|
/// expressions
|
||||||
|
Function,
|
||||||
|
Return,
|
||||||
|
/// Allows selectors to inherit styles from one another
|
||||||
|
Extend,
|
||||||
|
/// Puts styles within it at the root of the CSS document
|
||||||
|
AtRoot,
|
||||||
|
/// Causes compilation to fail with an error message
|
||||||
|
Error,
|
||||||
|
/// Prints a warning without stopping compilation entirely
|
||||||
|
Warn,
|
||||||
|
/// Prints a message for debugging purposes
|
||||||
|
Debug,
|
||||||
|
If,
|
||||||
|
Else,
|
||||||
|
Each,
|
||||||
|
For,
|
||||||
|
While,
|
||||||
|
|
||||||
|
// CSS @rules
|
||||||
|
/// Defines the character set used by the style sheet
|
||||||
|
Charset,
|
||||||
|
/// Tells the CSS engine that all its content must be considered
|
||||||
|
/// prefixed with an XML namespace
|
||||||
|
Namespace,
|
||||||
|
/// A conditional group rule that will apply its content if the
|
||||||
|
/// browser meets the criteria of the given condition
|
||||||
|
Supports,
|
||||||
|
/// Describes the aspect of layout changes that will be
|
||||||
|
/// applied when printing the document
|
||||||
|
Page,
|
||||||
|
/// Describes the aspect of an external font to be downloaded
|
||||||
|
FontFace,
|
||||||
|
/// Describes the aspect of intermediate steps in a CSS animation sequence
|
||||||
|
Keyframes,
|
||||||
|
|
||||||
|
// @rules related to @font-feature-values
|
||||||
|
FontFeatureValues,
|
||||||
|
Swash,
|
||||||
|
Ornaments,
|
||||||
|
Annotation,
|
||||||
|
Stylistic,
|
||||||
|
Styleset,
|
||||||
|
CharacterVariant,
|
||||||
|
|
||||||
|
// Experimental CSS @rules
|
||||||
|
/// Describes the aspects of the viewport for small screen devices
|
||||||
|
///
|
||||||
|
/// Currently at the Working Draft stage
|
||||||
|
Viewport,
|
||||||
|
/// A conditional group rule that will apply its content if the document in
|
||||||
|
/// which the style sheet is applied meets the criteria of the given condition
|
||||||
|
///
|
||||||
|
/// Deferred to Level 4 of CSS Spec
|
||||||
|
Document,
|
||||||
|
/// Defines specific counter styles that are not part of the predefined set of styles
|
||||||
|
///
|
||||||
|
/// At the Candidate Recommendation stage
|
||||||
|
CounterStyle,
|
||||||
|
|
||||||
|
/// An unknown at rule.
|
||||||
|
/// For forward compatibility, they are parsed the same as @media
|
||||||
|
Unknown(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&str> for AtRuleKind {
|
||||||
|
fn from(c: &str) -> Self {
|
||||||
|
match c.to_ascii_lowercase().as_str() {
|
||||||
|
"use" => Self::Use,
|
||||||
|
"forward" => Self::Forward,
|
||||||
|
"import" => Self::Import,
|
||||||
|
"mixin" => Self::Mixin,
|
||||||
|
"include" => Self::Include,
|
||||||
|
"function" => Self::Function,
|
||||||
|
"return" => Self::Return,
|
||||||
|
"extend" => Self::Extend,
|
||||||
|
"at-root" => Self::AtRoot,
|
||||||
|
"error" => Self::Error,
|
||||||
|
"warn" => Self::Warn,
|
||||||
|
"debug" => Self::Debug,
|
||||||
|
"if" => Self::If,
|
||||||
|
"else" => Self::Else,
|
||||||
|
"each" => Self::Each,
|
||||||
|
"for" => Self::For,
|
||||||
|
"while" => Self::While,
|
||||||
|
"charset" => Self::Charset,
|
||||||
|
"namespace" => Self::Namespace,
|
||||||
|
"supports" => Self::Supports,
|
||||||
|
"page" => Self::Page,
|
||||||
|
"fontface" => Self::FontFace,
|
||||||
|
"keyframes" => Self::Keyframes,
|
||||||
|
"fontfeaturevalues" => Self::FontFeatureValues,
|
||||||
|
"swash" => Self::Swash,
|
||||||
|
"ornaments" => Self::Ornaments,
|
||||||
|
"annotation" => Self::Annotation,
|
||||||
|
"stylistic" => Self::Stylistic,
|
||||||
|
"styleset" => Self::Styleset,
|
||||||
|
"charactervariant" => Self::CharacterVariant,
|
||||||
|
"viewport" => Self::Viewport,
|
||||||
|
"document" => Self::Document,
|
||||||
|
"counterstyle" => Self::CounterStyle,
|
||||||
|
"content" => Self::Content,
|
||||||
|
s => Self::Unknown(s.to_owned()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for AtRuleKind {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Use => write!(f, "@use"),
|
||||||
|
Self::Forward => write!(f, "@forward"),
|
||||||
|
Self::Import => write!(f, "@import"),
|
||||||
|
Self::Mixin => write!(f, "@mixin"),
|
||||||
|
Self::Include => write!(f, "@include"),
|
||||||
|
Self::Function => write!(f, "@function"),
|
||||||
|
Self::Return => write!(f, "@return"),
|
||||||
|
Self::Extend => write!(f, "@extend"),
|
||||||
|
Self::AtRoot => write!(f, "@at-root"),
|
||||||
|
Self::Error => write!(f, "@error"),
|
||||||
|
Self::Warn => write!(f, "@warn"),
|
||||||
|
Self::Debug => write!(f, "@debug"),
|
||||||
|
Self::If => write!(f, "@if"),
|
||||||
|
Self::Else => write!(f, "@else"),
|
||||||
|
Self::Each => write!(f, "@each"),
|
||||||
|
Self::For => write!(f, "@for"),
|
||||||
|
Self::While => write!(f, "@while"),
|
||||||
|
Self::Charset => write!(f, "@charset"),
|
||||||
|
Self::Namespace => write!(f, "@namespace"),
|
||||||
|
Self::Supports => write!(f, "@supports"),
|
||||||
|
Self::Page => write!(f, "@page"),
|
||||||
|
Self::FontFace => write!(f, "@fontface"),
|
||||||
|
Self::Keyframes => write!(f, "@keyframes"),
|
||||||
|
Self::FontFeatureValues => write!(f, "@fontfeaturevalues"),
|
||||||
|
Self::Swash => write!(f, "@swash"),
|
||||||
|
Self::Ornaments => write!(f, "@ornaments"),
|
||||||
|
Self::Annotation => write!(f, "@annotation"),
|
||||||
|
Self::Stylistic => write!(f, "@stylistic"),
|
||||||
|
Self::Styleset => write!(f, "@styleset"),
|
||||||
|
Self::CharacterVariant => write!(f, "@charactervariant"),
|
||||||
|
Self::Viewport => write!(f, "@viewport"),
|
||||||
|
Self::Document => write!(f, "@document"),
|
||||||
|
Self::CounterStyle => write!(f, "@counterstyle"),
|
||||||
|
Self::Content => write!(f, "@content"),
|
||||||
|
Self::Unknown(s) => write!(f, "@{}", s),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,3 @@
|
|||||||
use std::fmt::{self, Display};
|
|
||||||
use std::iter::Peekable;
|
use std::iter::Peekable;
|
||||||
|
|
||||||
use crate::common::{Brackets, ListSeparator, Pos};
|
use crate::common::{Brackets, ListSeparator, Pos};
|
||||||
@ -15,12 +14,14 @@ use crate::{Stmt, Token};
|
|||||||
pub(crate) use function::Function;
|
pub(crate) use function::Function;
|
||||||
pub(crate) use if_rule::If;
|
pub(crate) use if_rule::If;
|
||||||
pub(crate) use mixin::{eat_include, Mixin};
|
pub(crate) use mixin::{eat_include, Mixin};
|
||||||
|
pub(crate) use kind::AtRuleKind;
|
||||||
use parse::eat_stmts;
|
use parse::eat_stmts;
|
||||||
use unknown::UnknownAtRule;
|
use unknown::UnknownAtRule;
|
||||||
|
|
||||||
mod for_rule;
|
mod for_rule;
|
||||||
mod function;
|
mod function;
|
||||||
mod if_rule;
|
mod if_rule;
|
||||||
|
mod kind;
|
||||||
mod mixin;
|
mod mixin;
|
||||||
mod parse;
|
mod parse;
|
||||||
mod unknown;
|
mod unknown;
|
||||||
@ -226,169 +227,3 @@ impl AtRule {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
||||||
pub enum AtRuleKind {
|
|
||||||
// SASS specific @rules
|
|
||||||
/// Loads mixins, functions, and variables from other Sass
|
|
||||||
/// stylesheets, and combines CSS from multiple stylesheets together
|
|
||||||
Use,
|
|
||||||
/// Loads a Sass stylesheet and makes its mixins, functions,
|
|
||||||
/// and variables available when your stylesheet is loaded
|
|
||||||
/// with the `@use` rule
|
|
||||||
Forward,
|
|
||||||
/// Extends the CSS at-rule to load styles, mixins, functions,
|
|
||||||
/// and variables from other stylesheets
|
|
||||||
Import,
|
|
||||||
Mixin,
|
|
||||||
Content,
|
|
||||||
Include,
|
|
||||||
/// Defines custom functions that can be used in SassScript
|
|
||||||
/// expressions
|
|
||||||
Function,
|
|
||||||
Return,
|
|
||||||
/// Allows selectors to inherit styles from one another
|
|
||||||
Extend,
|
|
||||||
/// Puts styles within it at the root of the CSS document
|
|
||||||
AtRoot,
|
|
||||||
/// Causes compilation to fail with an error message
|
|
||||||
Error,
|
|
||||||
/// Prints a warning without stopping compilation entirely
|
|
||||||
Warn,
|
|
||||||
/// Prints a message for debugging purposes
|
|
||||||
Debug,
|
|
||||||
If,
|
|
||||||
Else,
|
|
||||||
Each,
|
|
||||||
For,
|
|
||||||
While,
|
|
||||||
|
|
||||||
// CSS @rules
|
|
||||||
/// Defines the character set used by the style sheet
|
|
||||||
Charset,
|
|
||||||
/// Tells the CSS engine that all its content must be considered
|
|
||||||
/// prefixed with an XML namespace
|
|
||||||
Namespace,
|
|
||||||
/// A conditional group rule that will apply its content if the
|
|
||||||
/// browser meets the criteria of the given condition
|
|
||||||
Supports,
|
|
||||||
/// Describes the aspect of layout changes that will be
|
|
||||||
/// applied when printing the document
|
|
||||||
Page,
|
|
||||||
/// Describes the aspect of an external font to be downloaded
|
|
||||||
FontFace,
|
|
||||||
/// Describes the aspect of intermediate steps in a CSS animation sequence
|
|
||||||
Keyframes,
|
|
||||||
|
|
||||||
// @rules related to @font-feature-values
|
|
||||||
FontFeatureValues,
|
|
||||||
Swash,
|
|
||||||
Ornaments,
|
|
||||||
Annotation,
|
|
||||||
Stylistic,
|
|
||||||
Styleset,
|
|
||||||
CharacterVariant,
|
|
||||||
|
|
||||||
// Experimental CSS @rules
|
|
||||||
/// Describes the aspects of the viewport for small screen devices
|
|
||||||
///
|
|
||||||
/// Currently at the Working Draft stage
|
|
||||||
Viewport,
|
|
||||||
/// A conditional group rule that will apply its content if the document in
|
|
||||||
/// which the style sheet is applied meets the criteria of the given condition
|
|
||||||
///
|
|
||||||
/// Deferred to Level 4 of CSS Spec
|
|
||||||
Document,
|
|
||||||
/// Defines specific counter styles that are not part of the predefined set of styles
|
|
||||||
///
|
|
||||||
/// At the Candidate Recommendation stage
|
|
||||||
CounterStyle,
|
|
||||||
|
|
||||||
/// An unknown at rule.
|
|
||||||
/// For forward compatibility, they are parsed the same as @media
|
|
||||||
Unknown(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&str> for AtRuleKind {
|
|
||||||
fn from(c: &str) -> Self {
|
|
||||||
match c.to_ascii_lowercase().as_str() {
|
|
||||||
"use" => Self::Use,
|
|
||||||
"forward" => Self::Forward,
|
|
||||||
"import" => Self::Import,
|
|
||||||
"mixin" => Self::Mixin,
|
|
||||||
"include" => Self::Include,
|
|
||||||
"function" => Self::Function,
|
|
||||||
"return" => Self::Return,
|
|
||||||
"extend" => Self::Extend,
|
|
||||||
"at-root" => Self::AtRoot,
|
|
||||||
"error" => Self::Error,
|
|
||||||
"warn" => Self::Warn,
|
|
||||||
"debug" => Self::Debug,
|
|
||||||
"if" => Self::If,
|
|
||||||
"else" => Self::Else,
|
|
||||||
"each" => Self::Each,
|
|
||||||
"for" => Self::For,
|
|
||||||
"while" => Self::While,
|
|
||||||
"charset" => Self::Charset,
|
|
||||||
"namespace" => Self::Namespace,
|
|
||||||
"supports" => Self::Supports,
|
|
||||||
"page" => Self::Page,
|
|
||||||
"fontface" => Self::FontFace,
|
|
||||||
"keyframes" => Self::Keyframes,
|
|
||||||
"fontfeaturevalues" => Self::FontFeatureValues,
|
|
||||||
"swash" => Self::Swash,
|
|
||||||
"ornaments" => Self::Ornaments,
|
|
||||||
"annotation" => Self::Annotation,
|
|
||||||
"stylistic" => Self::Stylistic,
|
|
||||||
"styleset" => Self::Styleset,
|
|
||||||
"charactervariant" => Self::CharacterVariant,
|
|
||||||
"viewport" => Self::Viewport,
|
|
||||||
"document" => Self::Document,
|
|
||||||
"counterstyle" => Self::CounterStyle,
|
|
||||||
"content" => Self::Content,
|
|
||||||
s => Self::Unknown(s.to_owned()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for AtRuleKind {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
Self::Use => write!(f, "@use"),
|
|
||||||
Self::Forward => write!(f, "@forward"),
|
|
||||||
Self::Import => write!(f, "@import"),
|
|
||||||
Self::Mixin => write!(f, "@mixin"),
|
|
||||||
Self::Include => write!(f, "@include"),
|
|
||||||
Self::Function => write!(f, "@function"),
|
|
||||||
Self::Return => write!(f, "@return"),
|
|
||||||
Self::Extend => write!(f, "@extend"),
|
|
||||||
Self::AtRoot => write!(f, "@at-root"),
|
|
||||||
Self::Error => write!(f, "@error"),
|
|
||||||
Self::Warn => write!(f, "@warn"),
|
|
||||||
Self::Debug => write!(f, "@debug"),
|
|
||||||
Self::If => write!(f, "@if"),
|
|
||||||
Self::Else => write!(f, "@else"),
|
|
||||||
Self::Each => write!(f, "@each"),
|
|
||||||
Self::For => write!(f, "@for"),
|
|
||||||
Self::While => write!(f, "@while"),
|
|
||||||
Self::Charset => write!(f, "@charset"),
|
|
||||||
Self::Namespace => write!(f, "@namespace"),
|
|
||||||
Self::Supports => write!(f, "@supports"),
|
|
||||||
Self::Page => write!(f, "@page"),
|
|
||||||
Self::FontFace => write!(f, "@fontface"),
|
|
||||||
Self::Keyframes => write!(f, "@keyframes"),
|
|
||||||
Self::FontFeatureValues => write!(f, "@fontfeaturevalues"),
|
|
||||||
Self::Swash => write!(f, "@swash"),
|
|
||||||
Self::Ornaments => write!(f, "@ornaments"),
|
|
||||||
Self::Annotation => write!(f, "@annotation"),
|
|
||||||
Self::Stylistic => write!(f, "@stylistic"),
|
|
||||||
Self::Styleset => write!(f, "@styleset"),
|
|
||||||
Self::CharacterVariant => write!(f, "@charactervariant"),
|
|
||||||
Self::Viewport => write!(f, "@viewport"),
|
|
||||||
Self::Document => write!(f, "@document"),
|
|
||||||
Self::CounterStyle => write!(f, "@counterstyle"),
|
|
||||||
Self::Content => write!(f, "@content"),
|
|
||||||
Self::Unknown(s) => write!(f, "@{}", s),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user