Skip to content

Commit 5e0aadd

Browse files
committed
added all utils files
1 parent c52714a commit 5e0aadd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+12015
-0
lines changed

utils/MyCSS/an+b.pl

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/usr/bin/perl -w
2+
3+
BEGIN {
4+
use FindBin;
5+
push @INC, $FindBin::Bin. "/../ext/";
6+
};
7+
8+
use bytes;
9+
use strict;
10+
use Encode;
11+
12+
use MyCSS::Grammar;
13+
use MyCSS::Token;
14+
use MyCSS::CFunction;
15+
16+
my $filename = "data/an+b.txt";
17+
18+
my $token = MyCSS::Token->new();
19+
my $grammar = MyCSS::Grammar->new();
20+
my $cfunc = MyCSS::CFunction->new(
21+
token => $token,
22+
grammar => $grammar,
23+
func_def => \&My::Functions::Basic::function_default,
24+
func_else => \&My::Functions::Basic::function_else,
25+
func_last => \&My::Functions::Basic::function_last,
26+
func_prefix => "mycss_an_plus_b_state_",
27+
func_whitespace => \&My::Functions::Basic::function_whitespace,
28+
func_not_whitespace => \&My::Functions::Basic::function_not_whitespace,
29+
func_string_before => \&My::Functions::Basic::function_string_before,
30+
func_string_after => \&My::Functions::Basic::function_string_after,
31+
func_proto_args => "mycss_result_t* result, mycss_an_plus_b_t* anb, mycss_an_plus_b_entry_t* anb_entry, mycss_token_t* token",
32+
all_chars_for_name => 1,
33+
reg_name => 1,
34+
func_list => {}
35+
);
36+
37+
my ($parse_res, $index_res) = $grammar->parser_file($filename);
38+
39+
my $index_list = {};
40+
41+
foreach my $key (@$index_res) {
42+
my $tree = $grammar->create_tree($parse_res->{$key}, $key);
43+
my $list = $grammar->parse_tree($tree);
44+
45+
$index_list->{$key} = $list;
46+
}
47+
48+
my $hash_full = {};
49+
my $hash_origin = {};
50+
51+
foreach my $key (@$index_res) {
52+
my ($work_full, $work_origin) = $grammar->decomposite($index_list, [$key]);
53+
54+
$hash_origin->{$key} = $work_origin->{$key};
55+
}
56+
57+
my $key = "<anb>";
58+
59+
my $ghash = {};
60+
my $attr = $grammar->make_combine_hash_from_decomposing_list($hash_origin->{$key}, $hash_origin, sub{ $_[1]->entry->name }, $ghash);
61+
62+
my $func_result = {};
63+
my $first_result = $cfunc->create($key, $attr);
64+
$cfunc->print_result_names($first_result);
65+
66+
foreach my $gkey (keys %$ghash) {
67+
$func_result->{ $gkey } = $cfunc->create($gkey, $ghash->{$gkey}, "shared")
68+
if %{$ghash->{$gkey}};
69+
}
70+
71+
foreach my $key (keys %$func_result) {
72+
$cfunc->print_result_names($func_result->{$key});
73+
}
74+
75+
print "\n";
76+
$cfunc->print_result_data($first_result);
77+
foreach my $key (keys %$func_result) {
78+
$cfunc->print_result_data($func_result->{$key});
79+
}
80+
81+
package My::Functions;
82+
83+
package My::Functions::Basic;
84+
85+
sub function_whitespace {
86+
my ($creater, $cfunc, $exists_delim) = @_;
87+
88+
[
89+
"if(result->parser != mycss_an_plus_b_state_token_skip_whitespace)",
90+
"\t"."result->parser = mycss_an_plus_b_state_token_skip_whitespace;"
91+
];
92+
}
93+
94+
sub function_not_whitespace {
95+
my ($creater, $cfunc, $exists_delim) = @_;
96+
97+
[
98+
"if(result->parser != mycss_an_plus_b_state_token_all)",
99+
"\t"."result->parser = mycss_an_plus_b_state_token_all;"
100+
];
101+
}
102+
103+
sub function_string_before {
104+
my ($creater, $cfunc, $exists_delim) = @_;
105+
106+
[
107+
"myhtml_string_t str;",
108+
"mycss_token_data_to_string(result->entry, token, &str, true);"
109+
];
110+
}
111+
112+
sub function_string_after {
113+
my ($creater, $cfunc, $exists_delim) = @_;
114+
115+
["myhtml_string_destroy(&str, false);"];
116+
}
117+
118+
sub function_default {
119+
my ($creater, $cfunc, $fname, $type) = @_;
120+
121+
return ["result->state = $fname;"];
122+
}
123+
124+
sub function_else {
125+
my ($creater, $cfunc, $fname) = @_;
126+
127+
[
128+
"mycss_an_plus_b_parser_expectations_error(result, anb, anb_entry, token);",
129+
"result->parser = result->parser_switch;",
130+
"return false;"
131+
];
132+
}
133+
134+
sub function_last {
135+
my ($creater, $cfunc, $fname, $type, $find_next) = @_;
136+
137+
if($find_next) {
138+
return [
139+
"MyCSS_DEBUG_MESSAGE(\"$fname\")"
140+
];
141+
}
142+
143+
[
144+
"MyCSS_DEBUG_MESSAGE(\"$fname\")",
145+
"result->parser = result->parser_switch;"
146+
];
147+
}
148+
149+
150+
151+

utils/MyCSS/begin.pl

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/perl -w
2+
3+
BEGIN {
4+
use FindBin;
5+
push @INC, $FindBin::Bin. "/../ext/";
6+
};
7+
8+
use bytes;
9+
use strict;
10+
use Encode;
11+
12+
use MyCSS::Grammar;
13+
use MyCSS::Token;
14+
use MyCSS::CFunction;
15+
16+
# !WARNING! Work! Draft version!
17+
18+
my $filename = "data/begin.txt";
19+
20+
my $token = MyCSS::Token->new();
21+
my $grammar = MyCSS::Grammar->new();
22+
my $cfunc = MyCSS::CFunction->new(
23+
token => $token,
24+
grammar => $grammar,
25+
func_def => \&function_default,
26+
func_else => \&function_else,
27+
func_last => \&function_last,
28+
func_prefix => "mycss_selectors_state_",
29+
func_whitespace => \&function_whitespace,
30+
func_string_before => \&function_string_before,
31+
func_string_after => \&function_string_after,
32+
);
33+
34+
my ($parse_res, $index_res) = $grammar->parser_file($filename);
35+
36+
sub function_whitespace {
37+
my ($creater, $cfunc, $exists_delim) = @_;
38+
39+
[
40+
"if(selectors->parser != mycss_parser_token_skip_whitespace)",
41+
"\t"."selectors->parser = mycss_parser_token_skip_whitespace;"
42+
];
43+
}
44+
45+
sub function_string_before {
46+
my ($creater, $cfunc, $exists_delim) = @_;
47+
48+
[
49+
"myhtml_string_t str;",
50+
"mycss_token_data_to_string(selectors->entry, token, &str);"
51+
];
52+
}
53+
54+
sub function_string_after {
55+
my ($creater, $cfunc, $exists_delim) = @_;
56+
57+
["myhtml_string_destroy(&str, false);"];
58+
}
59+
60+
sub function_default {
61+
my ($creater, $cfunc, $fname, $type) = @_;
62+
63+
["selectors->state = $fname;"];
64+
}
65+
66+
sub function_else {
67+
["selectors->state = mycss_selectors_state_simple_selector;"];
68+
}
69+
70+
sub function_last {
71+
my ($creater, $cfunc, $fname, $type) = @_;
72+
73+
[
74+
"printf(\"$fname\\n\"); /* End of selector */",
75+
"selectors->state = mycss_selectors_state_simple_selector;"
76+
];
77+
}
78+
79+
my $index_list = {};
80+
foreach my $key (@$index_res) {
81+
my $tree = $grammar->create_tree($parse_res->{$key}, $key);
82+
my $list = $grammar->parse_tree($tree);
83+
84+
$index_list->{$key} = $list;
85+
}
86+
87+
my $key = "<begin>";
88+
89+
my $workd = $grammar->decomposite($index_list, [$key]);
90+
$grammar->print_list($workd->{$key}, 1);
91+
92+
print "\n\n";
93+
94+
my $work = $grammar->decomposite($index_list, [$key], sub {
95+
return MyCSS::Token->new($_[1]);
96+
});
97+
98+
print "Work data for $key:\n";
99+
my $hash = $grammar->make_combine_hash_from_decomposing_list($work->{$key}, sub{ $_[1]->entry->name });
100+
print "Combine hash count: ", scalar(keys %$hash), "\n";
101+
102+
my $func_result = $cfunc->create($key, $hash);
103+
$cfunc->print_result_names($func_result);
104+
print "\n";
105+
$cfunc->print_result_data($func_result);
106+
107+

0 commit comments

Comments
 (0)