p_css 0.1.9 → 0.2.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c7c770667eefbfabcfd7543684970c971588c7d31ef7eaa8dfde8dfc71382ec
4
- data.tar.gz: fe5c819bb338d0417fed4e15fbf85f9c8a158038a0fd9d17e78e308c2e1c949f
3
+ metadata.gz: 6e1c61a7f32e19ad124aad07414de8bb8488807b0a93ec7ad54a88f987d26cf5
4
+ data.tar.gz: 2d3944768c2c6d1c1ea25f665fcb517644e47c41078426e522abbefeaccbac73
5
5
  SHA512:
6
- metadata.gz: cf33855007bc4c7691d7a9c726eb51f85215492643ec54c2510438a4d10da5afefa176cc062c8eab5774b4a86a23049c5b7b5f64f121682581f34aceb826870d
7
- data.tar.gz: c72b82737b2c24a7585022da646135f743dfc9a59dc918267482f57ae2e68cd79dcfd6da106a14b6962ac2fd325ab09032a40e59148191d4146b08cc057ef37f
6
+ metadata.gz: 69685dfaefa58845371a7dc4c4293d2257e43065a62a6201d51f8ec8a66f04694d61cc4924e9b7b3a15b4103b2f5e66e8d278c8b0208fae894c62ed4b102ee24
7
+ data.tar.gz: 16d6b7b6f526540f7f0472d21c796a2b47fc23b4a515ab603912776cc09706d815c2e0fcc4c9cfc21e698c0ab6d1fe84b9b6b6497b478a0246d9c7f505bcc46c
data/Cargo.lock ADDED
@@ -0,0 +1,282 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "aho-corasick"
7
+ version = "1.1.4"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
10
+ dependencies = [
11
+ "memchr",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "bindgen"
16
+ version = "0.72.1"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895"
19
+ dependencies = [
20
+ "bitflags",
21
+ "cexpr",
22
+ "clang-sys",
23
+ "itertools",
24
+ "proc-macro2",
25
+ "quote",
26
+ "regex",
27
+ "rustc-hash",
28
+ "shlex",
29
+ "syn",
30
+ ]
31
+
32
+ [[package]]
33
+ name = "bitflags"
34
+ version = "2.11.1"
35
+ source = "registry+https://github.com/rust-lang/crates.io-index"
36
+ checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3"
37
+
38
+ [[package]]
39
+ name = "cexpr"
40
+ version = "0.6.0"
41
+ source = "registry+https://github.com/rust-lang/crates.io-index"
42
+ checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
43
+ dependencies = [
44
+ "nom",
45
+ ]
46
+
47
+ [[package]]
48
+ name = "cfg-if"
49
+ version = "1.0.4"
50
+ source = "registry+https://github.com/rust-lang/crates.io-index"
51
+ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
52
+
53
+ [[package]]
54
+ name = "clang-sys"
55
+ version = "1.8.1"
56
+ source = "registry+https://github.com/rust-lang/crates.io-index"
57
+ checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
58
+ dependencies = [
59
+ "glob",
60
+ "libc",
61
+ "libloading",
62
+ ]
63
+
64
+ [[package]]
65
+ name = "css_native"
66
+ version = "0.1.0"
67
+ dependencies = [
68
+ "magnus",
69
+ "rb-sys",
70
+ ]
71
+
72
+ [[package]]
73
+ name = "either"
74
+ version = "1.15.0"
75
+ source = "registry+https://github.com/rust-lang/crates.io-index"
76
+ checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
77
+
78
+ [[package]]
79
+ name = "glob"
80
+ version = "0.3.3"
81
+ source = "registry+https://github.com/rust-lang/crates.io-index"
82
+ checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
83
+
84
+ [[package]]
85
+ name = "itertools"
86
+ version = "0.13.0"
87
+ source = "registry+https://github.com/rust-lang/crates.io-index"
88
+ checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
89
+ dependencies = [
90
+ "either",
91
+ ]
92
+
93
+ [[package]]
94
+ name = "lazy_static"
95
+ version = "1.5.0"
96
+ source = "registry+https://github.com/rust-lang/crates.io-index"
97
+ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
98
+
99
+ [[package]]
100
+ name = "libc"
101
+ version = "0.2.186"
102
+ source = "registry+https://github.com/rust-lang/crates.io-index"
103
+ checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
104
+
105
+ [[package]]
106
+ name = "libloading"
107
+ version = "0.8.9"
108
+ source = "registry+https://github.com/rust-lang/crates.io-index"
109
+ checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
110
+ dependencies = [
111
+ "cfg-if",
112
+ "windows-link",
113
+ ]
114
+
115
+ [[package]]
116
+ name = "magnus"
117
+ version = "0.8.2"
118
+ source = "registry+https://github.com/rust-lang/crates.io-index"
119
+ checksum = "3b36a5b126bbe97eb0d02d07acfeb327036c6319fd816139a49824a83b7f9012"
120
+ dependencies = [
121
+ "magnus-macros",
122
+ "rb-sys",
123
+ "rb-sys-env",
124
+ "seq-macro",
125
+ ]
126
+
127
+ [[package]]
128
+ name = "magnus-macros"
129
+ version = "0.8.0"
130
+ source = "registry+https://github.com/rust-lang/crates.io-index"
131
+ checksum = "47607461fd8e1513cb4f2076c197d8092d921a1ea75bd08af97398f593751892"
132
+ dependencies = [
133
+ "proc-macro2",
134
+ "quote",
135
+ "syn",
136
+ ]
137
+
138
+ [[package]]
139
+ name = "memchr"
140
+ version = "2.8.0"
141
+ source = "registry+https://github.com/rust-lang/crates.io-index"
142
+ checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
143
+
144
+ [[package]]
145
+ name = "minimal-lexical"
146
+ version = "0.2.1"
147
+ source = "registry+https://github.com/rust-lang/crates.io-index"
148
+ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
149
+
150
+ [[package]]
151
+ name = "nom"
152
+ version = "7.1.3"
153
+ source = "registry+https://github.com/rust-lang/crates.io-index"
154
+ checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
155
+ dependencies = [
156
+ "memchr",
157
+ "minimal-lexical",
158
+ ]
159
+
160
+ [[package]]
161
+ name = "proc-macro2"
162
+ version = "1.0.106"
163
+ source = "registry+https://github.com/rust-lang/crates.io-index"
164
+ checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
165
+ dependencies = [
166
+ "unicode-ident",
167
+ ]
168
+
169
+ [[package]]
170
+ name = "quote"
171
+ version = "1.0.45"
172
+ source = "registry+https://github.com/rust-lang/crates.io-index"
173
+ checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
174
+ dependencies = [
175
+ "proc-macro2",
176
+ ]
177
+
178
+ [[package]]
179
+ name = "rb-sys"
180
+ version = "0.9.128"
181
+ source = "registry+https://github.com/rust-lang/crates.io-index"
182
+ checksum = "45ca28513560e56cfb79a62b1fce363c73af170a182024ce880c77ee9429920a"
183
+ dependencies = [
184
+ "rb-sys-build",
185
+ ]
186
+
187
+ [[package]]
188
+ name = "rb-sys-build"
189
+ version = "0.9.128"
190
+ source = "registry+https://github.com/rust-lang/crates.io-index"
191
+ checksum = "ce04b2c55eff3a21aaa623fcc655d94373238e72cac6b3e1a3641ff31649f99a"
192
+ dependencies = [
193
+ "bindgen",
194
+ "lazy_static",
195
+ "proc-macro2",
196
+ "quote",
197
+ "regex",
198
+ "shell-words",
199
+ "syn",
200
+ ]
201
+
202
+ [[package]]
203
+ name = "rb-sys-env"
204
+ version = "0.2.3"
205
+ source = "registry+https://github.com/rust-lang/crates.io-index"
206
+ checksum = "cca7ad6a7e21e72151d56fe2495a259b5670e204c3adac41ee7ef676ea08117a"
207
+
208
+ [[package]]
209
+ name = "regex"
210
+ version = "1.12.3"
211
+ source = "registry+https://github.com/rust-lang/crates.io-index"
212
+ checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276"
213
+ dependencies = [
214
+ "aho-corasick",
215
+ "memchr",
216
+ "regex-automata",
217
+ "regex-syntax",
218
+ ]
219
+
220
+ [[package]]
221
+ name = "regex-automata"
222
+ version = "0.4.14"
223
+ source = "registry+https://github.com/rust-lang/crates.io-index"
224
+ checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f"
225
+ dependencies = [
226
+ "aho-corasick",
227
+ "memchr",
228
+ "regex-syntax",
229
+ ]
230
+
231
+ [[package]]
232
+ name = "regex-syntax"
233
+ version = "0.8.10"
234
+ source = "registry+https://github.com/rust-lang/crates.io-index"
235
+ checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
236
+
237
+ [[package]]
238
+ name = "rustc-hash"
239
+ version = "2.1.2"
240
+ source = "registry+https://github.com/rust-lang/crates.io-index"
241
+ checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe"
242
+
243
+ [[package]]
244
+ name = "seq-macro"
245
+ version = "0.3.6"
246
+ source = "registry+https://github.com/rust-lang/crates.io-index"
247
+ checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc"
248
+
249
+ [[package]]
250
+ name = "shell-words"
251
+ version = "1.1.1"
252
+ source = "registry+https://github.com/rust-lang/crates.io-index"
253
+ checksum = "dc6fe69c597f9c37bfeeeeeb33da3530379845f10be461a66d16d03eca2ded77"
254
+
255
+ [[package]]
256
+ name = "shlex"
257
+ version = "1.3.0"
258
+ source = "registry+https://github.com/rust-lang/crates.io-index"
259
+ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
260
+
261
+ [[package]]
262
+ name = "syn"
263
+ version = "2.0.117"
264
+ source = "registry+https://github.com/rust-lang/crates.io-index"
265
+ checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
266
+ dependencies = [
267
+ "proc-macro2",
268
+ "quote",
269
+ "unicode-ident",
270
+ ]
271
+
272
+ [[package]]
273
+ name = "unicode-ident"
274
+ version = "1.0.24"
275
+ source = "registry+https://github.com/rust-lang/crates.io-index"
276
+ checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
277
+
278
+ [[package]]
279
+ name = "windows-link"
280
+ version = "0.2.1"
281
+ source = "registry+https://github.com/rust-lang/crates.io-index"
282
+ checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
data/Cargo.toml ADDED
@@ -0,0 +1,3 @@
1
+ [workspace]
2
+ members = ['ext/css_native']
3
+ resolver = '2'
@@ -0,0 +1,12 @@
1
+ [package]
2
+ name = "css_native"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ publish = false
6
+
7
+ [lib]
8
+ crate-type = ["cdylib"]
9
+
10
+ [dependencies]
11
+ magnus = "0.8"
12
+ rb-sys = "0.9"
@@ -0,0 +1,4 @@
1
+ require 'mkmf'
2
+ require 'rb_sys/mkmf'
3
+
4
+ create_rust_makefile('css/css_native')
@@ -0,0 +1,117 @@
1
+ mod matcher;
2
+ mod selectors;
3
+ mod snapshot;
4
+ mod state;
5
+ mod tokenizer;
6
+
7
+ use magnus::{
8
+ function, kwargs, prelude::*, value::ReprValue, Error, RArray, RClass, Ruby, Value,
9
+ };
10
+ use tokenizer::{HashFlag, Kind, NumberFlag, Token, TokenValue, Tokenizer};
11
+
12
+ fn hello() -> &'static str {
13
+ "hello from rust"
14
+ }
15
+
16
+ fn tokenize(ruby: &Ruby, input: String, preserve_comments: bool) -> Result<RArray, Error> {
17
+ let tokens = Tokenizer::new(&input, preserve_comments).tokenize();
18
+ let array = ruby.ary_new_capa(tokens.len());
19
+ let klass = token_class(ruby)?;
20
+
21
+ for t in tokens {
22
+ array.push(build_token(ruby, klass, t)?)?;
23
+ }
24
+
25
+ Ok(array)
26
+ }
27
+
28
+ fn token_class(ruby: &Ruby) -> Result<RClass, Error> {
29
+ let css: Value = ruby.class_object().funcall("const_get", ("CSS",))?;
30
+ css.funcall("const_get", ("Token",))
31
+ }
32
+
33
+ fn build_token(ruby: &Ruby, klass: RClass, token: Token) -> Result<Value, Error> {
34
+ let kind_sym = kind_to_symbol(ruby, token.kind);
35
+ let value = value_to_ruby(ruby, &token.value);
36
+ let flag_sym = flag_to_symbol(ruby, token.number_flag, token.hash_flag);
37
+ let unit_val = unit_to_ruby(ruby, token.unit.as_deref());
38
+
39
+ klass.funcall(
40
+ "new",
41
+ (kind_sym, value, kwargs!("flag" => flag_sym, "unit" => unit_val))
42
+ )
43
+ }
44
+
45
+ fn kind_to_symbol(ruby: &Ruby, kind: Kind) -> magnus::value::StaticSymbol {
46
+ let name = match kind {
47
+ Kind::Ident => "ident",
48
+ Kind::Function => "function",
49
+ Kind::AtKeyword => "at_keyword",
50
+ Kind::Hash => "hash",
51
+ Kind::String_ => "string",
52
+ Kind::BadString => "bad_string",
53
+ Kind::Url => "url",
54
+ Kind::BadUrl => "bad_url",
55
+ Kind::Delim => "delim",
56
+ Kind::Number => "number",
57
+ Kind::Percentage => "percentage",
58
+ Kind::Dimension => "dimension",
59
+ Kind::Whitespace => "whitespace",
60
+ Kind::Cdo => "cdo",
61
+ Kind::Cdc => "cdc",
62
+ Kind::Comment => "comment",
63
+ Kind::Colon => "colon",
64
+ Kind::Semicolon => "semicolon",
65
+ Kind::Comma => "comma",
66
+ Kind::LBracket => "lbracket",
67
+ Kind::RBracket => "rbracket",
68
+ Kind::LParen => "lparen",
69
+ Kind::RParen => "rparen",
70
+ Kind::LBrace => "lbrace",
71
+ Kind::RBrace => "rbrace",
72
+ };
73
+
74
+ ruby.sym_new(name)
75
+ }
76
+
77
+ fn value_to_ruby(ruby: &Ruby, v: &TokenValue) -> Value {
78
+ match v {
79
+ TokenValue::None => ruby.qnil().as_value(),
80
+ TokenValue::Str(s) => ruby.str_new(s).as_value(),
81
+ TokenValue::Delim(c) => ruby.str_new(&c.to_string()).as_value(),
82
+ TokenValue::Int(i) => ruby.integer_from_i64(*i).as_value(),
83
+ TokenValue::Float(f) => ruby.float_from_f64(*f).as_value(),
84
+ }
85
+ }
86
+
87
+ fn flag_to_symbol(ruby: &Ruby, num: Option<NumberFlag>, hash: Option<HashFlag>) -> Value {
88
+ match (num, hash) {
89
+ (Some(NumberFlag::Integer), _) => ruby.sym_new("integer").as_value(),
90
+ (Some(NumberFlag::Number), _) => ruby.sym_new("number").as_value(),
91
+ (_, Some(HashFlag::Id)) => ruby.sym_new("id").as_value(),
92
+ (_, Some(HashFlag::Unrestricted)) => ruby.sym_new("unrestricted").as_value(),
93
+ _ => ruby.qnil().as_value(),
94
+ }
95
+ }
96
+
97
+ fn unit_to_ruby(ruby: &Ruby, unit: Option<&str>) -> Value {
98
+ match unit {
99
+ Some(s) => ruby.str_new(s).as_value(),
100
+ None => ruby.qnil().as_value(),
101
+ }
102
+ }
103
+
104
+ #[magnus::init]
105
+ fn init(ruby: &Ruby) -> Result<(), Error> {
106
+ let css = ruby.define_module("CSS")?;
107
+ let native = css.define_module("Native")?;
108
+
109
+ native.define_singleton_method("hello", function!(hello, 0))?;
110
+ native.define_singleton_method("tokenize", function!(tokenize, 2))?;
111
+
112
+ selectors::init(ruby)?;
113
+ state::init(ruby)?;
114
+ snapshot::init(ruby)?;
115
+
116
+ Ok(())
117
+ }