#!/usr/bin/perl # This perl script read stdin and write on stdout. It shall be an XML language file. # # * If the name of the language is 'HTML', then it creates the language 'PHP (HTML)' # which shall be used for PHP hl. # # * If the name of the language is something else (say '*'), it creates the language '*/PHP'. # This new language is the same as the old one, but is able to detect PHP everywhere. # # This script will correctly set extensions & mimetype, and will replace # by # # Generated languages need a language named 'PHP/PHP', which shall take care of PHP hl itself # and which will be called every time something like # License: LGPL my $file = ""; open(my $input, '<:encoding(UTF-8)', $ARGV[0]) or die "Could not open file '$ARGV[0]': $!"; open(my $output, '>:encoding(UTF-8)', $ARGV[1]) or die "Could not open file '$ARGV[1]': $!"; my $language = $ARGV[1]; if ($language =~ /-php\.xml$/) { $language = "PHP"; } else { $language = "Twig"; } while (<$input>) { $file .= $_; } $warning = "\n\n\n"; $file =~ s/(?=]+)priority="[^"]*"/]+)name="[^"]*"/]+)section="[^"]*"/]+)extensions="[^"]*"/]+)mimetype="[^"]*"/]+)*/]+)extensions="[^"]*"/]+)mimetype="[^"]*"/]+)hidden="[^"]*"/]+)section="[^"]*"/]+)mimetype="[^"]*"/]+)name="([^"]*)"/]+)extensions="[^"]*"/.*?<\/list>/$1##$syntaxName<\/include><\/list>/gs; $file =~ s/]+)kateversion="[^"]*"///gs; } } elsif ($root == 1 || $ARGV[0] =~ /mustache.xml$/) { $file =~ s/<(?:RegExpr (attribute="Processing Instruction" context="PI"|context="PI" attribute="Processing Instruction")|itemData name="Processing Instruction")[^\/]+\/>|//gs; } my $find_language = "##$language/$language"; my $language_suffix = "/$language"; if ($language eq "PHP") { $find_language = "FindPHP"; } $file =~ s/]*)context="([^"#]*)##(?!Alerts|Comments|Doxygen|Modelines)([^"]+)"/]*[^>\/]>)/$1\n/g; $file =~ s/(]*[^>\/])\s*\/>/$1>\n\n<\/context>/g; if ($language eq "PHP") { $findphp = "\n\n\n"; $file =~ s/(?=<\/contexts\s*>)/$findphp/; } print $output $file; print $output $warning;