| 1 |
# Copyright 2022 Jeffrey Kegler |
| 2 |
# This file is part of Marpa::R2. Marpa::R2 is free software: you can |
| 3 |
# redistribute it and/or modify it under the terms of the GNU Lesser |
| 4 |
# General Public License as published by the Free Software Foundation, |
| 5 |
# either version 3 of the License, or (at your option) any later version. |
| 6 |
# |
| 7 |
# Marpa::R2 is distributed in the hope that it will be useful, |
| 8 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 10 |
# Lesser General Public License for more details. |
| 11 |
# |
| 12 |
# You should have received a copy of the GNU Lesser |
| 13 |
# General Public License along with Marpa::R2. If not, see |
| 14 |
# http://www.gnu.org/licenses/. |
| 15 |
|
| 16 |
package Marpa::R2::HTML::Config; |
| 17 |
|
| 18 |
use 5.010001; |
| 19 |
use strict; |
| 20 |
use warnings; |
| 21 |
|
| 22 |
use vars qw($VERSION $STRING_VERSION); |
| 23 |
$VERSION = '14.000000'; |
| 24 |
$STRING_VERSION = $VERSION; |
| 25 |
## no critic(BuiltinFunctions::ProhibitStringyEval) |
| 26 |
$VERSION = eval $VERSION; |
| 27 |
## use critic |
| 28 |
|
| 29 |
use English qw( -no_match_vars ); |
| 30 |
|
| 31 |
# Generate the default configuration |
| 32 |
sub new { |
| 33 |
my ($class) = @_; |
| 34 |
require Marpa::R2::HTML::Config::Default; |
| 35 |
my $self = { |
| 36 |
rules => $Marpa::R2::HTML::Internal::Config::Default::CORE_RULES, |
| 37 |
runtime_tag => |
| 38 |
$Marpa::R2::HTML::Internal::Config::Default::RUNTIME_TAG, |
| 39 |
ruby_slippers_rank_by_name => |
| 40 |
$Marpa::R2::HTML::Internal::Config::Default::RUBY_SLIPPERS_RANK_BY_NAME, |
| 41 |
is_empty_element => |
| 42 |
$Marpa::R2::HTML::Internal::Config::Default::IS_EMPTY_ELEMENT, |
| 43 |
primary_group_by_tag => |
| 44 |
$Marpa::R2::HTML::Internal::Config::Default::PRIMARY_GROUP_BY_TAG |
| 45 |
}; |
| 46 |
return bless $self, $class; |
| 47 |
} ## end sub new |
| 48 |
|
| 49 |
sub new_from_compile { |
| 50 |
my ( $class, $source_ref ) = @_; |
| 51 |
require Marpa::R2::HTML::Config::Compile; |
| 52 |
return bless Marpa::R2::HTML::Config::Compile::compile($source_ref), $class; |
| 53 |
} ## end sub new_from_compile |
| 54 |
|
| 55 |
sub contents { |
| 56 |
my ($self) = @_; |
| 57 |
return @{$self}{ |
| 58 |
qw( rules runtime_tag |
| 59 |
ruby_slippers_rank_by_name is_empty_element |
| 60 |
primary_group_by_tag |
| 61 |
) |
| 62 |
}; |
| 63 |
} ## end sub contents |
| 64 |
|
| 65 |
my $legal_preamble = <<'END_OF_TEXT'; |
| 66 |
# Copyright 2022 Jeffrey Kegler |
| 67 |
# This file is part of Marpa::R2. Marpa::R2 is free software: you can |
| 68 |
# redistribute it and/or modify it under the terms of the GNU Lesser |
| 69 |
# General Public License as published by the Free Software Foundation, |
| 70 |
# either version 3 of the License, or (at your option) any later version. |
| 71 |
# |
| 72 |
# Marpa::R2 is distributed in the hope that it will be useful, |
| 73 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 74 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 75 |
# Lesser General Public License for more details. |
| 76 |
# |
| 77 |
# You should have received a copy of the GNU Lesser |
| 78 |
# General Public License along with Marpa::R2. If not, see |
| 79 |
# http://www.gnu.org/licenses/. |
| 80 |
|
| 81 |
END_OF_TEXT |
| 82 |
|
| 83 |
sub sort_bnf { |
| 84 |
my $cmp = $a->{lhs} cmp $b->{lhs}; |
| 85 |
return $cmp if $cmp; |
| 86 |
my $a_rhs_length = scalar @{ $a->{rhs} }; |
| 87 |
my $b_rhs_length = scalar @{ $b->{rhs} }; |
| 88 |
$cmp = $a_rhs_length <=> $b_rhs_length; |
| 89 |
return $cmp if $cmp; |
| 90 |
for my $ix ( 0 .. $a_rhs_length ) { |
| 91 |
$cmp = $a->{rhs}->[$ix] cmp $b->{rhs}->[$ix]; |
| 92 |
return $cmp if $cmp; |
| 93 |
} |
| 94 |
return 0; |
| 95 |
} ## end sub sort_bnf |
| 96 |
|
| 97 |
sub as_string { |
| 98 |
my ($self) = @_; |
| 99 |
|
| 100 |
require Data::Dumper; |
| 101 |
require Marpa::R2::HTML::Config::Default; |
| 102 |
|
| 103 |
local $Data::Dumper::Purity = 1; |
| 104 |
local $Data::Dumper::Sortkeys = 1; |
| 105 |
my @contents = $self->contents(); |
| 106 |
my @rules = sort sort_bnf @{$contents[0]}; |
| 107 |
$contents[0] = \@rules; |
| 108 |
|
| 109 |
# Start with the legal language |
| 110 |
return \( |
| 111 |
$legal_preamble |
| 112 |
. '# This file was generated automatically by ' |
| 113 |
. __PACKAGE__ . "\n" |
| 114 |
. '# The date of generation was ' |
| 115 |
. ( scalar localtime() ) . "\n" . "\n" |
| 116 |
. "package Marpa::R2::HTML::Internal::Config::Default;\n" . "\n" |
| 117 |
. Data::Dumper->Dump( |
| 118 |
\@contents, |
| 119 |
[ qw( CORE_RULES RUNTIME_TAG |
| 120 |
RUBY_SLIPPERS_RANK_BY_NAME IS_EMPTY_ELEMENT |
| 121 |
PRIMARY_GROUP_BY_TAG |
| 122 |
) |
| 123 |
] |
| 124 |
) |
| 125 |
); |
| 126 |
|
| 127 |
} ## end sub as_string |
| 128 |
|
| 129 |
1; |
| 130 |
|
| 131 |
# vim: set expandtab shiftwidth=4: |