Rosetta Code/Fix code tags: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup. still some issues with python) |
|||
Line 13: | Line 13: | ||
</pre> |
</pre> |
||
; |
;Demonstrate the task on these examples: |
||
<pre> |
<pre> |
||
<lang AutoHotkey>; usage: > fixtags.ahk input.txt ouput.txt |
<lang AutoHotkey>; usage: > fixtags.ahk input.txt ouput.txt |
||
Line 88: | Line 88: | ||
{{trans|Java}} |
{{trans|Java}} |
||
< |
<syntaxhighlight lang="11l">V languages = [‘abap’, ‘actionscript’, ‘actionscript3’, |
||
‘ada’, ‘apache’, ‘applescript’, ‘apt_sources’, ‘asm’, ‘asp’, |
‘ada’, ‘apache’, ‘applescript’, ‘apt_sources’, ‘asm’, ‘asp’, |
||
‘autoit’, ‘avisynth’, ‘bar’, ‘bash’, ‘basic4gl’, ‘bf’, |
‘autoit’, ‘avisynth’, ‘bar’, ‘bash’, ‘basic4gl’, ‘bf’, |
||
Line 124: | Line 124: | ||
text = text.replace(‘</code>’, ‘</’""‘lang>’) |
text = text.replace(‘</code>’, ‘</’""‘lang>’) |
||
print(text)</ |
print(text)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 137: | Line 137: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
< |
<syntaxhighlight lang="autohotkey">; usage: > fixtags.ahk input.txt ouput.txt |
||
FileRead, text, %1% |
FileRead, text, %1% |
||
langs = ada,awk,autohotkey,etc |
langs = ada,awk,autohotkey,etc |
||
Line 152: | Line 152: | ||
} |
} |
||
FileAppend, % text, %2% |
FileAppend, % text, %2% |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|D}}== |
=={{header|D}}== |
||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="d">import std.stdio, std.regex, std.string, std.array; |
||
immutable langs = "_div abap actionscript actionscript3 ada apache |
immutable langs = "_div abap actionscript actionscript3 ada apache |
||
Line 195: | Line 195: | ||
.fixTags |
.fixTags |
||
.writeln; |
.writeln; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>lorem ipsum <lang c>some c code</lang>dolor sit amet, <lang csharp>some csharp code</lang> consectetur adipisicing elit, <lang r> some r code </lang>sed do eiusmod tempor incididunt</pre> |
<pre>lorem ipsum <lang c>some c code</lang>dolor sit amet, <lang csharp>some csharp code</lang> consectetur adipisicing elit, <lang r> some r code </lang>sed do eiusmod tempor incididunt</pre> |
||
Line 204: | Line 204: | ||
{{libheader| System.RegularExpressions}} |
{{libheader| System.RegularExpressions}} |
||
{{Trans|Go}} |
{{Trans|Go}} |
||
<syntaxhighlight lang="delphi"> |
|||
<lang Delphi> |
|||
program Fix_code_tags; |
program Fix_code_tags; |
||
Line 322: | Line 322: | ||
begin |
begin |
||
Fix; |
Fix; |
||
end.</ |
end.</syntaxhighlight> |
||
=={{header|Erlang}}== |
=={{header|Erlang}}== |
||
Commented away are 3 lines that would create a dict of the existing languages on Rosetta Code. Since the examples have 3 imaginary code tags, I replaced that code this way. |
Commented away are 3 lines that would create a dict of the existing languages on Rosetta Code. Since the examples have 3 imaginary code tags, I replaced that code this way. |
||
<syntaxhighlight lang="erlang"> |
|||
<lang Erlang> |
|||
#! /usr/bin/env escript |
#! /usr/bin/env escript |
||
-module( fix_code_tags ). |
-module( fix_code_tags ). |
||
Line 365: | Line 365: | ||
loop( eof, Acc ) -> lists:reverse( Acc ); |
loop( eof, Acc ) -> lists:reverse( Acc ); |
||
loop( Line, Acc ) -> loop( io:get_line(""), [Line | Acc] ). |
loop( Line, Acc ) -> loop( io:get_line(""), [Line | Acc] ). |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 386: | Line 386: | ||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
While the ubiquitous loop over languages approach can be used, here we capture all tag variations to fix in one dotNet regex. |
While the ubiquitous loop over languages approach can be used, here we capture all tag variations to fix in one dotNet regex. |
||
< |
<syntaxhighlight lang="fsharp">open System |
||
open System.Text.RegularExpressions |
open System.Text.RegularExpressions |
||
Line 415: | Line 415: | ||
printfn "%s" (regexForOldLangSyntax.Replace(Console.In.ReadToEnd(), replaceEvaluator)) |
printfn "%s" (regexForOldLangSyntax.Replace(Console.In.ReadToEnd(), replaceEvaluator)) |
||
0</ |
0</syntaxhighlight> |
||
Output |
Output |
||
<pre>>Rosetta.exe |
<pre>>Rosetta.exe |
||
Line 425: | Line 425: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">package main |
||
import "fmt" |
import "fmt" |
||
Line 512: | Line 512: | ||
return in |
return in |
||
}</ |
}</syntaxhighlight> |
||
=={{header|J}}== |
=={{header|J}}== |
||
'''Solution:''' |
'''Solution:''' |
||
< |
<syntaxhighlight lang="j">require 'printf strings files' |
||
langs=. <;._1 LF -.~ noun define NB. replace with real lang strings |
langs=. <;._1 LF -.~ noun define NB. replace with real lang strings |
||
foo bar |
foo bar |
||
baz |
baz |
||
)</ |
)</syntaxhighlight> |
||
<pre>patterns=. noun define |
<pre>patterns=. noun define |
||
<%s>|<lang %s>| |
<%s>|<lang %s>| |
||
Line 528: | Line 528: | ||
</code>|</lang>| |
</code>|</lang>| |
||
)</pre> |
)</pre> |
||
< |
<syntaxhighlight lang="j">fixCodeTags=: rplc&(, <;._2;._2 &> patterns vbsprintf _5]\ 5#langs)</syntaxhighlight> |
||
'''Example Usage:''' |
'''Example Usage:''' |
||
Line 548: | Line 548: | ||
constituto id, mea an omittam fierent vituperatoribus.</pre> |
constituto id, mea an omittam fierent vituperatoribus.</pre> |
||
Reading/writing file: |
Reading/writing file: |
||
< |
<syntaxhighlight lang="j"> 'converted.txt' fwrite~ fixCodeTags fread 'wikisource.txt'</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
< |
<syntaxhighlight lang="java">import java.io.BufferedReader; |
||
import java.io.File; |
import java.io.File; |
||
import java.io.FileReader; |
import java.io.FileReader; |
||
Line 618: | Line 618: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
Example: |
Example: |
||
Line 643: | Line 643: | ||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
{{works with|SpiderMonkey}} |
{{works with|SpiderMonkey}} |
||
< |
<syntaxhighlight lang="javascript">var langs = ['foo', 'bar', 'baz']; // real list of langs goes here |
||
var end_tag = '</'+'lang>'; |
var end_tag = '</'+'lang>'; |
||
Line 653: | Line 653: | ||
.replace(new RegExp('</' + langs[i] + '>', 'gi'), end_tag); |
.replace(new RegExp('</' + langs[i] + '>', 'gi'), end_tag); |
||
print(line); |
print(line); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
Line 659: | Line 659: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="julia">function fixtags(text::AbstractString) |
||
langs = ["ada", "cpp-qt", "pascal", "lscript", "z80", "visualprolog", |
langs = ["ada", "cpp-qt", "pascal", "lscript", "z80", "visualprolog", |
||
"html4strict", "cil", "objc", "asm", "progress", "teraterm", "hq9plus", |
"html4strict", "cil", "objc", "asm", "progress", "teraterm", "hq9plus", |
||
Line 691: | Line 691: | ||
const txt = readstring(ARGS[1]) |
const txt = readstring(ARGS[1]) |
||
println(fixtags(txt))</ |
println(fixtags(txt))</syntaxhighlight> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
< |
<syntaxhighlight lang="lua"> |
||
--thanks, random python guy |
--thanks, random python guy |
||
langs = {'ada', 'cpp-qt', 'pascal', 'lscript', 'z80', 'visualprolog', |
langs = {'ada', 'cpp-qt', 'pascal', 'lscript', 'z80', 'visualprolog', |
||
Line 724: | Line 724: | ||
print(line) |
print(line) |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Maple}}== |
=={{header|Maple}}== |
||
< |
<syntaxhighlight lang="maple">#Used <#/lang> to desensitize wiki |
||
txt := FileTools[Text][ReadFile]("C:/Users/username/Desktop/text.txt"): |
txt := FileTools[Text][ReadFile]("C:/Users/username/Desktop/text.txt"): |
||
#langs should be a real list of programming languages |
#langs should be a real list of programming languages |
||
Line 737: | Line 737: | ||
txt := StringTools:-SubstituteAll(txt, "</code>", "<#/lang>"): |
txt := StringTools:-SubstituteAll(txt, "</code>", "<#/lang>"): |
||
end do; |
end do; |
||
print(txt);</ |
print(txt);</syntaxhighlight> |
||
{{Out|Output}} |
{{Out|Output}} |
||
<pre> |
<pre> |
||
Line 749: | Line 749: | ||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">StringReplace[Import["wikisource.txt"], |
||
{"</"~~Shortest[__]~~">"->"</lang>", |
{"</"~~Shortest[__]~~">"->"</lang>", |
||
("<code "|"<")~~Shortest[x__]~~">"->"<lang "~~ x~~">"} |
("<code "|"<")~~Shortest[x__]~~">"->"<lang "~~ x~~">"} |
||
]>>"converted.txt"</ |
]>>"converted.txt"</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Lorem ipsum<lang foo>saepe audire</lang>elaboraret ne quo,id equidem |
<pre>Lorem ipsum<lang foo>saepe audire</lang>elaboraret ne quo,id equidem |
||
Line 763: | Line 763: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="nim">import re, strutils |
||
const |
const |
||
Line 793: | Line 793: | ||
text = text.replacef(re"(?s)<code (.+?)>(.*?)</code>", r"<lang $1>$2</lang>") |
text = text.replacef(re"(?s)<code (.+?)>(.*?)</code>", r"<lang $1>$2</lang>") |
||
stdout.write text</ |
stdout.write text</syntaxhighlight> |
||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
< |
<syntaxhighlight lang="ocaml">#load "str.cma" |
||
let langs = |
let langs = |
||
Line 854: | Line 854: | ||
List.fold_left (fun str lang -> |
List.fold_left (fun str lang -> |
||
(repl4 lang (repl3 lang (repl2 lang (repl1 lang str)))) |
(repl4 lang (repl3 lang (repl2 lang (repl1 lang str)))) |
||
) (read_in stdin) langs)</ |
) (read_in stdin) langs)</syntaxhighlight> |
||
(in the code the strings <nowiki></lang></nowiki> have been split in order to not confuse the wiki) |
(in the code the strings <nowiki></lang></nowiki> have been split in order to not confuse the wiki) |
||
this line of code: |
this line of code: |
||
< |
<syntaxhighlight lang="ocaml"> (repl4 lang (repl3 lang (repl2 lang (repl1 lang str))))</syntaxhighlight> |
||
could also be written like this: |
could also be written like this: |
||
< |
<syntaxhighlight lang="ocaml"> List.fold_right (fun repl -> repl lang) [repl1; repl2; repl3; repl4] str</syntaxhighlight> |
||
Line 868: | Line 868: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
< |
<syntaxhighlight lang="perl">my @langs = qw(ada cpp-qt pascal lscript z80 visualprolog |
||
html4strict cil objc asm progress teraterm hq9plus genero tsql |
html4strict cil objc asm progress teraterm hq9plus genero tsql |
||
email pic16 tcl apt_sources io apache vhdl avisynth winbatch |
email pic16 tcl apt_sources io apache vhdl avisynth winbatch |
||
Line 893: | Line 893: | ||
$text =~ s|<code (.+?)>(.*?)</code>|<lang $1>$2<$slang>|sg; |
$text =~ s|<code (.+?)>(.*?)</code>|<lang $1>$2<$slang>|sg; |
||
print $text;</ |
print $text;</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{trans|D}} |
{{trans|D}} |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #008080;">constant</span> <span style="color: #000000;">ltext</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">`_div abap actionscript actionscript3 ada apache |
<span style="color: #008080;">constant</span> <span style="color: #000000;">ltext</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">`_div abap actionscript actionscript3 ada apache |
||
Line 936: | Line 936: | ||
"""</span> |
"""</span> |
||
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fix_tags</span><span style="color: #0000FF;">(</span><span style="color: #000000;">test</span><span style="color: #0000FF;">))</span> |
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fix_tags</span><span style="color: #0000FF;">(</span><span style="color: #000000;">test</span><span style="color: #0000FF;">))</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 945: | Line 945: | ||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
< |
<syntaxhighlight lang="lisp">#!/usr/bin/picolisp /usr/lib/picolisp/lib.l |
||
(let Lang '("ada" "awk" "c" "forth" "prolog" "python" "z80") |
(let Lang '("ada" "awk" "c" "forth" "prolog" "python" "z80") |
||
Line 958: | Line 958: | ||
(prin "</lang") ) |
(prin "</lang") ) |
||
(T (prin "<" S)) ) ) ) ) ) |
(T (prin "<" S)) ) ) ) ) ) |
||
(bye)</ |
(bye)</syntaxhighlight> |
||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
< |
<syntaxhighlight lang="basic">If Not OpenConsole() |
||
End |
End |
||
ElseIf CountProgramParameters() <> 2 |
ElseIf CountProgramParameters() <> 2 |
||
Line 1,000: | Line 1,000: | ||
CloseFile(1) |
CloseFile(1) |
||
EndIf |
EndIf |
||
EndIf</ |
EndIf</syntaxhighlight> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
Line 1,081: | Line 1,081: | ||
print(txt, '\n=>\n', text2) |
print(txt, '\n=>\n', text2) |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
<lang AutoHotkey>; usage: > fixtags.ahk input.txt ouput.txt |
<lang AutoHotkey>; usage: > fixtags.ahk input.txt ouput.txt |
||
Line 1,143: | Line 1,143: | ||
print $text;</lang> |
print $text;</lang> |
||
=> |
=> |
||
<syntaxhighlight lang=perl>my @langs = qw(ada cpp-qt pascal lscript z80 visualprolog |
<syntaxhighlight lang="perl">my @langs = qw(ada cpp-qt pascal lscript z80 visualprolog |
||
html4strict cil objc asm progress teraterm hq9plus genero tsql |
html4strict cil objc asm progress teraterm hq9plus genero tsql |
||
email pic16 tcl apt_sources io apache vhdl avisynth winbatch |
email pic16 tcl apt_sources io apache vhdl avisynth winbatch |
||
Line 1,192: | Line 1,192: | ||
=> |
=> |
||
<syntaxhighlight lang=text>HAI 1.3 |
<syntaxhighlight lang="text">HAI 1.3 |
||
I HAS A bottles ITZ 99 I HAS A plural ITZ "Z" I HAS A lyric ITZ "99 BOTTLZ OV BEER" |
I HAS A bottles ITZ 99 I HAS A plural ITZ "Z" I HAS A lyric ITZ "99 BOTTLZ OV BEER" |
||
Line 1,217: | Line 1,217: | ||
=={{header|R}}== |
=={{header|R}}== |
||
Note that the instances of ##### are to stop the wiki getting confused. Please remove them before running the code. |
Note that the instances of ##### are to stop the wiki getting confused. Please remove them before running the code. |
||
<syntaxhighlight lang="r"> |
|||
<lang R> |
|||
fixtags <- function(page) |
fixtags <- function(page) |
||
{ |
{ |
||
Line 1,232: | Line 1,232: | ||
consectetur adipisicing elit,<code r>some r code</code>sed do eiusmod tempor incididunt" |
consectetur adipisicing elit,<code r>some r code</code>sed do eiusmod tempor incididunt" |
||
fixtags(page) |
fixtags(page) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang="racket"> |
||
#lang racket |
#lang racket |
||
Line 1,257: | Line 1,257: | ||
[else all])) |
[else all])) |
||
(loop))) |
(loop))) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
Line 1,302: | Line 1,302: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
< |
<syntaxhighlight lang="rexx">/*REXX program fixes (changes) depreciated HTML code tags with newer tags. */ |
||
@="<"; old.=; old.1 = @'%s>' ; new.1 = @"lang %s>" |
@="<"; old.=; old.1 = @'%s>' ; new.1 = @"lang %s>" |
||
old.2 = @'/%s>' ; new.2 = @"/lang>" |
old.2 = @'/%s>' ; new.2 = @"/lang>" |
||
Line 1,317: | Line 1,317: | ||
end /*j*/ |
end /*j*/ |
||
call lineout oFID,$ /*write re-formatted record to output. */ |
call lineout oFID,$ /*write re-formatted record to output. */ |
||
end /*while*/ /*stick a fork in it, we're all done. */</ |
end /*while*/ /*stick a fork in it, we're all done. */</syntaxhighlight> |
||
Some older REXXes don't have a '''changestr''' BIF, so one is included here ───► [[CHANGESTR.REX]]. |
Some older REXXes don't have a '''changestr''' BIF, so one is included here ───► [[CHANGESTR.REX]]. |
||
<br><br> |
<br><br> |
||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<syntaxhighlight lang="ruby"># get all stdin in one string |
||
#text = $stdin.read |
#text = $stdin.read |
||
# for testing, use |
# for testing, use |
||
Line 1,342: | Line 1,342: | ||
altera electram. Tota adhuc altera te sea, <code bar>soluta appetere ut mel</bar>. |
altera electram. Tota adhuc altera te sea, <code bar>soluta appetere ut mel</bar>. |
||
Quo quis graecis vivendo te, <baz>posse nullam lobortis ex usu</code>. Eam volumus perpetua |
Quo quis graecis vivendo te, <baz>posse nullam lobortis ex usu</code>. Eam volumus perpetua |
||
constituto id, mea an omittam fierent vituperatoribus. </ |
constituto id, mea an omittam fierent vituperatoribus. </syntaxhighlight> |
||
<pre>Lorem ipsum <lang foo>saepe audire</lang> elaboraret ne quo, id equidem |
<pre>Lorem ipsum <lang foo>saepe audire</lang> elaboraret ne quo, id equidem |
||
Line 1,352: | Line 1,352: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
< |
<syntaxhighlight lang="rust"> |
||
extern crate regex; |
extern crate regex; |
||
Line 1,400: | Line 1,400: | ||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
Line 1,407: | Line 1,407: | ||
{{Out}} |
{{Out}} |
||
Experience it running in your browser at [https://scastie.scala-lang.org/5U6vqsOaTi6AU5FcqfA2lA Scastie (remote JVM)]. |
Experience it running in your browser at [https://scastie.scala-lang.org/5U6vqsOaTi6AU5FcqfA2lA Scastie (remote JVM)]. |
||
< |
<syntaxhighlight lang="scala">object FixCodeTags extends App { |
||
val rx = // See for regex explanation: https://regex101.com/r/N8X4x7/3/ |
val rx = // See for regex explanation: https://regex101.com/r/N8X4x7/3/ |
||
// Flags ignore case, dot matching line breaks, unicode support |
// Flags ignore case, dot matching line breaks, unicode support |
||
Line 1,428: | Line 1,428: | ||
})) // ${"/lan"}g is the <noWiki> escape. |
})) // ${"/lan"}g is the <noWiki> escape. |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<syntaxhighlight lang="ruby">var langs = %w(ada cpp-qt pascal lscript z80 visualprolog |
||
html4strict cil objc asm progress teraterm hq9plus genero tsql |
html4strict cil objc asm progress teraterm hq9plus genero tsql |
||
email pic16 tcl apt_sources io apache vhdl avisynth winbatch |
email pic16 tcl apt_sources io apache vhdl avisynth winbatch |
||
Line 1,456: | Line 1,456: | ||
); |
); |
||
print text;</ |
print text;</syntaxhighlight> |
||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
< |
<syntaxhighlight lang="tcl">set langs { |
||
ada cpp-qt pascal lscript z80 visualprolog html4strict cil objc asm progress teraterm |
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 |
hq9plus genero tsql email pic16 tcl apt_sources io apache vhdl avisynth winbatch vbnet |
||
Line 1,490: | Line 1,490: | ||
lappend replacements "<code $lang>" "<lang $lang>" |
lappend replacements "<code $lang>" "<lang $lang>" |
||
} |
} |
||
set text [string map $replacements $text]</ |
set text [string map $replacements $text]</syntaxhighlight> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|Wren-pattern}} |
{{libheader|Wren-pattern}} |
||
< |
<syntaxhighlight lang="ecmascript">import "./pattern" for Pattern |
||
var source = """ |
var source = """ |
||
Line 1,525: | Line 1,525: | ||
} |
} |
||
System.print(source)</ |
System.print(source)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,538: | Line 1,538: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
< |
<syntaxhighlight lang="zkl">fcn replace(data,src,dstpat){ |
||
re,n,buf:=RegExp(src),0,Data(); |
re,n,buf:=RegExp(src),0,Data(); |
||
while(re.search(data,True,n)){ |
while(re.search(data,True,n)){ |
||
Line 1,552: | Line 1,552: | ||
replace(data,src,dst) |
replace(data,src,dst) |
||
} |
} |
||
print(data.text);</ |
print(data.text);</syntaxhighlight> |
||
Note: the "</" "lang>" to keep /lang the wiki from getting confused (it is string concatenation). |
Note: the "</" "lang>" to keep /lang the wiki from getting confused (it is string concatenation). |
||
{{out}} |
{{out}} |