|
| 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 | + |
0 commit comments