Skip to content

Commit 36c11b7

Browse files
committed
cleanup of the css3 crate
1 parent 387270c commit 36c11b7

24 files changed

Lines changed: 26 additions & 282 deletions

Cargo.lock

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/gosub_css3/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@ gosub_shared = { version = "0.1.1", registry = "gosub", path = "../gosub_shared"
1111
gosub_interface = { version = "0.1.1", registry = "gosub", path = "../gosub_interface", features = [] }
1212
lazy_static = { workspace = true }
1313
log = { workspace = true }
14-
simple_logger = { workspace = true }
1514
anyhow = { workspace = true, features = [] }
1615
colors-transform = "0.2.11"
17-
rand = { workspace = true }
18-
itertools = "0.15.0"
1916
serde_json = { workspace = true }
2017
serde = { workspace = true, features = ["derive"] }
21-
thiserror = { workspace = true }
2218
nom = { workspace = true }
2319
cow-utils = { workspace = true }
2420
indexmap = { version = "2.13.0", optional = true }
2521

22+
[dev-dependencies]
23+
simple_logger = { workspace = true }
24+
2625
[features]
2726
default = []
2827
unresolved_syntax = ["dep:indexmap"]

crates/gosub_css3/src/errors.rs

Lines changed: 0 additions & 35 deletions
This file was deleted.

crates/gosub_css3/src/functions/attr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use gosub_interface::config::HasDocument;
33
use gosub_interface::document::Document;
44
use gosub_shared::node::NodeId;
55

6-
#[allow(dead_code)]
76
pub fn resolve_attr<C: HasDocument>(values: &[CssValue], doc: &C::Document, id: NodeId) -> Vec<CssValue> {
87
let Some(attr_name) = values.first().map(std::string::ToString::to_string) else {
98
return vec![];

crates/gosub_css3/src/lib.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
extern crate core;
1+
//! CSS3 parser for Gosub.
2+
//!
3+
//! This parser is heavily based on the MIT-licensed `CssTree` parser written by Roman Dvornov
4+
//! (<https://github.com/lahmatiy>). The original can be found at <https://github.com/csstree/csstree>.
25
36
use crate::ast::convert_ast_to_stylesheet;
47
use crate::stylesheet::CssStylesheet;
@@ -12,13 +15,8 @@ use gosub_shared::errors::{CssError, CssResult};
1215
use gosub_shared::{timing_start, timing_stop};
1316

1417
pub mod ast;
15-
/// This CSS3 parser is heavily based on the MIT licensed `CssTree` parser written by
16-
/// Roman Dvornov (<https://github.com/lahmatiy>).
17-
/// The original version can be found at <https://github.com/csstree/csstree>
1818
pub mod colors;
19-
pub mod errors;
2019
mod functions;
21-
#[allow(dead_code)]
2220
pub mod matcher;
2321
// The as_* accessors panic by contract when called on the wrong node type;
2422
// callers are expected to check the matching is_* predicate first.
@@ -117,10 +115,6 @@ impl<'stream> Css3<'stream> {
117115

118116
let t_id = timing_start!("css3.parse", self.config.source.as_deref().unwrap_or(""));
119117

120-
// let mut stream = ByteStream::new(Encoding::UTF8, None);
121-
// stream.read_from_str(data, Some(Encoding::UTF8));
122-
// stream.close();
123-
124118
let node_tree = match self.config.context {
125119
Context::Stylesheet => self.parse_stylesheet_internal(),
126120
Context::Rule => self.parse_rule(),
@@ -158,7 +152,6 @@ pub fn load_default_useragent_stylesheet() -> CssStylesheet {
158152
#[cfg(test)]
159153
mod tests {
160154
use super::*;
161-
// use crate::walker::Walker;
162155
use simple_logger::SimpleLogger;
163156

164157
#[test]
@@ -179,9 +172,5 @@ mod tests {
179172
if res.is_err() {
180173
println!("{:?}", res.err().unwrap());
181174
}
182-
183-
// let binding = res.unwrap();
184-
// let w = Walker::new(&binding);
185-
// w.walk_stdout();
186175
}
187176
}

crates/gosub_css3/src/logging.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -390,20 +390,6 @@ impl CssValue {
390390
mod test {
391391
use super::*;
392392

393-
// #[test]
394-
// fn test_css_value_to_color() {
395-
// assert_eq!(CssValue::from_str("color(#ff0000)").unwrap().to_color().unwrap(), RgbColor::from("#ff0000"));
396-
// assert_eq!(CssValue::from_str("'Hello'").unwrap().to_color().unwrap(), RgbColor::from("#000000"));
397-
// }
398-
//
399-
// #[test]
400-
// fn test_css_value_unit_to_px() {
401-
// assert_eq!(CssValue::from_str("10px").unwrap().unit_to_px(), 10.0);
402-
// assert_eq!(CssValue::from_str("10em").unwrap().unit_to_px(), 160.0);
403-
// assert_eq!(CssValue::from_str("10rem").unwrap().unit_to_px(), 160.0);
404-
// assert_eq!(CssValue::from_str("10").unwrap().unit_to_px(), 0.0);
405-
// }
406-
407393
#[test]
408394
fn test_css_rule() {
409395
let rule = CssRule {

crates/gosub_css3/src/matcher.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ pub mod shorthands;
33
pub mod styling;
44
pub mod syntax;
55
mod syntax_matcher;
6-
mod walker;

crates/gosub_css3/src/matcher/property_definitions.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,6 @@ impl PropertyDefinition {
132132
}
133133
}
134134

135-
#[must_use]
136-
pub fn check_expanded_properties(&self, _values: &[CssValue]) -> bool {
137-
// if values.len() != self.expanded_properties.len() {
138-
// return false;
139-
// }
140-
//
141-
// for (i, value) in values.iter().enumerate() {
142-
// let prop = self.expanded_properties.get(i).unwrap();
143-
// let prop_def = parse_definition_file().find(prop).unwrap();
144-
// if !prop_def.matches(&[value.clone()]) {
145-
// return false;
146-
// }
147-
// }
148-
149-
true
150-
}
151-
152135
#[must_use]
153136
pub fn is_shorthand(&self) -> bool {
154137
self.computed.len() > 1
@@ -552,12 +535,6 @@ fn parse_property_file<M: Map<String, PropertyDefinition>>(json: serde_json::Val
552535

553536
let initial_value = if obj["initial_value"].is_array() {
554537
warn!("Initial value is an array, not supported {obj:?}");
555-
// obj["initial_value"]
556-
// .as_array()
557-
// .unwrap()
558-
// .iter()
559-
// .map(|v| CssValue::from(v))
560-
// .collect()
561538
None
562539
} else if obj["initial_value"].is_string() {
563540
match CssValue::parse_str(obj["initial_value"].as_str().unwrap()) {
@@ -568,7 +545,6 @@ fn parse_property_file<M: Map<String, PropertyDefinition>>(json: serde_json::Val
568545
}
569546
}
570547
} else {
571-
// warn!("Initial value is not a string or array {:?}", obj);
572548
None
573549
};
574550

@@ -744,7 +720,6 @@ mod tests {
744720
let definitions = get_css_definitions();
745721
let def = definitions.find_property("background-color").unwrap();
746722

747-
// assert_some!(def.clone().matches(&CssValue::Inherit));
748723
assert_true!(def.clone().matches(&[str!("transparent")]));
749724

750725
assert_true!(def.clone().matches(&[str!("red")]));
@@ -766,7 +741,6 @@ mod tests {
766741
let definitions = get_css_definitions();
767742
let def = definitions.find_property("background-attachment").unwrap();
768743

769-
// assert_true!(def.clone().matches(&CssValue::Inherit));
770744
assert_true!(def.clone().matches(&[str!("scroll")]));
771745
assert_true!(def.clone().matches(&[str!("fixed")]));
772746

crates/gosub_css3/src/matcher/shorthands.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -671,18 +671,6 @@ impl CssDefinitions {
671671
}
672672
}
673673

674-
// if !found_props.is_empty() {
675-
// println!("Found partial expanded properties for shorthand: {}", name);
676-
// } else {
677-
// println!("Missing properties for shorthand: {}", name);
678-
// }
679-
// let missing = computed
680-
// .iter()
681-
// .filter(|computed| !found_props.iter().any(|p| p.name == **computed))
682-
// .collect::<Vec<_>>();
683-
//
684-
// println!("Missing properties: {:?}", missing);
685-
686674
None
687675
}
688676
}

crates/gosub_css3/src/matcher/styling.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use core::fmt::Debug;
22
use cow_utils::CowUtils;
3-
use itertools::Itertools;
43
use std::cmp::Ordering;
54
use std::collections::HashMap;
65
use std::fmt::Display;
@@ -293,7 +292,7 @@ fn match_selector_part<C: HasDocument>(
293292

294293
let children = doc.children(parent_id);
295294

296-
let Some(my_index) = children.iter().find_position(|&&c| c == current_id).map(|(i, _)| i) else {
295+
let Some(my_index) = children.iter().position(|&c| c == current_id) else {
297296
return false;
298297
};
299298

0 commit comments

Comments
 (0)