user
This task has been *revised* for the hosting change Rosetta Code has had in August 2022.

See the Python example for a new example to fit the revised task.

Task

Fix Rosetta Code deprecated code tags, with these rules:

```
Change <lang %s> to <syntaxhighlight lang=%s>
Change </lang> to </syntaxhighlight>
Change <lang> to <syntaxhighlight lang=text>

```

Demonstrate the task on these examples

```
<lang AutoHotkey>; usage: > fixtags.ahk input.txt ouput.txt
FileRead, text, %1%
langs = ada,awk,autohotkey,etc
slang = /lang
slang := "<" . slang . "/>"
Loop, Parse, langs, `,
{
  tag1 = <%A_LoopField%>
  tag2 = </%A_LoopField%>
  text := RegExReplace(text, tag1, "<lang " . A_LoopField . ">")
  text := RegExReplace(text, tag2, slang)
  text := RegExReplace(text, "<code (.+?)>(.*?)</code>"
          , "<lang $1>$2" . slang)
}
FileAppend, % text, %2%
</lang>

```

```
<lang perl>my @langs = qw(ada cpp-qt pascal lscript z80 visualprolog
html4strict cil objc asm progress teraterm hq9plus genero tsql
email pic16 tcl apt_sources io apache vhdl avisynth winbatch
vbnet ini scilab ocaml-brief sas actionscript3 qbasic perl bnf
cobol powershell php kixtart visualfoxpro mirc make javascript
cpp sdlbasic cadlisp php-brief rails verilog xml csharp
actionscript nsis bash typoscript freebasic dot applescript
haskell dos oracle8 cfdg glsl lotusscript mpasm latex sql klonec
ruby ocaml smarty python oracle11 caddcl robots groovy smalltalk
diff fortran cfm lua modula3 vb autoit java text scala
lotusformulas pixelbender reg _div whitespace providex asp css
lolcode lisp inno mysql plsql matlab oobas vim delphi xorg_conf
gml prolog bf per scheme mxml d basic4gl m68k gnuplot idl abap
intercal c_mac thinbasic java5 xpp boo klonecpp blitzbasic eiffel
povray c gettext);

my $text = join "", <STDIN>;
my $slang="/lang";
for (@langs) {
    $text =~ s|<$_>|<lang $_>|g;
    $text =~ s|</$_>|<$slang>|g;
}

$text =~ s|<code (.+?)>(.*?)</code>|<lang $1>$2<$slang>|sg;

print $text;</lang>

```

```
<lang>HAI 1.3

I HAS A bottles ITZ 99 I HAS A plural ITZ "Z" I HAS A lyric ITZ "99 BOTTLZ OV BEER"

IM IN YR song

   VISIBLE lyric " ON TEH WALL"
   VISIBLE lyric
   VISIBLE "TAEK 1 DOWN, PAZ IT AROUN"
   bottles R DIFF OF bottles AN 1
   NOT bottles, O RLY?
       YA RLY, VISIBLE "NO MOAR BOTTLZ OV BEER ON TEH WALL", GTFO
   OIC
   BOTH SAEM bottles AN 1, O RLY?
       YA RLY, plural R ""
   OIC
   lyric R SMOOSH bottles " BOTTL" plural " OV BEER" MKAY
   VISIBLE lyric " ON TEH WALL:)"
IM OUTTA YR song

KTHXBYE</lang>

```
assistant
(formerly Perl 6)

```
my @langs = <
    abap actionscript actionscript3 ada apache applescript apt_sources
    asm asp autoit avisynth bash basic4gl bf blitzbasic bnf boo c caddcl
    cadlisp cfdg cfm cil c_mac cobol cpp cpp-qt csharp css d delphi
    diff _div dos dot eiffel email fortran freebasic genero gettext
    glsl gml gnuplot groovy haskell hq9plus html4strict idl ini inno
    intercal io java java5 javascript kixtart klonec klonecpp latex lisp
    lolcode lotusformulas lotusscript lscript lua m68k make matlab mirc
    modula3 mpasm mxml mysql nsis objc ocaml ocaml-brief oobas oracle11
    oracle8 pascal per perl php php-brief pic16 pixelbender plsql povray
    powershell progress prolog providex python qbasic rails reg robots
    ruby sas scala scheme scilab sdlbasic smalltalk smarty sql tcl teraterm
    text thinbasic tsql typoscript vb vbnet verilog vhdl vim visualfoxpro
    visualprolog whitespace winbatch xml xorg_conf xpp z80
>;

$_ = slurp;

for @langs -> $l {
    s:g:i [ '<' 'lang '?  $l '>' ] = "<lang $l>";
    s:g [ '</' $l '>' ] = '</' ~ 'lang>';
}

s:g [ '<code '(.+?) '>' (.*?) '</code>' ] = "<lang $0>{$1}</"~"lang>";

.say;

```

```
use v6;

constant @langs = < abap actionscript actionscript3 ada  … >;

slurp().subst(
    rx:r{
        | '<' <( $<need-add-space>=<?> )> @langs '>'
        | '</' <( @langs )> '>'
        | '<' '/'? <( code )> [<.ws> @langs]? '>'
    },
    'lang' ~ " " x *<need-add-space>.so,
    :g,
).print

```