grass/src/atrule/kind.rs

103 lines
2.8 KiB
Rust
Raw Normal View History

2020-05-24 12:47:04 -04:00
use std::convert::TryFrom;
use codemap::Spanned;
use crate::error::SassError;
2020-04-05 23:37:55 -04:00
#[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,
2020-05-25 15:52:53 -04:00
2020-04-05 23:37:55 -04:00
/// Loads a Sass stylesheet and makes its mixins, functions,
/// and variables available when your stylesheet is loaded
/// with the `@use` rule
Forward,
2020-05-25 15:52:53 -04:00
2020-04-05 23:37:55 -04:00
/// Extends the CSS at-rule to load styles, mixins, functions,
/// and variables from other stylesheets
///
/// The definition inside `grass` however differs in that
/// the @import rule refers to a plain css import
/// e.g. `@import url(foo);`
2020-04-05 23:37:55 -04:00
Import,
2020-05-25 15:52:53 -04:00
2020-04-05 23:37:55 -04:00
Mixin,
Content,
Include,
2020-05-25 15:52:53 -04:00
2020-04-05 23:37:55 -04:00
/// Defines custom functions that can be used in SassScript
/// expressions
Function,
Return,
2020-05-25 15:52:53 -04:00
2020-04-05 23:37:55 -04:00
/// Allows selectors to inherit styles from one another
Extend,
2020-05-25 15:52:53 -04:00
2020-04-05 23:37:55 -04:00
/// Puts styles within it at the root of the CSS document
AtRoot,
2020-05-25 15:52:53 -04:00
2020-04-05 23:37:55 -04:00
/// Causes compilation to fail with an error message
Error,
2020-05-25 15:52:53 -04:00
2020-04-05 23:37:55 -04:00
/// Prints a warning without stopping compilation entirely
Warn,
2020-05-25 15:52:53 -04:00
2020-04-05 23:37:55 -04:00
/// Prints a message for debugging purposes
Debug,
2020-05-25 15:52:53 -04:00
2020-04-05 23:37:55 -04:00
If,
Each,
For,
While,
// CSS @rules
/// Defines the character set used by the style sheet
Charset,
2020-05-25 15:52:53 -04:00
2020-04-05 23:37:55 -04:00
/// A conditional group rule that will apply its content if the
/// browser meets the criteria of the given condition
Supports,
2020-05-25 15:52:53 -04:00
2020-04-05 23:37:55 -04:00
/// Describes the aspect of intermediate steps in a CSS animation sequence
Keyframes,
2020-05-25 15:52:53 -04:00
Media,
2020-04-05 23:37:55 -04:00
2020-05-25 15:52:53 -04:00
/// An unknown at-rule
2020-04-05 23:37:55 -04:00
Unknown(String),
}
2020-05-24 12:47:04 -04:00
impl TryFrom<&Spanned<String>> for AtRuleKind {
type Error = SassError;
fn try_from(c: &Spanned<String>) -> Result<Self, SassError> {
2020-06-01 21:35:23 -04:00
Ok(match c.node.as_str() {
2020-04-05 23:37:55 -04:00
"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,
"each" => Self::Each,
"for" => Self::For,
"while" => Self::While,
"charset" => Self::Charset,
"supports" => Self::Supports,
"keyframes" => Self::Keyframes,
"content" => Self::Content,
2020-05-20 20:13:53 -04:00
"media" => Self::Media,
2020-05-24 12:47:04 -04:00
"else" => return Err(("This at-rule is not allowed here.", c.span).into()),
"" => return Err(("Expected identifier.", c.span).into()),
2020-04-05 23:37:55 -04:00
s => Self::Unknown(s.to_owned()),
2020-05-24 12:47:04 -04:00
})
2020-04-05 23:37:55 -04:00
}
}