less_rs/lib.rs
1// use cssparser::{Parser, ParserInput};
2// use less_allocator::{Allocator, Vec};
3// use parser::TopLevelRuleParser;
4// use rules::CssRuleList;
5// use traits::ToCss;
6//
7// mod error;
8// mod parser;
9// mod printer;
10// mod properties;
11// mod rules;
12// mod selector;
13// mod traits;
14// mod values;
15//
16// /// In less specifications, syntax are defined as follows.
17// ///
18// /// The `primary` rule is the *entry* and *exit* point of the parser.
19// /// The rules here can appear at any level of the parse tree.
20// ///
21// /// The recursive nature of the grammar is an interplay between the `block`
22// /// rule, which represents `{ .. }`, the `ruleset` rule, and this `primary` rule,
23// /// as represented by this simplified grammar:
24// ///
25// /// primary → (ruleset | declaration)+
26// /// ruleset → selector+ block
27// /// block → '{' primary '}'
28// ///
29// /// Only at one point is the primary rule not called from the
30// /// block rule: at the root level.
31//
32// pub fn parse(code: &str) {
33// let allocator = Allocator::default();
34// let mut input = ParserInput::new(code);
35// let mut parser = Parser::new(&mut input);
36//
37// let rules = allocator.alloc(CssRuleList(Vec::new_in(&allocator)));
38// let mut at_rule_parser = TopLevelRuleParser::new(&allocator, rules);
39// let rule_set_parser = cssparser::StyleSheetParser::new(&mut parser, &mut at_rule_parser);
40//
41// for rule in rule_set_parser {
42// dbg!(rule);
43// }
44//
45// dbg!(&rules);
46// dbg!(allocator.allocated_bytes());
47//
48// dbg!(rules.to_css_string(&allocator).unwrap());
49// }
50//
51// #[cfg(test)]
52// mod test {
53//
54// use super::*;
55//
56// // fn foo() {
57// // let alloc = Allocator::default();
58// //
59// // let mut v = Vec::new_in(&alloc);
60// // v.push(1);
61// // v.push(2)
62// // }
63//
64// #[test]
65// fn test() {
66// // foo();
67// //
68// // println!("called");
69// let code = r#"
70// @foo: 16px;
71// .class {
72// @bar: 15px + @foo;
73// @r: 255
74// font-size: @bar + 17px;
75// background-color:rgb(0,0,1);
76// }
77// "#;
78// let code = r#"
79// @code: 255;
80// .class {
81// font-size: 16px + 12px;
82// background-color: rgb(0, 0, @code);
83// color: rgb(@code, 0, 1);
84// }
85// "#;
86// parse(code)
87// }
88// }