Skip to content

Commit

Permalink
WIP: ast
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Aug 17, 2020
1 parent 0848f89 commit 16faff9
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 26 deletions.
5 changes: 2 additions & 3 deletions css/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
swc_css_ast = { path = "./css" }
swc_css_parser = { path = "./parser" }
swc_css_visit = { path = "./visit" }
swc_css_ast = { path = "./ast" }
swc_css_parser = { path = "./parser" }
4 changes: 4 additions & 0 deletions css/ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
swc_atoms = { path = "../../atoms" }
swc_common = { path = "../../common" }
swc_visit = { path = "../../visit" }
serde = { version = "1", features = ["derive"] }
217 changes: 211 additions & 6 deletions css/ast/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,212 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
use swc_atoms::JsWord;
use swc_common::{ast_node, Span};

#[ast_node]
pub struct AnPlusB {
pub span: Span,
pub a: Option<JsWord>,
pub b: Option<JsWord>,
}

#[ast_node]
pub struct AtRule {
pub span: Span,
pub name: JsWord,
// prelude: <AtrulePrelude> | <Raw> | null,
pub block: Block,
}

#[ast_node]
pub enum AtrulePrelude {}

#[ast_node]
pub struct AttributeSelector {
pub span: Span,
pub name: Id,

pub matcher: Option<JsWord>,
/// <String> | <Identifier> | null
pub value: AttributeSelectorValue,

pub flags: Option<JsWord>,
}

#[ast_node]
pub struct Block {
pub span: Span,
pub children: Vec<BlockItem>,
}

#[ast_node]
pub enum BlockItem {}

#[ast_node]
pub struct Brackets {
pub span: Span,
}

#[ast_node]
pub struct ClassSelector {
pub span: Span,
pub name: JsWord,
}

#[ast_node]
pub struct Combinator {
pub span: Span,
pub name: JsWord,
}

#[ast_node]
pub struct Declaration {
pub span: Span,
// important: Boolean | String,
pub property: DeclarationProperty,
// value: <Value> | <Raw>
}

#[ast_node]
pub struct Dimension {
pub span: Span,
pub value: JsWord,
pub unit: JsWord,
}

#[ast_node]
pub struct Function {
pub span: Span,
pub name: JsWord,
pub children: Vec<FunctionChild>,
}

#[ast_node]
pub struct Hash {
pub span: Span,
pub value: JsWord,
}

#[ast_node]
pub struct IdSelector {
pub span: Span,
pub name: JsWord,
}

#[ast_node("Identifier")]
pub struct Id {
pub span: Span,
pub name: JsWord,
}

#[ast_node]
pub struct MediaFeature {
pub span: Span,
pub name: JsWord,
pub value: MediaFeatureValue,
}

#[ast_node]
pub struct MediaQuery {
pub span: Span,
pub children: Vec<MediaQueryChildren>,
}

#[ast_node]
pub struct Nth {
pub span: Span,
pub nth: NthValue,

pub selector: Vec<Selector>,
}

#[ast_node]
pub enum NthValue {
#[tag("AnPlusB")]
AnPlusB(AnPlusB),
#[tag("Identifier")]
Id(Id),
}

#[ast_node]
pub struct Number {
pub span: Span,
pub value: JsWord,
}

#[ast_node]
pub struct Operator {
pub span: Span,
pub value: JsWord,
}

#[ast_node]
pub struct Paren {
pub span: Span,
pub children: Vec<ParenChild>,
}

#[ast_node]
pub struct Percentage {
pub span: Span,
pub value: JsWord,
}

#[ast_node]
pub struct PseudoClassSelector {
pub span: Span,
pub name: JsWord,
pub children: Vec<PseudoClassSelectorChild>,
}

// {
// type: "PseudoClassSelector",
// name: String,
// children: List | null
// }

// {
// type: "PseudoElementSelector",
// name: String,
// children: List | null
// }

// {
// type: "Ratio",
// left: String,
// right: String
// }

// {
// type: "Raw",
// value: String
// }

// {
// type: "Rule",
// prelude: <SelectorList> | <Raw>,
// block: <Block>
// }

// {
// type: "Selector",
// children: List
//}

// {
// type: "StyleSheet",
// children: List
// }

// {
// type: "TypeSelector",
// name: String
// }

// {
// type: "Url",
// value: <String> | <Raw>
// }

// {
// type: "Value",
// children: List
// }
2 changes: 1 addition & 1 deletion css/parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "parser"
name = "swc_css_parser"
version = "0.1.0"
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
edition = "2018"
Expand Down
9 changes: 0 additions & 9 deletions css/visit/Cargo.toml

This file was deleted.

7 changes: 0 additions & 7 deletions css/visit/src/lib.rs

This file was deleted.

0 comments on commit 16faff9

Please sign in to comment.