cataract 0.1.0
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 +7 -0
- data/.clang-tidy +30 -0
- data/.github/workflows/ci-macos.yml +12 -0
- data/.github/workflows/ci.yml +77 -0
- data/.github/workflows/test.yml +76 -0
- data/.gitignore +45 -0
- data/.overcommit.yml +38 -0
- data/.rubocop.yml +83 -0
- data/BENCHMARKS.md +201 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +27 -0
- data/LICENSE +21 -0
- data/RAGEL_MIGRATION.md +60 -0
- data/README.md +292 -0
- data/Rakefile +209 -0
- data/benchmarks/benchmark_harness.rb +193 -0
- data/benchmarks/benchmark_merging.rb +121 -0
- data/benchmarks/benchmark_optimization_comparison.rb +168 -0
- data/benchmarks/benchmark_parsing.rb +153 -0
- data/benchmarks/benchmark_ragel_removal.rb +56 -0
- data/benchmarks/benchmark_runner.rb +70 -0
- data/benchmarks/benchmark_serialization.rb +180 -0
- data/benchmarks/benchmark_shorthand.rb +109 -0
- data/benchmarks/benchmark_shorthand_expansion.rb +176 -0
- data/benchmarks/benchmark_specificity.rb +124 -0
- data/benchmarks/benchmark_string_allocation.rb +151 -0
- data/benchmarks/benchmark_stylesheet_to_s.rb +62 -0
- data/benchmarks/benchmark_to_s_cached.rb +55 -0
- data/benchmarks/benchmark_value_splitter.rb +54 -0
- data/benchmarks/benchmark_yjit.rb +158 -0
- data/benchmarks/benchmark_yjit_workers.rb +61 -0
- data/benchmarks/profile_to_s.rb +23 -0
- data/benchmarks/speedup_calculator.rb +83 -0
- data/benchmarks/system_metadata.rb +81 -0
- data/benchmarks/templates/benchmarks.md.erb +221 -0
- data/benchmarks/yjit_tests.rb +141 -0
- data/cataract.gemspec +34 -0
- data/cliff.toml +92 -0
- data/examples/color_conversion_visual_test/color_conversion_test.html +3603 -0
- data/examples/color_conversion_visual_test/generate.rb +202 -0
- data/examples/color_conversion_visual_test/template.html.erb +259 -0
- data/examples/css_analyzer/analyzer.rb +164 -0
- data/examples/css_analyzer/analyzers/base.rb +33 -0
- data/examples/css_analyzer/analyzers/colors.rb +133 -0
- data/examples/css_analyzer/analyzers/important.rb +88 -0
- data/examples/css_analyzer/analyzers/properties.rb +61 -0
- data/examples/css_analyzer/analyzers/specificity.rb +68 -0
- data/examples/css_analyzer/templates/report.html.erb +575 -0
- data/examples/css_analyzer.rb +69 -0
- data/examples/github_analysis.html +5343 -0
- data/ext/cataract/cataract.c +1086 -0
- data/ext/cataract/cataract.h +174 -0
- data/ext/cataract/css_parser.c +1435 -0
- data/ext/cataract/extconf.rb +48 -0
- data/ext/cataract/import_scanner.c +174 -0
- data/ext/cataract/merge.c +973 -0
- data/ext/cataract/shorthand_expander.c +902 -0
- data/ext/cataract/specificity.c +213 -0
- data/ext/cataract/value_splitter.c +116 -0
- data/ext/cataract_color/cataract_color.c +16 -0
- data/ext/cataract_color/color_conversion.c +1687 -0
- data/ext/cataract_color/color_conversion.h +136 -0
- data/ext/cataract_color/color_conversion_lab.c +571 -0
- data/ext/cataract_color/color_conversion_named.c +259 -0
- data/ext/cataract_color/color_conversion_oklab.c +547 -0
- data/ext/cataract_color/extconf.rb +23 -0
- data/ext/cataract_old/cataract.c +393 -0
- data/ext/cataract_old/cataract.h +250 -0
- data/ext/cataract_old/css_parser.c +933 -0
- data/ext/cataract_old/extconf.rb +67 -0
- data/ext/cataract_old/import_scanner.c +174 -0
- data/ext/cataract_old/merge.c +776 -0
- data/ext/cataract_old/shorthand_expander.c +902 -0
- data/ext/cataract_old/specificity.c +213 -0
- data/ext/cataract_old/stylesheet.c +290 -0
- data/ext/cataract_old/value_splitter.c +116 -0
- data/lib/cataract/at_rule.rb +97 -0
- data/lib/cataract/color_conversion.rb +18 -0
- data/lib/cataract/declarations.rb +332 -0
- data/lib/cataract/import_resolver.rb +210 -0
- data/lib/cataract/rule.rb +131 -0
- data/lib/cataract/stylesheet.rb +716 -0
- data/lib/cataract/stylesheet_scope.rb +257 -0
- data/lib/cataract/version.rb +5 -0
- data/lib/cataract.rb +107 -0
- data/lib/tasks/gem.rake +158 -0
- data/scripts/fuzzer/run.rb +828 -0
- data/scripts/fuzzer/worker.rb +99 -0
- data/scripts/generate_benchmarks_md.rb +155 -0
- metadata +135 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
#ifndef CATARACT_NEW_H
|
|
2
|
+
#define CATARACT_NEW_H
|
|
3
|
+
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
#include <ruby/encoding.h>
|
|
6
|
+
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Global struct class references
|
|
9
|
+
// ============================================================================
|
|
10
|
+
|
|
11
|
+
extern VALUE cRule;
|
|
12
|
+
extern VALUE cDeclaration;
|
|
13
|
+
extern VALUE cAtRule;
|
|
14
|
+
extern VALUE cStylesheet;
|
|
15
|
+
|
|
16
|
+
// Error class references
|
|
17
|
+
extern VALUE eCataractError;
|
|
18
|
+
extern VALUE eDepthError;
|
|
19
|
+
extern VALUE eSizeError;
|
|
20
|
+
|
|
21
|
+
// ============================================================================
|
|
22
|
+
// Struct field indices
|
|
23
|
+
// ============================================================================
|
|
24
|
+
|
|
25
|
+
// Rule struct field indices (id, selector, declarations, specificity, parent_rule_id, nesting_style)
|
|
26
|
+
#define RULE_ID 0
|
|
27
|
+
#define RULE_SELECTOR 1
|
|
28
|
+
#define RULE_DECLARATIONS 2
|
|
29
|
+
#define RULE_SPECIFICITY 3
|
|
30
|
+
#define RULE_PARENT_RULE_ID 4
|
|
31
|
+
#define RULE_NESTING_STYLE 5
|
|
32
|
+
|
|
33
|
+
// Nesting style constants
|
|
34
|
+
#define NESTING_STYLE_IMPLICIT 0 // .parent { .child { } } - no &
|
|
35
|
+
#define NESTING_STYLE_EXPLICIT 1 // .parent { &.child { } } - has &
|
|
36
|
+
|
|
37
|
+
// Named constants for parse_css_recursive() call clarity
|
|
38
|
+
// (Makes call sites self-documenting)
|
|
39
|
+
#define NO_PARENT_MEDIA Qnil
|
|
40
|
+
#define NO_PARENT_SELECTOR Qnil
|
|
41
|
+
#define NO_PARENT_RULE_ID Qnil
|
|
42
|
+
|
|
43
|
+
// Declaration struct field indices (property, value, important)
|
|
44
|
+
#define DECL_PROPERTY 0
|
|
45
|
+
#define DECL_VALUE 1
|
|
46
|
+
#define DECL_IMPORTANT 2
|
|
47
|
+
|
|
48
|
+
// AtRule struct field indices (id, selector, content, specificity)
|
|
49
|
+
// Matches Rule interface for duck-typing
|
|
50
|
+
#define AT_RULE_ID 0
|
|
51
|
+
#define AT_RULE_SELECTOR 1
|
|
52
|
+
#define AT_RULE_CONTENT 2
|
|
53
|
+
#define AT_RULE_SPECIFICITY 3
|
|
54
|
+
|
|
55
|
+
// ============================================================================
|
|
56
|
+
// Macros
|
|
57
|
+
// ============================================================================
|
|
58
|
+
|
|
59
|
+
// Whitespace detection
|
|
60
|
+
#define IS_WHITESPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r')
|
|
61
|
+
|
|
62
|
+
// Debug output (disabled by default)
|
|
63
|
+
// #define CATARACT_DEBUG 1
|
|
64
|
+
|
|
65
|
+
#ifdef CATARACT_DEBUG
|
|
66
|
+
#define DEBUG_PRINTF(...) printf(__VA_ARGS__)
|
|
67
|
+
#else
|
|
68
|
+
#define DEBUG_PRINTF(...) ((void)0)
|
|
69
|
+
#endif
|
|
70
|
+
|
|
71
|
+
// Trim leading whitespace - modifies start pointer
|
|
72
|
+
static inline void trim_leading(const char **start, const char *end) {
|
|
73
|
+
while (*start < end && IS_WHITESPACE(**start)) {
|
|
74
|
+
(*start)++;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Trim trailing whitespace - modifies end pointer
|
|
79
|
+
static inline void trim_trailing(const char *start, const char **end) {
|
|
80
|
+
while (*end > start && IS_WHITESPACE(*(*end - 1))) {
|
|
81
|
+
(*end)--;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Strip whitespace from both ends and return new string
|
|
86
|
+
static inline VALUE strip_string(const char *str, long len) {
|
|
87
|
+
const char *start = str;
|
|
88
|
+
const char *end = str + len;
|
|
89
|
+
trim_leading(&start, end);
|
|
90
|
+
trim_trailing(start, &end);
|
|
91
|
+
return rb_str_new(start, end - start);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// US-ASCII string literal creation
|
|
95
|
+
// Only for compile-time string literals - uses sizeof() for length
|
|
96
|
+
// For runtime char*, use rb_usascii_str_new(ptr, len) directly
|
|
97
|
+
#define USASCII_STR(str) rb_usascii_str_new((str), sizeof(str) - 1)
|
|
98
|
+
|
|
99
|
+
// UTF-8 string literal creation
|
|
100
|
+
// Only for compile-time string literals - uses sizeof() for length
|
|
101
|
+
// For runtime char*, use rb_utf8_str_new(ptr, len) directly
|
|
102
|
+
#define UTF8_STR(str) rb_utf8_str_new((str), sizeof(str) - 1)
|
|
103
|
+
|
|
104
|
+
// String allocation macros (from old cataract.h)
|
|
105
|
+
#ifndef DISABLE_STR_BUF_OPTIMIZATION
|
|
106
|
+
#define STR_NEW_WITH_CAPACITY(capacity) rb_str_buf_new(capacity)
|
|
107
|
+
#define STR_NEW_CSTR(str) rb_str_new_cstr(str)
|
|
108
|
+
#else
|
|
109
|
+
#define STR_NEW_WITH_CAPACITY(capacity) rb_str_new_cstr("")
|
|
110
|
+
#define STR_NEW_CSTR(str) rb_str_new_cstr(str)
|
|
111
|
+
#endif
|
|
112
|
+
|
|
113
|
+
// Safety limits
|
|
114
|
+
#ifndef MAX_PARSE_DEPTH
|
|
115
|
+
#define MAX_PARSE_DEPTH 10 // Max recursion depth for nested @media/@supports blocks and CSS nesting
|
|
116
|
+
#endif
|
|
117
|
+
|
|
118
|
+
#ifndef MAX_PROPERTY_NAME_LENGTH
|
|
119
|
+
#define MAX_PROPERTY_NAME_LENGTH 256 // Max length of CSS property name
|
|
120
|
+
#endif
|
|
121
|
+
|
|
122
|
+
#ifndef MAX_PROPERTY_VALUE_LENGTH
|
|
123
|
+
#define MAX_PROPERTY_VALUE_LENGTH 32768 // Max length of CSS property value (32KB)
|
|
124
|
+
#endif
|
|
125
|
+
|
|
126
|
+
#ifndef MAX_MEDIA_QUERIES
|
|
127
|
+
#define MAX_MEDIA_QUERIES 1000 // Prevent symbol table exhaustion
|
|
128
|
+
#endif
|
|
129
|
+
|
|
130
|
+
// ============================================================================
|
|
131
|
+
// Function declarations
|
|
132
|
+
// ============================================================================
|
|
133
|
+
|
|
134
|
+
// CSS parser (css_parser_new.c)
|
|
135
|
+
VALUE parse_css_new(VALUE self, VALUE css_string);
|
|
136
|
+
VALUE parse_css_new_impl(VALUE css_string, int rule_id_offset);
|
|
137
|
+
VALUE parse_media_types(VALUE self, VALUE media_query_sym);
|
|
138
|
+
|
|
139
|
+
// Merge (merge_new.c)
|
|
140
|
+
VALUE cataract_merge_new(VALUE self, VALUE rules_array);
|
|
141
|
+
void init_merge_constants(void);
|
|
142
|
+
|
|
143
|
+
// Specificity (specificity.c)
|
|
144
|
+
VALUE calculate_specificity(VALUE self, VALUE selector);
|
|
145
|
+
|
|
146
|
+
// Import scanner (import_scanner.c)
|
|
147
|
+
VALUE extract_imports(VALUE self, VALUE css_string);
|
|
148
|
+
|
|
149
|
+
// Shorthand expander (shorthand_expander_new.c)
|
|
150
|
+
VALUE cataract_split_value(VALUE self, VALUE value);
|
|
151
|
+
VALUE cataract_expand_margin(VALUE self, VALUE value);
|
|
152
|
+
VALUE cataract_expand_padding(VALUE self, VALUE value);
|
|
153
|
+
VALUE cataract_expand_border(VALUE self, VALUE value);
|
|
154
|
+
VALUE cataract_expand_border_color(VALUE self, VALUE value);
|
|
155
|
+
VALUE cataract_expand_border_style(VALUE self, VALUE value);
|
|
156
|
+
VALUE cataract_expand_border_width(VALUE self, VALUE value);
|
|
157
|
+
VALUE cataract_expand_border_side(VALUE self, VALUE side, VALUE value);
|
|
158
|
+
VALUE cataract_expand_font(VALUE self, VALUE value);
|
|
159
|
+
VALUE cataract_expand_list_style(VALUE self, VALUE value);
|
|
160
|
+
VALUE cataract_expand_background(VALUE self, VALUE value);
|
|
161
|
+
VALUE cataract_create_margin_shorthand(VALUE self, VALUE properties);
|
|
162
|
+
VALUE cataract_create_padding_shorthand(VALUE self, VALUE properties);
|
|
163
|
+
VALUE cataract_create_border_width_shorthand(VALUE self, VALUE properties);
|
|
164
|
+
VALUE cataract_create_border_style_shorthand(VALUE self, VALUE properties);
|
|
165
|
+
VALUE cataract_create_border_color_shorthand(VALUE self, VALUE properties);
|
|
166
|
+
VALUE cataract_create_border_shorthand(VALUE self, VALUE properties);
|
|
167
|
+
VALUE cataract_create_font_shorthand(VALUE self, VALUE properties);
|
|
168
|
+
VALUE cataract_create_list_style_shorthand(VALUE self, VALUE properties);
|
|
169
|
+
VALUE cataract_create_background_shorthand(VALUE self, VALUE properties);
|
|
170
|
+
|
|
171
|
+
// Helper (from css_parser_new.c)
|
|
172
|
+
VALUE lowercase_property(VALUE property_str);
|
|
173
|
+
|
|
174
|
+
#endif // CATARACT_NEW_H
|